pw_user.c (645c2851e21b266ad21b9644a75dbc056606e1b9) pw_user.c (0aa2700123e22c2b0a977375e087dc2759b8e980)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (C) 1996
5 * David L. Nugent. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

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

79 gid_t prefer, bool dryrun);
80static char *pw_homepolicy(struct userconf * cnf, char *homedir,
81 const char *user);
82static char *pw_shellpolicy(struct userconf * cnf);
83static char *pw_password(struct userconf * cnf, char const * user,
84 bool dryrun);
85static char *shell_path(char const * path, char *shells[], char *sh);
86static void rmat(uid_t uid);
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (C) 1996
5 * David L. Nugent. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

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

79 gid_t prefer, bool dryrun);
80static char *pw_homepolicy(struct userconf * cnf, char *homedir,
81 const char *user);
82static char *pw_shellpolicy(struct userconf * cnf);
83static char *pw_password(struct userconf * cnf, char const * user,
84 bool dryrun);
85static char *shell_path(char const * path, char *shells[], char *sh);
86static void rmat(uid_t uid);
87static void rmopie(char const * name);
88
89static void
90mkdir_home_parents(int dfd, const char *dir)
91{
92 struct stat st;
93 char *dirs, *tmp;
94
95 if (*dir != '/')

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

702 e->d_name);
703 system(tmp);
704 }
705 }
706 closedir(d);
707 }
708}
709
87
88static void
89mkdir_home_parents(int dfd, const char *dir)
90{
91 struct stat st;
92 char *dirs, *tmp;
93
94 if (*dir != '/')

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

701 e->d_name);
702 system(tmp);
703 }
704 }
705 closedir(d);
706 }
707}
708
710static void
711rmopie(char const * name)
712{
713 char tmp[1014];
714 FILE *fp;
715 size_t len;
716 long atofs;
717 int fd;
718
719 if ((fd = openat(conf.rootfd, "etc/opiekeys", O_RDWR)) == -1)
720 return;
721
722 fp = fdopen(fd, "r+");
723 len = strlen(name);
724
725 for (atofs = 0; fgets(tmp, sizeof(tmp), fp) != NULL && atofs >= 0;
726 atofs = ftell(fp)) {
727 if (strncmp(name, tmp, len) == 0 && tmp[len]==' ') {
728 /* Comment username out */
729 if (fseek(fp, atofs, SEEK_SET) == 0)
730 fwrite("#", 1, 1, fp);
731 break;
732 }
733 }
734 /*
735 * If we got an error of any sort, don't update!
736 */
737 fclose(fp);
738}
739
740int
741pw_user_next(int argc, char **argv, char *name __unused)
742{
743 struct userconf *cnf = NULL;
744 const char *cfg = NULL;
745 int ch;
746 bool quiet = false;
747 uid_t next;

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

932
933 id = pwd->pw_uid;
934 if (name == NULL)
935 name = pwd->pw_name;
936
937 if (strcmp(pwd->pw_name, "root") == 0)
938 errx(EX_DATAERR, "cannot remove user 'root'");
939
709int
710pw_user_next(int argc, char **argv, char *name __unused)
711{
712 struct userconf *cnf = NULL;
713 const char *cfg = NULL;
714 int ch;
715 bool quiet = false;
716 uid_t next;

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

901
902 id = pwd->pw_uid;
903 if (name == NULL)
904 name = pwd->pw_name;
905
906 if (strcmp(pwd->pw_name, "root") == 0)
907 errx(EX_DATAERR, "cannot remove user 'root'");
908
940 /* Remove opie record from /etc/opiekeys */
941 if (PWALTDIR() != PWF_ALT)
942 rmopie(pwd->pw_name);
943
944 if (!PWALTDIR()) {
945 /* Remove crontabs */
946 snprintf(file, sizeof(file), "/var/cron/tabs/%s", pwd->pw_name);
947 if (access(file, F_OK) == 0) {
948 snprintf(file, sizeof(file), "crontab -u %s -r",
949 pwd->pw_name);
950 system(file);
951 }

--- 888 unchanged lines hidden ---
909 if (!PWALTDIR()) {
910 /* Remove crontabs */
911 snprintf(file, sizeof(file), "/var/cron/tabs/%s", pwd->pw_name);
912 if (access(file, F_OK) == 0) {
913 snprintf(file, sizeof(file), "crontab -u %s -r",
914 pwd->pw_name);
915 system(file);
916 }

--- 888 unchanged lines hidden ---