lockd.c (179489) | lockd.c (180025) |
---|---|
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 179489 2008-06-02 16:00:49Z dfr $ */ | 2/* $FreeBSD: head/usr.sbin/rpc.lockd/lockd.c 180025 2008-06-26 10:21:54Z dfr $ */ |
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: --- 64 unchanged lines hidden (view full) --- 75#include <rpcsvc/nlm_prot.h> 76 77int debug_level = 0; /* 0 = no debugging syslog() calls */ 78int _rpcsvcdirty = 0; 79 80int grace_expired; 81int nsm_state; 82int kernel_lockd; | 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: --- 64 unchanged lines hidden (view full) --- 75#include <rpcsvc/nlm_prot.h> 76 77int debug_level = 0; /* 0 = no debugging syslog() calls */ 78int _rpcsvcdirty = 0; 79 80int grace_expired; 81int nsm_state; 82int kernel_lockd; |
83int kernel_lockd_client; |
|
83pid_t client_pid; 84struct mon mon_host; 85char **hosts, *svcport_str = NULL; 86int nhosts = 0; 87int xcreated = 0; 88char **addrs; /* actually (netid, uaddr) pairs */ 89int naddrs; /* count of how many (netid, uaddr) pairs */ 90 --- 79 unchanged lines hidden (view full) --- 170 } 171 } 172 if (geteuid()) { /* This command allowed only to root */ 173 fprintf(stderr, "Sorry. You are not superuser\n"); 174 exit(1); 175 } 176 177 kernel_lockd = FALSE; | 84pid_t client_pid; 85struct mon mon_host; 86char **hosts, *svcport_str = NULL; 87int nhosts = 0; 88int xcreated = 0; 89char **addrs; /* actually (netid, uaddr) pairs */ 90int naddrs; /* count of how many (netid, uaddr) pairs */ 91 --- 79 unchanged lines hidden (view full) --- 171 } 172 } 173 if (geteuid()) { /* This command allowed only to root */ 174 fprintf(stderr, "Sorry. You are not superuser\n"); 175 exit(1); 176 } 177 178 kernel_lockd = FALSE; |
179 kernel_lockd_client = FALSE; |
|
178 if (modfind("nfslockd") < 0) { 179 if (kldload("nfslockd") < 0) { 180 fprintf(stderr, "Can't find or load kernel support for rpc.lockd - using non-kernel implementation\n"); 181 } else { 182 kernel_lockd = TRUE; 183 } 184 } else { 185 kernel_lockd = TRUE; 186 } | 180 if (modfind("nfslockd") < 0) { 181 if (kldload("nfslockd") < 0) { 182 fprintf(stderr, "Can't find or load kernel support for rpc.lockd - using non-kernel implementation\n"); 183 } else { 184 kernel_lockd = TRUE; 185 } 186 } else { 187 kernel_lockd = TRUE; 188 } |
189 if (kernel_lockd) { 190 if (getosreldate() >= 800040) 191 kernel_lockd_client = TRUE; 192 } |
|
187 188 (void)rpcb_unset(NLM_PROG, NLM_SM, NULL); 189 (void)rpcb_unset(NLM_PROG, NLM_VERS, NULL); 190 (void)rpcb_unset(NLM_PROG, NLM_VERSX, NULL); 191 (void)rpcb_unset(NLM_PROG, NLM_VERS4, NULL); 192 193 /* 194 * Check if IPv6 support is present. --- 45 unchanged lines hidden (view full) --- 240 nhosts += 1; 241 hosts = hosts_bak; 242 } 243 } 244 hosts[nhosts - 1] = "127.0.0.1"; 245 } 246 247 if (kernel_lockd) { | 193 194 (void)rpcb_unset(NLM_PROG, NLM_SM, NULL); 195 (void)rpcb_unset(NLM_PROG, NLM_VERS, NULL); 196 (void)rpcb_unset(NLM_PROG, NLM_VERSX, NULL); 197 (void)rpcb_unset(NLM_PROG, NLM_VERS4, NULL); 198 199 /* 200 * Check if IPv6 support is present. --- 45 unchanged lines hidden (view full) --- 246 nhosts += 1; 247 hosts = hosts_bak; 248 } 249 } 250 hosts[nhosts - 1] = "127.0.0.1"; 251 } 252 253 if (kernel_lockd) { |
248 /* 249 * For the kernel lockd case, we run a cut-down RPC 250 * service on a local-domain socket. The kernel's RPC 251 * server will pass what it can't handle (mainly 252 * client replies) down to us. This can go away 253 * entirely if/when we move the client side of NFS 254 * locking into the kernel. 255 */ 256 struct sockaddr_un sun; 257 int fd, oldmask; 258 SVCXPRT *xprt; | 254 if (!kernel_lockd_client) { 255 /* 256 * For the case where we have a kernel lockd but it 257 * doesn't provide client locking, we run a cut-down 258 * RPC service on a local-domain socket. The kernel's 259 * RPC server will pass what it can't handle (mainly 260 * client replies) down to us. 261 */ 262 struct sockaddr_un sun; 263 int fd, oldmask; 264 SVCXPRT *xprt; |
259 | 265 |
260 memset(&sun, 0, sizeof sun); 261 sun.sun_family = AF_LOCAL; 262 unlink(_PATH_RPCLOCKDSOCK); 263 strcpy(sun.sun_path, _PATH_RPCLOCKDSOCK); 264 sun.sun_len = SUN_LEN(&sun); 265 fd = socket(AF_LOCAL, SOCK_STREAM, 0); 266 if (!fd) { 267 err(1, "Can't create local lockd socket"); | 266 memset(&sun, 0, sizeof sun); 267 sun.sun_family = AF_LOCAL; 268 unlink(_PATH_RPCLOCKDSOCK); 269 strcpy(sun.sun_path, _PATH_RPCLOCKDSOCK); 270 sun.sun_len = SUN_LEN(&sun); 271 fd = socket(AF_LOCAL, SOCK_STREAM, 0); 272 if (!fd) { 273 err(1, "Can't create local lockd socket"); 274 } 275 oldmask = umask(S_IXUSR|S_IRWXG|S_IRWXO); 276 if (bind(fd, (struct sockaddr *) &sun, sun.sun_len) < 0) { 277 err(1, "Can't bind local lockd socket"); 278 } 279 umask(oldmask); 280 if (listen(fd, SOMAXCONN) < 0) { 281 err(1, "Can't listen on local lockd socket"); 282 } 283 xprt = svc_vc_create(fd, RPC_MAXDATASIZE, RPC_MAXDATASIZE); 284 if (!xprt) { 285 err(1, "Can't create transport for local lockd socket"); 286 } 287 if (!svc_reg(xprt, NLM_PROG, NLM_VERS4, nlm_prog_4, NULL)) { 288 err(1, "Can't register service for local lockd socket"); 289 } |
268 } | 290 } |
269 oldmask = umask(S_IXUSR|S_IRWXG|S_IRWXO); 270 if (bind(fd, (struct sockaddr *) &sun, sun.sun_len) < 0) { 271 err(1, "Can't bind local lockd socket"); 272 } 273 umask(oldmask); 274 if (listen(fd, SOMAXCONN) < 0) { 275 err(1, "Can't listen on local lockd socket"); 276 } 277 xprt = svc_vc_create(fd, RPC_MAXDATASIZE, RPC_MAXDATASIZE); 278 if (!xprt) { 279 err(1, "Can't create transport for local lockd socket"); 280 } 281 if (!svc_reg(xprt, NLM_PROG, NLM_VERS4, nlm_prog_4, NULL)) { 282 err(1, "Can't register service for local lockd socket"); 283 } | |
284 285 /* 286 * We need to look up the addresses so that we can 287 * hand uaddrs (ascii encoded address+port strings) to 288 * the kernel. 289 */ 290 nc_handle = setnetconfig(); 291 while ((nconf = getnetconfig(nc_handle))) { --- 45 unchanged lines hidden (view full) --- 337 sigalarm.sa_flags |= SA_RESTART; 338 if (sigaction(SIGALRM, &sigalarm, NULL) != 0) { 339 syslog(LOG_WARNING, "sigaction(SIGALRM) failed: %s", 340 strerror(errno)); 341 exit(1); 342 } 343 344 if (kernel_lockd) { | 291 292 /* 293 * We need to look up the addresses so that we can 294 * hand uaddrs (ascii encoded address+port strings) to 295 * the kernel. 296 */ 297 nc_handle = setnetconfig(); 298 while ((nconf = getnetconfig(nc_handle))) { --- 45 unchanged lines hidden (view full) --- 344 sigalarm.sa_flags |= SA_RESTART; 345 if (sigaction(SIGALRM, &sigalarm, NULL) != 0) { 346 syslog(LOG_WARNING, "sigaction(SIGALRM) failed: %s", 347 strerror(errno)); 348 exit(1); 349 } 350 351 if (kernel_lockd) { |
345 init_nsm(); 346 client_pid = client_request(); | 352 if (!kernel_lockd_client) { 353 init_nsm(); 354 client_pid = client_request(); |
347 | 355 |
348 /* 349 * Create a child process to enter the kernel and then 350 * wait for RPCs on our local domain socket. 351 */ 352 if (!fork()) | 356 /* 357 * Create a child process to enter the kernel and then 358 * wait for RPCs on our local domain socket. 359 */ 360 if (!fork()) 361 nlm_syscall(debug_level, grace_period, 362 naddrs, addrs); 363 else 364 svc_run(); 365 } else { 366 /* 367 * The kernel lockd implementation provides 368 * both client and server so we don't need to 369 * do anything else. 370 */ |
353 nlm_syscall(debug_level, grace_period, naddrs, addrs); | 371 nlm_syscall(debug_level, grace_period, naddrs, addrs); |
354 else 355 svc_run(); | 372 } |
356 } else { 357 grace_expired = 0; 358 alarm(grace_period); 359 360 init_nsm(); 361 362 client_pid = client_request(); 363 --- 459 unchanged lines hidden --- | 373 } else { 374 grace_expired = 0; 375 alarm(grace_period); 376 377 init_nsm(); 378 379 client_pid = client_request(); 380 --- 459 unchanged lines hidden --- |