Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Dec 2009 19:04:21 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r200142 - in head/lib/libc: gen posix1e
Message-ID:  <200912051904.nB5J4LTp096485@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ed
Date: Sat Dec  5 19:04:21 2009
New Revision: 200142
URL: http://svn.freebsd.org/changeset/base/200142

Log:
  Don't let the C library depend on <utmp.h>.
  
  The maximum length of a username has nothing to do with the size of the
  username in the utmp files. Use MAXLOGNAME, which is defined as 17
  (UT_USERSIZE + 1).

Modified:
  head/lib/libc/gen/getlogin.c
  head/lib/libc/gen/pwcache.c
  head/lib/libc/posix1e/acl_to_text.c

Modified: head/lib/libc/gen/getlogin.c
==============================================================================
--- head/lib/libc/gen/getlogin.c	Sat Dec  5 19:03:20 2009	(r200141)
+++ head/lib/libc/gen/getlogin.c	Sat Dec  5 19:04:21 2009	(r200142)
@@ -36,7 +36,6 @@ __FBSDID("$FreeBSD$");
 #include <sys/param.h>
 #include <errno.h>
 #include <pwd.h>
-#include <utmp.h>
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>

Modified: head/lib/libc/gen/pwcache.c
==============================================================================
--- head/lib/libc/gen/pwcache.c	Sat Dec  5 19:03:20 2009	(r200141)
+++ head/lib/libc/gen/pwcache.c	Sat Dec  5 19:04:21 2009	(r200142)
@@ -33,13 +33,13 @@ static char sccsid[] = "@(#)pwcache.c	8.
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include <sys/param.h>
 #include <sys/types.h>
 
 #include <grp.h>
 #include <pwd.h>
 #include <stdio.h>
 #include <string.h>
-#include <utmp.h>
 
 #define	NCACHE	64			/* power of 2 */
 #define	MASK	(NCACHE - 1)		/* bits to store with */
@@ -50,7 +50,7 @@ user_from_uid(uid_t uid, int nouser)
 	static struct ncache {
 		uid_t	uid;
 		int	found;
-		char	name[UT_NAMESIZE + 1];
+		char	name[MAXLOGNAME];
 	} c_uid[NCACHE];
 	static int pwopen;
 	struct passwd *pw;
@@ -66,11 +66,11 @@ user_from_uid(uid_t uid, int nouser)
 		cp->uid = uid;
 		if (pw != NULL) {
 			cp->found = 1;
-			(void)strncpy(cp->name, pw->pw_name, UT_NAMESIZE);
-			cp->name[UT_NAMESIZE] = '\0';
+			(void)strncpy(cp->name, pw->pw_name, MAXLOGNAME - 1);
+			cp->name[MAXLOGNAME - 1] = '\0';
 		} else {
 			cp->found = 0;
-			(void)snprintf(cp->name, UT_NAMESIZE, "%u", uid);
+			(void)snprintf(cp->name, MAXLOGNAME - 1, "%u", uid);
 			if (nouser)
 				return (NULL);
 		}
@@ -84,7 +84,7 @@ group_from_gid(gid_t gid, int nogroup)
 	static struct ncache {
 		gid_t	gid;
 		int	found;
-		char	name[UT_NAMESIZE + 1];
+		char	name[MAXLOGNAME];
 	} c_gid[NCACHE];
 	static int gropen;
 	struct group *gr;
@@ -100,11 +100,11 @@ group_from_gid(gid_t gid, int nogroup)
 		cp->gid = gid;
 		if (gr != NULL) {
 			cp->found = 1;
-			(void)strncpy(cp->name, gr->gr_name, UT_NAMESIZE);
-			cp->name[UT_NAMESIZE] = '\0';
+			(void)strncpy(cp->name, gr->gr_name, MAXLOGNAME - 1);
+			cp->name[MAXLOGNAME - 1] = '\0';
 		} else {
 			cp->found = 0;
-			(void)snprintf(cp->name, UT_NAMESIZE, "%u", gid);
+			(void)snprintf(cp->name, MAXLOGNAME - 1, "%u", gid);
 			if (nogroup)
 				return (NULL);
 		}

Modified: head/lib/libc/posix1e/acl_to_text.c
==============================================================================
--- head/lib/libc/posix1e/acl_to_text.c	Sat Dec  5 19:03:20 2009	(r200141)
+++ head/lib/libc/posix1e/acl_to_text.c	Sat Dec  5 19:04:21 2009	(r200142)
@@ -39,7 +39,6 @@ __FBSDID("$FreeBSD$");
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <utmp.h>
 
 #include "acl_support.h"
 
@@ -58,7 +57,7 @@ _posix1e_acl_to_text(acl_t acl, ssize_t 
 {
 	struct acl	*acl_int;
 	char		*buf, *tmpbuf;
-	char		 name_buf[UT_NAMESIZE+1];
+	char		 name_buf[MAXLOGNAME];
 	char		 perm_buf[_POSIX1E_ACL_STRING_PERM_MAXSIZE+1],
 			 effective_perm_buf[_POSIX1E_ACL_STRING_PERM_MAXSIZE+1];
 	int		 i, error, len;
@@ -103,7 +102,7 @@ _posix1e_acl_to_text(acl_t acl, ssize_t 
 				goto error_label;
 
 			error = _posix1e_acl_id_to_name(ae_tag, ae_id,
-			    UT_NAMESIZE+1, name_buf, flags);
+			    MAXLOGNAME, name_buf, flags);
 			if (error)
 				goto error_label;
 
@@ -163,7 +162,7 @@ _posix1e_acl_to_text(acl_t acl, ssize_t 
 				goto error_label;
 
 			error = _posix1e_acl_id_to_name(ae_tag, ae_id,
-			    UT_NAMESIZE+1, name_buf, flags);
+			    MAXLOGNAME, name_buf, flags);
 			if (error)
 				goto error_label;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200912051904.nB5J4LTp096485>