int pacFindNext(fhandle_t handle, fileinfo_t * fileinfo) { struct dirent *eps = fs_read_query((DIR*)handle.handle); if (eps == NULL) { return -1; } strcpy(fileinfo->name, eps->d_name); return 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; }
/* 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; }
/* note the FILE * based version is not supported as it makes no sense here */ int getpwent_r(struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp) { pw_tls_t *p; int err; int fd; struct dirent *dent; PRINT(("%s()\n", __FUNCTION__)); p = get_pw_tls(); if (!p) return ENOMEM; PRINT(("getpwent_r: pwq = %p, idx = %d\n", p->pwent_query, p->pwidx)); if (!p->pwent_query) setpwent(); /* y0u clumsy app! */ if (!p->pwent_query) return EIO; /* something happened... */ __set_errno(0); dent = fs_read_query(p->pwent_query); *pwbufp = NULL; if (!dent) { /* found nothing on first iteration ? */ if (p->pwidx == 0) { if (fill_pwent_default(pwbuf) < 0) return -1; *pwbufp = pwbuf; p->pwidx++; } return 0; } fd = dentopen(dent, p->pwfile); if (fd < B_OK) return errno?errno:-1; err = fill_pwent_from_fd(fd, pwbuf, buf, buflen); PRINT(("%s: fill_pwent_from_fd = %d\n", __FUNCTION__, err)); close(fd); if (err) return err; p->pwidx++; *pwbufp = pwbuf; return 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; }