Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Jan 2003 23:27:34 -0500
From:      Mike Makonnen <mtm@identd.net>
To:        Max Khon <fjoe@iclub.nsu.ru>
Cc:        rodrigc@attbi.com, freebsd-current@FreeBSD.org
Subject:   Re: pw
Message-ID:  <20030124042738.RNFU23484.out001.verizon.net@kokeb.ambesa.net>
In-Reply-To: <20030124030942.A37794@iclub.nsu.ru>
References:  <20030124022538.C36624@iclub.nsu.ru> <20030123205418.GA41199@attbi.com> <20030124030942.A37794@iclub.nsu.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
--Ydkc,)x78G(=.n)g
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

Attached is Terry's patch modified to include $ in group names as well. I have
tested it.  Both adduser(8) and rmuser(8) work as expected. Please give -audit a
chance to object and then commit it. Also, please close PR: bin/46890 when you
do.

We should have had this a long time ago. If -audit doesn't object I say go for
it!

Cheers.
-- 
Mike Makonnen  | GPG-KEY: http://www.identd.net/~mtm/mtm.asc
mtm@identd.net | Fingerprint: D228 1A6F C64E 120A A1C9  A3AA DAE1 E2AF DBCC 68B9

Index: usr.sbin/pw/pw.h
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pw/pw.h,v
retrieving revision 1.13
diff -u -r1.13 pw.h
--- usr.sbin/pw/pw.h	5 Jul 2001 08:01:15 -0000	1.13
+++ usr.sbin/pw/pw.h	24 Jan 2003 03:16:41 -0000
@@ -62,6 +62,13 @@
         W_NUM
 };
 
+enum _checktype
+{
+	PWC_DEFAULT,
+	PWC_GECOS,
+	PWC_LOGIN
+};
+
 struct carg
 {
 	int		  ch;
@@ -105,7 +112,7 @@
 
 int pw_user(struct userconf * cnf, int mode, struct cargs * _args);
 int pw_group(struct userconf * cnf, int mode, struct cargs * _args);
-char    *pw_checkname(u_char *name, int gecos);
+char    *pw_checkname(u_char *name, enum _checktype checktype);
 
 int addpwent(struct passwd * pwd);
 int delpwent(struct passwd * pwd);
Index: usr.sbin/pw/pw_group.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pw/pw_group.c,v
retrieving revision 1.13
diff -u -r1.13 pw_group.c
--- usr.sbin/pw/pw_group.c	22 Jun 2000 16:48:41 -0000	1.13
+++ usr.sbin/pw/pw_group.c	24 Jan 2003 03:59:07 -0000
@@ -135,7 +135,7 @@
 			grp->gr_gid = (gid_t) atoi(a_gid->val);
 
 		if ((arg = getarg(args, 'l')) != NULL)
-			grp->gr_name = pw_checkname((u_char *)arg->val, 0);
+			grp->gr_name = pw_checkname((u_char *)arg->val, PWC_LOGIN);
 	} else {
 		if (a_name == NULL)	/* Required */
 			errx(EX_DATAERR, "group name required");
@@ -145,7 +145,7 @@
 		extendarray(&members, &grmembers, 200);
 		members[0] = NULL;
 		grp = &fakegroup;
-		grp->gr_name = pw_checkname((u_char *)a_name->val, 0);
+		grp->gr_name = pw_checkname((u_char *)a_name->val, PWC_LOGIN);
 		grp->gr_passwd = "*";
 		grp->gr_gid = gr_gidpolicy(cnf, args);
 		grp->gr_mem = members;
Index: usr.sbin/pw/pw_user.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pw/pw_user.c,v
retrieving revision 1.51
diff -u -r1.51 pw_user.c
--- usr.sbin/pw/pw_user.c	24 Jun 2002 11:33:17 -0000	1.51
+++ usr.sbin/pw/pw_user.c	24 Jan 2003 03:48:44 -0000
@@ -231,7 +231,7 @@
 		}
 	}
 	if ((arg = getarg(args, 'L')) != NULL)
-		cnf->default_class = pw_checkname((u_char *)arg->val, 0);
+		cnf->default_class = pw_checkname((u_char *)arg->val, PWC_DEFAULT);
 
 	if ((arg = getarg(args, 'G')) != NULL && arg->val) {
 		int i = 0;
@@ -293,7 +293,7 @@
 	}
 
 	if ((a_name = getarg(args, 'n')) != NULL)
-		pwd = GETPWNAM(pw_checkname((u_char *)a_name->val, 0));
+		pwd = GETPWNAM(pw_checkname((u_char *)a_name->val, PWC_LOGIN));
 	a_uid = getarg(args, 'u');
 
 	if (a_uid == NULL) {
@@ -455,7 +455,7 @@
 		if ((arg = getarg(args, 'l')) != NULL) {
 			if (strcmp(pwd->pw_name, "root") == 0)
 				errx(EX_DATAERR, "can't rename `root' account");
-			pwd->pw_name = pw_checkname((u_char *)arg->val, 0);
+			pwd->pw_name = pw_checkname((u_char *)arg->val, PWC_LOGIN);
 			edited = 1;
 		}
 
@@ -595,7 +595,7 @@
 	 * Shared add/edit code
 	 */
 	if ((arg = getarg(args, 'c')) != NULL) {
-		char	*gecos = pw_checkname((u_char *)arg->val, 1);
+		char	*gecos = pw_checkname((u_char *)arg->val, PWC_GECOS);
 		if (strcmp(pwd->pw_gecos, gecos) != 0) {
 			pwd->pw_gecos = gecos;
 			edited = 1;
@@ -1192,10 +1192,26 @@
 }
 
 char    *
-pw_checkname(u_char *name, int gecos)
+pw_checkname(u_char *name, enum _checktype checktype)
 {
 	int             l = 0;
-	char const     *notch = gecos ? ":!@" : " ,\t:+&#%$^()!@~*?<>=|\\/\"";
+	char const     *notch;
+	int		gecos = (checktype == PWC_GECOS);
+
+	switch (checktype) {
+	case PWC_GECOS:
+		notch = ":!@";
+		break;
+
+	case PWC_LOGIN:
+		notch = " ,\t:+&#%^()!@~*?<>=|\\/\"";
+		break;
+
+	case PWC_DEFAULT:
+	default:
+		notch = " ,\t:+&#%$^()!@~*?<>=|\\/\"";
+		break;
+	}
 
 	while (name[l]) {
 		if (strchr(notch, name[l]) != NULL || name[l] < ' ' || name[l] == 127
||

--Ydkc,)x78G(=.n)g
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (FreeBSD)

iD8DBQE+MMC22uHir9vMaLkRAoDUAJ0SdD4eMVOLSKDYGJrUPQFLFl4TlwCg6y5l
223zkEsVC5MsuSyKL6fUlG0=
=nE2y
-----END PGP SIGNATURE-----

--Ydkc,)x78G(=.n)g--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030124042738.RNFU23484.out001.verizon.net>