⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clearopensmtp.c

📁 相当优秀的 UNIX 进程管理工具
💻 C
字号:
/* * $Id: clearopensmtp.c,v 1.3 2004/01/13 11:46:28 mbowe Exp $ * Copyright (C) 1999-2003 Inter7 Internet Technologies, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <time.h>#include <string.h>#include "config.h"#include "vpopmail.h"#include "vauth.h"#ifdef POP_AUTH_OPEN_RELAY#ifndef USE_SQL#define MAX_BUFF 256static char TmpBuf1[MAX_BUFF];static char TmpBuf2[MAX_BUFF];#endif /* ndef USE_SQL */int main(){#ifndef USE_SQL FILE *fs_smtp_cur; FILE *fs_smtp_tmp; char *tmpstr; time_t file_time;#endif /* ndef USE_SQL */ time_t mytime; time_t clear_minutes;	clear_minutes = RELAY_CLEAR_MINUTES * 60;	mytime = time(NULL);#ifdef USE_SQL        /* scan the relays table in mysql, and purge out any         * entries that are older than our specified timestamp         */	vclear_open_smtp(clear_minutes, mytime);#else        /* OPEN_SMTP_CUR_FILE is typically ~vpopmail/etc/open-smtp */	fs_smtp_cur = fopen(OPEN_SMTP_CUR_FILE, "r+");	if ( fs_smtp_cur != NULL ) {                /* OPEN_SMTP_TMP_FILE is typically ~vpopmail/etc/open-smtp.tmp */ 		/* create this file */		fs_smtp_tmp = fopen(OPEN_SMTP_TMP_FILE, "w+");		if ( fs_smtp_tmp == NULL ) {			printf ("Error, could not create open-smtp.tmp\n");			vexit(-1);		}		/* read in the contents of the open-smtp file */		while ( fgets(TmpBuf1, MAX_BUFF, fs_smtp_cur ) != NULL ) {			/* format is x.x.x.x:ALLOW,RELAYCLIENT="",RBLSMTPD=""<TAB>timestamp */			snprintf(TmpBuf2, sizeof(TmpBuf2), "%s", TmpBuf1);			tmpstr = strtok( TmpBuf2, "\t");			tmpstr = strtok( NULL, "\t");			/* extract the timestamp for this line */			if ( tmpstr != NULL ) {				/* compare the timestamp to see if it is not too old */				file_time = atoi(tmpstr);				if ( file_time + clear_minutes > mytime) {					/* if not too old, copy line out to .tmp file */					fputs(TmpBuf1, fs_smtp_tmp);				}			}		}		fclose(fs_smtp_cur);		fclose(fs_smtp_tmp);		/* replace open-relay with open-relay.tmp */		rename(OPEN_SMTP_TMP_FILE, OPEN_SMTP_CUR_FILE);		/* set correct permissions on file */		chown(OPEN_SMTP_CUR_FILE,VPOPMAILUID,VPOPMAILGID);	}#endif	/* Now, regardless of backend, build a new tcp.smtp.cdb file	 *	 * For mysql this involves combining the tcp.smtp file with         * the contents of the relay table.         * For cdb this involves combining the tcp.smtp file with         * the contents of the open-relay file.         * The resultant file will then be compiled by the tcprules tool         * to make a new tcp.smtp.cdb file for tcpserver to use         */	update_rules();	return(vexit(0));}#elseint main(){	printf("vpopmail not configure with --enable-roaming-users\n");	return(vexit(0));}#endif /* POP_AUTH_OPEN_RELAY */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -