lockd.c (161552) | lockd.c (168324) |
---|---|
1/* $NetBSD: lockd.c,v 1.7 2000/08/12 18:08:44 thorpej Exp $ */ | 1/* $NetBSD: lockd.c,v 1.7 2000/08/12 18:08:44 thorpej Exp $ */ |
2/* $FreeBSD: head/usr.sbin/rpc.lockd/lockd.c 161552 2006-08-23 15:59:43Z thomas $ */ | 2/* $FreeBSD: head/usr.sbin/rpc.lockd/lockd.c 168324 2007-04-03 20:58:28Z matteo $ */ |
3 4/* 5 * Copyright (c) 1995 6 * A.R. Gordon (andrew.gordon@net-tel.co.uk). All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: --- 76 unchanged lines hidden (view full) --- 87const char *transports[] = { "udp", "tcp", "udp6", "tcp6" }; 88 89int 90main(argc, argv) 91 int argc; 92 char **argv; 93{ 94 SVCXPRT *transp; | 3 4/* 5 * Copyright (c) 1995 6 * A.R. Gordon (andrew.gordon@net-tel.co.uk). All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: --- 76 unchanged lines hidden (view full) --- 87const char *transports[] = { "udp", "tcp", "udp6", "tcp6" }; 88 89int 90main(argc, argv) 91 int argc; 92 char **argv; 93{ 94 SVCXPRT *transp; |
95 int ch, i, maxindex, s; | 95 int ch, i, maxindex, r, s, sock; 96 struct sockaddr_in sin; 97 struct sockaddr_in6 sin6; 98 char *endptr; |
96 struct sigaction sigalarm; 97 int grace_period = 30; 98 struct netconfig *nconf; 99 int maxrec = RPC_MAXDATASIZE; | 99 struct sigaction sigalarm; 100 int grace_period = 30; 101 struct netconfig *nconf; 102 int maxrec = RPC_MAXDATASIZE; |
103 in_port_t svcport = 0; |
|
100 | 104 |
101 while ((ch = getopt(argc, argv, "d:g:")) != (-1)) { | 105 while ((ch = getopt(argc, argv, "d:g:p:")) != (-1)) { |
102 switch (ch) { 103 case 'd': 104 debug_level = atoi(optarg); 105 if (!debug_level) { 106 usage(); 107 /* NOTREACHED */ 108 } 109 break; 110 case 'g': 111 grace_period = atoi(optarg); 112 if (!grace_period) { 113 usage(); 114 /* NOTREACHED */ 115 } 116 break; | 106 switch (ch) { 107 case 'd': 108 debug_level = atoi(optarg); 109 if (!debug_level) { 110 usage(); 111 /* NOTREACHED */ 112 } 113 break; 114 case 'g': 115 grace_period = atoi(optarg); 116 if (!grace_period) { 117 usage(); 118 /* NOTREACHED */ 119 } 120 break; |
121 case 'p': 122 endptr = NULL; 123 svcport = (in_port_t)strtoul(optarg, &endptr, 10); 124 if (endptr == NULL || *endptr != '\0' || 125 svcport == 0 || svcport >= IPPORT_MAX) 126 usage(); 127 break; |
|
117 default: 118 case '?': 119 usage(); 120 /* NOTREACHED */ 121 } 122 } 123 if (geteuid()) { /* This command allowed only to root */ 124 fprintf(stderr, "Sorry. You are not superuser\n"); --- 11 unchanged lines hidden (view full) --- 136 s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); 137 if (s < 0) 138 maxindex = 2; 139 else { 140 close(s); 141 maxindex = 4; 142 } 143 | 128 default: 129 case '?': 130 usage(); 131 /* NOTREACHED */ 132 } 133 } 134 if (geteuid()) { /* This command allowed only to root */ 135 fprintf(stderr, "Sorry. You are not superuser\n"); --- 11 unchanged lines hidden (view full) --- 147 s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); 148 if (s < 0) 149 maxindex = 2; 150 else { 151 close(s); 152 maxindex = 4; 153 } 154 |
155 if (svcport != 0) { 156 bzero(&sin, sizeof(struct sockaddr_in)); 157 sin.sin_len = sizeof(struct sockaddr_in); 158 sin.sin_family = AF_INET; 159 sin.sin_port = htons(svcport); 160 161 bzero(&sin6, sizeof(struct sockaddr_in6)); 162 sin6.sin6_len = sizeof(struct sockaddr_in6); 163 sin6.sin6_family = AF_INET6; 164 sin6.sin6_port = htons(svcport); 165 } 166 |
|
144 rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec); 145 146 for (i = 0; i < maxindex; i++) { 147 nconf = getnetconfigent(transports[i]); 148 if (nconf == NULL) | 167 rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec); 168 169 for (i = 0; i < maxindex; i++) { 170 nconf = getnetconfigent(transports[i]); 171 if (nconf == NULL) |
149 errx(1, "cannot get %s netconf: %s.", transports[i], 150 nc_sperror()); | 172 errx(1, "cannot get %s netconf: %s.", transports[i], 173 nc_sperror()); |
151 | 174 |
152 transp = svc_tli_create(RPC_ANYFD, nconf, NULL, 153 RPC_MAXDATASIZE, RPC_MAXDATASIZE); | 175 if (svcport != 0) { 176 if (strcmp(nconf->nc_netid, "udp6") == 0) { 177 sock = socket(AF_INET6, SOCK_DGRAM, 178 IPPROTO_UDP); 179 if (sock != -1) { 180 r = bindresvport_sa(sock, 181 (struct sockaddr *)&sin6); 182 if (r != 0) { 183 syslog(LOG_ERR, "bindresvport: %m"); 184 exit(1); 185 } 186 } 187 } 188 else if (strcmp(nconf->nc_netid, "udp") == 0) { 189 sock = socket(AF_INET, SOCK_DGRAM, 190 IPPROTO_UDP); 191 if (sock != -1) { 192 r = bindresvport(sock, &sin); 193 if (r != 0) { 194 syslog(LOG_ERR, "bindresvport: %m"); 195 exit(1); 196 } 197 } 198 } 199 else if (strcmp(nconf->nc_netid, "tcp6") == 0) { 200 sock = socket(AF_INET6, SOCK_STREAM, 201 IPPROTO_TCP); 202 if (sock != -1) { 203 r = bindresvport_sa(sock, 204 (struct sockaddr *)&sin6); 205 if (r != 0) { 206 syslog(LOG_ERR, "bindresvport: %m"); 207 exit(1); 208 } 209 } 210 } 211 else if (strcmp(nconf->nc_netid, "tcp") == 0) { 212 sock = socket(AF_INET, SOCK_STREAM, 213 IPPROTO_TCP); 214 if (sock != -1) { 215 r = bindresvport(sock, &sin); 216 if (r != 0) { 217 syslog(LOG_ERR, "bindresvport: %m"); 218 exit(1); 219 } 220 } 221 } 222 223 transp = svc_tli_create(sock, nconf, NULL, 224 RPC_MAXDATASIZE, RPC_MAXDATASIZE); 225 } else { 226 transp = svc_tli_create(RPC_ANYFD, nconf, NULL, 227 RPC_MAXDATASIZE, RPC_MAXDATASIZE); 228 } 229 |
154 if (transp == NULL) { 155 errx(1, "cannot create %s service.", transports[i]); 156 /* NOTREACHED */ 157 } 158 if (!svc_reg(transp, NLM_PROG, NLM_SM, nlm_prog_0, nconf)) { 159 errx(1, "unable to register (NLM_PROG, NLM_SM, %s)", 160 transports[i]); 161 /* NOTREACHED */ --- 56 unchanged lines hidden (view full) --- 218{ 219 220 grace_expired = 1; 221} 222 223void 224usage() 225{ | 230 if (transp == NULL) { 231 errx(1, "cannot create %s service.", transports[i]); 232 /* NOTREACHED */ 233 } 234 if (!svc_reg(transp, NLM_PROG, NLM_SM, nlm_prog_0, nconf)) { 235 errx(1, "unable to register (NLM_PROG, NLM_SM, %s)", 236 transports[i]); 237 /* NOTREACHED */ --- 56 unchanged lines hidden (view full) --- 294{ 295 296 grace_expired = 1; 297} 298 299void 300usage() 301{ |
226 errx(1, "usage: rpc.lockd [-d <debuglevel>] [-g <grace period>]"); | 302 errx(1, "usage: rpc.lockd [-d <debuglevel>]" 303 " [-g <grace period>] [-p <port>]"); |
227} 228 229/* 230 * init_nsm -- 231 * Reset the NSM state-of-the-world and acquire its state. 232 */ 233void 234init_nsm(void) --- 44 unchanged lines hidden --- | 304} 305 306/* 307 * init_nsm -- 308 * Reset the NSM state-of-the-world and acquire its state. 309 */ 310void 311init_nsm(void) --- 44 unchanged lines hidden --- |