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

📄 inc.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* inc.c - incorporate messages from a maildrop into a folder */#ifndef	lintstatic char ident[] = "@(#)$Id: inc.c,v 1.22 1993/09/01 21:41:48 jromine Exp $";#endif	/* lint */#ifdef	MAILGROUP/* Revised: Sat Apr 14 17:08:17 PDT 1990 (marvit@hplabs) *    Added hpux hacks to set and reset gid to be "mail" as needed. The reset *    is necessary so inc'ed mail is the group of the inc'er, rather than *    "mail". We setgid to egid only when [un]locking the mail file. This *    is also a major security precaution which will not be explained here. * * Fri Feb  7 16:04:57 PST 1992		John Romine <bug-mh@ics.uci.edu> *   NB: I'm not 100% sure that this setgid stuff is secure even now. */#endif#include "../h/mh.h"#ifdef	POP#include "../h/dropsbr.h"#endif#ifdef KPOP#include <krb.h>#endif#ifdef HESIOD#include <hesiod.h>#endif#include "../h/formatsbr.h"#include "../h/scansbr.h"#include "../zotnet/tws.h"#include <stdio.h>#include "../zotnet/mts.h"#include <errno.h>#include <signal.h>#include <sys/types.h>#include <sys/stat.h>#ifdef LOCALE#include	<locale.h>#endif/*  */#ifndef	MF#define	MFminc(a)	(a)#else	/* MF */#define	MFminc(a)	0#endif	/* MF */#ifndef	POP#define	POPminc(a)	(a)#else	/* POP */#define	POPminc(a)	0#endif	/* POP */#ifndef	RPOP#define	RPOPminc(a)	(a)#else	/* RPOP */#define	RPOPminc(a)	0#endif	/* RPOP */#ifndef	APOP#define	APOPminc(a)	(a)#else#define	APOPminc(a)	0#endif	/* APOP */#ifndef	TMA#define	TMAminc(a)	(a)#else	/* TMA */#define	TMAminc(a)	0#endif	/* TMA */static struct swit  switches[] = {#define	AUDSW	0    "audit audit-file", 0,#define	NAUDSW	1    "noaudit", 0,#define	CHGSW	2    "changecur", 0,#define	NCHGSW	3    "nochangecur", 0,#define	DECRSW	4    "decrypt", TMAminc (-7),#define	NDECRSW	5    "nodecrypt", TMAminc (-9),#define	MSW	6    "file name", 0,#define	FORMSW	7    "form formatfile", 0,#define	FMTSW	8    "format string", 5,#define	HOSTSW	9    "host host", POPminc (-4),#define	USERSW	10    "user user", POPminc (-4),#define	PACKSW	11    "pack file", POPminc (-4),#define	NPACKSW	12    "nopack", POPminc (-6),#define	APOPSW	13    "apop", APOPminc (-4),#define	NAPOPSW	14    "noapop", APOPminc (-6),#define	RPOPSW	15    "rpop", RPOPminc (-4),#define	NRPOPSW	16    "norpop", RPOPminc (-6),#define	SILSW	17    "silent", 0,#define	NSILSW	18    "nosilent", 0,#define	TRNCSW	19    "truncate", 0,#define	NTRNCSW	20    "notruncate", 0,#define	UUCPSW	21    "uucp", MFminc (-4),#define	NUUCPSW	22    "nouucp", MFminc (-6),#define	WIDSW	23    "width columns", 0,#define	HELPSW	24    "help", 4,    NULL, 0};/*  */extern int  errno;#ifdef	POPint  snoop = 0;extern char response[];static  char *file = NULL;static int  size;static long pos;static long start;static long stop;static  int   pd = NOTOK;static	FILE *pf = NULL;static int	pop_action (), pop_pack ();static int	map_count();#endif	/* POP *//*  * //* ARGSUSED */#ifdef MAILGROUP	/* For setting and returning to "mail" gid */static int return_gid;#endif	/* MAILGROUP */main (argc, argv)int	argc;char   *argv[];{    int     chgflag = 1,	    trnflag = 1,	    decflag = 1,            noisy = 1,	    width = 0,#ifdef	MF	    uucp = 1,#endif	/* MF */	    locked = 0,#ifdef	POP	    nmsgs,	    nbytes,	    p = 0,#endif	/* POP */	    rpop = 1,            i,	    hghnum,            msgnum;    char   *cp,           *maildir,           *folder = NULL,	   *form = NULL,	   *format = NULL,           *audfile = NULL,           *from = NULL,	   *host = NULL,#ifdef	POP	   *pass = NULL,#endif	/* POP */           *newmail,            buf[100],          **ap,          **argp,           *nfs,           *arguments[MAXARGS];    char *user = NULL;    struct msgs *mp;    struct stat st,                s1;    FILE *in, *aud = NULL;#ifdef	MHE    FILE *mhe = NULL;#endif	/* MHE */#ifdef HESIOD    struct hes_postoffice *po;    char *tmphost;#endif#ifdef LOCALE	setlocale(LC_ALL, "");#endif    invo_name = r1bindex (argv[0], '/');    mts_init (invo_name);#ifdef	POP#ifdef HESIOD    /*     * Scheme is:     *        use MAILHOST environment variable if present,     *  else try Hesiod.     *  If that fails, use the default (if any)     *  provided by mtstailor in mts_init()     */    if ((tmphost = getenv("MAILHOST")) != NULL)	pophost = tmphost;    else if ((po = hes_getmailhost(getusr())) != NULL &&	    strcmp(po->po_type, "POP") == 0)	pophost = po->po_host;#endif /* HESIOD */    if (pophost && *pophost)	host = pophost;    if ((cp = getenv ("MHPOPDEBUG")) && *cp)	snoop++;#endif    if ((cp = m_find (invo_name)) != NULL) {	ap = brkstring (cp = getcpy (cp), " ", "\n");	ap = copyip (ap, arguments);    }    else	ap = arguments;    (void) copyip (argv + 1, ap);    argp = arguments;/*  */    while (cp = *argp++) {	if (*cp == '-')	    switch (smatch (++cp, switches)) {		case AMBIGSW: 		    ambigsw (cp, switches);		    done (1);		case UNKWNSW: 		    adios (NULLCP, "-%s unknown", cp);		case HELPSW: 		    (void) sprintf (buf, "%s [+folder] [switches]", invo_name);		    help (buf, switches);		    done (1);		case AUDSW: 		    if (!(cp = *argp++) || *cp == '-')			adios (NULLCP, "missing argument to %s", argp[-2]);		    audfile = getcpy (m_maildir (cp));		    continue;		case NAUDSW: 		    audfile = NULL;		    continue;		case CHGSW: 		    chgflag++;		    continue;		case NCHGSW: 		    chgflag = 0;		    continue;		case TRNCSW: 		    trnflag++;		    continue;		case MSW: 		    if (!(cp = *argp++) || *cp == '-')			adios (NULLCP, "missing argument to %s", argp[-2]);		    from = path (cp, TFILE);/* fall */		case NTRNCSW: 		    trnflag = 0;		    continue;		case SILSW: 		    noisy = 0;		    continue;		case NSILSW: 		    noisy++;		    continue;		case FORMSW: 		    if (!(form = *argp++) || *form == '-')			adios (NULLCP, "missing argument to %s", argp[-2]);		    format = NULL;		    continue;		case FMTSW: 		    if (!(format = *argp++) || *format == '-')			adios (NULLCP, "missing argument to %s", argp[-2]);		    form = NULL;		    continue;		case WIDSW: 		    if (!(cp = *argp++) || *cp == '-')			adios (NULLCP, "missing argument to %s", argp[-2]);		    width = atoi (cp);		    continue;		case DECRSW:		    decflag++;		    continue;		case NDECRSW:		    decflag = 0;		    continue;		case UUCPSW: #ifdef	MF		    uucp++;#endif	/* MF */		    continue;		case NUUCPSW: #ifdef	MF		    uucp = 0;#endif	/* MF */		    continue;		case HOSTSW:		    if (!(host = *argp++) || *host == '-')			adios (NULLCP, "missing argument to %s", argp[-2]);		    continue;		case USERSW:		    if (!(user = *argp++) || *user == '-')			adios (NULLCP, "missing argument to %s", argp[-2]);		    continue;		case PACKSW:#ifndef	POP		    if (!(cp = *argp++) || *cp == '-')			adios (NULLCP, "missing argument to %s", argp[-2]);#else	/* POP */		    if (!(file = *argp++) || *file == '-')			adios (NULLCP, "missing argument to %s", argp[-2]);#endif	/* POP */		    continue;		case NPACKSW:#ifdef	POP		    file = NULLCP;#endif	/* POP */		    continue;		case APOPSW:		    rpop = -1;		    continue;		case RPOPSW:		    rpop = 1;		    continue;		case NAPOPSW:		case NRPOPSW:		    rpop = 0;		    continue;	    }	if (*cp == '+' || *cp == '@') {	    if (folder)		adios (NULLCP, "only one folder at a time!");	    else		folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);	}	else	    adios (NULLCP, "usage: %s [+folder] [switches]", invo_name);    }/*  */#ifdef MAILGROUP    return_gid = getegid();	/* Save effective gid, assuming we'll use it */    setgid(getgid());		/* Turn off extraordinary privileges */#endif	/* MAILGROUP */#ifdef	POP    if (host && !*host)	host = NULL;    if (from || !host || rpop <= 0)	(void) setuid (getuid ());#endif /* POP */    if (from) {	newmail = from;#ifdef	POP	host = NULL;#endif	/* POP */	if (stat (newmail, &s1) == NOTOK || s1.st_size == 0)	    adios (NULLCP, "no mail to incorporate");    }#ifdef	POP    else if (host) {	if (user == NULL)	    user = getusr ();	if (rpop > 0)	    pass = getusr ();	else	    ruserpass (host, &user, &pass);	if (pop_init (host, user, pass, snoop, rpop) == NOTOK		|| pop_stat (&nmsgs, &nbytes) == NOTOK)	    adios (NULLCP, "%s", response);	if (rpop > 0)	    (void) setuid (getuid ());	if (nmsgs == 0) {	    (void) pop_quit ();	    adios (NULLCP, "no mail to incorporate");	}    }#endif	/* POP */    else {	if (((newmail = getenv ("MAILDROP")) && *newmail)		|| ((newmail = m_find ("maildrop")) && *newmail))	    newmail = m_mailpath (newmail);	else {#ifdef	MF	    if (uucp && umincproc && *umincproc)		get_uucp_mail ();#endif	/* MF */	    newmail = concat (MAILDIR, "/", MAILFIL, NULLCP);	}	if (stat (newmail, &s1) == NOTOK || s1.st_size == 0)	    adios (NULLCP, "no mail to incorporate");    }#ifdef	POP    if (host && file)	goto go_to_it;#endif	/* POP */    if (!m_find ("path"))	free (path ("./", TFOLDER));    if (!folder && !(folder = m_find (inbox)))	folder = defalt;    maildir = m_maildir (folder);    if (stat (maildir, &st) == NOTOK) {	if (errno != ENOENT)	    adios (maildir, "error on folder");	cp = concat ("Create folder \"", maildir, "\"? ", NULLCP);	if (noisy && !getanswer (cp))	    done (1);	free (cp);	if (!makedir (maildir))	    adios (NULLCP, "unable to create folder %s", maildir);    }    if (chdir (maildir) == NOTOK)	adios (maildir, "unable to change directory to");    if (!(mp = m_gmsg (folder)))	adios (NULLCP, "unable to read folder %s", folder);/*  */#ifdef	POPgo_to_it: ;    if (host == NULL)#endif	/* POP */    if (access (newmail, 02) == NOTOK) {	trnflag = 0;	if ((in = fopen (newmail, "r")) == NULL)	    adios (newmail, "unable to read");    }    else {	locked++;	if (trnflag) {	    (void) signal (SIGHUP, SIG_IGN);	    (void) signal (SIGINT, SIG_IGN);	    (void) signal (SIGQUIT, SIG_IGN);	    (void) signal (SIGTERM, SIG_IGN);	}

⌨️ 快捷键说明

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