X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fbio%2Fserv_bio.c;fp=citadel%2Fmodules%2Fbio%2Fserv_bio.c;h=e98131361f70598fd3c889dfc9c8051af62e0d3c;hb=fc5d97df37d1e203d501e9563aca0099a3529fdb;hp=a3a9c6a61646de1d59a99da4f89bea89ca34e4fc;hpb=e08b4586decea8b10b4ab2d65b67f43cf69f6e25;p=citadel.git diff --git a/citadel/modules/bio/serv_bio.c b/citadel/modules/bio/serv_bio.c index a3a9c6a61..e98131361 100644 --- a/citadel/modules/bio/serv_bio.c +++ b/citadel/modules/bio/serv_bio.c @@ -22,6 +22,9 @@ #include "ctdl_module.h" +#include +#include +#include /* @@ -86,27 +89,49 @@ void cmd_rbio(char *cmdbuf) /* * list of users who have entered bios */ -void cmd_lbio(char *cmdbuf) { - char buf[256]; - FILE *ls; +void cmd_lbio(char *cmdbuf) +{ + DIR *filedir = NULL; + struct dirent *filedir_entry; + struct dirent *d; + int dont_resolve_uids; + size_t d_namelen; struct ctdluser usbuf; - char listbios[256]; - snprintf(listbios, sizeof(listbios),"cd %s; ls",ctdl_bio_dir); - ls = popen(listbios, "r"); - if (ls == NULL) { + d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 2); + if (d == NULL) { cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND); return; } - cprintf("%d\n", LISTING_FOLLOWS); - while (fgets(buf, sizeof buf, ls)!=NULL) - if (CtdlGetUserByNumber(&usbuf,atol(buf))==0) + filedir = opendir (ctdl_bio_dir); + if (filedir == NULL) { + free(d); + cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND); + return; + } + dont_resolve_uids = *cmdbuf == '1'; + while ((readdir_r(filedir, d, &filedir_entry) == 0) && + (filedir_entry != NULL)) + { +#ifdef _DIRENT_HAVE_D_NAMELEN + d_namelen = filedir_entry->d_namelen; +#else + d_namelen = strlen(filedir_entry->d_name); +#endif + if (dont_resolve_uids) { + filedir_entry->d_name[d_namelen++] = '\n'; + filedir_entry->d_name[d_namelen] = '\0'; + client_write(filedir_entry->d_name, d_namelen); + } + else if (CtdlGetUserByNumber(&usbuf,atol(filedir_entry->d_name))==0) cprintf("%s\n", usbuf.fullname); - pclose(ls); + } + free(d); + closedir(filedir); cprintf("000\n"); -} +}