📄 env_ami.c
字号:
/* * Program: Amiga 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: 8 July 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 short anonymous = NIL; /* is anonymous */static short restrictBox = NIL; /* is a restricted box */static short has_no_life = NIL; /* is a cretin with no life */static short hideDotFiles = NIL;/* hide files whose names start with . */ /* advertise filesystem root */static short advertisetheworld = 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! */ /* 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;/* Amiga namespaces */ /* personal mh namespace */static NAMESPACE nsmhf = {"#mh/",'/',NIL,NIL};static NAMESPACE nsmh = {"#mhinbox",NIL,NIL,&nsmhf}; /* home namespace */static NAMESPACE nshome = {"",'/',NIL,&nsmh}; /* Amiga other user namespace */static NAMESPACE nsamigaother = {"~",'/',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};#include "write.c" /* include safe writing routines */#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_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_ADVERTISETHEWORLD: advertisetheworld = value ? T : NIL; case GET_ADVERTISETHEWORLD: ret = (void *) (advertisetheworld ? 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; } 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);}/* 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 * clock interrupt handler * kiss-of-death interrupt handler * hangup interrupt handler * termination interrupt handler */void server_init (char *server,char *service,char *sslservice, void *clkint,void *kodint,void *hupint,void *trmint){ /* only do this if for init call */ if (server && service && sslservice) { long port; struct servent *sv; struct sockaddr_in sin; int i = sizeof (struct sockaddr_in); /* Don't use tcp_clienthost() since reverse DNS problems may slow down the * greeting message and cause the client to time out. */ char *client = getpeername (0,(struct sockaddr *) &sin,(void *) &i) ? "UNKNOWN" : ((sin.sin_family == AF_INET) ? inet_ntoa (sin.sin_addr) : "NON-IPv4"); /* set server name in syslog */ openlog (server,LOG_PID,LOG_MAIL); fclose (stderr); /* possibly save a process ID */ /* Use SSL if SSL service, or if server starts with "s" and not service */ if (((port = tcp_serverport ()) >= 0)) { if ((sv = getservbyname (service,"tcp")) && (port == ntohs (sv->s_port))) syslog (LOG_DEBUG,"%s service init from %s",service,client); else if ((sv = getservbyname (sslservice,"tcp")) && (port == ntohs (sv->s_port))) { syslog (LOG_DEBUG,"%s SSL service init from %s",sslservice,client); ssl_server_init (server); } else { /* not service or SSL service port */ syslog (LOG_DEBUG,"port %ld service init from %s",port,client); if (*server == 's') ssl_server_init (server); } } switch (i = umask (022)) { /* check old umask */ case 0: /* definitely unreasonable */ case 022: /* don't need to change it */ break; default: /* already was a reasonable value */ umask (i); /* so change it back */ } } signal (SIGALRM,clkint); /* prepare for clock interrupt */ signal (SIGUSR2,kodint); /* prepare for Kiss Of Death */ signal (SIGHUP,hupint); /* prepare for hangup */ signal (SIGTERM,trmint); /* prepare for termination */}/* Wait for stdin input * Accepts: timeout in seconds * Returns: T if have input on stdin, else NIL */long server_input_wait (long seconds){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -