Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/user Add new functionality, and fix some bugs and o...



details:   https://anonhg.NetBSD.org/src/rev/82af12f301dd
branches:  trunk
changeset: 479875:82af12f301dd
user:      agc <agc%NetBSD.org@localhost>
date:      Fri Dec 24 09:08:48 1999 +0000

description:
Add new functionality, and fix some bugs and oversights:

+ Moved all internal definitions from usermgmt.h to user.c
+ Added prototypes to usermgmt.h
+ Allow defaults to be set at build time
+ Check the effective uid is 0 if any data is to be modified
+ Check all numeric uids and gids really are numeric
+ Fix a bug (reported by lenb at sasquatch.com) where new ranges were
appended to old ranges, rather than replacing them
+ Add userinfo(8) and groupinfo(8) utilities (if EXTENSIONS is
defined), whereby user and group information can be displayed.  Add
manual pages for new utilities.  Add front-end calling from user(8)
and group(8) accordingly.
+ Make all functions visible outside the user.c file again.  User and
group manipulation may be split out into a separate shared lib in the
future
+ Split off main function into a separate main.c
+ Changed default group to be "users"
+ Changed despatch table for commands to work in a more sane manner
+ Added "default-group" target to Makefile, so that the default group
can be made easily.

diffstat:

 usr.sbin/user/Makefile    |   53 ++++-
 usr.sbin/user/defs.h      |    2 +-
 usr.sbin/user/group.8     |    9 +-
 usr.sbin/user/groupadd.8  |    2 +-
 usr.sbin/user/groupdel.8  |    2 +-
 usr.sbin/user/groupinfo.8 |   81 ++++++++
 usr.sbin/user/groupmod.8  |    4 +-
 usr.sbin/user/main.c      |  104 ++++++++++
 usr.sbin/user/user.8      |    9 +-
 usr.sbin/user/user.c      |  459 +++++++++++++++++++++++++++++++++++----------
 usr.sbin/user/useradd.8   |    2 +-
 usr.sbin/user/userdel.8   |    2 +-
 usr.sbin/user/userinfo.8  |   81 ++++++++
 usr.sbin/user/usermgmt.h  |   89 +-------
 usr.sbin/user/usermod.8   |    4 +-
 15 files changed, 705 insertions(+), 198 deletions(-)

diffs (truncated from 1335 to 300 lines):

diff -r ed249e6f684e -r 82af12f301dd usr.sbin/user/Makefile
--- a/usr.sbin/user/Makefile    Fri Dec 24 08:32:58 1999 +0000
+++ b/usr.sbin/user/Makefile    Fri Dec 24 09:08:48 1999 +0000
@@ -1,13 +1,15 @@
-# $NetBSD: Makefile,v 1.5 1999/12/08 00:01:36 soren Exp $
+# $NetBSD: Makefile,v 1.6 1999/12/24 09:08:48 agc Exp $
 #
 .include <bsd.own.mk>
 
 CPPFLAGS+= -DEXTENSIONS
+WARNS= 1
 
 SKEL_DIR=      /etc/skel
 EXAMPLE_DIR=   ${DESTDIR}/usr/share/examples/usermgmt
 
 PROG= user
+SRCS+= user.c main.c
 LINKS+=        ${BINDIR}/user ${BINDIR}/useradd
 LINKS+=        ${BINDIR}/user ${BINDIR}/userdel
 LINKS+=        ${BINDIR}/user ${BINDIR}/usermod
@@ -15,9 +17,12 @@
 LINKS+=        ${BINDIR}/user ${BINDIR}/groupadd
 LINKS+=        ${BINDIR}/user ${BINDIR}/groupdel
 LINKS+=        ${BINDIR}/user ${BINDIR}/groupmod
+LINKS+=        ${BINDIR}/user ${BINDIR}/userinfo
+LINKS+=        ${BINDIR}/user ${BINDIR}/groupinfo
 LDADD+= -lutil 
 DPADD+= ${LIBUTIL}
-MAN= user.8 useradd.8 userdel.8 usermod.8 group.8 groupadd.8 groupdel.8 groupmod.8
+MAN= user.8 useradd.8 userdel.8 usermod.8 userinfo.8
+MAN+= group.8 groupadd.8 groupdel.8 groupmod.8 groupinfo.8
 MLINKS=        useradd.8 adduser.8
 
 .if ${MKSHARE} != "no"
