+ sz = 0;
+ buf = NULL;
+ buffp = open_memstream(&buf, &sz);
+ if (buffp == NULL)
+ err(EXIT_FAILURE, "open_memstream()");
+
+ for (i = _UC_NONE; i < _UC_FIELDS; i++) {
+ int quote = 1;
+
+ if (buf != NULL)
+ memset(buf, 0, sz);
+ rewind(buffp);
+ switch (i) {
+ case _UC_DEFAULTPWD:
+ fputs(boolean_str(cnf->default_password), buffp);
+ break;
+ case _UC_REUSEUID:
+ fputs(boolean_str(cnf->reuse_uids), buffp);
+ break;
+ case _UC_REUSEGID:
+ fputs(boolean_str(cnf->reuse_gids), buffp);
+ break;
+ case _UC_NISPASSWD:
+ fputs(cnf->nispasswd ? cnf->nispasswd : "", buffp);
+ quote = 0;
+ break;
+ case _UC_DOTDIR:
+ fputs(cnf->dotdir ? cnf->dotdir : boolean_str(0),
+ buffp);
+ break;
+ case _UC_NEWMAIL:
+ fputs(cnf->newmail ? cnf->newmail : boolean_str(0),
+ buffp);
+ break;
+ case _UC_LOGFILE:
+ fputs(cnf->logfile ? cnf->logfile : boolean_str(0),
+ buffp);
+ break;
+ case _UC_HOMEROOT:
+ fputs(cnf->home, buffp);
+ break;
+ case _UC_HOMEMODE:
+ fprintf(buffp, "%04o", cnf->homemode);
+ quote = 0;
+ break;
+ case _UC_SHELLPATH:
+ fputs(cnf->shelldir, buffp);
+ break;
+ case _UC_SHELLS:
+ for (j = 0; j < _UC_MAXSHELLS &&
+ system_shells[j] != NULL; j++)
+ fprintf(buffp, "%s\"%s\"", j ?
+ "," : "", system_shells[j]);
+ quote = 0;
+ break;
+ case _UC_DEFAULTSHELL:
+ fputs(cnf->shell_default ? cnf->shell_default :
+ bourne_shell, buffp);
+ break;
+ case _UC_DEFAULTGROUP:
+ fputs(cnf->default_group ? cnf->default_group : "",
+ buffp);
+ break;
+ case _UC_EXTRAGROUPS:
+ for (j = 0; cnf->groups != NULL &&
+ j < (int)cnf->groups->sl_cur; j++)
+ fprintf(buffp, "%s\"%s\"", j ?
+ "," : "", cnf->groups->sl_str[j]);
+ quote = 0;
+ break;
+ case _UC_DEFAULTCLASS:
+ fputs(cnf->default_class ? cnf->default_class : "",
+ buffp);
+ break;
+ case _UC_MINUID:
+ fprintf(buffp, "%ju", (uintmax_t)cnf->min_uid);
+ quote = 0;
+ break;
+ case _UC_MAXUID:
+ fprintf(buffp, "%ju", (uintmax_t)cnf->max_uid);
+ quote = 0;
+ break;
+ case _UC_MINGID:
+ fprintf(buffp, "%ju", (uintmax_t)cnf->min_gid);
+ quote = 0;
+ break;
+ case _UC_MAXGID:
+ fprintf(buffp, "%ju", (uintmax_t)cnf->max_gid);
+ quote = 0;
+ break;
+ case _UC_EXPIRE:
+ fprintf(buffp, "%jd", (intmax_t)cnf->expire_days);
+ quote = 0;
+ break;
+ case _UC_PASSWORD:
+ fprintf(buffp, "%jd", (intmax_t)cnf->password_days);
+ quote = 0;
+ break;
+ case _UC_NONE:
+ break;
+ }
+ fflush(buffp);
+
+ if (comments[i])
+ fputs(comments[i], fp);
+
+ if (*kwds[i]) {
+ if (quote)
+ fprintf(fp, "%s = \"%s\"\n", kwds[i], buf);
+ else
+ fprintf(fp, "%s = %s\n", kwds[i], buf);