* lib/utent.c (getutline): Remove getutline(). This function is

no more used.
	* lib/groupmem.c: Limit the scope of variable i.
	* lib/shadow.c: Avoid implicit conversion of pointers and integers
	to booleans.
	* lib/shadow.c: Added brackets.
	* libmisc/limits.c: Limit the scope of variable tmpmask.
	* libmisc/copydir.c: Close opened file on failure.
	* libmisc/loginprompt.c: Limit the scope of variable envc.
	* libmisc/find_new_uid.c, libmisc/find_new_gid.c: Limit the scope
	of variable id.
This commit is contained in:
nekral-guest 2010-03-23 08:56:52 +00:00
parent 5ebb35654b
commit 4375be4642
9 changed files with 71 additions and 51 deletions

View File

@ -1,3 +1,17 @@
2010-03-22 Nicolas François <nicolas.francois@centraliens.net>
* lib/utent.c (getutline): Remove getutline(). This function is
no more used.
* lib/groupmem.c: Limit the scope of variable i.
* lib/shadow.c: Avoid implicit conversion of pointers and integers
to booleans.
* lib/shadow.c: Added brackets.
* libmisc/limits.c: Limit the scope of variable tmpmask.
* libmisc/copydir.c: Close opened file on failure.
* libmisc/loginprompt.c: Limit the scope of variable envc.
* libmisc/find_new_uid.c, libmisc/find_new_gid.c: Limit the scope
of variable id.
2010-03-21 Nicolas François <nicolas.francois@centraliens.net> 2010-03-21 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/find_new_gid.c, libmisc/find_new_uid.c: Detect some * libmisc/find_new_gid.c, libmisc/find_new_uid.c: Detect some
@ -7,6 +21,8 @@
2010-03-20 Nicolas François <nicolas.francois@centraliens.net> 2010-03-20 Nicolas François <nicolas.francois@centraliens.net>
* NEWS, configure.in: Next version will be 4.1.5. * NEWS, configure.in: Next version will be 4.1.5.
* po/shadow.pot, man/po/shadow-man-pages.pot: Regenerated.
* po/*.po, man/po/*.po: Updated PO files.
2010-03-20 Nicolas François <nicolas.francois@centraliens.net> 2010-03-20 Nicolas François <nicolas.francois@centraliens.net>

View File

@ -90,13 +90,13 @@
void gr_free (/*@out@*/ /*@only@*/struct group *grent) void gr_free (/*@out@*/ /*@only@*/struct group *grent)
{ {
size_t i;
free (grent->gr_name); free (grent->gr_name);
if (NULL != grent->gr_passwd) { if (NULL != grent->gr_passwd) {
memzero (grent->gr_passwd, strlen (grent->gr_passwd)); memzero (grent->gr_passwd, strlen (grent->gr_passwd));
free (grent->gr_passwd); free (grent->gr_passwd);
} }
if (NULL != grent->gr_mem) { if (NULL != grent->gr_mem) {
size_t i;
for (i = 0; NULL != grent->gr_mem[i]; i++) { for (i = 0; NULL != grent->gr_mem[i]; i++) {
free (grent->gr_mem[i]); free (grent->gr_mem[i]);
} }

View File

@ -42,10 +42,10 @@
#include "defines.h" #include "defines.h"
#include <stdio.h> #include <stdio.h>
#ifdef USE_NIS #ifdef USE_NIS
static int nis_used; static bool nis_used;
static int nis_ignore; static bool nis_ignore;
static enum { native, start, middle, native2 } nis_state; static enum { native, start, middle, native2 } nis_state;
static int nis_bound; static bool nis_bound;
static char *nis_domain; static char *nis_domain;
static char *nis_key; static char *nis_key;
static int nis_keylen; static int nis_keylen;
@ -66,12 +66,12 @@ static FILE *shadow;
* __setspNIS - turn on or off NIS searches * __setspNIS - turn on or off NIS searches
*/ */
void __setspNIS (int flag) void __setspNIS (bool flag)
{ {
nis_ignore = !flag; nis_ignore = !flag;
if (nis_ignore) { if (nis_ignore) {
nis_used = 0; nis_used = false;
} }
} }
@ -81,10 +81,11 @@ void __setspNIS (int flag)
static int bind_nis (void) static int bind_nis (void)
{ {
if (yp_get_default_domain (&nis_domain)) if (yp_get_default_domain (&nis_domain)) {
return -1; return -1;
}
nis_bound = 1; nis_bound = true;
return 0; return 0;
} }
#endif #endif
@ -95,10 +96,11 @@ static int bind_nis (void)
void setspent (void) void setspent (void)
{ {
if (shadow) if (NULL != shadow) {
rewind (shadow); rewind (shadow);
else }else {
shadow = fopen (SHADOW_FILE, "r"); shadow = fopen (SHADOW_FILE, "r");
}
#ifdef USE_NIS #ifdef USE_NIS
nis_state = native; nis_state = native;
@ -111,8 +113,9 @@ void setspent (void)
void endspent (void) void endspent (void)
{ {
if (shadow) if (NULL != shadow) {
(void) fclose (shadow); (void) fclose (shadow);
}
shadow = (FILE *) 0; shadow = (FILE *) 0;
} }
@ -172,8 +175,9 @@ static struct spwd *my_sgetspent (const char *string)
spwd.sp_namp = fields[0]; spwd.sp_namp = fields[0];
#ifdef USE_NIS #ifdef USE_NIS
if (IS_NISCHAR (fields[0][0])) if (IS_NISCHAR (fields[0][0])) {
nis_used = 1; nis_used = true;
}
#endif #endif
spwd.sp_pwdp = fields[1]; spwd.sp_pwdp = fields[1];
@ -211,7 +215,9 @@ static struct spwd *my_sgetspent (const char *string)
spwd.sp_min = -1; spwd.sp_min = -1;
} else } else
#endif #endif
{
return 0; return 0;
}
} else if (spwd.sp_min < 0) { } else if (spwd.sp_min < 0) {
return 0; return 0;
} }
@ -263,7 +269,9 @@ static struct spwd *my_sgetspent (const char *string)
spwd.sp_warn = -1; spwd.sp_warn = -1;
} else } else
#endif #endif
{
return 0; return 0;
}
} else if (spwd.sp_warn < 0) { } else if (spwd.sp_warn < 0) {
return 0; return 0;
} }
@ -283,7 +291,9 @@ static struct spwd *my_sgetspent (const char *string)
spwd.sp_inact = -1; spwd.sp_inact = -1;
} else } else
#endif #endif
{
return 0; return 0;
}
} else if (spwd.sp_inact < 0) { } else if (spwd.sp_inact < 0) {
return 0; return 0;
} }
@ -303,7 +313,9 @@ static struct spwd *my_sgetspent (const char *string)
spwd.sp_expire = -1; spwd.sp_expire = -1;
} else } else
#endif #endif
{
return 0; return 0;
}
} else if (spwd.sp_expire < 0) { } else if (spwd.sp_expire < 0) {
return 0; return 0;
} }
@ -324,7 +336,9 @@ static struct spwd *my_sgetspent (const char *string)
spwd.sp_flag = SHADOW_SP_FLAG_UNSET; spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
} else } else
#endif #endif
{
return 0; return 0;
}
} else if (spwd.sp_flag < 0) { } else if (spwd.sp_flag < 0) {
return 0; return 0;
} }
@ -377,8 +391,9 @@ struct spwd *getspent (void)
struct spwd *val; struct spwd *val;
char buf[BUFSIZ]; char buf[BUFSIZ];
#endif #endif
if (!shadow) if (NULL == shadow) {
setspent (); setspent ();
}
#ifdef USE_NIS #ifdef USE_NIS
again: again:
@ -432,7 +447,7 @@ struct spwd *getspent (void)
return 0; return 0;
} else { } else {
if (nis_bound == 0) { if (!nis_bound) {
if (bind_nis ()) { if (bind_nis ()) {
nis_state = native2; nis_state = native2;
goto again; goto again;
@ -471,7 +486,7 @@ struct spwd *getspnam (const char *name)
#ifdef USE_NIS #ifdef USE_NIS
char buf[BUFSIZ]; char buf[BUFSIZ];
static char save_name[16]; static char save_name[16];
int nis_disabled = 0; bool nis_disabled = false;
#endif #endif
setspent (); setspent ();
@ -481,8 +496,9 @@ struct spwd *getspnam (const char *name)
* Search the shadow.byname map for this user. * Search the shadow.byname map for this user.
*/ */
if (!nis_ignore && !nis_bound) if (!nis_ignore && !nis_bound) {
bind_nis (); bind_nis ();
}
if (!nis_ignore && nis_bound) { if (!nis_ignore && nis_bound) {
char *cp; char *cp;
@ -491,8 +507,9 @@ struct spwd *getspnam (const char *name)
strlen (name), &nis_val, &nis_vallen) == 0) { strlen (name), &nis_val, &nis_vallen) == 0) {
cp = strchr (nis_val, '\n'); cp = strchr (nis_val, '\n');
if (NULL != cp) if (NULL != cp) {
*cp = '\0'; *cp = '\0';
}
nis_state = middle; nis_state = middle;
sp = my_sgetspent (nis_val); sp = my_sgetspent (nis_val);
@ -503,9 +520,10 @@ struct spwd *getspnam (const char *name)
} }
endspent (); endspent ();
return sp; return sp;
} else } else {
nis_state = native2; nis_state = native2;
} }
}
#endif #endif
#ifdef USE_NIS #ifdef USE_NIS
/* /*
@ -516,17 +534,19 @@ struct spwd *getspnam (const char *name)
*/ */
if (nis_used) { if (nis_used) {
nis_ignore++; nis_ignore = true;
nis_disabled++; nis_disabled = true;
} }
#endif #endif
while ((sp = getspent ()) != (struct spwd *) 0) { while ((sp = getspent ()) != (struct spwd *) 0) {
if (strcmp (name, sp->sp_namp) == 0) if (strcmp (name, sp->sp_namp) == 0) {
break; break;
} }
}
#ifdef USE_NIS #ifdef USE_NIS
if (nis_disabled) if (nis_disabled) {
nis_ignore--; nis_ignore = false;
}
#endif #endif
endspent (); endspent ();
return (sp); return (sp);

View File

@ -88,25 +88,6 @@ struct utmp *getutent (void)
return &utmp_buf; return &utmp_buf;
} }
/*
* getutline - get the utmp entry matching ut_line
*/
struct utmp *getutline (const struct utmp *utent)
{
struct utmp save;
struct utmp *new;
save = *utent;
while (new = getutent ())
if (strncmp (new->ut_line, save.ut_line, sizeof new->ut_line))
continue;
else
return new;
return (struct utmp *) 0;
}
#else #else
extern int errno; /* warning: ANSI C forbids an empty source file */ extern int errno; /* warning: ANSI C forbids an empty source file */
#endif #endif

View File

@ -635,6 +635,7 @@ static int copy_file (const char *src, const char *dst,
while ((cnt = read (ifd, buf, sizeof buf)) > 0) { while ((cnt = read (ifd, buf, sizeof buf)) > 0) {
if (write (ofd, buf, (size_t)cnt) != cnt) { if (write (ofd, buf, (size_t)cnt) != cnt) {
(void) close (ifd);
return -1; return -1;
} }
} }

View File

@ -52,7 +52,7 @@ int find_new_gid (bool sys_group,
/*@null@*/gid_t const *preferred_gid) /*@null@*/gid_t const *preferred_gid)
{ {
const struct group *grp; const struct group *grp;
gid_t gid_min, gid_max, group_id, id; gid_t gid_min, gid_max, group_id;
bool *used_gids; bool *used_gids;
assert (gid != NULL); assert (gid != NULL);
@ -100,6 +100,7 @@ int find_new_gid (bool sys_group,
* some groups were created but the changes were not committed yet. * some groups were created but the changes were not committed yet.
*/ */
if (sys_group) { if (sys_group) {
gid_t id;
/* setgrent / getgrent / endgrent can be very slow with /* setgrent / getgrent / endgrent can be very slow with
* LDAP configurations (and many accounts). * LDAP configurations (and many accounts).
* Since there is a limited amount of IDs to be tested * Since there is a limited amount of IDs to be tested

View File

@ -52,7 +52,7 @@ int find_new_uid (bool sys_user,
/*@null@*/uid_t const *preferred_uid) /*@null@*/uid_t const *preferred_uid)
{ {
const struct passwd *pwd; const struct passwd *pwd;
uid_t uid_min, uid_max, user_id, id; uid_t uid_min, uid_max, user_id;
bool *used_uids; bool *used_uids;
assert (uid != NULL); assert (uid != NULL);
@ -100,6 +100,7 @@ int find_new_uid (bool sys_user,
* some users were created but the changes were not committed yet. * some users were created but the changes were not committed yet.
*/ */
if (sys_user) { if (sys_user) {
uid_t id;
/* setpwent / getpwent / endpwent can be very slow with /* setpwent / getpwent / endpwent can be very slow with
* LDAP configurations (and many accounts). * LDAP configurations (and many accounts).
* Since there is a limited amount of IDs to be tested * Since there is a limited amount of IDs to be tested

View File

@ -507,7 +507,6 @@ static int setup_user_limits (const char *uname)
static void setup_usergroups (const struct passwd *info) static void setup_usergroups (const struct passwd *info)
{ {
const struct group *grp; const struct group *grp;
mode_t tmpmask;
/* /*
* if not root, and UID == GID, and username is the same as primary * if not root, and UID == GID, and username is the same as primary
@ -519,6 +518,7 @@ static void setup_usergroups (const struct passwd *info)
grp = getgrgid (info->pw_gid); grp = getgrgid (info->pw_gid);
if ( (NULL != grp) if ( (NULL != grp)
&& (strcmp (info->pw_name, grp->gr_name) == 0)) { && (strcmp (info->pw_name, grp->gr_name) == 0)) {
mode_t tmpmask;
tmpmask = umask (0777); tmpmask = umask (0777);
tmpmask = (tmpmask & ~070) | ((tmpmask >> 3) & 070); tmpmask = (tmpmask & ~070) | ((tmpmask >> 3) & 070);
(void) umask (tmpmask); (void) umask (tmpmask);

View File

@ -60,7 +60,6 @@ void login_prompt (const char *prompt, char *name, int namesize)
#define MAX_ENV 32 #define MAX_ENV 32
char *envp[MAX_ENV]; char *envp[MAX_ENV];
int envc;
char *cp; char *cp;
int i; int i;
FILE *fp; FILE *fp;
@ -148,6 +147,7 @@ void login_prompt (const char *prompt, char *name, int namesize)
if ('\0' != *cp) { /* process new variables */ if ('\0' != *cp) { /* process new variables */
char *nvar; char *nvar;
int count = 1; int count = 1;
int envc;
for (envc = 0; envc < MAX_ENV; envc++) { for (envc = 0; envc < MAX_ENV; envc++) {
nvar = strtok ((0 != envc) ? (char *) 0 : cp, " \t,"); nvar = strtok ((0 != envc) ? (char *) 0 : cp, " \t,");