View | Details | Raw Unified | Return to bug 223431 | Differences between
and this patch

Collapse All | Expand All

(-)b/usr.sbin/pw/pw_conf.c (-1 / +1 lines)
Lines 426-432 write_userconfig(struct userconf *cnf, const char *file) Link Here
426
		close(fd);
426
		close(fd);
427
		return (0);
427
		return (0);
428
	}
428
	}
429
			
429
430
	buf = sbuf_new_auto();
430
	buf = sbuf_new_auto();
431
	for (i = _UC_NONE; i < _UC_FIELDS; i++) {
431
	for (i = _UC_NONE; i < _UC_FIELDS; i++) {
432
		int             quote = 1;
432
		int             quote = 1;
(-)b/usr.sbin/pw/pw_user.c (-12 / +60 lines)
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
1168
		cmdcnf->expire_days = cfg->expire_days;
1169
	/*
1169
	if (cmdcnf->password_days == 0)
1170
	 * If we are writing the config, use the values specified on the command
1170
		cmdcnf->password_days = cfg->password_days;
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
1177
		if (edays != NULL) {
1178
			cmdcnf->expire_days = strtonum(edays, 0, INT_MAX,
1179
			    &errstr);
1180
			if (errstr != NULL) {
1181
				errx(EX_USAGE, "argument to -e must be "
1182
				    "numeric if -D is specified");
1183
			}
1184
		}
1185
		if (pdays != NULL) {
1186
			cmdcnf->password_days = strtonum(pdays, 0, INT_MAX,
1187
			    &errstr);
1188
			if (errstr != NULL) {
1189
				errx(EX_USAGE, "argument to -p must be "
1190
				    "numeric if -D is specified");
1191
			}
1192
		}
1193
	} else {
1194
		char *tmp;
1195
		time_t now;
1196
1197
		if (edays != NULL)
1198
			tmp = strdup(edays);
1199
		else if (cfg->expire_days != 0)
1200
			asprintf(&tmp, "+%ldd", cfg->expire_days);
1201
		else
1202
			tmp = strdup("0");
1203
		if (tmp == NULL)
1204
			errx(EX_UNAVAILABLE, "out of memory");
1205
		now = time(NULL);
1206
		cmdcnf->expire_days = parse_date(now, tmp);
1207
		free(tmp);
1208
1209
		if (pdays != NULL)
1210
			tmp = strdup(pdays);
1211
		else if (cfg->password_days != 0)
1212
			asprintf(&tmp, "+%ldd", cfg->password_days);
1213
		else
1214
			tmp = strdup("0");
1215
		if (tmp == NULL)
1216
			errx(EX_UNAVAILABLE, "out of memory");
1217
		now = time(NULL);
1218
		cmdcnf->password_days = parse_date(now, tmp);
1219
		free(tmp);
1220
	}
1171
}
1221
}
1172
1222
1173
int
1223
int
Lines 1181-1191 pw_user_add(int argc, char **argv, char *arg1) Link Here
1181
	char line[_PASSWORD_LEN+1], path[MAXPATHLEN];
1231
	char line[_PASSWORD_LEN+1], path[MAXPATHLEN];
1182
	char *gecos, *homedir, *skel, *walk, *userid, *groupid, *grname;
1232
	char *gecos, *homedir, *skel, *walk, *userid, *groupid, *grname;
1183
	char *default_passwd, *name, *p;
1233
	char *default_passwd, *name, *p;
1234
	char *edays = NULL, *pdays = NULL;
1184
	const char *cfg = NULL;
1235
	const char *cfg = NULL;
1185
	login_cap_t *lc;
1236
	login_cap_t *lc;
1186
	FILE *pfp, *fp;
1237
	FILE *pfp, *fp;
1187
	intmax_t id = -1;
1238
	intmax_t id = -1;
1188
	time_t now;
1189
	int rc, ch, fd = -1;
1239
	int rc, ch, fd = -1;
1190
	size_t i;
1240
	size_t i;
1191
	bool dryrun, nis, pretty, quiet, createhome, precrypted, genconf;
1241
	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;
1276
			homedir = optarg;
1227
			break;
1277
			break;
1228
		case 'e':
1278
		case 'e':
1229
			now = time(NULL);
1279
			edays = optarg;
1230
			cmdcnf->expire_days = parse_date(now, optarg);
1231
			break;
1280
			break;
1232
		case 'p':
1281
		case 'p':
1233
			now = time(NULL);
1282
			pdays = optarg;
1234
			cmdcnf->password_days = parse_date(now, optarg);
1235
			break;
1283
			break;
1236
		case 'g':
1284
		case 'g':
1237
			validate_grname(cmdcnf, optarg);
1285
			validate_grname(cmdcnf, optarg);
Lines 1317-1323 pw_user_add(int argc, char **argv, char *arg1) Link Here
1317
1365
1318
	cnf = get_userconfig(cfg);
1366
	cnf = get_userconfig(cfg);
1319
1367
1320
	mix_config(cmdcnf, cnf);
1368
	mix_config(cmdcnf, cnf, genconf, edays, pdays);
1321
	if (default_passwd)
1369
	if (default_passwd)
1322
		cmdcnf->default_password = passwd_val(default_passwd,
1370
		cmdcnf->default_password = passwd_val(default_passwd,
1323
		    cnf->default_password);
1371
		    cnf->default_password);

Return to bug 223431