#include <sys/resource.h>
#include <unistd.h>
#include <login_cap.h>
+#include <pwd.h>
+#include <grp.h>
+#include <libutil.h>
#include "pw.h"
#include "bitmap.h"
struct stat st;
char line[_PASSWORD_LEN+1];
FILE *fp;
- mode_t dmode;
char *dmode_c;
void *set = NULL;
if ((set = setmode(dmode_c)) == NULL)
errx(EX_DATAERR, "invalid directory creation mode '%s'",
dmode_c);
- dmode = getmode(set, S_IRWXU | S_IRWXG | S_IRWXO);
+ cnf->homemode = getmode(set, _DEF_DIRMODE);
free(set);
- cnf->homemode = dmode;
}
/*
if (strchr(cnf->home+1, '/') == NULL) {
strcpy(dbuf, "/usr");
strncat(dbuf, cnf->home, MAXPATHLEN-5);
- if (mkdir(dbuf, cnf->homemode) != -1 || errno == EEXIST) {
+ if (mkdir(dbuf, _DEF_DIRMODE) != -1 || errno == EEXIST) {
chown(dbuf, 0, 0);
/*
* Skip first "/" and create symlink:
while ((p = strchr(++p, '/')) != NULL) {
*p = '\0';
if (stat(dbuf, &st) == -1) {
- if (mkdir(dbuf, cnf->homemode) == -1)
+ if (mkdir(dbuf, _DEF_DIRMODE) == -1)
goto direrr;
chown(dbuf, 0, 0);
} else if (!S_ISDIR(st.st_mode))
}
}
if (stat(dbuf, &st) == -1) {
- if (mkdir(dbuf, cnf->homemode) == -1) {
+ if (mkdir(dbuf, _DEF_DIRMODE) == -1) {
direrr: err(EX_OSFILE, "mkdir '%s'", dbuf);
}
chown(dbuf, 0, 0);
if (mode == M_PRINT && getarg(args, 'a')) {
int pretty = getarg(args, 'P') != NULL;
int v7 = getarg(args, '7') != NULL;
-
SETPWENT();
while ((pwd = GETPWENT()) != NULL)
print_user(pwd, pretty, v7);
*/
if (mode != M_ADD && pwd == NULL
&& strspn(a_name->val, "0123456789") == strlen(a_name->val)
- && atoi(a_name->val) > 0) { /* Assume uid */
+ && *a_name->val) {
(a_uid = a_name)->ch = 'u';
a_name = NULL;
}
/* non-fatal */
}
- editgroups(a_name->val, NULL);
+ grp = GETGRNAM(a_name->val);
+ if (*grp->gr_mem == NULL)
+ delgrent(GETGRNAM(a_name->val));
+ SETGRENT();
+ while ((grp = GETGRENT()) != NULL) {
+ int i;
+ char group[MAXLOGNAME];
+ for (i = 0; grp->gr_mem[i] != NULL; i++) {
+ if (!strcmp(grp->gr_mem[i], a_name->val)) {
+ while (grp->gr_mem[i] != NULL) {
+ grp->gr_mem[i] = grp->gr_mem[i+1];
+ }
+ strlcpy(group, grp->gr_name, MAXLOGNAME);
+ chggrent(group, grp);
+ }
+ }
+ }
+ ENDGRENT();
pw_log(cnf, mode, W_USER, "%s(%ld) account removed", a_name->val, (long) uid);
* Ok, user is created or changed - now edit group file
*/
- if (mode == M_ADD || getarg(args, 'G') != NULL)
- editgroups(pwd->pw_name, cnf->groups);
+ if (mode == M_ADD || getarg(args, 'G') != NULL) {
+ int i, j;
+ for (i = 0; cnf->groups[i] != NULL; i++) {
+ grp = GETGRNAM(cnf->groups[i]);
+ for (j = 0; grp->gr_mem[j] != NULL; j++) {
+ if (!strcmp(grp->gr_mem[j], pwd->pw_name))
+ break;
+ }
+ if (grp->gr_mem[j] != NULL) /* user already member of group */
+ continue;
+
+ if (j == 0)
+ grp->gr_mem = NULL;
+
+ grp->gr_mem = reallocf(grp->gr_mem, sizeof(*grp->gr_mem) *
+ (j + 2));
+
+ grp->gr_mem[j] = pwd->pw_name;
+ grp->gr_mem[j+1] = NULL;
+ chggrent(cnf->groups[i], grp);
+ }
+ }
+
/* go get a current version of pwd */
pwd = GETPWNAM(a_name->val);
{
int i;
char salt[SALTSIZE + 1];
+ char *cryptpw;
static char buf[256];
salt[i] = chars[arc4random_uniform(sizeof(chars) - 1)];
salt[SALTSIZE] = '\0';
- return strcpy(buf, crypt(password, salt));
+ cryptpw = crypt(password, salt);
+ if (cryptpw == NULL)
+ errx(EX_CONFIG, "crypt(3) failure");
+ return strcpy(buf, cryptpw);
}
print_user(struct passwd * pwd, int pretty, int v7)
{
if (!pretty) {
- char buf[_UC_MAXLINE];
+ char *buf;
+
+ if (!v7)
+ pwd->pw_passwd = (pwd->pw_passwd == NULL) ? "" : "*";
- fmtpwentry(buf, pwd, v7 ? PWF_PASSWD : PWF_STANDARD);
- fputs(buf, stdout);
+ buf = v7 ? pw_make_v7(pwd) : pw_make(pwd);
+ printf("%s\n", buf);
+ free(buf);
} else {
int j;
char *p;
if (reject) {
snprintf(showch, sizeof(showch), (*ch >= ' ' && *ch < 127)
? "`%c'" : "0x%02x", *ch);
- errx(EX_DATAERR, "invalid character %s at position %d in %s",
+ errx(EX_DATAERR, "invalid character %s at position %td in %s",
showch, (ch - name), showtype);
}
if (!gecos && (ch - name) > LOGNAMESIZE)