pw_conf.c revision 283818
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 283818 2015-05-31 12:04:06Z bapt $"; 3030259Scharnier#endif /* not lint */ 3130259Scharnier 32282681Sbapt#include <sys/types.h> 33282681Sbapt#include <sys/sbuf.h> 3420253Sjoerg#include <string.h> 3520253Sjoerg#include <ctype.h> 3620253Sjoerg#include <fcntl.h> 37282718Sbapt#include <err.h> 3820253Sjoerg 3920253Sjoerg#include "pw.h" 4020253Sjoerg 4120253Sjoerg#define debugging 0 4220253Sjoerg 4320253Sjoergenum { 4420253Sjoerg _UC_NONE, 4520253Sjoerg _UC_DEFAULTPWD, 4620253Sjoerg _UC_REUSEUID, 4720253Sjoerg _UC_REUSEGID, 4821330Sdavidn _UC_NISPASSWD, 4920253Sjoerg _UC_DOTDIR, 5020253Sjoerg _UC_NEWMAIL, 5120253Sjoerg _UC_LOGFILE, 5220253Sjoerg _UC_HOMEROOT, 53168044Sle _UC_HOMEMODE, 5420253Sjoerg _UC_SHELLPATH, 5520253Sjoerg _UC_SHELLS, 5620253Sjoerg _UC_DEFAULTSHELL, 5720253Sjoerg _UC_DEFAULTGROUP, 5820253Sjoerg _UC_EXTRAGROUPS, 5920253Sjoerg _UC_DEFAULTCLASS, 6020253Sjoerg _UC_MINUID, 6120253Sjoerg _UC_MAXUID, 6220253Sjoerg _UC_MINGID, 6320253Sjoerg _UC_MAXGID, 6420253Sjoerg _UC_EXPIRE, 6520253Sjoerg _UC_PASSWORD, 6620253Sjoerg _UC_FIELDS 6720253Sjoerg}; 6820253Sjoerg 6920253Sjoergstatic char bourne_shell[] = "sh"; 7020253Sjoerg 7120253Sjoergstatic char *system_shells[_UC_MAXSHELLS] = 7220253Sjoerg{ 7320253Sjoerg bourne_shell, 7463239Sdavidn "csh", 7563239Sdavidn "tcsh" 7620253Sjoerg}; 7720253Sjoerg 7820253Sjoergstatic char const *booltrue[] = 7920253Sjoerg{ 8020253Sjoerg "yes", "true", "1", "on", NULL 8120253Sjoerg}; 8220253Sjoergstatic char const *boolfalse[] = 8320253Sjoerg{ 8420253Sjoerg "no", "false", "0", "off", NULL 8520253Sjoerg}; 8620253Sjoerg 8720253Sjoergstatic struct userconf config = 8820253Sjoerg{ 8920253Sjoerg 0, /* Default password for new users? (nologin) */ 9020253Sjoerg 0, /* Reuse uids? */ 9120253Sjoerg 0, /* Reuse gids? */ 9221330Sdavidn NULL, /* NIS version of the passwd file */ 9320253Sjoerg "/usr/share/skel", /* Where to obtain skeleton files */ 9420253Sjoerg NULL, /* Mail to send to new accounts */ 9520253Sjoerg "/var/log/userlog", /* Where to log changes */ 9620253Sjoerg "/home", /* Where to create home directory */ 97219408Sjkim _DEF_DIRMODE, /* Home directory perms, modified by umask */ 9820253Sjoerg "/bin", /* Where shells are located */ 9920253Sjoerg system_shells, /* List of shells (first is default) */ 10020253Sjoerg bourne_shell, /* Default shell */ 10120253Sjoerg NULL, /* Default group name */ 10220747Sdavidn NULL, /* Default (additional) groups */ 10320253Sjoerg NULL, /* Default login class */ 10420253Sjoerg 1000, 32000, /* Allowed range of uids */ 10520253Sjoerg 1000, 32000, /* Allowed range of gids */ 10620253Sjoerg 0, /* Days until account expires */ 10749171Sdavidn 0, /* Days until password expires */ 10849171Sdavidn 0 /* size of default_group array */ 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; 23320253Sjoerg 234264781Sbapt buf = NULL; 235264781Sbapt linecap = 0; 236264781Sbapt 237282720Sbapt config.numgroups = 200; 238282720Sbapt config.groups = calloc(config.numgroups, sizeof(char *)); 239282720Sbapt if (config.groups == NULL) 240282720Sbapt err(1, "calloc()"); 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: 319283815Sbapt for (i = 0; q != NULL; q = strtok(NULL, toks)) { 320283815Sbapt if (extendarray(&config.groups, &config.numgroups, i + 2) != -1) 321283815Sbapt config.groups[i++] = newstr(q); 32220253Sjoerg } 323283815Sbapt if (i > 0) 324283815Sbapt while (i < config.numgroups) 325283815Sbapt config.groups[i++] = NULL; 326283815Sbapt break; 327283815Sbapt case _UC_DEFAULTCLASS: 328283815Sbapt config.default_class = (q == NULL || !boolean_val(q, 1)) 329283815Sbapt ? NULL : newstr(q); 330283815Sbapt break; 331283815Sbapt case _UC_MINUID: 332283815Sbapt if ((q = unquote(q)) != NULL && isdigit(*q)) 333283815Sbapt config.min_uid = (uid_t) atol(q); 334283815Sbapt break; 335283815Sbapt case _UC_MAXUID: 336283815Sbapt if ((q = unquote(q)) != NULL && isdigit(*q)) 337283815Sbapt config.max_uid = (uid_t) atol(q); 338283815Sbapt break; 339283815Sbapt case _UC_MINGID: 340283815Sbapt if ((q = unquote(q)) != NULL && isdigit(*q)) 341283815Sbapt config.min_gid = (gid_t) atol(q); 342283815Sbapt break; 343283815Sbapt case _UC_MAXGID: 344283815Sbapt if ((q = unquote(q)) != NULL && isdigit(*q)) 345283815Sbapt config.max_gid = (gid_t) atol(q); 346283815Sbapt break; 347283815Sbapt case _UC_EXPIRE: 348283815Sbapt if ((q = unquote(q)) != NULL && isdigit(*q)) 349283815Sbapt config.expire_days = atoi(q); 350283815Sbapt break; 351283815Sbapt case _UC_PASSWORD: 352283815Sbapt if ((q = unquote(q)) != NULL && isdigit(*q)) 353283815Sbapt config.password_days = atoi(q); 354283815Sbapt break; 355283815Sbapt case _UC_FIELDS: 356283815Sbapt case _UC_NONE: 357283815Sbapt break; 35820253Sjoerg } 35920253Sjoerg } 36020253Sjoerg } 361283818Sbapt free(buf); 362283818Sbapt fclose(fp); 363283818Sbapt 364283815Sbapt return (&config); 36520253Sjoerg} 36620253Sjoerg 36720253Sjoerg 36820253Sjoergint 36920253Sjoergwrite_userconfig(char const * file) 37020253Sjoerg{ 37120253Sjoerg int fd; 372282697Sbapt int i, j; 373282681Sbapt struct sbuf *buf; 374282697Sbapt FILE *fp; 37520253Sjoerg 37620253Sjoerg if (file == NULL) 37720253Sjoerg file = _PATH_PW_CONF; 37820253Sjoerg 379282697Sbapt if ((fd = open(file, O_CREAT|O_RDWR|O_TRUNC|O_EXLOCK, 0644)) == -1) 380282697Sbapt return (0); 38120253Sjoerg 382282697Sbapt if ((fp = fdopen(fd, "w")) == NULL) { 383282697Sbapt close(fd); 384282697Sbapt return (0); 385282697Sbapt } 386282681Sbapt 387282697Sbapt buf = sbuf_new_auto(); 388282697Sbapt for (i = _UC_NONE; i < _UC_FIELDS; i++) { 389282697Sbapt int quote = 1; 39020253Sjoerg 391282697Sbapt sbuf_clear(buf); 392282697Sbapt switch (i) { 393282697Sbapt case _UC_DEFAULTPWD: 394282697Sbapt sbuf_cat(buf, boolean_str(config.default_password)); 395282697Sbapt break; 396282697Sbapt case _UC_REUSEUID: 397282697Sbapt sbuf_cat(buf, boolean_str(config.reuse_uids)); 398282697Sbapt break; 399282697Sbapt case _UC_REUSEGID: 400282697Sbapt sbuf_cat(buf, boolean_str(config.reuse_gids)); 401282697Sbapt break; 402282697Sbapt case _UC_NISPASSWD: 403282697Sbapt sbuf_cat(buf, config.nispasswd ? config.nispasswd : 404282697Sbapt ""); 405282697Sbapt quote = 0; 406282697Sbapt break; 407282697Sbapt case _UC_DOTDIR: 408282697Sbapt sbuf_cat(buf, config.dotdir ? config.dotdir : 409282697Sbapt boolean_str(0)); 410282697Sbapt break; 411282697Sbapt case _UC_NEWMAIL: 412282697Sbapt sbuf_cat(buf, config.newmail ? config.newmail : 413282697Sbapt boolean_str(0)); 414282697Sbapt break; 415282697Sbapt case _UC_LOGFILE: 416282697Sbapt sbuf_cat(buf, config.logfile ? config.logfile : 417282697Sbapt boolean_str(0)); 418282697Sbapt break; 419282697Sbapt case _UC_HOMEROOT: 420282697Sbapt sbuf_cat(buf, config.home); 421282697Sbapt break; 422282697Sbapt case _UC_HOMEMODE: 423282697Sbapt sbuf_printf(buf, "%04o", config.homemode); 424282697Sbapt quote = 0; 425282697Sbapt break; 426282697Sbapt case _UC_SHELLPATH: 427282697Sbapt sbuf_cat(buf, config.shelldir); 428282697Sbapt break; 429282697Sbapt case _UC_SHELLS: 430282697Sbapt for (j = 0; j < _UC_MAXSHELLS && 431282697Sbapt system_shells[j] != NULL; j++) 432282697Sbapt sbuf_printf(buf, "%s\"%s\"", j ? 433282697Sbapt "," : "", system_shells[j]); 434282697Sbapt quote = 0; 435282697Sbapt break; 436282697Sbapt case _UC_DEFAULTSHELL: 437282697Sbapt sbuf_cat(buf, config.shell_default ? 438282697Sbapt config.shell_default : bourne_shell); 439282697Sbapt break; 440282697Sbapt case _UC_DEFAULTGROUP: 441282697Sbapt sbuf_cat(buf, config.default_group ? 442282697Sbapt config.default_group : ""); 443282697Sbapt break; 444282697Sbapt case _UC_EXTRAGROUPS: 445282697Sbapt for (j = 0; j < config.numgroups && 446282697Sbapt config.groups[j] != NULL; j++) 447282697Sbapt sbuf_printf(buf, "%s\"%s\"", j ? 448282697Sbapt "," : "", config.groups[j]); 449282697Sbapt quote = 0; 450282697Sbapt break; 451282697Sbapt case _UC_DEFAULTCLASS: 452282697Sbapt sbuf_cat(buf, config.default_class ? 453282697Sbapt config.default_class : ""); 454282697Sbapt break; 455282697Sbapt case _UC_MINUID: 456282697Sbapt sbuf_printf(buf, "%lu", (unsigned long) config.min_uid); 457282697Sbapt quote = 0; 458282697Sbapt break; 459282697Sbapt case _UC_MAXUID: 460282697Sbapt sbuf_printf(buf, "%lu", (unsigned long) config.max_uid); 461282697Sbapt quote = 0; 462282697Sbapt break; 463282697Sbapt case _UC_MINGID: 464282697Sbapt sbuf_printf(buf, "%lu", (unsigned long) config.min_gid); 465282697Sbapt quote = 0; 466282697Sbapt break; 467282697Sbapt case _UC_MAXGID: 468282697Sbapt sbuf_printf(buf, "%lu", (unsigned long) config.max_gid); 469282697Sbapt quote = 0; 470282697Sbapt break; 471282697Sbapt case _UC_EXPIRE: 472282697Sbapt sbuf_printf(buf, "%d", config.expire_days); 473282697Sbapt quote = 0; 474282697Sbapt break; 475282697Sbapt case _UC_PASSWORD: 476282697Sbapt sbuf_printf(buf, "%d", config.password_days); 477282697Sbapt quote = 0; 478282697Sbapt break; 479282697Sbapt case _UC_NONE: 480282697Sbapt break; 481282697Sbapt } 482282697Sbapt sbuf_finish(buf); 48320253Sjoerg 484282697Sbapt if (comments[i]) 485282697Sbapt fputs(comments[i], fp); 48620253Sjoerg 487282697Sbapt if (*kwds[i]) { 488282697Sbapt if (quote) 489282697Sbapt fprintf(fp, "%s = \"%s\"\n", kwds[i], 490282697Sbapt sbuf_data(buf)); 491282697Sbapt else 492282697Sbapt fprintf(fp, "%s = %s\n", kwds[i], sbuf_data(buf)); 49320253Sjoerg#if debugging 494282697Sbapt printf("WROTE: %s = %s\n", kwds[i], sbuf_data(buf)); 49520253Sjoerg#endif 49620253Sjoerg } 49720253Sjoerg } 498282697Sbapt sbuf_delete(buf); 499282697Sbapt return (fclose(fp) != EOF); 50020253Sjoerg} 501