1 -- $Id: 200_add_user.lua,v 1.7 2005/03/29 12:12:15 den Exp $
5 local is_gecos_clean = function(gecos)
9 while i <= string.len(gecos) do
10 char = string.sub(gecos, i, i)
11 if string.find(char, "%c") or -- no ctrl chars
12 string.byte(char) == 127 or -- no 'DEL' char
13 string.find(":!@", char, 1, true) then -- none of these
22 local is_name_clean = function(name)
26 while i <= string.len(name) do
27 char = string.sub(name, i, i)
28 if string.find(char, "%c") or -- no ctrl chars
29 string.byte(char) == 127 or -- no 'DEL' char
30 string.byte(char) > 127 or -- no 8-bit chars
32 string.find(" ,\t:+&#%^()!@~*?<>=|\\/\"", char, 1, true) or
33 (char == "-" and i == 1) or -- no '-' at start
35 (char == "$" and i ~= string.len(name)) then
44 local add_user = function()
52 short_desc = _("Here you can add a user to an installed system.\n\n" ..
53 "You can leave the Home Directory, User ID, and Login Group " ..
54 "fields empty if you want these items to be automatically " ..
55 "allocated by the system."),
60 short_desc = _("Enter the username the user will log in as")
64 name = _("Real Name"),
65 short_desc = _("Enter the real name (or GECOS field) of this user")
70 short_desc = _("Enter the user's password (will not be displayed)"),
75 name = _("Password (Again)"),
76 short_desc = _("Re-enter the user's password to confirm"),
82 short_desc = _("Enter the full path to the user's shell program")
86 name = _("Home Directory"),
87 short_desc = _("Enter the full path to the user's home directory, or leave blank")
92 short_desc = _("Enter this account's numeric user id, or leave blank")
96 name = _("Login Group"),
97 short_desc = _("Enter the primary group for this account, or leave blank")
101 name = _("Other Group Memberships"),
103 "Enter a comma-separated list of other groups " ..
104 "that this user should belong to"
111 name = _("Accept and Add User")
115 name = _("Return to Configure Menu")
134 result = App.ui:present(form)
135 if result.action_id == "ok" then
136 form.datasets = result.datasets
139 -- Fetch form field values.
141 local username = result.datasets[1].username
142 local gecos = result.datasets[1].gecos
143 local passwd_1 = result.datasets[1].passwd_1
144 local passwd_2 = result.datasets[1].passwd_2
145 local shell = result.datasets[1].shell
146 local home = result.datasets[1].home
147 local uid = result.datasets[1].uid
148 local group = result.datasets[1].group
149 local groups = result.datasets[1].groups
152 -- Valid field values.
155 if string.len(username) == 0 then
157 "You must enter a username."
159 elseif passwd_1 ~= passwd_2 then
161 "The passwords do not match."
163 elseif not is_name_clean(username) then
165 "The username contains illegal characters."
167 elseif not is_gecos_clean(gecos) then
169 "The text specified in the Real Name " ..
170 "field contains illegal characters."
172 elseif not is_name_clean(group) then
174 "The name of the login group contains " ..
175 "illegal characters."
178 !assert_clean(a->c, _("Home Directory"), home, FILENAME_NOT_ALLOWED) ||
179 !assert_clean(a->c, _("User ID"), uid, PW_NOT_ALLOWED) ||
180 !assert_clean(a->c, _("Group Memberships"), groups, MEMBERSHIPS_NOT_ALLOWED)) {
183 elseif not FileSystem.is_program(App.dir.root .. shell) and
184 shell ~= "/nonexistent" then
186 "The selected shell does not exist on the system."
189 local cmds = CmdChain.new()
191 App.state.target:cmds_add_user(cmds, {
201 if cmds:execute() then
203 "User `%s' was added.",
209 "User was not successfully added."
221 name = _("Add User"),