如何列出vpopmail一个虚拟域下的所有用户

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

/*

* vpopmail2txt jieer xjb@bjsing.net

* URL: http://bycd.bjsing.net/vpopmail2txt.c

*/

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include "config.h"

#include "vpopmail.h"

#include "vauth.h"

struct vqpasswd *vpwd = NULL;

int conv_domain(char *);

int main(int n, char *cmd[])

{

if (n 2) {

printf("vpopmail2txt [domainname|all]\n");

return 0;

}

if (strcasecmp(cmd[1], "all") == 0) {

DIR *mydir;

char domain[100];

struct dirent *mydirent;

if (chdir(VPOPMAILDIR) != 0) {

perror("vpopmail2txt: change dir to vpopmail home");

return (-1);

}

if (chdir(DOMAINS_DIR) != 0) {

perror("vpopmail2txt: change dir to vpopmail home");

return (-1);

}

mydir = opendir(".");

if (mydir == NULL) {

perror("vpopmail2txt: opendir failed");

return (-1);

}

while ((mydirent = readdir(mydir)) != NULL) {

if (strncmp(mydirent-d_name, ".", 1) == 0)

continue;

strncpy(domain, mydirent-d_name, 99);

printf("converting %s \t\t--", domain);

if (conv_domain(domain) != 0) {

printf("failed\n");

} else {

printf("done\n");

}

}

closedir(mydir);

} else

conv_domain(cmd[1]);

return 0;

}

int conv_domain(char *domain)

{

FILE *fp;

char buf[256];

vpwd = vauth_getall(domain, 1, 0);

if (NULL == vpwd) {

printf("empty", domain);

return -1;

}

snprintf(buf, 255, "%s.txt%c", domain, 0);

if ((fp = fopen(buf, "w")) == NULL) {

printf("can not open %s\n", buf);

return -2;

}

while (vpwd != NULL) {

fprintf(fp,"%s@%s:%s%s:%s\n", vpwd-pw_name, domain,

#ifdef CLEAR_PASS

"", vpwd-pw_clear_passwd,

#else

"{crypt}", vpwd-pw_passwd,

#endif

vpwd-pw_gecos);

vpwd = vauth_getall(domain, 0, 0);

}

fclose(fp);

return 0;

}

gcc -O2 -I/home/vpopmail/include vpopmail2txt.c -o vpopmail2txt -L/home/vpopmail/lib -lvpopmail

可能根据你的实际情况需要一些库,具体情况根据~vpopmail/etc下的inc_deps,lib_deps确定

如果你用db来存储用户数据,就不用这个程序了~vpopmail/domains/mydomain/下边有这样的列表。

,

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航