[转帖]如何列出vpopmail一个虚拟域下的所有用户
/* <br>* vpopmail2txt jieer xjb@bjsing.net <br>
* URL: <a target=_blank href=http://bycd.bjsing.net/vpopmail2txt.c>http://bycd.bjsing.net/vpopmail2txt.c</a> <br>
*/ <br>
#include <stdio.h> <br>
#include <stdlib.h> <br>
#include <unistd.h> <br>
#include <string.h> <br>
#include <time.h> <br>
#include <pwd.h> <br>
#include <sys/types.h> <br>
#include <dirent.h> <br>
#include <sys/stat.h> <br>
#include "config.h" <br>
#include "vpopmail.h" <br>
#include "vauth.h" <br>
<br>
struct vqpasswd *vpwd = NULL; <br>
int conv_domain(char *); <br>
int main(int n, char *cmd[]) <br>
{ <br>
if (n < 2 || n > 2) { <br>
printf("vpopmail2txt \n"); <br>
return 0; <br>
} <br>
if (strcasecmp(cmd, "all") == 0) { <br>
DIR *mydir; <br>
char domain; <br>
struct dirent *mydirent; <br>
<br>
if (chdir(VPOPMAILDIR) != 0) { <br>
perror("vpopmail2txt: change dir to vpopmail home"); <br>
return (-1); <br>
} <br>
if (chdir(DOMAINS_DIR) != 0) { <br>
perror("vpopmail2txt: change dir to vpopmail home"); <br>
return (-1); <br>
} <br>
<br>
mydir = opendir("."); <br>
if (mydir == NULL) { <br>
perror("vpopmail2txt: opendir failed"); <br>
return (-1); <br>
} <br>
<br>
while ((mydirent = readdir(mydir)) != NULL) { <br>
if (strncmp(mydirent->d_name, ".", 1) == 0) <br>
continue; <br>
strncpy(domain, mydirent->d_name, 99); <br>
printf("converting %s \t\t---->", domain); <br>
if (conv_domain(domain) != 0) { <br>
printf("failed\n"); <br>
} else { <br>
printf("done\n"); <br>
} <br>
} <br>
closedir(mydir); <br>
<br>
} else <br>
conv_domain(cmd); <br>
<br>
return 0; <br>
} <br>
int conv_domain(char *domain) <br>
{ <br>
FILE *fp; <br>
char buf; <br>
<br>
vpwd = vauth_getall(domain, 1, 0); <br>
if (NULL == vpwd) { <br>
printf("empty", domain); <br>
return -1; <br>
} <br>
snprintf(buf, 255, "%s.txt%c", domain, 0); <br>
if ((fp = fopen(buf, "w")) == NULL) { <br>
printf("can not open %s\n", buf); <br>
return -2; <br>
} <br>
while (vpwd != NULL) { <br>
fprintf(fp,"%s@%s:%s%s:%s\n", vpwd->pw_name, domain, <br>
#ifdef CLEAR_PASS <br>
"", vpwd->pw_clear_passwd, <br>
#else <br>
"{crypt}", vpwd->pw_passwd, <br>
#endif <br>
vpwd->pw_gecos); <br>
vpwd = vauth_getall(domain, 0, 0); <br>
} <br>
fclose(fp); <br>
return 0; <br>
} <br>
<br>
<br>
gcc -O2 -I/home/vpopmail/include vpopmail2txt.c -o vpopmail2txt -L/home/vpopmail/lib -lvpopmail <br>
<br>
可能根据你的实际情况需要一些库,具体情况根据~vpopmail/etc下的inc_deps,lib_deps确定<br>
<br>
如果你用db来存储用户数据,就不用这个程序了~vpopmail/domains/mydomain/下边有这样的列表。
页:
[1]