/* * 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 || 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/下边有这样的列表。 | ,
|