[Midnightbsd-cvs] src [10349] trunk/usr.sbin/rpc.lockd: sync with freebsd 10-stable
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sun Jun 3 18:53:46 EDT 2018
Revision: 10349
http://svnweb.midnightbsd.org/src/?rev=10349
Author: laffer1
Date: 2018-06-03 18:53:45 -0400 (Sun, 03 Jun 2018)
Log Message:
-----------
sync with freebsd 10-stable
Modified Paths:
--------------
trunk/usr.sbin/rpc.lockd/Makefile
trunk/usr.sbin/rpc.lockd/kern.c
trunk/usr.sbin/rpc.lockd/lock_proc.c
trunk/usr.sbin/rpc.lockd/lockd.c
trunk/usr.sbin/rpc.lockd/lockd.h
trunk/usr.sbin/rpc.lockd/lockd_lock.c
Modified: trunk/usr.sbin/rpc.lockd/Makefile
===================================================================
--- trunk/usr.sbin/rpc.lockd/Makefile 2018-06-03 22:52:56 UTC (rev 10348)
+++ trunk/usr.sbin/rpc.lockd/Makefile 2018-06-03 22:53:45 UTC (rev 10349)
@@ -1,5 +1,6 @@
+# $MidnightBSD$
# $NetBSD: Makefile,v 1.12 2000/08/07 16:23:31 thorpej Exp $
-# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/rpc.lockd/Makefile 321274 2017-07-20 01:03:50Z ngie $
PROG= rpc.lockd
MAN= rpc.lockd.8
@@ -18,10 +19,10 @@
RPCGEN= RPCGEN_CPP=${CPP:Q} rpcgen -L -C
nlm_prot_svc.c: ${RPCSRC}
- ${RPCGEN} -m -o ${.TARGET} ${RPCSRC}
+ ${RPCGEN} -m -o ${.TARGET} ${.ALLSRC}
nlm_prot.h: ${RPCSRC}
- ${RPCGEN} -h -o ${.TARGET} ${RPCSRC}
+ ${RPCGEN} -h -o ${.TARGET} ${.ALLSRC}
test: ${.CURDIR}/test.c
cc -o test ${.CURDIR}/test.c -lrpcsvc
Modified: trunk/usr.sbin/rpc.lockd/kern.c
===================================================================
--- trunk/usr.sbin/rpc.lockd/kern.c 2018-06-03 22:52:56 UTC (rev 10348)
+++ trunk/usr.sbin/rpc.lockd/kern.c 2018-06-03 22:53:45 UTC (rev 10349)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved.
*
@@ -29,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/rpc.lockd/kern.c 235822 2012-05-23 06:49:50Z delphij $");
#include <sys/param.h>
#include <sys/mount.h>
@@ -167,7 +168,7 @@
goto err;
}
daemon_uid = pw->pw_uid;
- /* drop our root priviledges */
+ /* drop our root privileges */
(void)lockd_seteuid(daemon_uid);
for (;;) {
@@ -595,7 +596,7 @@
syslog(LOG_DEBUG, "fh_len %d, fh %s\n", (int)mp->lm_fh_len, buf);
/* Show flock structure. */
- syslog(LOG_DEBUG, "start %qu; len %qu; pid %lu; type %d; whence %d\n",
+ syslog(LOG_DEBUG, "start %llu; len %llu; pid %lu; type %d; whence %d\n",
(unsigned long long)mp->lm_fl.l_start,
(unsigned long long)mp->lm_fl.l_len, (u_long)mp->lm_fl.l_pid,
mp->lm_fl.l_type, mp->lm_fl.l_whence);
Modified: trunk/usr.sbin/rpc.lockd/lock_proc.c
===================================================================
--- trunk/usr.sbin/rpc.lockd/lock_proc.c 2018-06-03 22:52:56 UTC (rev 10348)
+++ trunk/usr.sbin/rpc.lockd/lock_proc.c 2018-06-03 22:53:45 UTC (rev 10349)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
/* $NetBSD: lock_proc.c,v 1.7 2000/10/11 20:23:56 is Exp $ */
-/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rpc.lockd/lock_proc.c 320587 2017-07-03 05:30:31Z delphij $ */
/*
* Copyright (c) 1995
* A.R. Gordon (andrew.gordon at net-tel.co.uk). All rights reserved.
@@ -115,7 +116,7 @@
}
/* Prevent the security hazard from the buffer overflow */
maxlen = (obj->n_len < MAX_NETOBJ_SZ ? obj->n_len : MAX_NETOBJ_SZ);
- for (i=0, tmp1 = objvalbuffer, tmp2 = objascbuffer; i < obj->n_len;
+ for (i=0, tmp1 = objvalbuffer, tmp2 = objascbuffer; i < maxlen;
i++, tmp1 +=2, tmp2 +=1) {
sprintf(tmp1,"%02X",*(obj->n_bytes+i));
sprintf(tmp2,"%c",*(obj->n_bytes+i));
@@ -283,7 +284,10 @@
/* Regain root privileges, for bindresvport. */
old_euid = geteuid();
- seteuid(0);
+ if (seteuid(0) != 0) {
+ syslog(LOG_ERR, "seteuid(0) failed");
+ return NULL;
+ }
/*
* Bind the client FD to a reserved port.
@@ -292,7 +296,10 @@
bindresvport(clnt_fd, NULL);
/* Drop root privileges again. */
- seteuid(old_euid);
+ if (seteuid(old_euid) != 0) {
+ syslog(LOG_ERR, "seteuid(%d) failed", old_euid);
+ return NULL;
+ }
/* Success - update the cache entry */
clnt_cache_ptr[clnt_cache_next_to_use] = client;
Modified: trunk/usr.sbin/rpc.lockd/lockd.c
===================================================================
--- trunk/usr.sbin/rpc.lockd/lockd.c 2018-06-03 22:52:56 UTC (rev 10348)
+++ trunk/usr.sbin/rpc.lockd/lockd.c 2018-06-03 22:53:45 UTC (rev 10349)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
/* $NetBSD: lockd.c,v 1.7 2000/08/12 18:08:44 thorpej Exp $ */
-/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rpc.lockd/lockd.c 320303 2017-06-24 07:44:05Z delphij $ */
/*
* Copyright (c) 1995
@@ -99,13 +100,12 @@
static int create_service(struct netconfig *nconf);
static void complete_service(struct netconfig *nconf, char *port_str);
static void clearout_service(void);
-void lookup_addresses(struct netconfig *nconf);
+static void out_of_mem(void) __dead2;
void init_nsm(void);
void nlm_prog_0(struct svc_req *, SVCXPRT *);
void nlm_prog_1(struct svc_req *, SVCXPRT *);
void nlm_prog_3(struct svc_req *, SVCXPRT *);
void nlm_prog_4(struct svc_req *, SVCXPRT *);
-void out_of_mem(void);
void usage(void);
void sigalarm_handler(void);
@@ -148,7 +148,6 @@
break;
case 'h':
++nhosts;
- hosts_bak = hosts;
hosts_bak = realloc(hosts, nhosts * sizeof(char *));
if (hosts_bak == NULL) {
if (hosts != NULL) {
@@ -176,7 +175,6 @@
svcport_str = strdup(optarg);
break;
default:
- case '?':
usage();
/* NOTREACHED */
}
@@ -231,7 +229,6 @@
hosts[0] = "*";
nhosts = 1;
} else {
- hosts_bak = hosts;
if (have_v6) {
hosts_bak = realloc(hosts, (nhosts + 2) *
sizeof(char *));
@@ -313,7 +310,7 @@
if (have_v6 == 0 && strcmp(nconf->nc_protofmly, "inet6") == 0) {
/* DO NOTHING */
} else {
- lookup_addresses(nconf);
+ create_service(nconf);
}
}
}
@@ -486,9 +483,14 @@
/*
* This routine creates and binds sockets on the appropriate
- * addresses. It gets called one time for each transport.
+ * addresses if lockd for user NLM, or perform a lookup of
+ * addresses for the kernel to create transports.
+ *
+ * It gets called one time for each transport.
+ *
* It returns 0 upon success, 1 for ingore the call and -1 to indicate
* bind failed with EADDRINUSE.
+ *
* Any file descriptors that have been created are stored in sock_fd and
* the total count of them is maintained in sock_fdcnt.
*/
@@ -522,7 +524,6 @@
/* Get rpc.statd's address on this transport */
memset(&hints, 0, sizeof hints);
- hints.ai_flags = AI_PASSIVE;
hints.ai_family = si.si_af;
hints.ai_socktype = si.si_socktype;
hints.ai_protocol = si.si_proto;
@@ -533,19 +534,23 @@
nhostsbak = nhosts;
while (nhostsbak > 0) {
--nhostsbak;
- sock_fd = realloc(sock_fd, (sock_fdcnt + 1) * sizeof(int));
- if (sock_fd == NULL)
- out_of_mem();
- sock_fd[sock_fdcnt++] = -1; /* Set invalid for now. */
mallocd_res = 0;
+ hints.ai_flags = AI_PASSIVE;
- /*
- * XXX - using RPC library internal functions.
- */
- if ((fd = __rpc_nconf2fd(nconf)) < 0) {
- syslog(LOG_ERR, "cannot create socket for %s",
- nconf->nc_netid);
- continue;
+ if (!kernel_lockd) {
+ sock_fd = realloc(sock_fd, (sock_fdcnt + 1) * sizeof(int));
+ if (sock_fd == NULL)
+ out_of_mem();
+ sock_fd[sock_fdcnt++] = -1; /* Set invalid for now. */
+
+ /*
+ * XXX - using RPC library internal functions.
+ */
+ if ((fd = __rpc_nconf2fd(nconf)) < 0) {
+ syslog(LOG_ERR, "cannot create socket for %s",
+ nconf->nc_netid);
+ continue;
+ }
}
switch (hints.ai_family) {
@@ -559,7 +564,8 @@
*/
if (inet_pton(AF_INET6, hosts[nhostsbak],
host_addr) == 1) {
- close(fd);
+ if (!kernel_lockd)
+ close(fd);
continue;
}
}
@@ -574,7 +580,8 @@
*/
if (inet_pton(AF_INET, hosts[nhostsbak],
host_addr) == 1) {
- close(fd);
+ if (!kernel_lockd)
+ close(fd);
continue;
}
}
@@ -588,8 +595,7 @@
*/
if (strcmp("*", hosts[nhostsbak]) == 0) {
if (svcport_str == NULL) {
- res = malloc(sizeof(struct addrinfo));
- if (res == NULL)
+ if ((res = malloc(sizeof(struct addrinfo))) == NULL)
out_of_mem();
mallocd_res = 1;
res->ai_flags = hints.ai_flags;
@@ -620,7 +626,7 @@
break;
default:
syslog(LOG_ERR,
- "bad addr fam %d",
+ "bad address family %d",
res->ai_family);
exit(1);
}
@@ -631,7 +637,8 @@
"cannot get local address for %s: %s",
nconf->nc_netid,
gai_strerror(aicode));
- close(fd);
+ if (!kernel_lockd)
+ close(fd);
continue;
}
}
@@ -641,42 +648,62 @@
syslog(LOG_ERR,
"cannot get local address for %s: %s",
nconf->nc_netid, gai_strerror(aicode));
- close(fd);
+ if (!kernel_lockd)
+ close(fd);
continue;
}
}
+ if (kernel_lockd) {
+ struct netbuf servaddr;
+ char *uaddr;
- /* Store the fd. */
- sock_fd[sock_fdcnt - 1] = fd;
+ /*
+ * Look up addresses for the kernel to create transports for.
+ */
+ servaddr.len = servaddr.maxlen = res->ai_addrlen;
+ servaddr.buf = res->ai_addr;
+ uaddr = taddr2uaddr(nconf, &servaddr);
- /* Now, attempt the bind. */
- r = bindresvport_sa(fd, res->ai_addr);
- if (r != 0) {
- if (errno == EADDRINUSE && mallocd_svcport != 0) {
- if (mallocd_res != 0) {
- free(res->ai_addr);
- free(res);
- } else
- freeaddrinfo(res);
- return (-1);
+ addrs = realloc(addrs, 2 * (naddrs + 1) * sizeof(char *));
+ if (!addrs)
+ out_of_mem();
+ addrs[2 * naddrs] = strdup(nconf->nc_netid);
+ addrs[2 * naddrs + 1] = uaddr;
+ naddrs++;
+ } else {
+ /* Store the fd. */
+ sock_fd[sock_fdcnt - 1] = fd;
+
+ /* Now, attempt the bind. */
+ r = bindresvport_sa(fd, res->ai_addr);
+ if (r != 0) {
+ if (errno == EADDRINUSE && mallocd_svcport != 0) {
+ if (mallocd_res != 0) {
+ free(res->ai_addr);
+ free(res);
+ } else
+ freeaddrinfo(res);
+ return (-1);
+ }
+ syslog(LOG_ERR, "bindresvport_sa: %m");
+ exit(1);
}
- syslog(LOG_ERR, "bindresvport_sa: %m");
- exit(1);
- }
- if (svcport_str == NULL) {
- svcport_str = malloc(NI_MAXSERV * sizeof(char));
- if (svcport_str == NULL)
- out_of_mem();
- mallocd_svcport = 1;
+ if (svcport_str == NULL) {
+ svcport_str = malloc(NI_MAXSERV * sizeof(char));
+ if (svcport_str == NULL)
+ out_of_mem();
+ mallocd_svcport = 1;
- if (getnameinfo(res->ai_addr,
- res->ai_addr->sa_len, NULL, NI_MAXHOST,
- svcport_str, NI_MAXSERV * sizeof(char),
- NI_NUMERICHOST | NI_NUMERICSERV))
- errx(1, "Cannot get port number");
+ if (getnameinfo(res->ai_addr,
+ res->ai_addr->sa_len, NULL, NI_MAXHOST,
+ svcport_str, NI_MAXSERV * sizeof(char),
+ NI_NUMERICHOST | NI_NUMERICSERV))
+ errx(1, "Cannot get port number");
+ }
}
+
if (mallocd_res != 0) {
free(res->ai_addr);
free(res);
@@ -809,153 +836,7 @@
}
}
-/*
- * Look up addresses for the kernel to create transports for.
- */
void
-lookup_addresses(struct netconfig *nconf)
-{
- struct addrinfo hints, *res = NULL;
- struct sockaddr_in *sin;
- struct sockaddr_in6 *sin6;
- struct __rpc_sockinfo si;
- struct netbuf servaddr;
- int aicode;
- int nhostsbak;
- u_int32_t host_addr[4]; /* IPv4 or IPv6 */
- char *uaddr;
-
- if ((nconf->nc_semantics != NC_TPI_CLTS) &&
- (nconf->nc_semantics != NC_TPI_COTS) &&
- (nconf->nc_semantics != NC_TPI_COTS_ORD))
- return; /* not my type */
-
- /*
- * XXX - using RPC library internal functions.
- */
- if (!__rpc_nconf2sockinfo(nconf, &si)) {
- syslog(LOG_ERR, "cannot get information for %s",
- nconf->nc_netid);
- return;
- }
-
- /* Get rpc.statd's address on this transport */
- memset(&hints, 0, sizeof hints);
- hints.ai_flags = AI_PASSIVE;
- hints.ai_family = si.si_af;
- hints.ai_socktype = si.si_socktype;
- hints.ai_protocol = si.si_proto;
-
- /*
- * Bind to specific IPs if asked to
- */
- nhostsbak = nhosts;
- while (nhostsbak > 0) {
- --nhostsbak;
-
- switch (hints.ai_family) {
- case AF_INET:
- if (inet_pton(AF_INET, hosts[nhostsbak],
- host_addr) == 1) {
- hints.ai_flags &= AI_NUMERICHOST;
- } else {
- /*
- * Skip if we have an AF_INET6 address.
- */
- if (inet_pton(AF_INET6, hosts[nhostsbak],
- host_addr) == 1) {
- continue;
- }
- }
- break;
- case AF_INET6:
- if (inet_pton(AF_INET6, hosts[nhostsbak],
- host_addr) == 1) {
- hints.ai_flags &= AI_NUMERICHOST;
- } else {
- /*
- * Skip if we have an AF_INET address.
- */
- if (inet_pton(AF_INET, hosts[nhostsbak],
- host_addr) == 1) {
- continue;
- }
- }
- break;
- default:
- break;
- }
-
- /*
- * If no hosts were specified, just bind to INADDR_ANY
- */
- if (strcmp("*", hosts[nhostsbak]) == 0) {
- if (svcport_str == NULL) {
- res = malloc(sizeof(struct addrinfo));
- if (res == NULL)
- out_of_mem();
- res->ai_flags = hints.ai_flags;
- res->ai_family = hints.ai_family;
- res->ai_protocol = hints.ai_protocol;
- switch (res->ai_family) {
- case AF_INET:
- sin = malloc(sizeof(struct sockaddr_in));
- if (sin == NULL)
- out_of_mem();
- sin->sin_family = AF_INET;
- sin->sin_port = htons(0);
- sin->sin_addr.s_addr = htonl(INADDR_ANY);
- res->ai_addr = (struct sockaddr*) sin;
- res->ai_addrlen = (socklen_t)
- sizeof(res->ai_addr);
- break;
- case AF_INET6:
- sin6 = malloc(sizeof(struct sockaddr_in6));
- if (sin6 == NULL)
- out_of_mem();
- sin6->sin6_family = AF_INET6;
- sin6->sin6_port = htons(0);
- sin6->sin6_addr = in6addr_any;
- res->ai_addr = (struct sockaddr*) sin6;
- res->ai_addrlen = (socklen_t) sizeof(res->ai_addr);
- break;
- default:
- break;
- }
- } else {
- if ((aicode = getaddrinfo(NULL, svcport_str,
- &hints, &res)) != 0) {
- syslog(LOG_ERR,
- "cannot get local address for %s: %s",
- nconf->nc_netid,
- gai_strerror(aicode));
- continue;
- }
- }
- } else {
- if ((aicode = getaddrinfo(hosts[nhostsbak], svcport_str,
- &hints, &res)) != 0) {
- syslog(LOG_ERR,
- "cannot get local address for %s: %s",
- nconf->nc_netid, gai_strerror(aicode));
- continue;
- }
- }
-
- servaddr.len = servaddr.maxlen = res->ai_addr->sa_len;
- servaddr.buf = res->ai_addr;
- uaddr = taddr2uaddr(nconf, &servaddr);
-
- addrs = realloc(addrs, 2 * (naddrs + 1) * sizeof(char *));
- if (!addrs)
- out_of_mem();
- addrs[2 * naddrs] = strdup(nconf->nc_netid);
- addrs[2 * naddrs + 1] = uaddr;
- naddrs++;
- } /* end while */
-}
-
-void
sigalarm_handler(void)
{
Modified: trunk/usr.sbin/rpc.lockd/lockd.h
===================================================================
--- trunk/usr.sbin/rpc.lockd/lockd.h 2018-06-03 22:52:56 UTC (rev 10348)
+++ trunk/usr.sbin/rpc.lockd/lockd.h 2018-06-03 22:53:45 UTC (rev 10349)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
/* $NetBSD: lockd.h,v 1.2 2000/06/07 14:34:40 bouyer Exp $ */
-/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rpc.lockd/lockd.h 87096 2001-11-29 17:36:45Z alfred $ */
/*
* Copyright (c) 1995
Modified: trunk/usr.sbin/rpc.lockd/lockd_lock.c
===================================================================
--- trunk/usr.sbin/rpc.lockd/lockd_lock.c 2018-06-03 22:52:56 UTC (rev 10348)
+++ trunk/usr.sbin/rpc.lockd/lockd_lock.c 2018-06-03 22:53:45 UTC (rev 10349)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: lockd_lock.c,v 1.5 2000/11/21 03:47:41 enami Exp $ */
/*
@@ -35,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/rpc.lockd/lockd_lock.c 302455 2016-07-08 20:50:44Z ngie $");
#define LOCKD_DEBUG
@@ -69,7 +70,7 @@
* A set of utilities for managing file locking
*
* XXX: All locks are in a linked list, a better structure should be used
- * to improve search/access effeciency.
+ * to improve search/access efficiency.
*/
/* struct describing a lock */
@@ -98,7 +99,7 @@
#define LKST_LOCKED 1 /* lock is locked */
/* XXX: Is this flag file specific or lock specific? */
#define LKST_WAITING 2 /* file is already locked by another host */
-#define LKST_PROCESSING 3 /* child is trying to aquire the lock */
+#define LKST_PROCESSING 3 /* child is trying to acquire the lock */
#define LKST_DYING 4 /* must dies when we get news from the child */
/* struct describing a monitored host */
@@ -494,8 +495,6 @@
} else {
return 1;
}
-
- return (result);
}
/*
@@ -1428,6 +1427,7 @@
break;
case NFS_RESERR:
retval = PFL_NFSRESERR;
+ break;
default:
debuglog("Unmatched lnlstatus %d\n");
retval = PFL_NFSDENIED_NOLOCK;
@@ -1602,6 +1602,7 @@
*/
deallocate_file_lock(releasedfl);
+ releasedfl = NULL;
}
}
@@ -1917,7 +1918,7 @@
}
/*
- * getlock: try to aquire the lock.
+ * getlock: try to acquire the lock.
* If file is already locked and we can sleep, put the lock in the list with
* status LKST_WAITING; it'll be processed later.
* Otherwise try to lock. If we're allowed to block, fork a child which
@@ -1947,7 +1948,7 @@
}
if (lckarg->alock.fh.n_len != sizeof(fhandle_t)) {
- debuglog("recieved fhandle size %d, local size %d",
+ debuglog("received fhandle size %d, local size %d",
lckarg->alock.fh.n_len, (int)sizeof(fhandle_t));
}
More information about the Midnightbsd-cvs
mailing list