Ejemplo n.º 1
0
Archivo: user.c Proyecto: tararc/talc
struct pop_passwd *unix_getpwuid(int uid) {
    return (convert_passwd(getpwuid(uid)));
}
Ejemplo n.º 2
0
/* this matches the code in uam_randnum.c */
static int update_passwd(const char *path, const char *name, int flags)
{
    char password[PASSWDLEN + 1], *p, *passwd;
    FILE *fp;
    off_t pos;
    int keyfd = -1, err = 0;

    if ((fp = fopen(path, "r+")) == NULL) {
        fprintf(stderr, "afppasswd: can't open %s\n", path);
        return -1;
    }

    /* open the key file if it exists */
    strcpy(buf, path);
    if (strlen(path) < sizeof(buf) - 5) {
        strcat(buf, ".key");
        keyfd = open(buf, O_RDONLY);
    }

    pos = ftell(fp);
    memset(buf, 0, sizeof(buf));
    while (fgets(buf, sizeof(buf), fp)) {
        if ((p = strchr(buf, ':'))) {
            /* check for a match */
            if (strlen(name) == (p - buf) &&
                    strncmp(buf, name, p - buf) == 0) {
                p++;
                if (!(flags & OPT_ISROOT) && (*p == PASSWD_ILLEGAL)) {
                    fprintf(stderr, "Your password is disabled. Please see your administrator.\n");
                    break;
                }
                goto found_entry;
            }
        }
        pos = ftell(fp);
        memset(buf, 0, sizeof(buf));
    }

    if (flags & OPT_ADDUSER) {
        strcpy(buf, name);
        strcat(buf, FORMAT);
        p = strchr(buf, ':') + 1;
        fwrite(buf, strlen(buf), 1, fp);
    } else {
        fprintf(stderr, "afppasswd: can't find %s in %s\n", name, path);
        err = -1;
        goto update_done;
    }

found_entry:
    /* need to verify against old password */
    if ((flags & OPT_ISROOT) == 0) {
        passwd = getpass("Enter OLD AFP password: "******"afppasswd: invalid password.\n");
            err = -1;
            goto update_done;
        }
    }

    /* new password */
    passwd = getpass("Enter NEW AFP password: "******"Error: %s\n", passwd);
            err = -1;
            goto update_done;
        }
    }
#endif /* USE_CRACKLIB */

    passwd = getpass("Enter NEW AFP password again: ");
    if (strcmp(passwd, password) == 0) {
        struct flock lock;
        int fd = fileno(fp);

        convert_passwd(p, password, keyfd);
        lock.l_type = F_WRLCK;
        lock.l_start = pos;
        lock.l_len = 1;
        lock.l_whence = SEEK_SET;
        fseek(fp, pos, SEEK_SET);
        fcntl(fd, F_SETLKW, &lock);
        fwrite(buf, p - buf + HEXPASSWDLEN, 1, fp);
        lock.l_type = F_UNLCK;
        fcntl(fd, F_SETLK, &lock);
        printf("afppasswd: updated password.\n");

    } else {
        fprintf(stderr, "afppasswd: passwords don't match!\n");
        err = -1;
    }

update_done:
    if (keyfd > -1)
        close(keyfd);
    fclose(fp);
    return err;
}
Ejemplo n.º 3
0
Archivo: user.c Proyecto: tararc/talc
struct pop_passwd *unix_getpwnam(string name) {
    char *Cname = convert_pop_string(name);
    return (convert_passwd(getpwnam(Cname)));
}