pw_conf.c revision 286152
120253Sjoerg/*-
220302Sjoerg * Copyright (C) 1996
320302Sjoerg *	David L. Nugent.  All rights reserved.
420253Sjoerg *
520253Sjoerg * Redistribution and use in source and binary forms, with or without
620253Sjoerg * modification, are permitted provided that the following conditions
720253Sjoerg * are met:
820253Sjoerg * 1. Redistributions of source code must retain the above copyright
920302Sjoerg *    notice, this list of conditions and the following disclaimer.
1020253Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
1120253Sjoerg *    notice, this list of conditions and the following disclaimer in the
1220253Sjoerg *    documentation and/or other materials provided with the distribution.
1320253Sjoerg *
1420302Sjoerg * THIS SOFTWARE IS PROVIDED BY DAVID L. NUGENT AND CONTRIBUTORS ``AS IS'' AND
1520253Sjoerg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1620253Sjoerg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1720302Sjoerg * ARE DISCLAIMED.  IN NO EVENT SHALL DAVID L. NUGENT OR CONTRIBUTORS BE LIABLE
1820253Sjoerg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1920253Sjoerg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2020253Sjoerg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2120253Sjoerg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2220253Sjoerg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2320253Sjoerg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2420253Sjoerg * SUCH DAMAGE.
2520253Sjoerg */
2620253Sjoerg
2730259Scharnier#ifndef lint
2830259Scharnierstatic const char rcsid[] =
2950479Speter  "$FreeBSD: head/usr.sbin/pw/pw_conf.c 286152 2015-08-01 10:25:55Z bapt $";
3030259Scharnier#endif /* not lint */
3130259Scharnier
32282681Sbapt#include <sys/types.h>
33282681Sbapt#include <sys/sbuf.h>
34286150Sbapt#include <inttypes.h>
3520253Sjoerg#include <string.h>
3620253Sjoerg#include <ctype.h>
3720253Sjoerg#include <fcntl.h>
38282718Sbapt#include <err.h>
3920253Sjoerg
4020253Sjoerg#include "pw.h"
4120253Sjoerg
4220253Sjoerg#define debugging 0
4320253Sjoerg
4420253Sjoergenum {
4520253Sjoerg	_UC_NONE,
4620253Sjoerg	_UC_DEFAULTPWD,
4720253Sjoerg	_UC_REUSEUID,
4820253Sjoerg	_UC_REUSEGID,
4921330Sdavidn	_UC_NISPASSWD,
5020253Sjoerg	_UC_DOTDIR,
5120253Sjoerg	_UC_NEWMAIL,
5220253Sjoerg	_UC_LOGFILE,
5320253Sjoerg	_UC_HOMEROOT,
54168044Sle	_UC_HOMEMODE,
5520253Sjoerg	_UC_SHELLPATH,
5620253Sjoerg	_UC_SHELLS,
5720253Sjoerg	_UC_DEFAULTSHELL,
5820253Sjoerg	_UC_DEFAULTGROUP,
5920253Sjoerg	_UC_EXTRAGROUPS,
6020253Sjoerg	_UC_DEFAULTCLASS,
6120253Sjoerg	_UC_MINUID,
6220253Sjoerg	_UC_MAXUID,
6320253Sjoerg	_UC_MINGID,
6420253Sjoerg	_UC_MAXGID,
6520253Sjoerg	_UC_EXPIRE,
6620253Sjoerg	_UC_PASSWORD,
6720253Sjoerg	_UC_FIELDS
6820253Sjoerg};
6920253Sjoerg
7020253Sjoergstatic char     bourne_shell[] = "sh";
7120253Sjoerg
7220253Sjoergstatic char    *system_shells[_UC_MAXSHELLS] =
7320253Sjoerg{
7420253Sjoerg	bourne_shell,
7563239Sdavidn	"csh",
7663239Sdavidn	"tcsh"
7720253Sjoerg};
7820253Sjoerg
7920253Sjoergstatic char const *booltrue[] =
8020253Sjoerg{
8120253Sjoerg	"yes", "true", "1", "on", NULL
8220253Sjoerg};
8320253Sjoergstatic char const *boolfalse[] =
8420253Sjoerg{
8520253Sjoerg	"no", "false", "0", "off", NULL
8620253Sjoerg};
8720253Sjoerg
8820253Sjoergstatic struct userconf config =
8920253Sjoerg{
9020253Sjoerg	0,			/* Default password for new users? (nologin) */
9120253Sjoerg	0,			/* Reuse uids? */
9220253Sjoerg	0,			/* Reuse gids? */
9321330Sdavidn	NULL,			/* NIS version of the passwd file */
9420253Sjoerg	"/usr/share/skel",	/* Where to obtain skeleton files */
9520253Sjoerg	NULL,			/* Mail to send to new accounts */
9620253Sjoerg	"/var/log/userlog",	/* Where to log changes */
9720253Sjoerg	"/home",		/* Where to create home directory */
98219408Sjkim	_DEF_DIRMODE,		/* Home directory perms, modified by umask */
9920253Sjoerg	"/bin",			/* Where shells are located */
10020253Sjoerg	system_shells,		/* List of shells (first is default) */
10120253Sjoerg	bourne_shell,		/* Default shell */
10220253Sjoerg	NULL,			/* Default group name */
10320747Sdavidn	NULL,			/* Default (additional) groups */
10420253Sjoerg	NULL,			/* Default login class */
10520253Sjoerg	1000, 32000,		/* Allowed range of uids */
10620253Sjoerg	1000, 32000,		/* Allowed range of gids */
10720253Sjoerg	0,			/* Days until account expires */
108285412Sbapt	0			/* Days until password expires */
10920253Sjoerg};
11020253Sjoerg
11120253Sjoergstatic char const *comments[_UC_FIELDS] =
11220253Sjoerg{
11320253Sjoerg	"#\n# pw.conf - user/group configuration defaults\n#\n",
11420253Sjoerg	"\n# Password for new users? no=nologin yes=loginid none=blank random=random\n",
11520253Sjoerg	"\n# Reuse gaps in uid sequence? (yes or no)\n",
11620253Sjoerg	"\n# Reuse gaps in gid sequence? (yes or no)\n",
11721330Sdavidn	"\n# Path to the NIS passwd file (blank or 'no' for none)\n",
11820253Sjoerg	"\n# Obtain default dotfiles from this directory\n",
11920253Sjoerg	"\n# Mail this file to new user (/etc/newuser.msg or no)\n",
12020253Sjoerg	"\n# Log add/change/remove information in this file\n",
12120253Sjoerg	"\n# Root directory in which $HOME directory is created\n",
122168044Sle	"\n# Mode for the new $HOME directory, will be modified by umask\n",
12320253Sjoerg	"\n# Colon separated list of directories containing valid shells\n",
12470133Sdougb	"\n# Comma separated list of available shells (without paths)\n",
12520253Sjoerg	"\n# Default shell (without path)\n",
12620253Sjoerg	"\n# Default group (leave blank for new group per user)\n",
12720253Sjoerg	"\n# Extra groups for new users\n",
12820253Sjoerg	"\n# Default login class for new users\n",
12920253Sjoerg	"\n# Range of valid default user ids\n",
13020253Sjoerg	NULL,
13120253Sjoerg	"\n# Range of valid default group ids\n",
13220253Sjoerg	NULL,
13320253Sjoerg	"\n# Days after which account expires (0=disabled)\n",
13420253Sjoerg	"\n# Days after which password expires (0=disabled)\n"
13520253Sjoerg};
13620253Sjoerg
13720253Sjoergstatic char const *kwds[] =
13820253Sjoerg{
13920253Sjoerg	"",
14020253Sjoerg	"defaultpasswd",
14120253Sjoerg	"reuseuids",
14220253Sjoerg	"reusegids",
14321330Sdavidn	"nispasswd",
14420253Sjoerg	"skeleton",
14520253Sjoerg	"newmail",
14620253Sjoerg	"logfile",
14720253Sjoerg	"home",
148168044Sle	"homemode",
14920253Sjoerg	"shellpath",
15020253Sjoerg	"shells",
15120253Sjoerg	"defaultshell",
15220253Sjoerg	"defaultgroup",
15320253Sjoerg	"extragroups",
15420253Sjoerg	"defaultclass",
15520253Sjoerg	"minuid",
15620253Sjoerg	"maxuid",
15720253Sjoerg	"mingid",
15820253Sjoerg	"maxgid",
15920253Sjoerg	"expire_days",
16020253Sjoerg	"password_days",
16120253Sjoerg	NULL
16220253Sjoerg};
16320253Sjoerg
16420253Sjoergstatic char    *
16520253Sjoergunquote(char const * str)
16620253Sjoerg{
16720253Sjoerg	if (str && (*str == '"' || *str == '\'')) {
16820253Sjoerg		char           *p = strchr(str + 1, *str);
16920253Sjoerg
17020253Sjoerg		if (p != NULL)
17120253Sjoerg			*p = '\0';
17220253Sjoerg		return (char *) (*++str ? str : NULL);
17320253Sjoerg	}
17420253Sjoerg	return (char *) str;
17520253Sjoerg}
17620253Sjoerg
17720253Sjoergint
17820253Sjoergboolean_val(char const * str, int dflt)
17920253Sjoerg{
18020253Sjoerg	if ((str = unquote(str)) != NULL) {
18120253Sjoerg		int             i;
18220253Sjoerg
18320253Sjoerg		for (i = 0; booltrue[i]; i++)
18420253Sjoerg			if (strcmp(str, booltrue[i]) == 0)
18520253Sjoerg				return 1;
18620253Sjoerg		for (i = 0; boolfalse[i]; i++)
18720253Sjoerg			if (strcmp(str, boolfalse[i]) == 0)
18820253Sjoerg				return 0;
18920253Sjoerg
19020253Sjoerg		/*
19120253Sjoerg		 * Special cases for defaultpassword
19220253Sjoerg		 */
19320253Sjoerg		if (strcmp(str, "random") == 0)
19420253Sjoerg			return -1;
19520253Sjoerg		if (strcmp(str, "none") == 0)
19620253Sjoerg			return -2;
19720253Sjoerg	}
19820253Sjoerg	return dflt;
19920253Sjoerg}
20020253Sjoerg
20120253Sjoergchar const     *
20220253Sjoergboolean_str(int val)
20320253Sjoerg{
20420253Sjoerg	if (val == -1)
20520253Sjoerg		return "random";
20620253Sjoerg	else if (val == -2)
20720253Sjoerg		return "none";
20820253Sjoerg	else
20920253Sjoerg		return val ? booltrue[0] : boolfalse[0];
21020253Sjoerg}
21120253Sjoerg
21220253Sjoergchar           *
21320253Sjoergnewstr(char const * p)
21420253Sjoerg{
215282718Sbapt	char	*q;
21620253Sjoerg
217282718Sbapt	if ((p = unquote(p)) == NULL)
218282718Sbapt		return (NULL);
21920253Sjoerg
220282719Sbapt	if ((q = strdup(p)) == NULL)
221282719Sbapt		err(1, "strdup()");
222282718Sbapt
223282718Sbapt	return (q);
22420253Sjoerg}
22520253Sjoerg
22620253Sjoergstruct userconf *
22720253Sjoergread_userconfig(char const * file)
22820253Sjoerg{
229264781Sbapt	FILE	*fp;
230264781Sbapt	char	*buf, *p;
231264781Sbapt	size_t	linecap;
232264781Sbapt	ssize_t	linelen;
233286151Sbapt	const char *errstr;
23420253Sjoerg
235264781Sbapt	buf = NULL;
236264781Sbapt	linecap = 0;
237264781Sbapt
238285412Sbapt	config.groups = sl_init();
239282720Sbapt	if (config.groups == NULL)
240285412Sbapt		err(1, "sl_init()");
24120253Sjoerg	if (file == NULL)
24220253Sjoerg		file = _PATH_PW_CONF;
243264781Sbapt
244283815Sbapt	if ((fp = fopen(file, "r")) == NULL)
245283815Sbapt		return (&config);
24620747Sdavidn
247283815Sbapt	while ((linelen = getline(&buf, &linecap, fp)) > 0) {
248283815Sbapt		if (*buf && (p = strtok(buf, " \t\r\n=")) != NULL && *p != '#') {
249283815Sbapt			static char const toks[] = " \t\r\n,=";
250283815Sbapt			char           *q = strtok(NULL, toks);
251283815Sbapt			int             i = 0;
252283815Sbapt			mode_t          *modeset;
253283815Sbapt
254283815Sbapt			while (i < _UC_FIELDS && strcmp(p, kwds[i]) != 0)
255283815Sbapt				++i;
25620253Sjoerg#if debugging
257283815Sbapt			if (i == _UC_FIELDS)
258283815Sbapt				printf("Got unknown kwd `%s' val=`%s'\n", p, q ? q : "");
259283815Sbapt			else
260283815Sbapt				printf("Got kwd[%s]=%s\n", p, q);
26120253Sjoerg#endif
262283815Sbapt			switch (i) {
263283815Sbapt			case _UC_DEFAULTPWD:
264283815Sbapt				config.default_password = boolean_val(q, 1);
265283815Sbapt				break;
266283815Sbapt			case _UC_REUSEUID:
267283815Sbapt				config.reuse_uids = boolean_val(q, 0);
268283815Sbapt				break;
269283815Sbapt			case _UC_REUSEGID:
270283815Sbapt				config.reuse_gids = boolean_val(q, 0);
271283815Sbapt				break;
272283815Sbapt			case _UC_NISPASSWD:
273283815Sbapt				config.nispasswd = (q == NULL || !boolean_val(q, 1))
274283815Sbapt					? NULL : newstr(q);
275283815Sbapt				break;
276283815Sbapt			case _UC_DOTDIR:
277283815Sbapt				config.dotdir = (q == NULL || !boolean_val(q, 1))
278283815Sbapt					? NULL : newstr(q);
279283815Sbapt				break;
28020747Sdavidn				case _UC_NEWMAIL:
281283815Sbapt				config.newmail = (q == NULL || !boolean_val(q, 1))
282283815Sbapt					? NULL : newstr(q);
283283815Sbapt				break;
284283815Sbapt			case _UC_LOGFILE:
285283815Sbapt				config.logfile = (q == NULL || !boolean_val(q, 1))
286283815Sbapt					? NULL : newstr(q);
287283815Sbapt				break;
288283815Sbapt			case _UC_HOMEROOT:
289283815Sbapt				config.home = (q == NULL || !boolean_val(q, 1))
290283815Sbapt					? "/home" : newstr(q);
291283815Sbapt				break;
292283815Sbapt			case _UC_HOMEMODE:
293283815Sbapt				modeset = setmode(q);
294283815Sbapt				config.homemode = (q == NULL || !boolean_val(q, 1))
295283815Sbapt					? _DEF_DIRMODE : getmode(modeset, _DEF_DIRMODE);
296283815Sbapt				free(modeset);
297283815Sbapt				break;
298283815Sbapt			case _UC_SHELLPATH:
299283815Sbapt				config.shelldir = (q == NULL || !boolean_val(q, 1))
300283815Sbapt					? "/bin" : newstr(q);
301283815Sbapt				break;
302283815Sbapt			case _UC_SHELLS:
303283815Sbapt				for (i = 0; i < _UC_MAXSHELLS && q != NULL; i++, q = strtok(NULL, toks))
304283815Sbapt					system_shells[i] = newstr(q);
305283815Sbapt				if (i > 0)
306283815Sbapt					while (i < _UC_MAXSHELLS)
307283815Sbapt						system_shells[i++] = NULL;
308283815Sbapt				break;
309283815Sbapt			case _UC_DEFAULTSHELL:
310283815Sbapt				config.shell_default = (q == NULL || !boolean_val(q, 1))
311283815Sbapt					? (char *) bourne_shell : newstr(q);
312283815Sbapt				break;
313283815Sbapt			case _UC_DEFAULTGROUP:
314283815Sbapt				q = unquote(q);
315283815Sbapt				config.default_group = (q == NULL || !boolean_val(q, 1) || GETGRNAM(q) == NULL)
316283815Sbapt					? NULL : newstr(q);
317283815Sbapt				break;
318283815Sbapt			case _UC_EXTRAGROUPS:
319285412Sbapt				for (i = 0; q != NULL; q = strtok(NULL, toks))
320285412Sbapt					sl_add(config.groups, newstr(q));
321283815Sbapt				break;
322283815Sbapt			case _UC_DEFAULTCLASS:
323283815Sbapt				config.default_class = (q == NULL || !boolean_val(q, 1))
324283815Sbapt					? NULL : newstr(q);
325283815Sbapt				break;
326283815Sbapt			case _UC_MINUID:
327286151Sbapt				if ((q = unquote(q)) != NULL) {
328286151Sbapt					errstr = NULL;
329286151Sbapt					config.min_uid = strtounum(q, 0, UID_MAX, &errstr);
330286151Sbapt					if (errstr)
331286151Sbapt						warnx("Invalid min_uid: '%s', ignoring", q);
332286151Sbapt				}
333283815Sbapt				break;
334283815Sbapt			case _UC_MAXUID:
335286151Sbapt				if ((q = unquote(q)) != NULL) {
336286151Sbapt					errstr = NULL;
337286151Sbapt					config.max_uid = strtounum(q, 0, UID_MAX, &errstr);
338286151Sbapt					if (errstr)
339286151Sbapt						warnx("Invalid max_uid: '%s', ignoring", q);
340286151Sbapt				}
341283815Sbapt				break;
342283815Sbapt			case _UC_MINGID:
343283815Sbapt				if ((q = unquote(q)) != NULL && isdigit(*q))
344286151Sbapt					errstr = NULL;
345286151Sbapt					config.min_gid = strtounum(q, 0, GID_MAX, &errstr);
346286151Sbapt					if (errstr)
347286151Sbapt						warnx("Invalid min_gid: '%s', ignoring", q);
348283815Sbapt				break;
349283815Sbapt			case _UC_MAXGID:
350286151Sbapt				if ((q = unquote(q)) != NULL) {
351286151Sbapt					errstr = NULL;
352286151Sbapt					config.max_gid = strtounum(q, 0, GID_MAX, &errstr);
353286151Sbapt					if (errstr)
354286151Sbapt						warnx("Invalid max_gid: '%s', ignoring", q);
355286151Sbapt				}
356283815Sbapt				break;
357283815Sbapt			case _UC_EXPIRE:
358286152Sbapt				if ((q = unquote(q)) != NULL) {
359286152Sbapt					errstr = NULL;
360286152Sbapt					config.expire_days = strtonum(q, 0, INT_MAX, &errstr);
361286152Sbapt					if (errstr)
362286152Sbapt						warnx("Invalid expire days: '%s', ignoring", q);
363286152Sbapt				}
364283815Sbapt				break;
365283815Sbapt			case _UC_PASSWORD:
366286152Sbapt				if ((q = unquote(q)) != NULL) {
367286152Sbapt					errstr = NULL;
368286152Sbapt					config.password_days = strtonum(q, 0, INT_MAX, &errstr);
369286152Sbapt					if (errstr)
370286152Sbapt						warnx("Invalid password days: '%s', ignoring", q);
371286152Sbapt				}
372283815Sbapt				break;
373283815Sbapt			case _UC_FIELDS:
374283815Sbapt			case _UC_NONE:
375283815Sbapt				break;
37620253Sjoerg			}
37720253Sjoerg		}
37820253Sjoerg	}
379283818Sbapt	free(buf);
380283818Sbapt	fclose(fp);
381283818Sbapt
382283815Sbapt	return (&config);
38320253Sjoerg}
38420253Sjoerg
38520253Sjoerg
38620253Sjoergint
38720253Sjoergwrite_userconfig(char const * file)
38820253Sjoerg{
38920253Sjoerg	int             fd;
390282697Sbapt	int             i, j;
391282681Sbapt	struct sbuf	*buf;
392282697Sbapt	FILE           *fp;
39320253Sjoerg
39420253Sjoerg	if (file == NULL)
39520253Sjoerg		file = _PATH_PW_CONF;
39620253Sjoerg
397282697Sbapt	if ((fd = open(file, O_CREAT|O_RDWR|O_TRUNC|O_EXLOCK, 0644)) == -1)
398282697Sbapt		return (0);
39920253Sjoerg
400282697Sbapt	if ((fp = fdopen(fd, "w")) == NULL) {
401282697Sbapt		close(fd);
402282697Sbapt		return (0);
403282697Sbapt	}
404282681Sbapt
405282697Sbapt	buf = sbuf_new_auto();
406282697Sbapt	for (i = _UC_NONE; i < _UC_FIELDS; i++) {
407282697Sbapt		int             quote = 1;
40820253Sjoerg
409282697Sbapt		sbuf_clear(buf);
410282697Sbapt		switch (i) {
411282697Sbapt		case _UC_DEFAULTPWD:
412282697Sbapt			sbuf_cat(buf, boolean_str(config.default_password));
413282697Sbapt			break;
414282697Sbapt		case _UC_REUSEUID:
415282697Sbapt			sbuf_cat(buf, boolean_str(config.reuse_uids));
416282697Sbapt			break;
417282697Sbapt		case _UC_REUSEGID:
418282697Sbapt			sbuf_cat(buf, boolean_str(config.reuse_gids));
419282697Sbapt			break;
420282697Sbapt		case _UC_NISPASSWD:
421282697Sbapt			sbuf_cat(buf, config.nispasswd ?  config.nispasswd :
422282697Sbapt			    "");
423282697Sbapt			quote = 0;
424282697Sbapt			break;
425282697Sbapt		case _UC_DOTDIR:
426282697Sbapt			sbuf_cat(buf, config.dotdir ?  config.dotdir :
427282697Sbapt			    boolean_str(0));
428282697Sbapt			break;
429282697Sbapt		case _UC_NEWMAIL:
430282697Sbapt			sbuf_cat(buf, config.newmail ?  config.newmail :
431282697Sbapt			    boolean_str(0));
432282697Sbapt			break;
433282697Sbapt		case _UC_LOGFILE:
434282697Sbapt			sbuf_cat(buf, config.logfile ?  config.logfile :
435282697Sbapt			    boolean_str(0));
436282697Sbapt			break;
437282697Sbapt		case _UC_HOMEROOT:
438282697Sbapt			sbuf_cat(buf, config.home);
439282697Sbapt			break;
440282697Sbapt		case _UC_HOMEMODE:
441282697Sbapt			sbuf_printf(buf, "%04o", config.homemode);
442282697Sbapt			quote = 0;
443282697Sbapt			break;
444282697Sbapt		case _UC_SHELLPATH:
445282697Sbapt			sbuf_cat(buf, config.shelldir);
446282697Sbapt			break;
447282697Sbapt		case _UC_SHELLS:
448282697Sbapt			for (j = 0; j < _UC_MAXSHELLS &&
449282697Sbapt			    system_shells[j] != NULL; j++)
450282697Sbapt				sbuf_printf(buf, "%s\"%s\"", j ?
451282697Sbapt				    "," : "", system_shells[j]);
452282697Sbapt			quote = 0;
453282697Sbapt			break;
454282697Sbapt		case _UC_DEFAULTSHELL:
455282697Sbapt			sbuf_cat(buf, config.shell_default ?
456282697Sbapt			    config.shell_default : bourne_shell);
457282697Sbapt			break;
458282697Sbapt		case _UC_DEFAULTGROUP:
459282697Sbapt			sbuf_cat(buf, config.default_group ?
460282697Sbapt			    config.default_group : "");
461282697Sbapt			break;
462282697Sbapt		case _UC_EXTRAGROUPS:
463285412Sbapt			for (j = 0; config.groups != NULL &&
464285412Sbapt			    j < (int)config.groups->sl_cur; j++)
465282697Sbapt				sbuf_printf(buf, "%s\"%s\"", j ?
466285412Sbapt				    "," : "", config.groups->sl_str[j]);
467282697Sbapt			quote = 0;
468282697Sbapt			break;
469282697Sbapt		case _UC_DEFAULTCLASS:
470282697Sbapt			sbuf_cat(buf, config.default_class ?
471282697Sbapt			    config.default_class : "");
472282697Sbapt			break;
473282697Sbapt		case _UC_MINUID:
474286150Sbapt			sbuf_printf(buf, "%ju", (uintmax_t)config.min_uid);
475282697Sbapt			quote = 0;
476282697Sbapt			break;
477282697Sbapt		case _UC_MAXUID:
478286150Sbapt			sbuf_printf(buf, "%ju", (uintmax_t)config.max_uid);
479282697Sbapt			quote = 0;
480282697Sbapt			break;
481282697Sbapt		case _UC_MINGID:
482286150Sbapt			sbuf_printf(buf, "%ju", (uintmax_t)config.min_gid);
483282697Sbapt			quote = 0;
484282697Sbapt			break;
485282697Sbapt		case _UC_MAXGID:
486286150Sbapt			sbuf_printf(buf, "%ju", (uintmax_t)config.max_gid);
487282697Sbapt			quote = 0;
488282697Sbapt			break;
489282697Sbapt		case _UC_EXPIRE:
490282697Sbapt			sbuf_printf(buf, "%d", config.expire_days);
491282697Sbapt			quote = 0;
492282697Sbapt			break;
493282697Sbapt		case _UC_PASSWORD:
494282697Sbapt			sbuf_printf(buf, "%d", config.password_days);
495282697Sbapt			quote = 0;
496282697Sbapt			break;
497282697Sbapt		case _UC_NONE:
498282697Sbapt			break;
499282697Sbapt		}
500282697Sbapt		sbuf_finish(buf);
50120253Sjoerg
502282697Sbapt		if (comments[i])
503282697Sbapt			fputs(comments[i], fp);
50420253Sjoerg
505282697Sbapt		if (*kwds[i]) {
506282697Sbapt			if (quote)
507282697Sbapt				fprintf(fp, "%s = \"%s\"\n", kwds[i],
508282697Sbapt				    sbuf_data(buf));
509282697Sbapt			else
510282697Sbapt				fprintf(fp, "%s = %s\n", kwds[i], sbuf_data(buf));
51120253Sjoerg#if debugging
512282697Sbapt			printf("WROTE: %s = %s\n", kwds[i], sbuf_data(buf));
51320253Sjoerg#endif
51420253Sjoerg		}
51520253Sjoerg	}
516282697Sbapt	sbuf_delete(buf);
517282697Sbapt	return (fclose(fp) != EOF);
51820253Sjoerg}
519