@@ -28,18 +33,56 @@
 FILESDIR=              /usr/share/examples/usermgmt
 .endif
 
+# this target checks the built-in default group, and, if it doesn't exist,
+# creates it
+default-group:
+       @ln -fs ${.OBJDIR}/user ${.OBJDIR}/group;                       \
+       defgrp=`${.OBJDIR}/user add -D | awk '/^group/ { print $$2 }'`; \
+       if ${.OBJDIR}/group info -e $$defgrp; then                      \
+               defgid=`${.OBJDIR}/group info $$defgrp | awk '/^gid/ { print $$2 }'`; \
+       else                                                            \
+               defgid=99;                                              \
+               while [ $$defgid -gt 0 ]; do                            \
+                       ${.OBJDIR}/group info -e $$defgid || break;     \
+                       defgid=`expr $$defgid - 1`;                     \
+               done;                                                   \
+               if [ $$defgid -eq 0 ]; then                             \
+                       defgid=100;                                     \
+                       while [ $$defgid -lt 60000 ]; do                \
+                               ${.OBJDIR}/group info -e $$defgid || break; \
+                               defgid=`expr $$defgid + 1`;             \
+                       done;                                           \
+                       if [ $$defgid -eq 60000 ]; then                 \
+                               echo "No gids left";                    \
+                               exit 1;                                 \
+                       fi;                                             \
+               fi;                                                     \
+               ${.OBJDIR}/group add -g $$defgid $$defgrp;              \
+       fi;                                                             \
+       echo "Default group is $$defgrp ($$defgid):";                   \
+       ${.OBJDIR}/group info $$defgrp
+
 .include <bsd.prog.mk>
 
 test: ${PROG}
        @echo "No news is good news"
        @echo "1. Adding new user"
-       ./${PROG} add -m -g=uid test1.1
+       @rm -f useradd
+       @ln -s user useradd
+       -./useradd -m -g=uid test1.1
        @echo "2. Modifying new user"
-       ./${PROG} mod -l test1.2 test1.1
+       -./${PROG} mod -l test1.2 test1.1
        @echo "3. Deleting new user"
-       ./${PROG} del -r test1.2
+       -./${PROG} del -r test1.2
        @echo "4. Attempting to add an invalid user name - IGNORE ANY ERROR"
        -./${PROG} add -m test1%1
        @echo "5. Bad usage - IGNORE ANY ERROR"
        -./${PROG} add -m
+       @echo "6. Set range defaults"
+       -./${PROG} add -D -r4000..6000
+       -./${PROG} add -D
+       @echo "7. Get user information"
+       -./${PROG} info root
+       @echo "8. Bad user name - IGNORE ANY ERROR"
+       -./${PROG} info test1%1 || echo "User not found"
        @echo "All tests completed"
diff -r ed249e6f684e -r 82af12f301dd usr.sbin/user/defs.h
--- a/usr.sbin/user/defs.h      Fri Dec 24 08:32:58 1999 +0000
+++ b/usr.sbin/user/defs.h      Fri Dec 24 09:08:48 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.4 1999/12/07 10:37:57 lukem Exp $ */
+/* $NetBSD: defs.h,v 1.5 1999/12/24 09:08:49 agc Exp $ */
 
 /*
  * Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
diff -r ed249e6f684e -r 82af12f301dd usr.sbin/user/group.8
--- a/usr.sbin/user/group.8     Fri Dec 24 08:32:58 1999 +0000
+++ b/usr.sbin/user/group.8     Fri Dec 24 09:08:48 1999 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: group.8,v 1.2 1999/12/07 10:14:02 lukem Exp $ */
+.\" $NetBSD: group.8,v 1.3 1999/12/24 09:08:49 agc Exp $ */
 .\"
 .\"
 .\" Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
@@ -49,6 +49,11 @@
 .Op Fl v
 group
 .Nm ""
+info
+.Op Fl e
+.Op Fl v
+group
+.Nm ""
 mod
 .Op Fl g Ar gid
 .Op Fl n Ar newname
@@ -61,6 +66,7 @@
 utility acts as a frontend to the
 .Xr groupadd 8 ,
 .Xr groupmod 8 ,
+.Xr groupinfo 8 ,
 and
 .Xr groupdel 8
 commands.
@@ -86,4 +92,5 @@
 .Xr group 5 ,
 .Xr groupadd 8 ,
 .Xr groupdel 8 ,
+.Xr groupinfo 8 ,
 .Xr groupmod 8 .
