From: Wilfried Goesgens Date: Fri, 15 Jul 2011 15:01:54 +0000 (+0000) Subject: LBIO: add parameter X-Git-Tag: v8.11~575 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=fc5d97df37d1e203d501e9563aca0099a3529fdb LBIO: add parameter - if the user provided '1' just the UIDs are listed instead of the actual user name. - we now use dirent and friends instead of outputting the output of the unix ls command *cough* --- 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"); -} +}