|
Lines 22-28
Link Here
|
| 22 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
22 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 23 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
23 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 24 |
* SUCH DAMAGE. |
24 |
* SUCH DAMAGE. |
| 25 |
* |
25 |
* |
| 26 |
*/ |
26 |
*/ |
| 27 |
|
27 |
|
| 28 |
#ifndef lint |
28 |
#ifndef lint |
|
Lines 1123-1129
validate_mode(char *mode)
Link Here
|
| 1123 |
} |
1123 |
} |
| 1124 |
|
1124 |
|
| 1125 |
static void |
1125 |
static void |
| 1126 |
mix_config(struct userconf *cmdcnf, struct userconf *cfg) |
1126 |
mix_config(struct userconf *cmdcnf, struct userconf *cfg, bool genconf, |
|
|
1127 |
char *edays, char *pdays) |
| 1127 |
{ |
1128 |
{ |
| 1128 |
|
1129 |
|
| 1129 |
if (cmdcnf->default_password == 0) |
1130 |
if (cmdcnf->default_password == 0) |
|
Lines 1164-1173
mix_config(struct userconf *cmdcnf, struct userconf *cfg)
Link Here
|
| 1164 |
cmdcnf->min_gid = cfg->min_gid; |
1165 |
cmdcnf->min_gid = cfg->min_gid; |
| 1165 |
if (cmdcnf->max_gid == 0) |
1166 |
if (cmdcnf->max_gid == 0) |
| 1166 |
cmdcnf->max_gid = cfg->max_gid; |
1167 |
cmdcnf->max_gid = cfg->max_gid; |
| 1167 |
if (cmdcnf->expire_days == 0) |
1168 |
|
|
|
1169 |
/* |
| 1170 |
* If we are writing the config, use the values specified on the command |
| 1171 |
* line. Otherwise, if the values are not specified, use the ones from |
| 1172 |
* config file. |
| 1173 |
*/ |
| 1174 |
if (genconf) { |
| 1175 |
const char *errstr; |
| 1176 |
|
| 1168 |
cmdcnf->expire_days = cfg->expire_days; |
1177 |
cmdcnf->expire_days = cfg->expire_days; |
| 1169 |
if (cmdcnf->password_days == 0) |
1178 |
if (edays != NULL) { |
|
|
1179 |
cmdcnf->expire_days = strtonum(edays, 0, INT_MAX, |
| 1180 |
&errstr); |
| 1181 |
if (errstr != NULL) { |
| 1182 |
errx(EX_USAGE, "argument to -e must be " |
| 1183 |
"numeric if -D is specified"); |
| 1184 |
} |
| 1185 |
} |
| 1186 |
|
| 1170 |
cmdcnf->password_days = cfg->password_days; |
1187 |
cmdcnf->password_days = cfg->password_days; |
|
|
1188 |
if (pdays != NULL) { |
| 1189 |
cmdcnf->password_days = strtonum(pdays, 0, INT_MAX, |
| 1190 |
&errstr); |
| 1191 |
if (errstr != NULL) { |
| 1192 |
errx(EX_USAGE, "argument to -p must be " |
| 1193 |
"numeric if -D is specified"); |
| 1194 |
} |
| 1195 |
} |
| 1196 |
} else { |
| 1197 |
char *tmp; |
| 1198 |
time_t now; |
| 1199 |
|
| 1200 |
if (edays != NULL) |
| 1201 |
tmp = strdup(edays); |
| 1202 |
else if (cfg->expire_days != 0) |
| 1203 |
asprintf(&tmp, "+%ldd", cfg->expire_days); |
| 1204 |
else |
| 1205 |
tmp = strdup("0"); |
| 1206 |
if (tmp == NULL) |
| 1207 |
errx(EX_UNAVAILABLE, "out of memory"); |
| 1208 |
now = time(NULL); |
| 1209 |
cmdcnf->expire_days = parse_date(now, tmp); |
| 1210 |
free(tmp); |
| 1211 |
|
| 1212 |
if (pdays != NULL) |
| 1213 |
tmp = strdup(pdays); |
| 1214 |
else if (cfg->password_days != 0) |
| 1215 |
asprintf(&tmp, "+%ldd", cfg->password_days); |
| 1216 |
else |
| 1217 |
tmp = strdup("0"); |
| 1218 |
if (tmp == NULL) |
| 1219 |
errx(EX_UNAVAILABLE, "out of memory"); |
| 1220 |
now = time(NULL); |
| 1221 |
cmdcnf->password_days = parse_date(now, tmp); |
| 1222 |
free(tmp); |
| 1223 |
} |
| 1171 |
} |
1224 |
} |
| 1172 |
|
1225 |
|
| 1173 |
int |
1226 |
int |
|
Lines 1181-1191
pw_user_add(int argc, char **argv, char *arg1)
Link Here
|
| 1181 |
char line[_PASSWORD_LEN+1], path[MAXPATHLEN]; |
1234 |
char line[_PASSWORD_LEN+1], path[MAXPATHLEN]; |
| 1182 |
char *gecos, *homedir, *skel, *walk, *userid, *groupid, *grname; |
1235 |
char *gecos, *homedir, *skel, *walk, *userid, *groupid, *grname; |
| 1183 |
char *default_passwd, *name, *p; |
1236 |
char *default_passwd, *name, *p; |
|
|
1237 |
char *edays = NULL, *pdays = NULL; |
| 1184 |
const char *cfg = NULL; |
1238 |
const char *cfg = NULL; |
| 1185 |
login_cap_t *lc; |
1239 |
login_cap_t *lc; |
| 1186 |
FILE *pfp, *fp; |
1240 |
FILE *pfp, *fp; |
| 1187 |
intmax_t id = -1; |
1241 |
intmax_t id = -1; |
| 1188 |
time_t now; |
|
|
| 1189 |
int rc, ch, fd = -1; |
1242 |
int rc, ch, fd = -1; |
| 1190 |
size_t i; |
1243 |
size_t i; |
| 1191 |
bool dryrun, nis, pretty, quiet, createhome, precrypted, genconf; |
1244 |
bool dryrun, nis, pretty, quiet, createhome, precrypted, genconf; |
|
Lines 1226-1237
pw_user_add(int argc, char **argv, char *arg1)
Link Here
|
| 1226 |
homedir = optarg; |
1279 |
homedir = optarg; |
| 1227 |
break; |
1280 |
break; |
| 1228 |
case 'e': |
1281 |
case 'e': |
| 1229 |
now = time(NULL); |
1282 |
edays = optarg; |
| 1230 |
cmdcnf->expire_days = parse_date(now, optarg); |
|
|
| 1231 |
break; |
1283 |
break; |
| 1232 |
case 'p': |
1284 |
case 'p': |
| 1233 |
now = time(NULL); |
1285 |
pdays = optarg; |
| 1234 |
cmdcnf->password_days = parse_date(now, optarg); |
|
|
| 1235 |
break; |
1286 |
break; |
| 1236 |
case 'g': |
1287 |
case 'g': |
| 1237 |
validate_grname(cmdcnf, optarg); |
1288 |
validate_grname(cmdcnf, optarg); |
|
Lines 1317-1323
pw_user_add(int argc, char **argv, char *arg1)
Link Here
|
| 1317 |
|
1368 |
|
| 1318 |
cnf = get_userconfig(cfg); |
1369 |
cnf = get_userconfig(cfg); |
| 1319 |
|
1370 |
|
| 1320 |
mix_config(cmdcnf, cnf); |
1371 |
mix_config(cmdcnf, cnf, genconf, edays, pdays); |
| 1321 |
if (default_passwd) |
1372 |
if (default_passwd) |
| 1322 |
cmdcnf->default_password = passwd_val(default_passwd, |
1373 |
cmdcnf->default_password = passwd_val(default_passwd, |
| 1323 |
cnf->default_password); |
1374 |
cnf->default_password); |