📄 env_unix.c
字号:
if (pid && !fstat (fd,&fsb) && (i = min (fsb.st_size,MAILTMPLEN-1)) && (read (fd,tmp,i) == i) && !(tmp[i] = 0) && ((i = atol (tmp)) > 0)) *pid = i; close (fd); /* failed, give up on lock */ return -1; /* fail: can't lock */ } /* make sure this lock is good for us */ if (!lstat (lock,&lsb) && ((lsb.st_mode & S_IFMT) != S_IFLNK) && !fstat (fd,&fsb) && (lsb.st_dev == fsb.st_dev) && (lsb.st_ino == fsb.st_ino) && (fsb.st_nlink == 1)) break; close (fd); /* lock not right, drop fd and try again */ } /* make sure mode OK (don't use fchmod()) */ chmod (lock,(int) lock_protection); return fd; /* success */}/* Check to make sure not a symlink * Accepts: file name * stat buffer * Returns: -1 if doesn't exist, NIL if symlink, else number of hard links */long chk_notsymlink (char *name,void *sb){ struct stat *sbuf = (struct stat *) sb; /* name exists? */ if (lstat (name,sbuf)) return -1; /* forbid symbolic link */ if ((sbuf->st_mode & S_IFMT) == S_IFLNK) { mm_log ("symbolic link on lock name",ERROR); syslog (LOG_CRIT,"SECURITY PROBLEM: symbolic link on lock name: %.80s", name); return NIL; } return (long) sbuf->st_nlink; /* return number of hard links */}/* Unlock file descriptor * Accepts: file descriptor * lock file name from lockfd() */void unlockfd (int fd,char *lock){ /* delete the file if no sharers */ if (!flock (fd,LOCK_EX|LOCK_NB)) unlink (lock); flock (fd,LOCK_UN); /* unlock it */ close (fd); /* close it */}/* Set proper file protection for mailbox * Accepts: mailbox name * actual file path name * Returns: T, always */long set_mbx_protections (char *mailbox,char *path){ struct stat sbuf; int mode = (int) mbx_protection; if (*mailbox == '#') { /* possible namespace? */ if (((mailbox[1] == 'f') || (mailbox[1] == 'F')) && ((mailbox[2] == 't') || (mailbox[2] == 'T')) && ((mailbox[3] == 'p') || (mailbox[3] == 'P')) && (mailbox[4] == '/')) mode = (int) ftp_protection; else if (((mailbox[1] == 'p') || (mailbox[1] == 'P')) && ((mailbox[2] == 'u') || (mailbox[2] == 'U')) && ((mailbox[3] == 'b') || (mailbox[3] == 'B')) && ((mailbox[4] == 'l') || (mailbox[4] == 'L')) && ((mailbox[5] == 'i') || (mailbox[5] == 'I')) && ((mailbox[6] == 'c') || (mailbox[6] == 'C')) && (mailbox[7] == '/')) mode = (int) public_protection; else if (((mailbox[1] == 's') || (mailbox[1] == 'S')) && ((mailbox[2] == 'h') || (mailbox[2] == 'H')) && ((mailbox[3] == 'a') || (mailbox[3] == 'A')) && ((mailbox[4] == 'r') || (mailbox[4] == 'R')) && ((mailbox[5] == 'e') || (mailbox[5] == 'E')) && ((mailbox[6] == 'd') || (mailbox[6] == 'D')) && (mailbox[7] == '/')) mode = (int) shared_protection; } /* if a directory */ if (!stat (path,&sbuf) && ((sbuf.st_mode & S_IFMT) == S_IFDIR)) { /* set owner search if allow read or write */ if (mode & 0600) mode |= 0100; if (mode & 060) mode |= 010;/* set group search if allow read or write */ if (mode & 06) mode |= 01; /* set world search if allow read or write */ } chmod (path,mode); /* set the new protection, ignore failure */ return LONGT;}/* Determine default prototype stream to user * Accepts: type (NIL for create, T for append) * Returns: default prototype stream */MAILSTREAM *default_proto (long type){ myusername (); /* make sure initialized */ /* return default driver's prototype */ return type ? appendProto : createProto;}/* Set up user flags for stream * Accepts: MAIL stream * Returns: MAIL stream with user flags set up */MAILSTREAM *user_flags (MAILSTREAM *stream){ int i; myusername (); /* make sure initialized */ for (i = 0; i < NUSERFLAGS && userFlags[i]; ++i) if (!stream->user_flags[i]) stream->user_flags[i] = cpystr (userFlags[i]); return stream;}/* Return nth user flag * Accepts: user flag number * Returns: flag */char *default_user_flag (unsigned long i){ myusername (); /* make sure initialized */ return userFlags[i];}/* Process rc file * Accepts: file name * .mminit flag * Don't even think of using this feature. */void dorc (char *file,long flag){ int i; char *s,*t,*k,tmp[MAILTMPLEN],tmpx[MAILTMPLEN]; extern MAILSTREAM CREATEPROTO; extern MAILSTREAM EMPTYPROTO; DRIVER *d; FILE *f = fopen (file,"r"); /* no file or ill-advised usage */ if (!(f && (s = fgets (tmp,MAILTMPLEN,f)) && (t = strchr (s,'\n')) && (flag || (!strcmp (s,"I accept the risk for IMAP toolkit 4.1.\n") && (s = fgets (tmp,MAILTMPLEN,f)) && (t = strchr (s,'\n')))))) return; do { *t++ = '\0'; /* tie off line, find second space */ if ((k = strchr (s,' ')) && (k = strchr (++k,' '))) { *k++ = '\0'; /* tie off two words*/ lcase (s); /* make case-independent */ if (!(userFlags[0] || strcmp (s,"set keywords"))) { k = strtok (k,", "); /* yes, get first keyword */ /* copy keyword list */ for (i = 0; k && i < NUSERFLAGS; ++i) if (strlen (k) <= MAXUSERFLAG) { if (userFlags[i]) fs_give ((void **) &userFlags[i]); userFlags[i] = cpystr (k); k = strtok (NIL,", "); } } else if (!flag) { /* none of these valid in .mminit */ if (!(createProto || strcmp (s,"set new-folder-format"))) { if (!strcmp (lcase (k),"same-as-inbox")) createProto = ((d = mail_valid (NIL,"INBOX",NIL)) && strcmp (d->name,"dummy")) ? ((*d->open) (NIL)) : &CREATEPROTO; else if (!strcmp (k,"system-standard")) createProto = &CREATEPROTO; else { /* see if a driver name */ for (d = (DRIVER *) mail_parameters (NIL,GET_DRIVERS,NIL); d && strcmp (d->name,k); d = d->next); if (d) createProto = (*d->open) (NIL); else { /* duh... */ sprintf (tmpx,"Unknown new folder format in %s: %s",file,k); mm_log (tmpx,WARN); } } } if (!(appendProto || strcmp (s,"set empty-folder-format"))) { if (!strcmp (lcase (k),"same-as-inbox")) appendProto = ((d = mail_valid (NIL,"INBOX",NIL)) && strcmp (d->name,"dummy")) ? ((*d->open) (NIL)) : &EMPTYPROTO; else if (!strcmp (k,"system-standard")) appendProto = &EMPTYPROTO; else { /* see if a driver name */ for (d = (DRIVER *) mail_parameters (NIL,GET_DRIVERS,NIL); d && strcmp (d->name,k); d = d->next); if (d) appendProto = (*d->open) (NIL); else { /* duh... */ sprintf (tmpx,"Unknown empty folder format in %s: %s",file,k); mm_log (tmpx,WARN); } } } else if (!strcmp (s,"set from-widget")) mail_parameters (NIL,SET_FROMWIDGET,strcmp (lcase (k),"header-only") ? (void *) T : NIL); else if (!strcmp (s,"set black-box-directory")) { if (blackBoxDir) /* users aren't allowed to do this */ mm_log ("Can't set black-box-directory in user init",ERROR); else blackBoxDir = cpystr (k); } else if (!strcmp (s,"set black-box-default-home-directory")) { if (!blackBoxDir) mm_log ("Must set black-box-directory before default-home",ERROR); else if (blackBoxDefaultHome) mm_log ("Can't set black-box-default-home-directory in user init", ERROR); else blackBoxDefaultHome = cpystr (k); } else if (!strcmp (s,"set local-host")) { fs_give ((void **) &myLocalHost); myLocalHost = cpystr (k); } else if (!strcmp (s,"set news-active-file")) { fs_give ((void **) &newsActive); newsActive = cpystr (k); } else if (!strcmp (s,"set news-spool-directory")) { fs_give ((void **) &newsSpool); newsSpool = cpystr (k); } else if (!strcmp (s,"set news-state-file")) { fs_give ((void **) &myNewsrc); myNewsrc = cpystr (k); } else if (!strcmp (s,"set anonymous-home-directory")) { if (anonymousHome) /* users aren't allowed to do this */ mm_log ("Can't set anonymous-home-directory in user init",ERROR); else anonymousHome = cpystr (k); } else if (!strcmp (s,"set ftp-export-directory")) { fs_give ((void **) &ftpHome); ftpHome = cpystr (k); } else if (!strcmp (s,"set public-home-directory")) { fs_give ((void **) &publicHome); publicHome = cpystr (k); } else if (!strcmp (s,"set shared-home-directory")) { fs_give ((void **) &sharedHome); sharedHome = cpystr (k); } else if (!strcmp (s,"set system-inbox")) { fs_give ((void **) &sysInbox); sysInbox = cpystr (k); } else if (!strcmp (s,"set rsh-command")) mail_parameters (NIL,SET_RSHCOMMAND,(void *) k); else if (!strcmp (s,"set rsh-path")) mail_parameters (NIL,SET_RSHPATH,(void *) k); else if (!strcmp (s,"set tcp-open-timeout")) mail_parameters (NIL,SET_OPENTIMEOUT,(void *) atol (k)); else if (!strcmp (s,"set tcp-read-timeout")) mail_parameters (NIL,SET_READTIMEOUT,(void *) atol (k)); else if (!strcmp (s,"set tcp-write-timeout")) mail_parameters (NIL,SET_WRITETIMEOUT,(void *) atol (k)); else if (!strcmp (s,"set rsh-timeout")) mail_parameters (NIL,SET_RSHTIMEOUT,(void *) atol (k)); else if (!strcmp (s,"set maximum-login-trials")) mail_parameters (NIL,SET_MAXLOGINTRIALS,(void *) atol (k)); else if (!strcmp (s,"set lookahead")) mail_parameters (NIL,SET_LOOKAHEAD,(void *) atol (k)); else if (!strcmp (s,"set prefetch")) mail_parameters (NIL,SET_PREFETCH,(void *) atol (k)); else if (!strcmp (s,"set close-on-error")) mail_parameters (NIL,SET_CLOSEONERROR,(void *) atol (k)); else if (!strcmp (s,"set imap-port")) mail_parameters (NIL,SET_IMAPPORT,(void *) atol (k)); else if (!strcmp (s,"set pop3-port")) mail_parameters (NIL,SET_POP3PORT,(void *) atol (k)); else if (!strcmp (s,"set uid-lookahead")) mail_parameters (NIL,SET_UIDLOOKAHEAD,(void *) atol (k)); else if (!strcmp (s,"set mailbox-protection")) mbx_protection = atol (k); else if (!strcmp (s,"set directory-protection")) dir_protection = atol (k); else if (!strcmp (s,"set lock-protection")) lock_protection = atol (k); else if (!strcmp (s,"set ftp-protection")) ftp_protection = atol (k); else if (!strcmp (s,"set public-protection")) public_protection = atol (k); else if (!strcmp (s,"set shared-protection")) shared_protection = atol (k); else if (!strcmp (s,"set dot-lock-file-timeout")) locktimeout = atol (k); else if (!strcmp (s,"set disable-fcntl-locking")) disableFcntlLock = atol (k); else if (!strcmp (s,"set lock-eacces-error")) lockEaccesError = atol (k); else if (!strcmp (s,"set hide-dot-files")) hideDotFiles = atol (k); else if (!strcmp (s,"set list-maximum-level")) list_max_level = atol (k); else if (!strcmp (s,"set allowed-login-attempts")) logtry = atoi (k); else if (!strcmp (s,"set try-alt-driver-first")) mail_parameters (NIL,SET_TRYALTFIRST,(void *) atol (k)); else if (!strcmp (s,"set allow-reverse-dns")) mail_parameters (NIL,SET_ALLOWREVERSEDNS,(void *) atol (k)); } } } while ((s = fgets (tmp,MAILTMPLEN,f)) && (t = strchr (s,'\n'))); fclose (f); /* flush the file */}/* INBOX create function for tmail/dmail use only * Accepts: mail stream * path name buffer, preloaded with driver-dependent path * Returns: T on success, NIL on failure * * This routine is evil and a truly incredible kludge. It is private for * tmail/dmail and is not supported for any other application. */long path_create (MAILSTREAM *stream,char *path){ long ret; /* do the easy thing if not a black box */ if (!blackBox) return mail_create (stream,path); /* toss out driver dependent names */ printf (path,"%s/INBOX",myhomedir ()); blackBox = NIL; /* well that's evil - evil is going on */ ret = mail_create (stream,path); blackBox = T; /* restore the box */ return ret;}/* Default block notify routine * Accepts: reason for calling * data * Returns: data */void *mm_blocknotify (int reason,void *data){ void *ret = data; switch (reason) { case BLOCK_SENSITIVE: /* entering sensitive code */ ret = (void *) alarm (0); break; case BLOCK_NONSENSITIVE: /* exiting sensitive code */ if ((unsigned int) data) alarm ((unsigned int) data); break; default: /* ignore all other reasons */ break; } return ret;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -