]> granicus.if.org Git - shadow/commitdiff
* lib/groupio.c, lib/sgroupio.c, lib/shadowio.c, lib/pwio.c: Check
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Wed, 16 Feb 2011 20:32:16 +0000 (20:32 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Wed, 16 Feb 2011 20:32:16 +0000 (20:32 +0000)
entry validity before commits to databases.
* libmisc/fields.c, libmisc/Makefile.am, lib/fields.c,
lib/Makefile.am, po/POTFILES.in: fields.c moved from libmisc to
lib.

ChangeLog
lib/Makefile.am
lib/fields.c [moved from libmisc/fields.c with 99% similarity]
lib/groupio.c
lib/pwio.c
lib/sgroupio.c
lib/shadowio.c
libmisc/Makefile.am
libmisc/user_busy.c
po/POTFILES.in

index 2b56263223119cd7ace154e366bf18e487971c36..06a9a9973a3fa44e1acc08f536b7e52dd6b79bf8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-02-15  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * lib/groupio.c, lib/sgroupio.c, lib/shadowio.c, lib/pwio.c: Check
+       entry validity before commits to databases.
+       * libmisc/fields.c, libmisc/Makefile.am, lib/fields.c,
+       lib/Makefile.am, po/POTFILES.in: fields.c moved from libmisc to
+       lib.
+
 2010-02-13  Nicolas François  <nicolas.francois@centraliens.net>
 
        * NEWS, src/chfn.c, src/chsh.c: Fix CVE-2011-0721: forbid \n in
index ee7ec6ee89906392c6ccac22c030719be275ad57..a04623cd34ebc066f2ea8f0066568f73ee4f31da 100644 (file)
@@ -14,6 +14,7 @@ libshadow_la_SOURCES = \
        encrypt.c \
        exitcodes.h \
        faillog.h \
+       fields.c \
        fputsx.c \
        getdef.c \
        getdef.h \
similarity index 99%
rename from libmisc/fields.c
rename to lib/fields.c
index a673659de58cbd06939495ae40c134bce8d116af..12377dc41ac4abec83a1a967189271c8d5769209 100644 (file)
@@ -54,6 +54,10 @@ int valid_field (const char *field, const char *illegal)
        const char *cp;
        int err = 0;
 
+       if (NULL == cp) {
+               return -1;
+       }
+
        /* For each character of field, search if it appears in the list
         * of illegal characters. */
        for (cp = field; '\0' != *cp; cp++) {
index e6fa69a1fd2a58e8748b427c57a7d8a9a6f693f2..109c5886a30988442d4e378d050576193d4133e9 100644 (file)
@@ -80,6 +80,23 @@ static int group_put (const void *ent, FILE * file)
 {
        const struct group *gr = ent;
 
+       if (   (NULL == gr)
+           || (valid_field (gr->gr_name, ":\n") == -1)
+           || (valid_field (gr->gr_passwd, ":\n") == -1)
+           || (gr->gr_gid == (gid_t)-1)) {
+               return -1;
+       }
+
+       /* FIXME: fail also if gr->gr_mem == NULL ?*/
+       if (NULL != gr->gr_mem) {
+               size_t i;
+               for (i = 0; NULL != gr->gr_mem[i]; i++) {
+                       if (valid_field (gr->gr_mem[i], ",:\n") == -1) {
+                               return -1;
+                       }
+               }
+       }
+
        return (putgrent (gr, file) == -1) ? -1 : 0;
 }
 
index fc6d8af44a946753ca7ce92081a5992c28080e60..793c2e5a96776f108e5d937c7695d63b812efcb3 100644 (file)
@@ -72,6 +72,17 @@ static int passwd_put (const void *ent, FILE * file)
 {
        const struct passwd *pw = ent;
 
+       if (   (NULL == pw)
+           || (valid_field (pw->pw_name, ":\n") == -1)
+           || (valid_field (pw->pw_passwd, ":\n") == -1)
+           || (pw->pw_uid == (uid_t)-1)
+           || (pw->pw_gid == (gid_t)-1)
+           || (valid_field (pw->pw_gecos, ":\n") == -1)
+           || (valid_field (pw->pw_dir, ":\n") == -1)
+           || (valid_field (pw->pw_shell, ":\n") == -1)) {
+               return -1;
+       }
+
        return (putpwent (pw, file) == -1) ? -1 : 0;
 }
 
index 836fc2768c557c5fa29b8fcc13c2aef8830ba1ef..352383318af1a3633ec0ccd204fec6686c940500 100644 (file)
@@ -169,6 +169,32 @@ static int gshadow_put (const void *ent, FILE * file)
 {
        const struct sgrp *sg = ent;
 
+       if (   (NULL == sg)
+           || (valid_field (sg->sg_name, ":\n") == -1)
+           || (valid_field (sg->sg_passwd, ":\n") == -1)) {
+               return -1;
+       }
+
+       /* FIXME: fail also if sg->sg_adm == NULL ?*/
+       if (NULL != sg->sg_adm) {
+               size_t i;
+               for (i = 0; NULL != sg->sg_adm[i]; i++) {
+                       if (valid_field (sg->sg_adm[i], ",:\n") == -1) {
+                               return -1;
+                       }
+               }
+       }
+
+       /* FIXME: fail also if sg->sg_mem == NULL ?*/
+       if (NULL != sg->sg_mem) {
+               size_t i;
+               for (i = 0; NULL != sg->sg_mem[i]; i++) {
+                       if (valid_field (sg->sg_mem[i], ",:\n") == -1) {
+                               return -1;
+                       }
+               }
+       }
+
        return (putsgent (sg, file) == -1) ? -1 : 0;
 }
 
index aec90cd972a1f953dfae9f120125111663221413..2930e65d10ebb9cc2da3bc5204e5e07ad256466f 100644 (file)
@@ -76,6 +76,12 @@ static int shadow_put (const void *ent, FILE * file)
 {
        const struct spwd *sp = ent;
 
+       if (   (NULL == sp)
+           || (valid_field (sp->sp_namp, ":\n") == -1)
+           || (valid_field (sp->sp_pwdp, ":\n") == -1)) {
+               return -1;
+       }
+
        return (putspent (sp, file) == -1) ? -1 : 0;
 }
 
index fa254749cd15711d00e544a82af4dcf1a94aadf3..a8afc177f2d4dec300f639776bf86a6e18d73a57 100644 (file)
@@ -23,7 +23,6 @@ libmisc_a_SOURCES = \
        env.c \
        failure.c \
        failure.h \
-       fields.c \
        find_new_gid.c \
        find_new_uid.c \
        getdate.h \
index ff626b041afd268bec2552a9d30e9c33668ba1b2..168f9d55b66ce8a3b77f47d24aa37cc3e7222f08 100644 (file)
@@ -43,7 +43,7 @@
 
 #ifdef __linux__
 static int check_status (const char *sname, uid_t uid);
-static int user_busy_processes (uid_t uid);
+static int user_busy_processes (const char *name, uid_t uid);
 #else                          /* !__linux__ */
 static int user_busy_utmp (const char *name);
 #endif                         /* !__linux__ */
@@ -58,7 +58,7 @@ int user_busy (const char *name, uid_t uid)
         */
 #ifdef __linux__
        /* On Linux, directly parse /proc */
-       return user_busy_processes (uid);
+       return user_busy_processes (name, uid);
 #else                          /* !__linux__ */
        /* If we cannot rely on /proc, check is there is a record in utmp
         * indicating that the user is still logged in */
@@ -91,6 +91,9 @@ static int user_busy_utmp (const char *name)
                        continue;
                }
 
+               fprintf (stderr,
+                        _("%s: user %s is currently logged in\n"),
+                        Prog, name);
                return 1;
        }
 
@@ -137,7 +140,7 @@ static int check_status (const char *sname, uid_t uid)
        return 0;
 }
 
-static int user_busy_processes (uid_t uid)
+static int user_busy_processes (const char *name, uid_t uid)
 {
        DIR *proc;
        struct dirent *ent;
@@ -195,6 +198,9 @@ static int user_busy_processes (uid_t uid)
 
                if (check_status (tmp_d_name, uid) != 0) {
                        (void) closedir (proc);
+                       fprintf (stderr,
+                                _("%s: user %s is currently used by process %d\n"),
+                                Prog, name, pid);
                        return 1;
                }
 
@@ -212,6 +218,9 @@ static int user_busy_processes (uid_t uid)
                                }
                                if (check_status (task_path+6, uid) != 0) {
                                        (void) closedir (proc);
+                                       fprintf (stderr,
+                                                _("%s: user %s is currently used by process %d\n"),
+                                                Prog, name, pid);
                                        return 1;
                                }
                        }
index 6cb3cdb578482d7eae9fa59411479f8f9ea4e181..065333e55987a201bc55b58e08f8b4d695d55d75 100644 (file)
@@ -2,6 +2,7 @@
 
 lib/commonio.c
 lib/encrypt.c
+lib/fields.c
 lib/fputsx.c
 lib/getdef.c
 lib/get_gid.c
@@ -40,7 +41,6 @@ libmisc/copydir.c
 libmisc/entry.c
 libmisc/env.c
 libmisc/failure.c
-libmisc/fields.c
 libmisc/find_new_gid.c
 libmisc/find_new_uid.c
 libmisc/getgr_nam_gid.c