Deleted Added
full compact
pw_conf.c (286157) pw_conf.c (286196)
1/*-
2 * Copyright (C) 1996
3 * David L. Nugent. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
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
24 * SUCH DAMAGE.
25 */
26
27#ifndef lint
28static const char rcsid[] =
1/*-
2 * Copyright (C) 1996
3 * David L. Nugent. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
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
24 * SUCH DAMAGE.
25 */
26
27#ifndef lint
28static const char rcsid[] =
29 "$FreeBSD: head/usr.sbin/pw/pw_conf.c 286157 2015-08-01 12:20:55Z bapt $";
29 "$FreeBSD: head/usr.sbin/pw/pw_conf.c 286196 2015-08-02 12:47:50Z bapt $";
30#endif /* not lint */
31
32#include <sys/types.h>
33#include <sys/sbuf.h>
34#include <inttypes.h>
35#include <string.h>
36#include <ctype.h>
37#include <fcntl.h>

--- 192 unchanged lines hidden (view full) ---

230 char *buf, *p;
231 const char *errstr;
232 size_t linecap;
233 ssize_t linelen;
234
235 buf = NULL;
236 linecap = 0;
237
30#endif /* not lint */
31
32#include <sys/types.h>
33#include <sys/sbuf.h>
34#include <inttypes.h>
35#include <string.h>
36#include <ctype.h>
37#include <fcntl.h>

--- 192 unchanged lines hidden (view full) ---

230 char *buf, *p;
231 const char *errstr;
232 size_t linecap;
233 ssize_t linelen;
234
235 buf = NULL;
236 linecap = 0;
237
238 config.groups = sl_init();
239 if (config.groups == NULL)
240 err(1, "sl_init()");
241 if (file == NULL)
242 file = _PATH_PW_CONF;
243
244 if ((fp = fopen(file, "r")) == NULL)
245 return (&config);
246
247 while ((linelen = getline(&buf, &linecap, fp)) > 0) {
248 if (*buf && (p = strtok(buf, " \t\r\n=")) != NULL && *p != '#') {

--- 62 unchanged lines hidden (view full) ---

311 ? (char *) bourne_shell : newstr(q);
312 break;
313 case _UC_DEFAULTGROUP:
314 q = unquote(q);
315 config.default_group = (q == NULL || !boolean_val(q, 1) || GETGRNAM(q) == NULL)
316 ? NULL : newstr(q);
317 break;
318 case _UC_EXTRAGROUPS:
238 if (file == NULL)
239 file = _PATH_PW_CONF;
240
241 if ((fp = fopen(file, "r")) == NULL)
242 return (&config);
243
244 while ((linelen = getline(&buf, &linecap, fp)) > 0) {
245 if (*buf && (p = strtok(buf, " \t\r\n=")) != NULL && *p != '#') {

--- 62 unchanged lines hidden (view full) ---

308 ? (char *) bourne_shell : newstr(q);
309 break;
310 case _UC_DEFAULTGROUP:
311 q = unquote(q);
312 config.default_group = (q == NULL || !boolean_val(q, 1) || GETGRNAM(q) == NULL)
313 ? NULL : newstr(q);
314 break;
315 case _UC_EXTRAGROUPS:
319 for (i = 0; q != NULL; q = strtok(NULL, toks))
316 for (i = 0; q != NULL; q = strtok(NULL, toks)) {
317 if (config.groups == NULL)
318 config.groups = sl_init();
320 sl_add(config.groups, newstr(q));
319 sl_add(config.groups, newstr(q));
320 }
321 break;
322 case _UC_DEFAULTCLASS:
323 config.default_class = (q == NULL || !boolean_val(q, 1))
324 ? NULL : newstr(q);
325 break;
326 case _UC_MINUID:
327 if ((q = unquote(q)) != NULL) {
328 config.min_uid = strtounum(q, 0,

--- 57 unchanged lines hidden (view full) ---

386 free(buf);
387 fclose(fp);
388
389 return (&config);
390}
391
392
393int
321 break;
322 case _UC_DEFAULTCLASS:
323 config.default_class = (q == NULL || !boolean_val(q, 1))
324 ? NULL : newstr(q);
325 break;
326 case _UC_MINUID:
327 if ((q = unquote(q)) != NULL) {
328 config.min_uid = strtounum(q, 0,

--- 57 unchanged lines hidden (view full) ---

386 free(buf);
387 fclose(fp);
388
389 return (&config);
390}
391
392
393int
394write_userconfig(char const * file)
394write_userconfig(struct userconf *cnf, const char *file)
395{
396 int fd;
397 int i, j;
398 struct sbuf *buf;
399 FILE *fp;
400
401 if (file == NULL)
402 file = _PATH_PW_CONF;

--- 8 unchanged lines hidden (view full) ---

411
412 buf = sbuf_new_auto();
413 for (i = _UC_NONE; i < _UC_FIELDS; i++) {
414 int quote = 1;
415
416 sbuf_clear(buf);
417 switch (i) {
418 case _UC_DEFAULTPWD:
395{
396 int fd;
397 int i, j;
398 struct sbuf *buf;
399 FILE *fp;
400
401 if (file == NULL)
402 file = _PATH_PW_CONF;

--- 8 unchanged lines hidden (view full) ---

411
412 buf = sbuf_new_auto();
413 for (i = _UC_NONE; i < _UC_FIELDS; i++) {
414 int quote = 1;
415
416 sbuf_clear(buf);
417 switch (i) {
418 case _UC_DEFAULTPWD:
419 sbuf_cat(buf, boolean_str(config.default_password));
419 sbuf_cat(buf, boolean_str(cnf->default_password));
420 break;
421 case _UC_REUSEUID:
420 break;
421 case _UC_REUSEUID:
422 sbuf_cat(buf, boolean_str(config.reuse_uids));
422 sbuf_cat(buf, boolean_str(cnf->reuse_uids));
423 break;
424 case _UC_REUSEGID:
423 break;
424 case _UC_REUSEGID:
425 sbuf_cat(buf, boolean_str(config.reuse_gids));
425 sbuf_cat(buf, boolean_str(cnf->reuse_gids));
426 break;
427 case _UC_NISPASSWD:
426 break;
427 case _UC_NISPASSWD:
428 sbuf_cat(buf, config.nispasswd ? config.nispasswd :
429 "");
428 sbuf_cat(buf, cnf->nispasswd ? cnf->nispasswd : "");
430 quote = 0;
431 break;
432 case _UC_DOTDIR:
429 quote = 0;
430 break;
431 case _UC_DOTDIR:
433 sbuf_cat(buf, config.dotdir ? config.dotdir :
432 sbuf_cat(buf, cnf->dotdir ? cnf->dotdir :
434 boolean_str(0));
435 break;
436 case _UC_NEWMAIL:
433 boolean_str(0));
434 break;
435 case _UC_NEWMAIL:
437 sbuf_cat(buf, config.newmail ? config.newmail :
436 sbuf_cat(buf, cnf->newmail ? cnf->newmail :
438 boolean_str(0));
439 break;
440 case _UC_LOGFILE:
437 boolean_str(0));
438 break;
439 case _UC_LOGFILE:
441 sbuf_cat(buf, config.logfile ? config.logfile :
440 sbuf_cat(buf, cnf->logfile ? cnf->logfile :
442 boolean_str(0));
443 break;
444 case _UC_HOMEROOT:
441 boolean_str(0));
442 break;
443 case _UC_HOMEROOT:
445 sbuf_cat(buf, config.home);
444 sbuf_cat(buf, cnf->home);
446 break;
447 case _UC_HOMEMODE:
445 break;
446 case _UC_HOMEMODE:
448 sbuf_printf(buf, "%04o", config.homemode);
447 sbuf_printf(buf, "%04o", cnf->homemode);
449 quote = 0;
450 break;
451 case _UC_SHELLPATH:
448 quote = 0;
449 break;
450 case _UC_SHELLPATH:
452 sbuf_cat(buf, config.shelldir);
451 sbuf_cat(buf, cnf->shelldir);
453 break;
454 case _UC_SHELLS:
455 for (j = 0; j < _UC_MAXSHELLS &&
456 system_shells[j] != NULL; j++)
457 sbuf_printf(buf, "%s\"%s\"", j ?
458 "," : "", system_shells[j]);
459 quote = 0;
460 break;
461 case _UC_DEFAULTSHELL:
452 break;
453 case _UC_SHELLS:
454 for (j = 0; j < _UC_MAXSHELLS &&
455 system_shells[j] != NULL; j++)
456 sbuf_printf(buf, "%s\"%s\"", j ?
457 "," : "", system_shells[j]);
458 quote = 0;
459 break;
460 case _UC_DEFAULTSHELL:
462 sbuf_cat(buf, config.shell_default ?
463 config.shell_default : bourne_shell);
461 sbuf_cat(buf, cnf->shell_default ?
462 cnf->shell_default : bourne_shell);
464 break;
465 case _UC_DEFAULTGROUP:
463 break;
464 case _UC_DEFAULTGROUP:
466 sbuf_cat(buf, config.default_group ?
467 config.default_group : "");
465 sbuf_cat(buf, cnf->default_group ?
466 cnf->default_group : "");
468 break;
469 case _UC_EXTRAGROUPS:
467 break;
468 case _UC_EXTRAGROUPS:
470 for (j = 0; config.groups != NULL &&
471 j < (int)config.groups->sl_cur; j++)
469 for (j = 0; cnf->groups != NULL &&
470 j < (int)cnf->groups->sl_cur; j++)
472 sbuf_printf(buf, "%s\"%s\"", j ?
471 sbuf_printf(buf, "%s\"%s\"", j ?
473 "," : "", config.groups->sl_str[j]);
472 "," : "", cnf->groups->sl_str[j]);
474 quote = 0;
475 break;
476 case _UC_DEFAULTCLASS:
473 quote = 0;
474 break;
475 case _UC_DEFAULTCLASS:
477 sbuf_cat(buf, config.default_class ?
478 config.default_class : "");
476 sbuf_cat(buf, cnf->default_class ?
477 cnf->default_class : "");
479 break;
480 case _UC_MINUID:
478 break;
479 case _UC_MINUID:
481 sbuf_printf(buf, "%ju", (uintmax_t)config.min_uid);
480 sbuf_printf(buf, "%ju", (uintmax_t)cnf->min_uid);
482 quote = 0;
483 break;
484 case _UC_MAXUID:
481 quote = 0;
482 break;
483 case _UC_MAXUID:
485 sbuf_printf(buf, "%ju", (uintmax_t)config.max_uid);
484 sbuf_printf(buf, "%ju", (uintmax_t)cnf->max_uid);
486 quote = 0;
487 break;
488 case _UC_MINGID:
485 quote = 0;
486 break;
487 case _UC_MINGID:
489 sbuf_printf(buf, "%ju", (uintmax_t)config.min_gid);
488 sbuf_printf(buf, "%ju", (uintmax_t)cnf->min_gid);
490 quote = 0;
491 break;
492 case _UC_MAXGID:
489 quote = 0;
490 break;
491 case _UC_MAXGID:
493 sbuf_printf(buf, "%ju", (uintmax_t)config.max_gid);
492 sbuf_printf(buf, "%ju", (uintmax_t)cnf->max_gid);
494 quote = 0;
495 break;
496 case _UC_EXPIRE:
493 quote = 0;
494 break;
495 case _UC_EXPIRE:
497 sbuf_printf(buf, "%d", config.expire_days);
496 sbuf_printf(buf, "%ld", cnf->expire_days);
498 quote = 0;
499 break;
500 case _UC_PASSWORD:
497 quote = 0;
498 break;
499 case _UC_PASSWORD:
501 sbuf_printf(buf, "%d", config.password_days);
500 sbuf_printf(buf, "%ld", cnf->password_days);
502 quote = 0;
503 break;
504 case _UC_NONE:
505 break;
506 }
507 sbuf_finish(buf);
508
509 if (comments[i])

--- 16 unchanged lines hidden ---
501 quote = 0;
502 break;
503 case _UC_NONE:
504 break;
505 }
506 sbuf_finish(buf);
507
508 if (comments[i])

--- 16 unchanged lines hidden ---