imap/src/dmail/dmail.c
/* Verify that delivery is safe
 * Accepts: path name
 *	    stat buffer
 *	    scratch buffer for messages
 * Returns: NIL if delivery is safe, error code if unsafe
 */
Verify that delivery is safe
Accepts: path name
stat buffer
scratch buffer for messages
Returns: NIL if delivery is safe, error code if unsafe
Verify that delivery is safe Accepts : path name stat buffer scratch buffer for messages Returns : NIL if delivery is safe error code if unsafe
int delivery_unsafe (char *path,struct stat *sbuf,char *tmp)
{
  u_short type;
  sprintf (tmp,"Verifying safe delivery to %.80s",path);
  mm_dlog (tmp);
  sprintf (tmp,"delivery to %.80s unsafe: ",path);
  if (lstat (path,sbuf)) strcat (tmp,strerror (errno));
  else switch (sbuf->st_mode & S_IFMT) {
  case S_IFDIR:			
    return NIL;
  case S_IFREG:			
    if (sbuf->st_mode & S_ISUID) strcat (tmp,"setuid file");
    else if (sbuf->st_mode & S_ISGID) strcat (tmp,"setgid file");
    else return NIL;		
    break;
  case S_IFCHR: strcat (tmp,"character special"); break;
  case S_IFBLK: strcat (tmp,"block special"); break;
  case S_IFLNK: strcat (tmp,"symbolic link"); break;
  case S_IFSOCK: strcat (tmp,"socket"); break;
  default:
    sprintf (tmp + strlen (tmp),"file type %07o",(unsigned int) type);
  }
  return fail (tmp,EX_CANTCREAT);
}
int delivery_unsafe ( char * path , struct stat * sbuf , char * tmp ) { u_short type ; sprintf ( tmp , " " , path ) ; mm_dlog ( tmp ) ; sprintf ( tmp , " " , path ) ; if ( lstat ( path , sbuf ) ) strcat ( tmp , strerror ( errno ) ) ; else switch ( sbuf -> st_mode & S_IFMT ) { case S_IFDIR : return NIL ; case S_IFREG : if ( sbuf -> st_mode & S_ISUID ) strcat ( tmp , " " ) ; else if ( sbuf -> st_mode & S_ISGID ) strcat ( tmp , " " ) ; else return NIL ; break ; case S_IFCHR : strcat ( tmp , " " ) ; break ; case S_IFBLK : strcat ( tmp , " " ) ; break ; case S_IFLNK : strcat ( tmp , " " ) ; break ; case S_IFSOCK : strcat ( tmp , " " ) ; break ; default : sprintf ( tmp + strlen ( tmp ) , " " , ( unsigned int ) type ) ; } return fail ( tmp , EX_CANTCREAT ) ; }
Verify that delivery is safe
 Accepts: path name
          stat buffer
          scratch buffer for messages
 Returns: NIL if delivery is safe, error code if unsafe
Verify that delivery is safe Accepts : path name stat buffer scratch buffer for messages Returns : NIL if delivery is safe error code if unsafe
/* prepare message just in case */ /* unsafe if can't get its status */ /* check file type */ /* directory is always OK */ /* file is unsafe if setuid */ /* or setgid */ /* otherwise safe */