nfsuserd.c (192811) | nfsuserd.c (193070) |
---|---|
1/*- 2 * Copyright (c) 2009 Rick Macklem, University of Guelph 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 */ 27 28#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2009 Rick Macklem, University of Guelph 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 */ 27 28#include <sys/cdefs.h> |
29__FBSDID("$FreeBSD: head/usr.sbin/nfsuserd/nfsuserd.c 192811 2009-05-26 15:19:04Z rmacklem $"); | 29__FBSDID("$FreeBSD: head/usr.sbin/nfsuserd/nfsuserd.c 193070 2009-05-29 22:19:45Z delphij $"); |
30 31#include <sys/param.h> 32#include <sys/errno.h> 33#include <sys/linker.h> 34#include <sys/module.h> 35#include <sys/mount.h> 36#include <sys/socket.h> 37#include <sys/socketvar.h> --- 23 unchanged lines hidden (view full) --- 61#include <syslog.h> 62#include <unistd.h> 63 64/* 65 * This program loads the password and group databases into the kernel 66 * for NFS V4. 67 */ 68 | 30 31#include <sys/param.h> 32#include <sys/errno.h> 33#include <sys/linker.h> 34#include <sys/module.h> 35#include <sys/mount.h> 36#include <sys/socket.h> 37#include <sys/socketvar.h> --- 23 unchanged lines hidden (view full) --- 61#include <syslog.h> 62#include <unistd.h> 63 64/* 65 * This program loads the password and group databases into the kernel 66 * for NFS V4. 67 */ 68 |
69void cleanup_term(int); 70void usage(void); 71void nfsuserdsrv(struct svc_req *, SVCXPRT *); 72bool_t xdr_getid(XDR *, caddr_t); 73bool_t xdr_getname(XDR *, caddr_t); 74bool_t xdr_retval(XDR *, caddr_t); | 69static void cleanup_term(int); 70static void usage(void); 71static void nfsuserdsrv(struct svc_req *, SVCXPRT *); 72static bool_t xdr_getid(XDR *, caddr_t); 73static bool_t xdr_getname(XDR *, caddr_t); 74static bool_t xdr_retval(XDR *, caddr_t); |
75 76#define MAXNAME 1024 77#define MAXNFSUSERD 20 78#define DEFNFSUSERD 4 79#define DEFUSERMAX 200 80#define DEFUSERTIMEOUT (1 * 60) 81struct info { 82 long id; --- 6 unchanged lines hidden (view full) --- 89uid_t defaultuid = (uid_t)32767; 90u_char *defaultgroup = "nogroup"; 91gid_t defaultgid = (gid_t)32767; 92int verbose = 0, im_a_slave = 0, nfsuserdcnt = -1, forcestart = 0; 93int defusertimeout = DEFUSERTIMEOUT; 94pid_t slaves[MAXNFSUSERD]; 95 96int | 75 76#define MAXNAME 1024 77#define MAXNFSUSERD 20 78#define DEFNFSUSERD 4 79#define DEFUSERMAX 200 80#define DEFUSERTIMEOUT (1 * 60) 81struct info { 82 long id; --- 6 unchanged lines hidden (view full) --- 89uid_t defaultuid = (uid_t)32767; 90u_char *defaultgroup = "nogroup"; 91gid_t defaultgid = (gid_t)32767; 92int verbose = 0, im_a_slave = 0, nfsuserdcnt = -1, forcestart = 0; 93int defusertimeout = DEFUSERTIMEOUT; 94pid_t slaves[MAXNFSUSERD]; 95 96int |
97main(int argc, char *argv[], char *envp[]) | 97main(int argc, char *argv[]) |
98{ 99 int i; 100 int error, len, mustfreeai = 0; 101 struct nfsd_idargs nid; 102 struct passwd *pwd; 103 struct group *grp; 104 int sock, one = 1; | 98{ 99 int i; 100 int error, len, mustfreeai = 0; 101 struct nfsd_idargs nid; 102 struct passwd *pwd; 103 struct group *grp; 104 int sock, one = 1; |
105 SVCXPRT *udptransp, *tcptransp; 106 struct passwd *pw; | 105 SVCXPRT *udptransp; |
107 u_short portnum; 108 sigset_t signew; | 106 u_short portnum; 107 sigset_t signew; |
109 char hostname[MAXHOSTNAMELEN + 1], *cp, **aliases; | 108 char hostname[MAXHOSTNAMELEN + 1], *cp; |
110 struct addrinfo *aip, hints; 111 112 if (modfind("nfscommon") < 0) { 113 /* Not present in kernel, try loading it */ 114 if (kldload("nfscommon") < 0 || 115 modfind("nfscommon") < 0) 116 errx(1, "Experimental nfs subsystem is not available"); 117 } --- 43 unchanged lines hidden (view full) --- 161 } else if (!strcmp(*argv, "-usermax")) { 162 if (argc == 1) 163 usage(); 164 argc--; 165 argv++; 166 i = atoi(*argv); 167 if (i < 10 || i > 100000) { 168 fprintf(stderr, | 109 struct addrinfo *aip, hints; 110 111 if (modfind("nfscommon") < 0) { 112 /* Not present in kernel, try loading it */ 113 if (kldload("nfscommon") < 0 || 114 modfind("nfscommon") < 0) 115 errx(1, "Experimental nfs subsystem is not available"); 116 } --- 43 unchanged lines hidden (view full) --- 160 } else if (!strcmp(*argv, "-usermax")) { 161 if (argc == 1) 162 usage(); 163 argc--; 164 argv++; 165 i = atoi(*argv); 166 if (i < 10 || i > 100000) { 167 fprintf(stderr, |
169 "usermax out of range 10<->100000\n", i); | 168 "usermax %d out of range 10<->100000\n", i); |
170 usage(); 171 } 172 nid.nid_usermax = i; 173 } else if (!strcmp(*argv, "-usertimeout")) { 174 if (argc == 1) 175 usage(); 176 argc--; 177 argv++; 178 i = atoi(*argv); 179 if (i < 0 || i > 100000) { 180 fprintf(stderr, | 169 usage(); 170 } 171 nid.nid_usermax = i; 172 } else if (!strcmp(*argv, "-usertimeout")) { 173 if (argc == 1) 174 usage(); 175 argc--; 176 argv++; 177 i = atoi(*argv); 178 if (i < 0 || i > 100000) { 179 fprintf(stderr, |
181 "usertimeout out of range 0<->100000\n", | 180 "usertimeout %d out of range 0<->100000\n", |
182 i); 183 usage(); 184 } 185 nid.nid_usertimeout = defusertimeout = i * 60; 186 } else if (nfsuserdcnt == -1) { 187 nfsuserdcnt = atoi(*argv); 188 if (nfsuserdcnt < 1) 189 usage(); --- 214 unchanged lines hidden (view full) --- 404 sigemptyset(&signew); 405 while (1) 406 sigsuspend(&signew); 407} 408 409/* 410 * The nfsuserd rpc service 411 */ | 181 i); 182 usage(); 183 } 184 nid.nid_usertimeout = defusertimeout = i * 60; 185 } else if (nfsuserdcnt == -1) { 186 nfsuserdcnt = atoi(*argv); 187 if (nfsuserdcnt < 1) 188 usage(); --- 214 unchanged lines hidden (view full) --- 403 sigemptyset(&signew); 404 while (1) 405 sigsuspend(&signew); 406} 407 408/* 409 * The nfsuserd rpc service 410 */ |
412void | 411static void |
413nfsuserdsrv(struct svc_req *rqstp, SVCXPRT *transp) 414{ | 412nfsuserdsrv(struct svc_req *rqstp, SVCXPRT *transp) 413{ |
415 int i; 416 char *cp; | |
417 struct passwd *pwd; 418 struct group *grp; 419 int error; 420 u_short sport; 421 struct info info; 422 struct nfsd_idargs nid; 423 u_int32_t saddr; 424 --- 147 unchanged lines hidden (view full) --- 572 svcerr_noproc(transp); 573 return; 574 }; 575} 576 577/* 578 * Xdr routine to get an id number 579 */ | 414 struct passwd *pwd; 415 struct group *grp; 416 int error; 417 u_short sport; 418 struct info info; 419 struct nfsd_idargs nid; 420 u_int32_t saddr; 421 --- 147 unchanged lines hidden (view full) --- 569 svcerr_noproc(transp); 570 return; 571 }; 572} 573 574/* 575 * Xdr routine to get an id number 576 */ |
580bool_t | 577static bool_t |
581xdr_getid(XDR *xdrsp, caddr_t cp) 582{ 583 struct info *ifp = (struct info *)cp; 584 585 return (xdr_long(xdrsp, &ifp->id)); 586} 587 588/* 589 * Xdr routine to get a user name 590 */ | 578xdr_getid(XDR *xdrsp, caddr_t cp) 579{ 580 struct info *ifp = (struct info *)cp; 581 582 return (xdr_long(xdrsp, &ifp->id)); 583} 584 585/* 586 * Xdr routine to get a user name 587 */ |
591bool_t | 588static bool_t |
592xdr_getname(XDR *xdrsp, caddr_t cp) 593{ 594 struct info *ifp = (struct info *)cp; 595 long len; 596 597 if (!xdr_long(xdrsp, &len)) 598 return (0); 599 if (len > MAXNAME) 600 return (0); 601 if (!xdr_opaque(xdrsp, ifp->name, len)) 602 return (0); 603 ifp->name[len] = '\0'; 604 return (1); 605} 606 607/* 608 * Xdr routine to return the value. 609 */ | 589xdr_getname(XDR *xdrsp, caddr_t cp) 590{ 591 struct info *ifp = (struct info *)cp; 592 long len; 593 594 if (!xdr_long(xdrsp, &len)) 595 return (0); 596 if (len > MAXNAME) 597 return (0); 598 if (!xdr_opaque(xdrsp, ifp->name, len)) 599 return (0); 600 ifp->name[len] = '\0'; 601 return (1); 602} 603 604/* 605 * Xdr routine to return the value. 606 */ |
610bool_t | 607static bool_t |
611xdr_retval(XDR *xdrsp, caddr_t cp) 612{ 613 struct info *ifp = (struct info *)cp; 614 long val; 615 616 val = ifp->retval; 617 return (xdr_long(xdrsp, &val)); 618} 619 620/* 621 * cleanup_term() called via SIGUSR1. 622 */ | 608xdr_retval(XDR *xdrsp, caddr_t cp) 609{ 610 struct info *ifp = (struct info *)cp; 611 long val; 612 613 val = ifp->retval; 614 return (xdr_long(xdrsp, &val)); 615} 616 617/* 618 * cleanup_term() called via SIGUSR1. 619 */ |
623void 624cleanup_term(int signo) | 620static void 621cleanup_term(int signo __unused) |
625{ 626 int i, cnt; 627 628 if (im_a_slave) 629 exit(0); 630 631 /* 632 * Ok, so I'm the master. --- 18 unchanged lines hidden (view full) --- 651 */ 652 if (nfssvc(NFSSVC_NFSUSERDDELPORT, NULL) < 0) { 653 syslog(LOG_ERR, "Can't do nfssvc() to delete the port\n"); 654 exit(1); 655 } 656 exit(0); 657} 658 | 622{ 623 int i, cnt; 624 625 if (im_a_slave) 626 exit(0); 627 628 /* 629 * Ok, so I'm the master. --- 18 unchanged lines hidden (view full) --- 648 */ 649 if (nfssvc(NFSSVC_NFSUSERDDELPORT, NULL) < 0) { 650 syslog(LOG_ERR, "Can't do nfssvc() to delete the port\n"); 651 exit(1); 652 } 653 exit(0); 654} 655 |
659void | 656static void |
660usage(void) 661{ 662 663 errx(1, 664 "usage: nfsuserd [-usermax cache_size] [-usertimeout minutes] [-verbose] [-domain domain_name] [n]"); 665} | 657usage(void) 658{ 659 660 errx(1, 661 "usage: nfsuserd [-usermax cache_size] [-usertimeout minutes] [-verbose] [-domain domain_name] [n]"); 662} |