Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/user Handle multiple ranges on the command line and...



details:   https://anonhg.NetBSD.org/src/rev/5843e41736c1
branches:  trunk
changeset: 526427:5843e41736c1
user:      agc <agc%NetBSD.org@localhost>
date:      Fri May 03 10:31:14 2002 +0000

description:
Handle multiple ranges on the command line and in the defaults file,
based on some code from Todd C.  Miller, which in turn was based on a
patch from Brian Poole <raj%cerias.purdue.edu@localhost>.

Look first in any uid ranges specified on the command line, in the order
they were given on the command line, and then in any ranges specified in
the defaults file.

With thanks to Brian for nudging me a number of times to fix this.

diffstat:

 usr.sbin/user/user.c |  30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)

diffs (52 lines):

diff -r 2af93160fa02 -r 5843e41736c1 usr.sbin/user/user.c
--- a/usr.sbin/user/user.c      Fri May 03 10:11:16 2002 +0000
+++ b/usr.sbin/user/user.c      Fri May 03 10:31:14 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: user.c,v 1.50 2002/05/03 10:11:16 agc Exp $ */
+/* $NetBSD: user.c,v 1.51 2002/05/03 10:31:14 agc Exp $ */
 
 /*
  * Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
@@ -35,7 +35,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1999 \
                The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: user.c,v 1.50 2002/05/03 10:11:16 agc Exp $");
+__RCSID("$NetBSD: user.c,v 1.51 2002/05/03 10:31:14 agc Exp $");
 #endif
 
 #include <sys/types.h>
@@ -903,14 +903,26 @@
        /* if no uid was specified, get next one in [low_uid..high_uid] range */
        sync_uid_gid = (strcmp(up->u_primgrp, "=uid") == 0);
        if (up->u_uid == -1) {
-               /* default is in index '0' in u_rv array */
-               for (i = 1 ; i < up->u_rc ; i++) {
-                       if (getnextuid(sync_uid_gid, &up->u_uid, up->u_rv[i].r_from, up->u_rv[i].r_to)) {
-                               break;
-                       }
+               int     got_id = 0;
+
+               /*
+                * Look for a free UID in the command line ranges (if any).
+                * These start after the ranges specified in the config file.
+                */
+               for (i = up->u_defrc; !got_id && i < up->u_rc ; i++) {
+                       got_id = getnextuid(sync_uid_gid, &up->u_uid,
+                                       up->u_rv[i].r_from, up->u_rv[i].r_to);
                }
-               if (i == up->u_rc &&
-                   !getnextuid(sync_uid_gid, &up->u_uid, up->u_rv[0].r_from, up->u_rv[0].r_to)) {
+               /*
+                * If there were no free UIDs in the command line ranges,
+                * try the ranges from the config file (there will always
+                * be at least one default).
+                */
+               for (i = 0; !got_id && i < up->u_defrc; i++) {
+                       got_id = getnextuid(sync_uid_gid, &up->u_uid,
+                                       up->u_rv[i].r_from, up->u_rv[i].r_to);
+               }
+               if (!got_id) {
                        (void) close(ptmpfd);
                        (void) pw_abort();
                        errx(EXIT_FAILURE, "can't get next uid for %d", up->u_uid);



Home | Main Index | Thread Index | Old Index