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