今天中午接待了enli. 重阳节&老人节快乐~
Oct 10
作者: 肖建彬 | 可以转载, 转载时务必以超链接形式标明文章原始出处和作者信息及版权声明
网址:http://www.xiaojb.com/archives/mailtech/vpopmail.shtml

/*
* vpopmail2txt jieer xjb@bjsing.net
* URL: http://bycd.bjsing.net/vpopmail2txt.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <pwd.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#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/下边有这样的列表。

3 Responses to “导vpopmail用户信息的小程序”

  1. nobody Says:

    根本没必要写个C程序,vuserinfo足够了。

  2. xjb Says:

    的确是有这么个程序,写这个程序的时候没有仔细看,也就当练手了。

  3. xjb Says:

    vuserinfo输出的东西需要整理才可以供eyou的工具使用。
    这个程序当时是为了把qmail用户导入eyou邮件系统而写的。

Leave a Reply