The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 |
| 3 | * The Regents of the University of California. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that: (1) source code distributions |
| 7 | * retain the above copyright notice and this paragraph in its entirety, (2) |
| 8 | * distributions including binary code include the above copyright notice and |
| 9 | * this paragraph in its entirety in the documentation or other materials |
| 10 | * provided with the distribution, and (3) all advertising materials mentioning |
| 11 | * features or use of this software display the following acknowledgement: |
| 12 | * ``This product includes software developed by the University of California, |
| 13 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of |
| 14 | * the University nor the names of its contributors may be used to endorse |
| 15 | * or promote products derived from this software without specific prior |
| 16 | * written permission. |
| 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 20 | */ |
| 21 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 22 | /* \summary: Sun Remote Procedure Call printer */ |
| 23 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 24 | #ifdef HAVE_CONFIG_H |
| 25 | #include "config.h" |
| 26 | #endif |
| 27 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 28 | /* |
| 29 | * At least on HP-UX: |
| 30 | * |
| 31 | * 1) getrpcbynumber() is declared in <netdb.h>, not any of the RPC |
| 32 | * header files |
| 33 | * |
| 34 | * and |
| 35 | * |
| 36 | * 2) if _XOPEN_SOURCE_EXTENDED is defined, <netdb.h> doesn't declare |
| 37 | * it |
| 38 | * |
| 39 | * so we undefine it. |
| 40 | */ |
| 41 | #undef _XOPEN_SOURCE_EXTENDED |
| 42 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 43 | #include <netdissect-stdinc.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 44 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 45 | #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 46 | #include <rpc/rpc.h> |
| 47 | #ifdef HAVE_RPC_RPCENT_H |
| 48 | #include <rpc/rpcent.h> |
| 49 | #endif /* HAVE_RPC_RPCENT_H */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 50 | #endif /* defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H) */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 51 | |
| 52 | #include <stdio.h> |
| 53 | #include <string.h> |
| 54 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 55 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 56 | #include "addrtoname.h" |
| 57 | #include "extract.h" |
| 58 | |
| 59 | #include "ip.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 60 | #include "ip6.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 61 | |
| 62 | #include "rpc_auth.h" |
| 63 | #include "rpc_msg.h" |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for |
| 67 | * unrestricted use provided that this legend is included on all tape |
| 68 | * media and as a part of the software program in whole or part. Users |
| 69 | * may copy or modify Sun RPC without charge, but are not authorized |
| 70 | * to license or distribute it to anyone else except as part of a product or |
| 71 | * program developed by the user. |
| 72 | * |
| 73 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE |
| 74 | * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 75 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. |
| 76 | * |
| 77 | * Sun RPC is provided with no support and without any obligation on the |
| 78 | * part of Sun Microsystems, Inc. to assist in its use, correction, |
| 79 | * modification or enhancement. |
| 80 | * |
| 81 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE |
| 82 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC |
| 83 | * OR ANY PART THEREOF. |
| 84 | * |
| 85 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue |
| 86 | * or profits or other special, indirect and consequential damages, even if |
| 87 | * Sun has been advised of the possibility of such damages. |
| 88 | * |
| 89 | * Sun Microsystems, Inc. |
| 90 | * 2550 Garcia Avenue |
| 91 | * Mountain View, California 94043 |
| 92 | * |
| 93 | * from: @(#)pmap_prot.h 1.14 88/02/08 SMI |
| 94 | * from: @(#)pmap_prot.h 2.1 88/07/29 4.0 RPCSRC |
| 95 | * $FreeBSD: src/include/rpc/pmap_prot.h,v 1.9.2.1 1999/08/29 14:39:05 peter Exp $ |
| 96 | */ |
| 97 | |
| 98 | /* |
| 99 | * pmap_prot.h |
| 100 | * Protocol for the local binder service, or pmap. |
| 101 | * |
| 102 | * Copyright (C) 1984, Sun Microsystems, Inc. |
| 103 | * |
| 104 | * The following procedures are supported by the protocol: |
| 105 | * |
| 106 | * PMAPPROC_NULL() returns () |
| 107 | * takes nothing, returns nothing |
| 108 | * |
| 109 | * PMAPPROC_SET(struct pmap) returns (bool_t) |
| 110 | * TRUE is success, FALSE is failure. Registers the tuple |
| 111 | * [prog, vers, prot, port]. |
| 112 | * |
| 113 | * PMAPPROC_UNSET(struct pmap) returns (bool_t) |
| 114 | * TRUE is success, FALSE is failure. Un-registers pair |
| 115 | * [prog, vers]. prot and port are ignored. |
| 116 | * |
| 117 | * PMAPPROC_GETPORT(struct pmap) returns (long unsigned). |
| 118 | * 0 is failure. Otherwise returns the port number where the pair |
| 119 | * [prog, vers] is registered. It may lie! |
| 120 | * |
| 121 | * PMAPPROC_DUMP() RETURNS (struct pmaplist *) |
| 122 | * |
| 123 | * PMAPPROC_CALLIT(unsigned, unsigned, unsigned, string<>) |
| 124 | * RETURNS (port, string<>); |
| 125 | * usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc, encapsulatedargs); |
| 126 | * Calls the procedure on the local machine. If it is not registered, |
| 127 | * this procedure is quite; ie it does not return error information!!! |
| 128 | * This procedure only is supported on rpc/udp and calls via |
| 129 | * rpc/udp. This routine only passes null authentication parameters. |
| 130 | * This file has no interface to xdr routines for PMAPPROC_CALLIT. |
| 131 | * |
| 132 | * The service supports remote procedure calls on udp/ip or tcp/ip socket 111. |
| 133 | */ |
| 134 | |
| 135 | #define SUNRPC_PMAPPORT ((uint16_t)111) |
| 136 | #define SUNRPC_PMAPPROG ((uint32_t)100000) |
| 137 | #define SUNRPC_PMAPVERS ((uint32_t)2) |
| 138 | #define SUNRPC_PMAPVERS_PROTO ((uint32_t)2) |
| 139 | #define SUNRPC_PMAPVERS_ORIG ((uint32_t)1) |
| 140 | #define SUNRPC_PMAPPROC_NULL ((uint32_t)0) |
| 141 | #define SUNRPC_PMAPPROC_SET ((uint32_t)1) |
| 142 | #define SUNRPC_PMAPPROC_UNSET ((uint32_t)2) |
| 143 | #define SUNRPC_PMAPPROC_GETPORT ((uint32_t)3) |
| 144 | #define SUNRPC_PMAPPROC_DUMP ((uint32_t)4) |
| 145 | #define SUNRPC_PMAPPROC_CALLIT ((uint32_t)5) |
| 146 | |
| 147 | struct sunrpc_pmap { |
| 148 | uint32_t pm_prog; |
| 149 | uint32_t pm_vers; |
| 150 | uint32_t pm_prot; |
| 151 | uint32_t pm_port; |
| 152 | }; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 153 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 154 | static const struct tok proc2str[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 155 | { SUNRPC_PMAPPROC_NULL, "null" }, |
| 156 | { SUNRPC_PMAPPROC_SET, "set" }, |
| 157 | { SUNRPC_PMAPPROC_UNSET, "unset" }, |
| 158 | { SUNRPC_PMAPPROC_GETPORT, "getport" }, |
| 159 | { SUNRPC_PMAPPROC_DUMP, "dump" }, |
| 160 | { SUNRPC_PMAPPROC_CALLIT, "call" }, |
| 161 | { 0, NULL } |
| 162 | }; |
| 163 | |
| 164 | /* Forwards */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 165 | static char *progstr(uint32_t); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 166 | |
| 167 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 168 | sunrpcrequest_print(netdissect_options *ndo, register const u_char *bp, |
| 169 | register u_int length, register const u_char *bp2) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 170 | { |
| 171 | register const struct sunrpc_msg *rp; |
| 172 | register const struct ip *ip; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 173 | register const struct ip6_hdr *ip6; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 174 | uint32_t x; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 175 | char srcid[20], dstid[20]; /*fits 32bit*/ |
| 176 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 177 | rp = (const struct sunrpc_msg *)bp; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 178 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 179 | if (!ndo->ndo_nflag) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 180 | snprintf(srcid, sizeof(srcid), "0x%x", |
| 181 | EXTRACT_32BITS(&rp->rm_xid)); |
| 182 | strlcpy(dstid, "sunrpc", sizeof(dstid)); |
| 183 | } else { |
| 184 | snprintf(srcid, sizeof(srcid), "0x%x", |
| 185 | EXTRACT_32BITS(&rp->rm_xid)); |
| 186 | snprintf(dstid, sizeof(dstid), "0x%x", SUNRPC_PMAPPORT); |
| 187 | } |
| 188 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 189 | switch (IP_V((const struct ip *)bp2)) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 190 | case 4: |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 191 | ip = (const struct ip *)bp2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 192 | ND_PRINT((ndo, "%s.%s > %s.%s: %d", |
| 193 | ipaddr_string(ndo, &ip->ip_src), srcid, |
| 194 | ipaddr_string(ndo, &ip->ip_dst), dstid, length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 195 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 196 | case 6: |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 197 | ip6 = (const struct ip6_hdr *)bp2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 198 | ND_PRINT((ndo, "%s.%s > %s.%s: %d", |
| 199 | ip6addr_string(ndo, &ip6->ip6_src), srcid, |
| 200 | ip6addr_string(ndo, &ip6->ip6_dst), dstid, length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 201 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 202 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 203 | ND_PRINT((ndo, "%s.%s > %s.%s: %d", "?", srcid, "?", dstid, length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 204 | break; |
| 205 | } |
| 206 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 207 | ND_PRINT((ndo, " %s", tok2str(proc2str, " proc #%u", |
| 208 | EXTRACT_32BITS(&rp->rm_call.cb_proc)))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 209 | x = EXTRACT_32BITS(&rp->rm_call.cb_rpcvers); |
| 210 | if (x != 2) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 211 | ND_PRINT((ndo, " [rpcver %u]", x)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 212 | |
| 213 | switch (EXTRACT_32BITS(&rp->rm_call.cb_proc)) { |
| 214 | |
| 215 | case SUNRPC_PMAPPROC_SET: |
| 216 | case SUNRPC_PMAPPROC_UNSET: |
| 217 | case SUNRPC_PMAPPROC_GETPORT: |
| 218 | case SUNRPC_PMAPPROC_CALLIT: |
| 219 | x = EXTRACT_32BITS(&rp->rm_call.cb_prog); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 220 | if (!ndo->ndo_nflag) |
| 221 | ND_PRINT((ndo, " %s", progstr(x))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 222 | else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 223 | ND_PRINT((ndo, " %u", x)); |
| 224 | ND_PRINT((ndo, ".%u", EXTRACT_32BITS(&rp->rm_call.cb_vers))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 225 | break; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | static char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 230 | progstr(uint32_t prog) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 231 | { |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 232 | #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 233 | register struct rpcent *rp; |
| 234 | #endif |
| 235 | static char buf[32]; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 236 | static uint32_t lastprog = 0; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 237 | |
| 238 | if (lastprog != 0 && prog == lastprog) |
| 239 | return (buf); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 240 | #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 241 | rp = getrpcbynumber(prog); |
| 242 | if (rp == NULL) |
| 243 | #endif |
| 244 | (void) snprintf(buf, sizeof(buf), "#%u", prog); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 245 | #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 246 | else |
| 247 | strlcpy(buf, rp->r_name, sizeof(buf)); |
| 248 | #endif |
| 249 | return (buf); |
| 250 | } |