imap/src/dmail/dmail.c
/* Deliver safely
 * Accepts: prototype stream to force mailbox format
 *	    stringstruct of message temporary file or NIL for check only
 *	    mailbox name
 *	    filesystem path name
 *	    scratch buffer for messages
 * Returns: NIL if success, else error code
 */
Deliver safely
Accepts: prototype stream to force mailbox format
stringstruct of message temporary file or NIL for check only
mailbox name
filesystem path name
scratch buffer for messages
Returns: NIL if success, else error code
Deliver safely Accepts : prototype stream to force mailbox format stringstruct of message temporary file or NIL for check only mailbox name filesystem path name scratch buffer for messages Returns : NIL if success else error code
int deliver_safely (MAILSTREAM *prt,STRING *st,char *mailbox,char *path,
		    char *tmp)
{
  struct stat sbuf;
  char *flags = NIL;
  int i = delivery_unsafe (path,&sbuf,tmp);
  if (i) return i;		
  if ((sbuf.st_mode & S_IFMT) == S_IFDIR) {
    if (sbuf.st_mode & 0001) {	
      sprintf (tmp,"WARNING: directory %.80s is listable",path);
      mm_log (tmp,WARN);
    }
  }
  else {			
    if (sbuf.st_nlink != 1) {	
      sprintf (tmp,"WARNING: multiple links to file %.80s",path);
      mm_log (tmp,WARN);
    }
    if (sbuf.st_mode & 0111) {	
      sprintf (tmp,"WARNING: file %.80s is executable",path);
      mm_log (tmp,WARN);
    }
  }
  if (sbuf.st_mode & 0002) {	
    sprintf (tmp,"WARNING: file %.80s is publicly-writable",path);
    mm_log (tmp,WARN);
  }
  if (sbuf.st_mode & 0004) {	
    sprintf (tmp,"WARNING: file %.80s is publicly-readable",path);
    mm_log (tmp,WARN);
  }
  if (!dmail_quota (st,path,tmp,sender,precedence))
    return fail (tmp,EX_CANTCREAT);
  sprintf (tmp,"%s appending to %.80s (%s %.80s)",
	   prt ? prt->dtb->name : "default",mailbox,
	   ((sbuf.st_mode & S_IFMT) == S_IFDIR) ? "directory" : "file",path);
  mm_dlog (tmp);
  if (keywords) {		
    if (flagseen) sprintf (flags = tmp,"\\Seen %.1000s",keywords);
    else flags = keywords;
  }
  else if (flagseen) flags = "\\Seen";
  if (!mail_append_full (prt,mailbox,flags,NIL,st)) {
    sprintf (tmp,"message delivery failed to %.80s",path);
    return fail (tmp,EX_CANTCREAT);
  }
  sprintf (tmp,"delivered to %.80s",path);
  mm_log (tmp,NIL);
  return delivery_unsafe (path,&sbuf,tmp);
}
int deliver_safely ( MAILSTREAM * prt , STRING * st , char * mailbox , char * path , char * tmp ) { struct stat sbuf ; char * flags = NIL ; int i = delivery_unsafe ( path , & sbuf , tmp ) ; if ( i ) return i ; if ( ( sbuf . st_mode & S_IFMT ) == S_IFDIR ) { if ( sbuf . st_mode & 0001 ) { sprintf ( tmp , " " , path ) ; mm_log ( tmp , WARN ) ; } } else { if ( sbuf . st_nlink != 1 ) { sprintf ( tmp , " " , path ) ; mm_log ( tmp , WARN ) ; } if ( sbuf . st_mode & 0111 ) { sprintf ( tmp , " " , path ) ; mm_log ( tmp , WARN ) ; } } if ( sbuf . st_mode & 0002 ) { sprintf ( tmp , " " , path ) ; mm_log ( tmp , WARN ) ; } if ( sbuf . st_mode & 0004 ) { sprintf ( tmp , " " , path ) ; mm_log ( tmp , WARN ) ; } if ( ! dmail_quota ( st , path , tmp , sender , precedence ) ) return fail ( tmp , EX_CANTCREAT ) ; sprintf ( tmp , " " , prt ? prt -> dtb -> name : " " , mailbox , ( ( sbuf . st_mode & S_IFMT ) == S_IFDIR ) ? " " : " " , path ) ; mm_dlog ( tmp ) ; if ( keywords ) { if ( flagseen ) sprintf ( flags = tmp , " \\ " , keywords ) ; else flags = keywords ; } else if ( flagseen ) flags = " \\ " ; if ( ! mail_append_full ( prt , mailbox , flags , NIL , st ) ) { sprintf ( tmp , " " , path ) ; return fail ( tmp , EX_CANTCREAT ) ; } sprintf ( tmp , " " , path ) ; mm_log ( tmp , NIL ) ; return delivery_unsafe ( path , & sbuf , tmp ) ; }
Deliver safely
 Accepts: prototype stream to force mailbox format
          stringstruct of message temporary file or NIL for check only
          mailbox name
          filesystem path name
          scratch buffer for messages
 Returns: NIL if success, else error code
Deliver safely Accepts : prototype stream to force mailbox format stringstruct of message temporary file or NIL for check only mailbox name filesystem path name scratch buffer for messages Returns : NIL if success else error code
/* give up now if delivery unsafe */ /* directory, not file */ /* listable directories may be worrisome */ /* file, not directory */ /* multiple links may be worrisome */ /* executable files may be worrisome */ /* public-write files may be worrisome */ /* public-write files may be worrisome */ /* check site-written quota procedure */ /* so far, so good */ /* any keywords requested? */ /* do the append now! */ /* note success */ /* make sure nothing evil this way comes */