예제 #1
0
/* by name */
struct passwd *getpwnam(const char *name)
{
    struct dirent *dent;
    pw_tls_t *p;
    DIR *query;
    int err;
    int fd;

    PRINT(("%s(%s)\n", __FUNCTION__, name));
    p = get_pw_tls();
    if (!p) {
        /* we are really bork */
        __set_errno(ENOMEM);
        return NULL;
    }

    if (!name || strlen(name) > PW_MAX_NAME) {
        __set_errno(EINVAL);
        return NULL;
    }
    /* reusing path */
    sprintf(p->pwfile, QT_PW_NAM, name);
    PRINT(("%s: query(%s)\n", __FUNCTION__, p->pwfile));
    query = fs_open_query(boot_device, p->pwfile, 0);
    PRINT(("q: %p\n", query));
    if (!query)
        return NULL;

    dent = fs_read_query(query);
    if (!dent) {
        fs_close_query(query);
        return NULL;
    }
    PRINT(("%s: dentopen()\n", __FUNCTION__));
    fd = dentopen(dent, p->pwfile);
    fs_close_query(query);
    if (fd < B_OK)
        return NULL;
    err = fill_pwent_from_fd(fd, &p->pwent, p->pwbuff, PWBUFFSZ);
    PRINT(("%s: fill_pwent_from_fd = %d\n", __FUNCTION__, err));
    close(fd);
    if (err)
        return NULL;
    return &p->pwent;

}
예제 #2
0
void endpwent(void)
{
    pw_tls_t *p;
    PRINT(("%s()\n", __FUNCTION__));
    p = get_pw_tls();

    if (p->pwent_query)
        fs_close_query(p->pwent_query);
    p->pwent_query = NULL;
    p->pwidx = -1;
}
예제 #3
0
void setpwent(void)
{
    pw_tls_t *p;
    p = get_pw_tls();
    PRINT(("%s()\n", __FUNCTION__));
    if (p->pwent_query) /* clumsy apps */
        fs_close_query(p->pwent_query);
    p->pwent_query = fs_open_query(boot_device, Q_PW_ALL, 0);
    PRINT(("pwq: %p\n", p->pwent_query));
    p->pwidx = 0;
}
예제 #4
0
/* by gid */
struct passwd *getpwuid(uid_t uid)
{
    struct dirent *dent;
    pw_tls_t *p;
    DIR *query;
    int err;
    int fd;

    PRINT(("%s(%d)\n", __FUNCTION__, uid));
    p = get_pw_tls();
    if (!p) {
        /* we are really bork */
        __set_errno(ENOMEM);
        return NULL;
    }

    /* reusing path */
    sprintf(p->pwfile, QT_PW_UID, uid);
    PRINT(("%s: query(%s)\n", __FUNCTION__, p->pwfile));
    query = fs_open_query(boot_device, p->pwfile, 0);
    PRINT(("q: %p\n", query));
    if (!query)
        return NULL;

    dent = fs_read_query(query);
    if (!dent) {
        fs_close_query(query);
        return NULL;
    }
    fd = dentopen(dent, p->pwfile);
    fs_close_query(query);
    if (fd < B_OK)
        return NULL;
    err = fill_pwent_from_fd(fd, &p->pwent, p->pwbuff, PWBUFFSZ);
    PRINT(("%s: fill_pwent_from_fd = %d\n", __FUNCTION__, err));
    close(fd);
    if (err)
        return NULL;
    return &p->pwent;

}
예제 #5
0
/* by gid */
struct group *getgrgid(gid_t gid)
{
    struct dirent *dent;
    pw_tls_t *p;
    DIR *query;
    int err;
    int fd;

    PRINT(("%s()\n", __FUNCTION__));
    p = get_pw_tls();
    if (!p) {
        /* we are really bork */
        __set_errno(ENOMEM);
        return NULL;
    }

    /* reusing path */
    sprintf(p->grfile, QT_GR_GID, gid);
    query = fs_open_query(boot_device, p->grfile, 0);
    PRINT(("q: %p\n", query));
    if (!query)
        return NULL;

    dent = fs_read_query(query);
    if (!dent) {
        fs_close_query(query);
        return NULL;
    }
    fd = dentopen(dent, p->grfile);
    fs_close_query(query);
    if (fd < B_OK)
        return NULL;
    err = fill_grent_from_fd(fd, &p->grent, p->grbuff, GRBUFFSZ);
    PRINT(("%s: fill_grent_from_fd = %d\n", __FUNCTION__, err));
    close(fd);
    if (err)
        return NULL;
    return &p->grent;

}
예제 #6
0
int pacFindClose(fhandle_t handle)
{
	fs_close_query((DIR*)handle.handle);
	return 0;
}