]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
usermod: check if shell exists & is executable
authorGeert Ijewski <gm.ijewski@web.de>
Sun, 7 Feb 2021 18:26:55 +0000 (19:26 +0100)
committerGeert Ijewski <gm.ijewski@web.de>
Sun, 7 Feb 2021 18:26:55 +0000 (19:26 +0100)
src/usermod.c

index ef430296eaabcf539f271f5c8bd78504b956ae1d..3ba011c2b217df940ee284afb3231daf616cf77f 100644 (file)
@@ -1032,7 +1032,7 @@ static void grp_update (void)
 static void process_flags (int argc, char **argv)
 {
        const struct group *grp;
-
+       struct stat st;
        bool anyflag = false;
 
        {
@@ -1180,12 +1180,25 @@ static void process_flags (int argc, char **argv)
                        case 'P': /* no-op, handled in process_prefix_flag () */
                                break;
                        case 's':
-                               if (!VALID (optarg)) {
+                               if (   ( !VALID (optarg) )
+                                   || (   ('\0' != optarg[0])
+                                       && ('/'  != optarg[0])
+                                       && ('*'  != optarg[0]) )) {
                                        fprintf (stderr,
-                                                _("%s: invalid field '%s'\n"),
+                                                _("%s: invalid shell '%s'\n"),
                                                 Prog, optarg);
                                        exit (E_BAD_ARG);
                                }
+                               if (    '\0' != optarg[0]
+                                    && '*'  != optarg[0]
+                                    && strcmp(optarg, "/sbin/nologin") != 0
+                                    && (   stat(optarg, &st) != 0
+                                        || S_ISDIR(st.st_mode)
+                                        || access(optarg, X_OK) != 0)) {
+                                       fprintf (stderr,
+                                                _("%s: Warning: missing or non-executable shell '%s'\n"),
+                                                Prog, optarg);
+                               }
                                user_newshell = optarg;
                                sflg = true;
                                break;