showmount.c (146466) | showmount.c (194880) |
---|---|
1/* 2 * Copyright (c) 1989, 1993, 1995 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Rick Macklem at The University of Guelph. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 31 unchanged lines hidden (view full) --- 40 The Regents of the University of California. All rights reserved.\n"; 41#endif /* not lint */ 42 43#ifndef lint 44#if 0 45static char sccsid[] = "@(#)showmount.c 8.3 (Berkeley) 3/29/95"; 46#endif 47static const char rcsid[] = | 1/* 2 * Copyright (c) 1989, 1993, 1995 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Rick Macklem at The University of Guelph. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 31 unchanged lines hidden (view full) --- 40 The Regents of the University of California. All rights reserved.\n"; 41#endif /* not lint */ 42 43#ifndef lint 44#if 0 45static char sccsid[] = "@(#)showmount.c 8.3 (Berkeley) 3/29/95"; 46#endif 47static const char rcsid[] = |
48 "$FreeBSD: head/usr.bin/showmount/showmount.c 146466 2005-05-21 09:55:10Z ru $"; | 48 "$FreeBSD: head/usr.bin/showmount/showmount.c 194880 2009-06-24 18:42:21Z dfr $"; |
49#endif /* not lint */ 50 51#include <sys/types.h> 52#include <sys/queue.h> 53#include <sys/file.h> 54#include <sys/socket.h> 55#include <sys/socketvar.h> 56 57#include <err.h> 58#include <netdb.h> 59#include <rpc/rpc.h> 60#include <rpc/pmap_clnt.h> 61#include <rpc/pmap_prot.h> | 49#endif /* not lint */ 50 51#include <sys/types.h> 52#include <sys/queue.h> 53#include <sys/file.h> 54#include <sys/socket.h> 55#include <sys/socketvar.h> 56 57#include <err.h> 58#include <netdb.h> 59#include <rpc/rpc.h> 60#include <rpc/pmap_clnt.h> 61#include <rpc/pmap_prot.h> |
62#include <nfs/rpcv2.h> | 62#include <rpcsvc/mount.h> |
63 64#include <stdio.h> 65#include <stdlib.h> 66#include <string.h> 67#include <unistd.h> 68 69/* Constant defs */ 70#define ALL 1 71#define DIRS 2 72 73#define DODUMP 0x1 74#define DOEXPORTS 0x2 75 76struct mountlist { 77 struct mountlist *ml_left; 78 struct mountlist *ml_right; | 63 64#include <stdio.h> 65#include <stdlib.h> 66#include <string.h> 67#include <unistd.h> 68 69/* Constant defs */ 70#define ALL 1 71#define DIRS 2 72 73#define DODUMP 0x1 74#define DOEXPORTS 0x2 75 76struct mountlist { 77 struct mountlist *ml_left; 78 struct mountlist *ml_right; |
79 char ml_host[RPCMNT_NAMELEN+1]; 80 char ml_dirp[RPCMNT_PATHLEN+1]; | 79 char ml_host[MNTNAMLEN+1]; 80 char ml_dirp[MNTPATHLEN+1]; |
81}; 82 83struct grouplist { 84 struct grouplist *gr_next; | 81}; 82 83struct grouplist { 84 struct grouplist *gr_next; |
85 char gr_name[RPCMNT_NAMELEN+1]; | 85 char gr_name[MNTNAMLEN+1]; |
86}; 87 88struct exportslist { 89 struct exportslist *ex_next; 90 struct grouplist *ex_groups; | 86}; 87 88struct exportslist { 89 struct exportslist *ex_next; 90 struct grouplist *ex_groups; |
91 char ex_dirp[RPCMNT_PATHLEN+1]; | 91 char ex_dirp[MNTPATHLEN+1]; |
92}; 93 94static struct mountlist *mntdump; | 92}; 93 94static struct mountlist *mntdump; |
95static struct exportslist *exports; | 95static struct exportslist *exportslist; |
96static int type = 0; 97 98void print_dump(struct mountlist *); 99static void usage(void); 100int xdr_mntdump(XDR *, struct mountlist **); | 96static int type = 0; 97 98void print_dump(struct mountlist *); 99static void usage(void); 100int xdr_mntdump(XDR *, struct mountlist **); |
101int xdr_exports(XDR *, struct exportslist **); | 101int xdr_exportslist(XDR *, struct exportslist **); |
102int tcp_callrpc(const char *host, int prognum, int versnum, int procnum, 103 xdrproc_t inproc, char *in, xdrproc_t outproc, char *out); 104 105/* 106 * This command queries the NFS mount daemon for it's mount list and/or 107 * it's exports list and prints them out. 108 * See "NFS: Network File System Protocol Specification, RFC1094, Appendix A" 109 * and the "Network File System Protocol XXX.." --- 43 unchanged lines hidden (view full) --- 153 host = *argv; 154 else 155 host = "localhost"; 156 157 if (rpcs == 0) 158 rpcs = DODUMP; 159 160 if (rpcs & DODUMP) | 102int tcp_callrpc(const char *host, int prognum, int versnum, int procnum, 103 xdrproc_t inproc, char *in, xdrproc_t outproc, char *out); 104 105/* 106 * This command queries the NFS mount daemon for it's mount list and/or 107 * it's exports list and prints them out. 108 * See "NFS: Network File System Protocol Specification, RFC1094, Appendix A" 109 * and the "Network File System Protocol XXX.." --- 43 unchanged lines hidden (view full) --- 153 host = *argv; 154 else 155 host = "localhost"; 156 157 if (rpcs == 0) 158 rpcs = DODUMP; 159 160 if (rpcs & DODUMP) |
161 if ((estat = tcp_callrpc(host, RPCPROG_MNT, mntvers, 162 RPCMNT_DUMP, (xdrproc_t)xdr_void, (char *)0, | 161 if ((estat = tcp_callrpc(host, MOUNTPROG, mntvers, 162 MOUNTPROC_DUMP, (xdrproc_t)xdr_void, (char *)0, |
163 (xdrproc_t)xdr_mntdump, (char *)&mntdump)) != 0) { 164 clnt_perrno(estat); 165 errx(1, "can't do mountdump rpc"); 166 } 167 if (rpcs & DOEXPORTS) | 163 (xdrproc_t)xdr_mntdump, (char *)&mntdump)) != 0) { 164 clnt_perrno(estat); 165 errx(1, "can't do mountdump rpc"); 166 } 167 if (rpcs & DOEXPORTS) |
168 if ((estat = tcp_callrpc(host, RPCPROG_MNT, mntvers, 169 RPCMNT_EXPORT, (xdrproc_t)xdr_void, (char *)0, 170 (xdrproc_t)xdr_exports, (char *)&exports)) != 0) { | 168 if ((estat = tcp_callrpc(host, MOUNTPROG, mntvers, 169 MOUNTPROC_EXPORT, (xdrproc_t)xdr_void, (char *)0, 170 (xdrproc_t)xdr_exportslist, (char *)&exportslist)) != 0) { |
171 clnt_perrno(estat); 172 errx(1, "can't do exports rpc"); 173 } 174 175 /* Now just print out the results */ 176 if (rpcs & DODUMP) { 177 switch (type) { 178 case ALL: --- 5 unchanged lines hidden (view full) --- 184 default: 185 printf("Hosts on %s:\n", host); 186 break; 187 }; 188 print_dump(mntdump); 189 } 190 if (rpcs & DOEXPORTS) { 191 printf("Exports list on %s:\n", host); | 171 clnt_perrno(estat); 172 errx(1, "can't do exports rpc"); 173 } 174 175 /* Now just print out the results */ 176 if (rpcs & DODUMP) { 177 switch (type) { 178 case ALL: --- 5 unchanged lines hidden (view full) --- 184 default: 185 printf("Hosts on %s:\n", host); 186 break; 187 }; 188 print_dump(mntdump); 189 } 190 if (rpcs & DOEXPORTS) { 191 printf("Exports list on %s:\n", host); |
192 exp = exports; | 192 exp = exportslist; |
193 while (exp) { 194 printf("%-35s", exp->ex_dirp); 195 grp = exp->ex_groups; 196 if (grp == NULL) { 197 printf("Everyone\n"); 198 } else { 199 while (grp) { 200 printf("%s ", grp->gr_name); --- 59 unchanged lines hidden (view full) --- 260 if (!xdr_bool(xdrsp, &bool)) 261 return (0); 262 while (bool) { 263 mp = (struct mountlist *)malloc(sizeof(struct mountlist)); 264 if (mp == NULL) 265 return (0); 266 mp->ml_left = mp->ml_right = (struct mountlist *)0; 267 strp = mp->ml_host; | 193 while (exp) { 194 printf("%-35s", exp->ex_dirp); 195 grp = exp->ex_groups; 196 if (grp == NULL) { 197 printf("Everyone\n"); 198 } else { 199 while (grp) { 200 printf("%s ", grp->gr_name); --- 59 unchanged lines hidden (view full) --- 260 if (!xdr_bool(xdrsp, &bool)) 261 return (0); 262 while (bool) { 263 mp = (struct mountlist *)malloc(sizeof(struct mountlist)); 264 if (mp == NULL) 265 return (0); 266 mp->ml_left = mp->ml_right = (struct mountlist *)0; 267 strp = mp->ml_host; |
268 if (!xdr_string(xdrsp, &strp, RPCMNT_NAMELEN)) | 268 if (!xdr_string(xdrsp, &strp, MNTNAMLEN)) |
269 return (0); 270 strp = mp->ml_dirp; | 269 return (0); 270 strp = mp->ml_dirp; |
271 if (!xdr_string(xdrsp, &strp, RPCMNT_PATHLEN)) | 271 if (!xdr_string(xdrsp, &strp, MNTPATHLEN)) |
272 return (0); 273 274 /* 275 * Build a binary tree on sorted order of either host or dirp. 276 * Drop any duplications. 277 */ 278 if (*mlp == NULL) { 279 *mlp = mp; --- 42 unchanged lines hidden (view full) --- 322 } 323 return (1); 324} 325 326/* 327 * Xdr routine to retrieve exports list 328 */ 329int | 272 return (0); 273 274 /* 275 * Build a binary tree on sorted order of either host or dirp. 276 * Drop any duplications. 277 */ 278 if (*mlp == NULL) { 279 *mlp = mp; --- 42 unchanged lines hidden (view full) --- 322 } 323 return (1); 324} 325 326/* 327 * Xdr routine to retrieve exports list 328 */ 329int |
330xdr_exports(xdrsp, exp) | 330xdr_exportslist(xdrsp, exp) |
331 XDR *xdrsp; 332 struct exportslist **exp; 333{ 334 register struct exportslist *ep; 335 register struct grouplist *gp; 336 int bool, grpbool; 337 char *strp; 338 339 *exp = (struct exportslist *)0; 340 if (!xdr_bool(xdrsp, &bool)) 341 return (0); 342 while (bool) { 343 ep = (struct exportslist *)malloc(sizeof(struct exportslist)); 344 if (ep == NULL) 345 return (0); 346 ep->ex_groups = (struct grouplist *)0; 347 strp = ep->ex_dirp; | 331 XDR *xdrsp; 332 struct exportslist **exp; 333{ 334 register struct exportslist *ep; 335 register struct grouplist *gp; 336 int bool, grpbool; 337 char *strp; 338 339 *exp = (struct exportslist *)0; 340 if (!xdr_bool(xdrsp, &bool)) 341 return (0); 342 while (bool) { 343 ep = (struct exportslist *)malloc(sizeof(struct exportslist)); 344 if (ep == NULL) 345 return (0); 346 ep->ex_groups = (struct grouplist *)0; 347 strp = ep->ex_dirp; |
348 if (!xdr_string(xdrsp, &strp, RPCMNT_PATHLEN)) | 348 if (!xdr_string(xdrsp, &strp, MNTPATHLEN)) |
349 return (0); 350 if (!xdr_bool(xdrsp, &grpbool)) 351 return (0); 352 while (grpbool) { 353 gp = (struct grouplist *)malloc(sizeof(struct grouplist)); 354 if (gp == NULL) 355 return (0); 356 strp = gp->gr_name; | 349 return (0); 350 if (!xdr_bool(xdrsp, &grpbool)) 351 return (0); 352 while (grpbool) { 353 gp = (struct grouplist *)malloc(sizeof(struct grouplist)); 354 if (gp == NULL) 355 return (0); 356 strp = gp->gr_name; |
357 if (!xdr_string(xdrsp, &strp, RPCMNT_NAMELEN)) | 357 if (!xdr_string(xdrsp, &strp, MNTNAMLEN)) |
358 return (0); 359 gp->gr_next = ep->ex_groups; 360 ep->ex_groups = gp; 361 if (!xdr_bool(xdrsp, &grpbool)) 362 return (0); 363 } 364 ep->ex_next = *exp; 365 *exp = ep; --- 39 unchanged lines hidden --- | 358 return (0); 359 gp->gr_next = ep->ex_groups; 360 ep->ex_groups = gp; 361 if (!xdr_bool(xdrsp, &grpbool)) 362 return (0); 363 } 364 ep->ex_next = *exp; 365 *exp = ep; --- 39 unchanged lines hidden --- |