/var/run/ypbind.lock doesn't need to be created with an advisory lock anymore,
authorderaadt <deraadt@openbsd.org>
Sun, 17 Jul 2022 03:12:20 +0000 (03:12 +0000)
committerderaadt <deraadt@openbsd.org>
Sun, 17 Jul 2022 03:12:20 +0000 (03:12 +0000)
because libc & pledge() doesn't care.
libc now calls ypconnect(), which still cares about the advisory lock on
/var/yp/bindings/$domain.2, so that code remains.
ok jmatthew miod

usr.sbin/ypbind/ypbind.c

index fae94ff..fba44ef 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ypbind.c,v 1.75 2022/07/15 16:59:49 deraadt Exp $ */
+/*     $OpenBSD: ypbind.c,v 1.76 2022/07/17 03:12:20 deraadt Exp $ */
 
 /*
  * Copyright (c) 1992, 1993, 1996, 1997, 1998 Theo de Raadt <deraadt@openbsd.org>
@@ -58,7 +58,6 @@
 
 #define SERVERSDIR     "/etc/yp"
 #define BINDINGDIR     "/var/yp/binding"
-#define YPBINDLOCK     "/var/run/ypbind.lock"
 
 struct _dom_binding {
        struct _dom_binding *dom_pnext;
@@ -339,7 +338,7 @@ main(int argc, char *argv[])
        char path[PATH_MAX];
        struct sockaddr_in sin;
        struct pollfd *pfd = NULL;
-       int width = 0, nready, lockfd, lsock;
+       int width = 0, nready, lsock;
        socklen_t len;
        int evil = 0, one = 1;
        DIR *dirp;
@@ -377,23 +376,6 @@ main(int argc, char *argv[])
                (void)mkdir(BINDINGDIR, 0755);
        }
 
-#ifdef O_SHLOCK
-       if ((lockfd = open(YPBINDLOCK, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC,
-           0644)) == -1) {
-               fprintf(stderr, "ypbind: cannot create %s\n", YPBINDLOCK);
-               exit(1);
-       }
-#else
-       if ((lockfd = open(YPBINDLOCK, O_CREAT|O_RDWR|O_TRUNC, 0644)) == -1) {
-               fprintf(stderr, "ypbind: cannot create %s.\n", YPBINDLOCK);
-               exit(1);
-       }
-       flock(lockfd, LOCK_SH);
-#endif
-
-       if (fchmod(lockfd, 0644) == -1)
-               err(1, "fchmod");
-
        (void)pmap_unset(YPBINDPROG, YPBINDVERS);
 
        udptransp = svcudp_create(RPC_ANYSOCK);
@@ -1036,24 +1018,12 @@ rpc_received(char *dom, struct sockaddr_in *raddrp, int force)
 
        snprintf(path, sizeof path, "%s/%s.%d", BINDINGDIR,
            ypdb->dom_domain, (int)ypdb->dom_vers);
-#ifdef O_SHLOCK
        if ((fd = open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644)) == -1) {
                (void)mkdir(BINDINGDIR, 0755);
                if ((fd = open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC,
                    0644)) == -1)
                        return;
        }
-#else
-       if ((fd = open(path, O_CREAT|O_RDWR|O_TRUNC, 0644)) == -1) {
-               (void)mkdir(BINDINGDIR, 0755);
-               if ((fd = open(path, O_CREAT|O_RDWR|O_TRUNC, 0644)) == -1)
-                       return;
-       }
-       flock(fd, LOCK_SH);
-#endif
-
-       if (fchmod(fd, 0644) == -1)
-               err(1, "fchmod");
 
        /*
         * ok, if BINDINGDIR exists, and we can create the binding file,