env_unix.c

来自「这是用C编写IMAP源代码」· C语言 代码 · 共 1,641 行 · 第 1/4 页

C
1,641
字号
/* * Program:	UNIX environment routines * * Author:	Mark Crispin *		Networks and Distributed Computing *		Computing & Communications *		University of Washington *		Administration Building, AG-44 *		Seattle, WA  98195 *		Internet: MRC@CAC.Washington.EDU * * Date:	1 August 1988 * Last Edited:	13 September 2004 *  * The IMAP toolkit provided in this Distribution is * Copyright 1988-2004 University of Washington. * The full text of our legal notices is contained in the file called * CPYRIGHT, included with this Distribution. */#include <grp.h>#include <signal.h>#include <sys/wait.h>/* c-client environment parameters */static char *myUserName = NIL;	/* user name */static char *myHomeDir = NIL;	/* home directory name */static char *myMailboxDir = NIL;/* mailbox directory name */static char *myLocalHost = NIL;	/* local host name */static char *myNewsrc = NIL;	/* newsrc file name */static char *mailsubdir = NIL;	/* mail subdirectory name */static char *sysInbox = NIL;	/* system inbox name */static char *newsActive = NIL;	/* news active file */static char *newsSpool = NIL;	/* news spool */				/* anonymous home directory */static char *anonymousHome = NIL;static char *ftpHome = NIL;	/* ftp export home directory */static char *publicHome = NIL;	/* public home directory */static char *sharedHome = NIL;	/* shared home directory */static char *blackBoxDir = NIL;	/* black box directory name */				/* black box default home directory */static char *blackBoxDefaultHome = NIL;static short anonymous = NIL;	/* is anonymous */static short blackBox = NIL;	/* is a black box */static short closedBox = NIL;	/* is a closed box */static short restrictBox = NIL;	/* is a restricted box */static short has_no_life = NIL;	/* is a cretin with no life */				/* flock() emulator is a no-op */static short disableFcntlLock = NIL;static short hideDotFiles = NIL;/* hide files whose names start with . */				/* advertise filesystem root */static short advertisetheworld = NIL;				/* only advertise own mailboxes and #shared */static short limitedadvertise = NIL;				/* disable automatic shared namespaces */static short noautomaticsharedns = NIL;static short no822tztext = NIL;	/* disable RFC [2]822 timezone text */static short netfsstatbug = NIL;/* compensate for broken stat() on network				 * filesystems (AFS and old NFS).  Don't do				 * this unless you really have to!				 */				/* allow user config files */static short allowuserconfig = NIL;				/* 1 = disable plaintext, 2 = if not SSL */static long disablePlaintext = NIL;static long list_max_level = 20;/* maximum level of list recursion */				/* default file protection */static long mbx_protection = 0600;				/* default directory protection */static long dir_protection = 0700;				/* default lock file protection */static long lock_protection = MANDATORYLOCKPROT;				/* default ftp file protection */static long ftp_protection = 0644;static long ftp_dir_protection = 0755;				/* default public file protection */static long public_protection = 0666;static long public_dir_protection = 0777;				/* default shared file protection */static long shared_protection = 0660;static long shared_dir_protection = 0770;static long locktimeout = 5;	/* default lock timeout */				/* default prototypes */static MAILSTREAM *createProto = NIL;static MAILSTREAM *appendProto = NIL;				/* default user flags */static char *userFlags[NUSERFLAGS] = {NIL};static NAMESPACE *nslist[3];	/* namespace list */static int logtry = 3;		/* number of server login tries */				/* block notification */static blocknotify_t mailblocknotify = mm_blocknotify;				/* logout function */static logouthook_t maillogouthook = NIL;				/* logout data */static void *maillogoutdata = NIL;/* Note: setting disableLockWarning means that you assert that the * so-modified copy of this software will NEVER be used: *  1) in conjunction with any software which expects .lock files *  2) to access NFS-mounted files and directories * * Unless both of these conditions apply, then do not set this flag. * Instead, read the FAQ (item 7.10) and either use 1777 protection * on the mail spool, or install mlock. */				/* disable warning if can't make .lock file */static short disableLockWarning = NIL;/* UNIX namespaces */				/* personal mh namespace */static NAMESPACE nsmhf = {"#mh/",'/',NIL,NIL};static NAMESPACE nsmh = {"#mhinbox",NIL,NIL,&nsmhf};				/* home namespace */static NAMESPACE nshome = {"",'/',NIL,&nsmh};				/* UNIX other user namespace */static NAMESPACE nsunixother = {"~",'/',NIL,NIL};				/* black box other user namespace */static NAMESPACE nsblackother = {"/",'/',NIL,NIL};				/* public (anonymous OK) namespace */static NAMESPACE nspublic = {"#public/",'/',NIL,NIL};				/* netnews namespace */static NAMESPACE nsnews = {"#news.",'.',NIL,&nspublic};				/* FTP export namespace */static NAMESPACE nsftp = {"#ftp/",'/',NIL,&nsnews};				/* shared (no anonymous) namespace */static NAMESPACE nsshared = {"#shared/",'/',NIL,&nsftp};				/* world namespace */static NAMESPACE nsworld = {"/",'/',NIL,&nsshared};				/* only shared and public namespaces */static NAMESPACE nslimited = {"#shared/",'/',NIL,&nspublic};#include "write.c"		/* include safe writing routines */#include "crexcl.c"		/* include exclusive create */#include "pmatch.c"		/* include wildcard pattern matcher *//* Get all authenticators */#include "auths.c"/* Environment manipulate parameters * Accepts: function code *	    function-dependent value * Returns: function-dependent return value */void *env_parameters (long function,void *value){  void *ret = NIL;  switch ((int) function) {  case GET_NAMESPACE:    ret = (void *) nslist;    break;  case SET_USERNAME:    if (myUserName) fs_give ((void **) &myUserName);    myUserName = cpystr ((char *) value);  case GET_USERNAME:    ret = (void *) myUserName;    break;  case SET_HOMEDIR:    if (myHomeDir) fs_give ((void **) &myHomeDir);    myHomeDir = cpystr ((char *) value);  case GET_HOMEDIR:    ret = (void *) myHomeDir;    break;  case SET_LOCALHOST:    if (myLocalHost) fs_give ((void **) &myLocalHost);    myLocalHost = cpystr ((char *) value);  case GET_LOCALHOST:    ret = (void *) myLocalHost;    break;  case SET_NEWSRC:    if (myNewsrc) fs_give ((void **) &myNewsrc);    myNewsrc = cpystr ((char *) value);  case GET_NEWSRC:    ret = (void *) myNewsrc;    break;  case SET_NEWSACTIVE:    if (newsActive) fs_give ((void **) &newsActive);    newsActive = cpystr ((char *) value);  case GET_NEWSACTIVE:    ret = (void *) newsActive;    break;  case SET_NEWSSPOOL:    if (newsSpool) fs_give ((void **) &newsSpool);    newsSpool = cpystr ((char *) value);  case GET_NEWSSPOOL:    ret = (void *) newsSpool;    break;  case SET_ANONYMOUSHOME:    if (anonymousHome) fs_give ((void **) &anonymousHome);    anonymousHome = cpystr ((char *) value);  case GET_ANONYMOUSHOME:    if (!anonymousHome) anonymousHome = cpystr (ANONYMOUSHOME);    ret = (void *) anonymousHome;    break;  case SET_FTPHOME:    if (ftpHome) fs_give ((void **) &ftpHome);    ftpHome = cpystr ((char *) value);  case GET_FTPHOME:    ret = (void *) ftpHome;    break;  case SET_PUBLICHOME:    if (publicHome) fs_give ((void **) &publicHome);    publicHome = cpystr ((char *) value);  case GET_PUBLICHOME:    ret = (void *) publicHome;    break;  case SET_SHAREDHOME:    if (sharedHome) fs_give ((void **) &sharedHome);    sharedHome = cpystr ((char *) value);  case GET_SHAREDHOME:    ret = (void *) sharedHome;    break;  case SET_SYSINBOX:    if (sysInbox) fs_give ((void **) &sysInbox);    sysInbox = cpystr ((char *) value);  case GET_SYSINBOX:    ret = (void *) sysInbox;    break;  case SET_LISTMAXLEVEL:    list_max_level = (long) value;  case GET_LISTMAXLEVEL:    ret = (void *) list_max_level;    break;  case SET_MBXPROTECTION:    mbx_protection = (long) value;  case GET_MBXPROTECTION:    ret = (void *) mbx_protection;    break;  case SET_DIRPROTECTION:    dir_protection = (long) value;  case GET_DIRPROTECTION:    ret = (void *) dir_protection;    break;  case SET_LOCKPROTECTION:    lock_protection = (long) value;  case GET_LOCKPROTECTION:    ret = (void *) lock_protection;    break;  case SET_FTPPROTECTION:    ftp_protection = (long) value;  case GET_FTPPROTECTION:    ret = (void *) ftp_protection;    break;  case SET_PUBLICPROTECTION:    public_protection = (long) value;  case GET_PUBLICPROTECTION:    ret = (void *) public_protection;    break;  case SET_SHAREDPROTECTION:    shared_protection = (long) value;  case GET_SHAREDPROTECTION:    ret = (void *) shared_protection;    break;  case SET_FTPDIRPROTECTION:    ftp_dir_protection = (long) value;  case GET_FTPDIRPROTECTION:    ret = (void *) ftp_dir_protection;    break;  case SET_PUBLICDIRPROTECTION:    public_dir_protection = (long) value;  case GET_PUBLICDIRPROTECTION:    ret = (void *) public_dir_protection;    break;  case SET_SHAREDDIRPROTECTION:    shared_dir_protection = (long) value;  case GET_SHAREDDIRPROTECTION:    ret = (void *) shared_dir_protection;    break;  case SET_LOCKTIMEOUT:    locktimeout = (long) value;  case GET_LOCKTIMEOUT:    ret = (void *) locktimeout;    break;  case SET_DISABLEFCNTLLOCK:    disableFcntlLock = value ? T : NIL;  case GET_DISABLEFCNTLLOCK:    ret = (void *) (disableFcntlLock ? VOIDT : NIL);    break;  case SET_LOCKEACCESERROR:    disableLockWarning = value ? NIL : T;  case GET_LOCKEACCESERROR:    ret = (void *) (disableLockWarning ? NIL : VOIDT);    break;  case SET_HIDEDOTFILES:    hideDotFiles = value ? T : NIL;  case GET_HIDEDOTFILES:    ret = (void *) (hideDotFiles ? VOIDT : NIL);    break;  case SET_DISABLEPLAINTEXT:    disablePlaintext = (long) value;  case GET_DISABLEPLAINTEXT:    ret = (void *) disablePlaintext;    break;  case SET_CHROOTSERVER:    closedBox = value ? T : NIL;  case GET_CHROOTSERVER:    ret = (void *) (closedBox ? VOIDT : NIL);    break;  case SET_ADVERTISETHEWORLD:    advertisetheworld = value ? T : NIL;  case GET_ADVERTISETHEWORLD:    ret = (void *) (advertisetheworld ? VOIDT : NIL);    break;  case SET_LIMITEDADVERTISE:    limitedadvertise = value ? T : NIL;  case GET_LIMITEDADVERTISE:    ret = (void *) (limitedadvertise ? VOIDT : NIL);    break;  case SET_DISABLEAUTOSHAREDNS:    noautomaticsharedns = value ? T : NIL;  case GET_DISABLEAUTOSHAREDNS:    ret = (void *) (noautomaticsharedns ? VOIDT : NIL);    break;  case SET_DISABLE822TZTEXT:    no822tztext = value ? T : NIL;  case GET_DISABLE822TZTEXT:    ret = (void *) (no822tztext ? VOIDT : NIL);    break;  case SET_USERHASNOLIFE:    has_no_life = value ? T : NIL;  case GET_USERHASNOLIFE:    ret = (void *) (has_no_life ? VOIDT : NIL);    break;  case SET_NETFSSTATBUG:    netfsstatbug = value ? T : NIL;  case GET_NETFSSTATBUG:    ret = (void *) (netfsstatbug ? VOIDT : NIL);    break;  case SET_BLOCKNOTIFY:    mailblocknotify = (blocknotify_t) value;  case GET_BLOCKNOTIFY:    ret = (void *) mailblocknotify;    break;  case SET_LOGOUTHOOK:    maillogouthook = (logouthook_t) value;  case GET_LOGOUTHOOK:    ret = maillogouthook;    break;  case SET_LOGOUTDATA:    maillogoutdata = (void *) value;  case GET_LOGOUTDATA:    ret = maillogoutdata;  }  return ret;}/* Write current time * Accepts: destination string *	    optional format of day-of-week prefix *	    format of date and time *	    flag whether to append symbolic timezone */static void do_date (char *date,char *prefix,char *fmt,int suffix){  time_t tn = time (0);  struct tm *t = gmtime (&tn);  int zone = t->tm_hour * 60 + t->tm_min;  int julian = t->tm_yday;  t = localtime (&tn);		/* get local time now */				/* minus UTC minutes since midnight */  zone = t->tm_hour * 60 + t->tm_min - zone;  /* julian can be one of:   *  36x  local time is December 31, UTC is January 1, offset -24 hours   *    1  local time is 1 day ahead of UTC, offset +24 hours   *    0  local time is same day as UTC, no offset   *   -1  local time is 1 day behind UTC, offset -24 hours   * -36x  local time is January 1, UTC is December 31, offset +24 hours   */  if (julian = t->tm_yday -julian)    zone += ((julian < 0) == (abs (julian) == 1)) ? -24*60 : 24*60;  if (prefix) {			/* want day of week? */    sprintf (date,prefix,days[t->tm_wday]);    date += strlen (date);	/* make next sprintf append */  }				/* output the date */  sprintf (date,fmt,t->tm_mday,months[t->tm_mon],t->tm_year+1900,	   t->tm_hour,t->tm_min,t->tm_sec,zone/60,abs (zone) % 60);				/* append timezone suffix if desired */  if (suffix) rfc822_timezone (date,(void *) t);}/* Write current time in RFC 822 format * Accepts: destination string */void rfc822_date (char *date){  do_date (date,"%s, ","%d %s %d %02d:%02d:%02d %+03d%02d",	   no822tztext ? NIL : T);}/* Write current time in fixed-width RFC 822 format * Accepts: destination string */void rfc822_fixed_date (char *date){  do_date (date,NIL,"%02d %s %4d %02d:%02d:%02d %+03d%02d",NIL);}

⌨️ 快捷键说明

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