Esempio n. 1
0
        public IEnumerable <string> GetCodeItems(OptionPreference preferLongNames = OptionPreference.Short)
        {
            // -l, --no-log-init: Do not add the user to the lastlog and faillog databases.
            if ((Flags & UserAddFlags.NoLogInit) != 0)
            {
                yield return(preferLongNames == OptionPreference.Long ? "--no-log-init" : "-l");
            }
            // -m, --create-home: Create the user's home directory if it does not exist.
            if ((Flags & UserAddFlags.CreateHome) != 0)
            {
                yield return(preferLongNames == OptionPreference.Long ? "--create-home" : "-m");
            }
            // -M: Do not create the user's home directory, even if the system wide setting from /etc/login.defs (CREATE_HOME) is set to yes.
            if ((Flags & UserAddFlags.DoNotCreateHomeDirectory) != 0)
            {
                yield return("-M");
            }
            // -N, --no-user-group: Do not create a group with the same name as the user, but add the user to the group specified by the -g option or by the GROUP variable in /etc/default/useradd.
            if ((Flags & UserAddFlags.NoUserGroup) != 0)
            {
                yield return(preferLongNames == OptionPreference.Long ? "--no-user-group" : "-N");
            }
            // -o, --non-unique: Allow the creation of a user account with a duplicate (non-unique) UID.
            if ((Flags & UserAddFlags.NonUnique) != 0)
            {
                yield return(preferLongNames == OptionPreference.Long ? "--non-unique" : "-o");
            }
            // -r, --system: Create a system account.
            if ((Flags & UserAddFlags.System) != 0)
            {
                yield return(preferLongNames == OptionPreference.Long ? "--system" : "-r");
            }
            // -U, --user-group: Create a group with the same name as the user, and add the user to this group. The default behavior (if the -g, -N, and -U options are not specified) is defined by the USERGROUPS_ENAB variable in /etc/login.defs.
            if ((Flags & UserAddFlags.UserGroup) != 0)
            {
                yield return(preferLongNames == OptionPreference.Long ? "--user-group" : "-U");
            }
            // -b, --base-dir =BASE_DIR: BASE_DIR is concatenated with the account name to define the home directory.
            if (!string.IsNullOrEmpty(BaseDir))
            {
                yield return("--base-dir");

                yield return(BaseDir.ShellQuote());
            }
            // -c, --comment =COMMENT: Any text string.
            if (!string.IsNullOrEmpty(Comment))
            {
                yield return("--comment");

                yield return(Comment.ShellQuote());
            }
            // -d, --home =HOME_DIR: The new user will be created using HOME_DIR as the value for the user's login directory.
            if (!string.IsNullOrEmpty(Home))
            {
                yield return("--home");

                yield return(Home.ShellQuote());
            }
            // -g, --gid =GROUP: The group name or number of the user's initial login group. The group name must exist.
            if (!string.IsNullOrEmpty(Gid))
            {
                yield return("--gid");

                yield return(Gid.ShellQuote());
            }
            // -K, --key KEY=VALUE: Overrides /etc/login.defs defaults (UID_MIN, UID_MAX, UMASK, PASS_MAX_DAYS and others)
            foreach (var pair in Key)
            {
                yield return("--key");

                var value = pair.Value.ShellQuote();
                yield return($"{pair.Key}={value}");
            }
            // -p, --password =PASSWORD: The encrypted password, as returned by crypt(3). The default is to disable the password.
            if (!string.IsNullOrEmpty(Password))
            {
                yield return("--password");

                yield return(Password.ShellQuote());
            }
        }