diff -r ed249e6f684e -r 82af12f301dd usr.sbin/user/groupadd.8
--- a/usr.sbin/user/groupadd.8  Fri Dec 24 08:32:58 1999 +0000
+++ b/usr.sbin/user/groupadd.8  Fri Dec 24 09:08:48 1999 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: groupadd.8,v 1.2 1999/12/07 10:14:02 lukem Exp $ */
+.\" $NetBSD: groupadd.8,v 1.3 1999/12/24 09:08:49 agc Exp $ */
 .\"
 .\"
 .\" Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
diff -r ed249e6f684e -r 82af12f301dd usr.sbin/user/groupdel.8
--- a/usr.sbin/user/groupdel.8  Fri Dec 24 08:32:58 1999 +0000
+++ b/usr.sbin/user/groupdel.8  Fri Dec 24 09:08:48 1999 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: groupdel.8,v 1.3 1999/12/07 10:14:02 lukem Exp $ */
+.\" $NetBSD: groupdel.8,v 1.4 1999/12/24 09:08:49 agc Exp $ */
 .\"
 .\"
 .\" Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
diff -r ed249e6f684e -r 82af12f301dd usr.sbin/user/groupinfo.8
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/user/groupinfo.8 Fri Dec 24 09:08:48 1999 +0000
@@ -0,0 +1,81 @@
+.\" $NetBSD: groupinfo.8,v 1.1 1999/12/24 09:08:49 agc Exp $ */
+.\"
+.\"
+.\" Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"    This product includes software developed by Alistair G. Crooks.
+.\" 4. The name of the author may not be used to endorse or promote
+.\"    products derived from this software without specific prior written
+.\"    permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+.\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\"
+.Dd November 30, 1999
+.Dt GROUPINFO 8
+.Os NetBSD
+.Sh NAME
+.Nm groupinfo
+.Nd displays group information
+.Sh SYNOPSIS
+.Nm
+.Op Fl e
+.Op Fl v
+group
+.Sh DESCRIPTION
+The
+.Nm
+utility retrieves the group information from the system.
+.Pp
+The following command line options are recognised:
+.Bl -tag -width Ds
+.It Fl e
+return 0 if the group exists, and non-zero if the
+group does not exist, on the system. No information is
+displayed. This form of the command is useful for
+scripts which need to check whether a particular group
+name or gid is already in use on the system.
+.It Fl v
+perform any actions in a verbose manner.
+.El
+.Pp
+The group argument may either be a group's name, or a gid.
+.Pp
+The
+.Nm
+utility exits 0 if the group name or gid exists, and non-zero if it does not.
+.Sh HISTORY
+The
+.Nm
+utility first appeared in
+.Nx 1.5 .
+It is based on the
+.Ar addnerd
+package by the same author.
+.Sh AUTHOR
+The
+.Nm
+utility was written by Alistair G. Crooks (agc%netbsd.org@localhost).
+.Sh SEE ALSO
+.Xr passwd 5 ,
+.Xr /etc/usermgmt.conf
diff -r ed249e6f684e -r 82af12f301dd usr.sbin/user/groupmod.8
--- a/usr.sbin/user/groupmod.8  Fri Dec 24 08:32:58 1999 +0000
+++ b/usr.sbin/user/groupmod.8  Fri Dec 24 09:08:48 1999 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: groupmod.8,v 1.2 1999/12/07 10:14:02 lukem Exp $ */
+.\" $NetBSD: groupmod.8,v 1.3 1999/12/24 09:08:50 agc Exp $ */
 .\"
 .\"
 .\" Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
@@ -52,7 +52,7 @@
 .Bl -tag -width Ds
 .It Fl g Ar gid
 gives the numeric group identifier to be used for the new group.
-.It Fl n Ar new group name
+.It Fl n Ar new-group-name
 gives the new name which the group shall have.
 .It Fl o
 allow the new group to have a gid which is already in use for another group.
diff -r ed249e6f684e -r 82af12f301dd usr.sbin/user/main.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/user/main.c      Fri Dec 24 09:08:48 1999 +0000
@@ -0,0 +1,104 @@
+/* $NetBSD: main.c,v 1.1 1999/12/24 09:08:50 agc Exp $ */
+
+/*
+ * Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by Alistair G. Crooks.
+ * 4. The name of the author may not be used to endorse or promote
+ *    products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>



Home | Main Index | Thread Index | Old Index