Changeset 5464
- Timestamp:
- 04/02/08 14:03:42 (4 months ago)
- Files:
-
- framework3/trunk/lib/rex/proto/sunrpc/client.rb (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
framework3/trunk/lib/rex/proto/sunrpc/client.rb
r3562 r5464 5 5 module Proto 6 6 module SunRPC 7 8 class RPCTimeout < ::Interrupt 9 def initialize(msg = 'Operation timed out.') 10 @msg = msg 11 end 12 13 def to_s 14 @msg 15 end 16 end 7 17 8 18 # XXX: CPORT! … … 32 42 def initialize(rhost, rport, proto, program, version) 33 43 if proto.downcase !~ /^(tcp|udp)$/ 34 raise ArgumentError, 'Protocol is not "tcp" or "udp"'44 raise ::Rex::ArgumentError, 'Protocol is not "tcp" or "udp"' 35 45 end 36 46 … … 63 73 send_rpc(sock, buf) 64 74 ret = recv_rpc(sock) 75 raise ::Rex::RuntimeError, "No response to SunRPC PortMap request" if ! ret 65 76 close_rpc(sock) 66 77 … … 69 80 if arr[1] != MSG_ACCEPTED || arr[4] != SUCCESS || arr[5] == 0 70 81 # Check PRO[CG]_*/GARBAGE_ARGS 71 raise RuntimeError, 'create failed' 82 err = "SunRPC PortMap request to #{@rhost}:#{rport} failed: " 83 err << 'Message not accepted' if arr[1] != MSG_ACCEPTED 84 err << 'RPC did not execute' if arr[4] != SUCCESS 85 err << 'Program not available' if arr[5] == 0 86 raise ::Rex::RuntimeError, err 72 87 end 73 88 74 89 @pport = arr[5] 75 90 end 76 91 77 92 def call(procedure, buffer) 78 93 buf = … … 87 102 send_rpc(@call_sock, buf) 88 103 ret = recv_rpc(@call_sock) 89 90 arr = Rex::Encoder::XDR.decode!(ret, Integer, Integer, Integer, String, Integer) 91 if arr[1] != MSG_ACCEPTED || arr[4] != SUCCESS 92 raise 'call failed' 104 105 if ret 106 arr = Rex::Encoder::XDR.decode!(ret, Integer, Integer, Integer, String, Integer) 107 if arr[1] != MSG_ACCEPTED || arr[4] != SUCCESS 108 err = "SunRPC call for program #{program}, procedure #{procedure}, failed: " 109 case arr[4] 110 when PROG_UMAVAIL then err << "Program Unavailable" 111 when PROG_MISMATCH then err << "Program Version Mismatch" 112 when PROC_UNAVAIL then err << "Procedure Unavailable" 113 when GARBAGE_ARGS then err << "Garbage Arguments" 114 else err << "Unknown Error" 115 end 116 raise ::Rex::RuntimeError, err 117 end 118 else 119 raise RPCTimeout, "No response to SunRPC call for procedure #{procedure}" 93 120 end 94 121 … … 101 128 end 102 129 103 104 130 def authnull_create 105 131 @auth_type = AUTH_NULL … … 108 134 109 135 def authunix_create(host, uid, gid, groupz) 110 raise ArgumentError, 'Hostname length is too long' if host.length > 255136 raise ::Rex::ArgumentError, 'Hostname length is too long' if host.length > 255 111 137 # 10? 112 raise ArgumentError, 'Too many groups' if groupz.length > 10138 raise ::Rex::ArgumentError, 'Too many groups' if groupz.length > 10 113 139 114 140 @auth_type = AUTH_UNIX … … 116 142 Rex::Encoder::XDR.encode(0, host, uid, gid, groupz) # XXX: TIME! GROUPZ?! 117 143 end 118 119 144 120 145 # XXX: Dirty, integrate some sort of request system into create/call? … … 126 151 send_rpc(sock, buf) 127 152 ret = recv_rpc(sock) 153 raise ::Rex::RuntimeError, "No response to SunRPC request" if ! ret 128 154 close_rpc(sock) 129 155 130 156 arr = Rex::Encoder::XDR.decode!(ret, Integer, Integer, Integer, String, Integer) 131 157 if arr[1] != MSG_ACCEPTED || arr[4] != SUCCESS || arr[5] == 0 132 raise 'portmap_req failed' 158 err = "SunRPC call for program #{program}, procedure #{procedure}, failed: " 159 case arr[4] 160 when PROG_UMAVAIL then err << "Program Unavailable" 161 when PROG_MISMATCH then err << "Program Version Mismatch" 162 when PROC_UNAVAIL then err << "Procedure Unavailable" 163 when GARBAGE_ARGS then err << "Garbage Arguments" 164 else err << "Unknown Error" 165 end 166 raise ::Rex::RuntimeError, err 133 167 end 134 168 … … 188 222 189 223 def recv_rpc(sock) 190 buf = sock.get( 5)224 buf = sock.get(60) # 5 secs was WAY too slow for some RPC calls 191 225 buf.slice!(0..3) 192 226 if sock.type?.eql?('tcp') 193 227 buf.slice!(0..3) 194 228 end 195 return buf 229 return buf if buf.length > 1 230 return nil 196 231 end 197 232
