📄 env_unix.c
字号:
/* * 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: 17 August 2000 * * Copyright 2000 by the University of Washington * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, provided * that the above copyright notice appears in all copies and that both the * above copyright notice and this permission notice appear in supporting * documentation, and that the name of the University of Washington not be * used in advertising or publicity pertaining to distribution of the software * without specific, written prior permission. This software is made available * "as is", and * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */#include <grp.h>#include <signal.h>#include <sys/wait.h>/* c-client environment parameters */ /* don't change these */static const char *anonymous_user = "nobody";static const char *unlogged_user = "root";static const char *admin_grp = "mailadm";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 *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 has_no_life = NIL; /* is a cretin with no life */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 = 0666; /* default ftp file protection */static long ftp_protection = 0644; /* default public file protection */static long public_protection = 0666; /* default shared file protection */static long shared_protection = 0660;static long locktimeout = 5; /* default lock timeout */ /* flock() emulator is a no-op */static long disableFcntlLock = NIL;static long lockEaccesError = T;/* warning on EACCES errors on .lock files */static long hideDotFiles = NIL; /* hide files whose names start with . */ /* 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;/* 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};#ifdef ADVERTISE_THE_WORLD/* This is not something that you want to do, since certain IMAP clients will * treat it as license to download the entire filesystem!! */ /* world namespace */static NAMESPACE nsworld = {"/",'/',NIL,&nsshared};#endif#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 SET_NAMESPACE: fatal ("SET_NAMESPACE not permitted"); 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: 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_LOCKTIMEOUT: locktimeout = (long) value; case GET_LOCKTIMEOUT: ret = (void *) locktimeout; break; case SET_DISABLEFCNTLLOCK: disableFcntlLock = (long) value; case GET_DISABLEFCNTLLOCK: ret = (void *) disableFcntlLock; break; case SET_LOCKEACCESERROR: lockEaccesError = (long) value; case GET_LOCKEACCESERROR: ret = (void *) lockEaccesError; break; case SET_HIDEDOTFILES: hideDotFiles = (long) value; case GET_HIDEDOTFILES: ret = (void *) hideDotFiles; break; case SET_USERHASNOLIFE: has_no_life = value ? T : NIL; case GET_USERHASNOLIFE: ret = (void *) (has_no_life ? T : NIL); break; case SET_BLOCKNOTIFY: mailblocknotify = (blocknotify_t) value; case GET_BLOCKNOTIFY: ret = (void *) mailblocknotify; break; } 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",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);}/* Write current time in internal format * Accepts: destination string */void internal_date (char *date){ do_date (date,NIL,"%02d-%s-%d %02d:%02d:%02d %+03d%02d",NIL);}/* Initialize server * Accepts: server name for syslog or NIL * /etc/services service name or NIL * alternate /etc/services service name or NIL * SASL service name or NIL * clock interrupt handler * kiss-of-death interrupt handler * hangup interrupt handler * termination interrupt handler */void server_init (char *server,char *service,char *altservice,char *sasl, void *clkint,void *kodint,void *hupint,void *trmint){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -