-/* $OpenBSD: user.c,v 1.5 2000/04/24 22:40:11 jakob Exp $ */
+/* $OpenBSD: user.c,v 1.6 2000/04/24 22:52:36 jakob Exp $ */
/* $NetBSD: user.c,v 1.17 2000/04/14 06:26:55 simonb Exp $ */
/*
#define DEF_EXPIRE (char *) NULL
#endif
-#ifndef MASTER
-#define MASTER "/etc/master.passwd"
-#endif
-
-#ifndef ETCGROUP
-#define ETCGROUP "/etc/group"
-#endif
-
#ifndef WAITSECS
#define WAITSECS 10
#endif
warnx("group `%s' already exists", group);
return 0;
}
- if ((from = fopen(ETCGROUP, "r")) == (FILE *) NULL) {
- warn("can't create gid for %s: can't open %s", name, ETCGROUP);
+ if ((from = fopen(_PATH_GROUP, "r")) == (FILE *) NULL) {
+ warn("can't create gid for %s: can't open %s", name, _PATH_GROUP);
return 0;
}
if (flock(fileno(from), LOCK_EX | LOCK_NB) < 0) {
- warn("can't lock `%s'", ETCGROUP);
+ warn("can't lock `%s'", _PATH_GROUP);
}
(void) fstat(fileno(from), &st);
- (void) snprintf(f, sizeof(f), "%s.XXXXXX", ETCGROUP);
+ (void) snprintf(f, sizeof(f), "%s.XXXXXX", _PATH_GROUP);
if ((fd = mkstemp(f)) < 0) {
(void) fclose(from);
warn("can't create gid: mkstemp failed");
(void) fprintf(to, "%s:*:%d:%s\n", group, gid, name);
(void) fclose(from);
(void) fclose(to);
- if (rename(f, ETCGROUP) < 0) {
- warn("can't create gid: can't rename `%s' to `%s'", f, ETCGROUP);
+ if (rename(f, _PATH_GROUP) < 0) {
+ warn("can't create gid: can't rename `%s' to `%s'", f, _PATH_GROUP);
return 0;
}
- (void) chmod(ETCGROUP, st.st_mode & 07777);
+ (void) chmod(_PATH_GROUP, st.st_mode & 07777);
return 1;
}
int fd;
int cc;
- if ((from = fopen(ETCGROUP, "r")) == (FILE *) NULL) {
- warn("can't create gid for %s: can't open %s", group, ETCGROUP);
+ if ((from = fopen(_PATH_GROUP, "r")) == (FILE *) NULL) {
+ warn("can't create gid for %s: can't open %s", group, _PATH_GROUP);
return 0;
}
if (flock(fileno(from), LOCK_EX | LOCK_NB) < 0) {
- warn("can't lock `%s'", ETCGROUP);
+ warn("can't lock `%s'", _PATH_GROUP);
}
(void) fstat(fileno(from), &st);
- (void) snprintf(f, sizeof(f), "%s.XXXXXX", ETCGROUP);
+ (void) snprintf(f, sizeof(f), "%s.XXXXXX", _PATH_GROUP);
if ((fd = mkstemp(f)) < 0) {
(void) fclose(from);
warn("can't create gid: mkstemp failed");
}
(void) fclose(from);
(void) fclose(to);
- if (rename(f, ETCGROUP) < 0) {
- warn("can't create gid: can't rename `%s' to `%s'", f, ETCGROUP);
+ if (rename(f, _PATH_GROUP) < 0) {
+ warn("can't create gid: can't rename `%s' to `%s'", f, _PATH_GROUP);
return 0;
}
- (void) chmod(ETCGROUP, st.st_mode & 07777);
+ (void) chmod(_PATH_GROUP, st.st_mode & 07777);
return 1;
}
if (!valid_login(login)) {
errx(EXIT_FAILURE, "`%s' is not a valid login name", login);
}
- if ((masterfd = open(MASTER, O_RDONLY)) < 0) {
- err(EXIT_FAILURE, "can't open `%s'", MASTER);
+ if ((masterfd = open(_PATH_MASTERPASSWD, O_RDONLY)) < 0) {
+ err(EXIT_FAILURE, "can't open `%s'", _PATH_MASTERPASSWD);
}
if (flock(masterfd, LOCK_EX | LOCK_NB) < 0) {
- err(EXIT_FAILURE, "can't lock `%s'", MASTER);
+ err(EXIT_FAILURE, "can't lock `%s'", _PATH_MASTERPASSWD);
}
pw_init();
if ((ptmpfd = pw_lock(WAITSECS)) < 0) {
if ((pwp = getpwnam(login)) == (struct passwd *) NULL) {
errx(EXIT_FAILURE, "No such user `%s'", login);
}
- if ((masterfd = open(MASTER, O_RDONLY)) < 0) {
- err(EXIT_FAILURE, "can't open `%s'", MASTER);
+ if ((masterfd = open(_PATH_MASTERPASSWD, O_RDONLY)) < 0) {
+ err(EXIT_FAILURE, "can't open `%s'", _PATH_MASTERPASSWD);
}
if (flock(masterfd, LOCK_EX | LOCK_NB) < 0) {
- err(EXIT_FAILURE, "can't lock `%s'", MASTER);
+ err(EXIT_FAILURE, "can't lock `%s'", _PATH_MASTERPASSWD);
}
pw_init();
if ((ptmpfd = pw_lock(WAITSECS)) < 0) {
(void) close(masterfd);
(void) close(ptmpfd);
(void) pw_abort();
- err(EXIT_FAILURE, "can't fdopen fd for %s", MASTER);
+ err(EXIT_FAILURE, "can't fdopen fd for %s", _PATH_MASTERPASSWD);
}
if (up != (user_t *) NULL) {
if (up->u_mkdir) {
warnx("warning - invalid group name `%s'", argv[optind]);
}
if (!creategid(argv[optind], gid, "")) {
- err(EXIT_FAILURE, "can't add group: problems with %s file", ETCGROUP);
+ err(EXIT_FAILURE, "can't add group: problems with %s file", _PATH_GROUP);
}
return EXIT_SUCCESS;
}
}
checkeuid();
if (!modify_gid(argv[optind], NULL)) {
- err(EXIT_FAILURE, "can't change %s file", ETCGROUP);
+ err(EXIT_FAILURE, "can't change %s file", _PATH_GROUP);
}
return EXIT_SUCCESS;
}
(cpp[1] == NULL) ? "" : ",");
}
if (!modify_gid(argv[optind], buf)) {
- err(EXIT_FAILURE, "can't change %s file", ETCGROUP);
+ err(EXIT_FAILURE, "can't change %s file", _PATH_GROUP);
}
return EXIT_SUCCESS;
}