imapext-2007

diff src/c-client/auth_md5.c @ 4:d741b3ecc917

imapext-2007f
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 30 Oct 2014 00:03:05 +0900
parents 2366b362676d
children
line diff
     1.1 --- a/src/c-client/auth_md5.c	Thu Oct 30 00:00:57 2014 +0900
     1.2 +++ b/src/c-client/auth_md5.c	Thu Oct 30 00:03:05 2014 +0900
     1.3 @@ -75,9 +75,11 @@
     1.4  
     1.5  long auth_md5_valid (void)
     1.6  {
     1.7 +#ifndef QMAIL			/* qmail extension can always handle MD5 */
     1.8    struct stat sbuf;
     1.9  				/* server forbids MD5 if no MD5 enable file */
    1.10    if (stat (MD5ENABLE,&sbuf)) auth_md5.server = NIL;
    1.11 +#endif
    1.12    return T;			/* MD5 is otherwise valid */
    1.13  }
    1.14  
    1.15 @@ -186,6 +188,7 @@
    1.16  char *auth_md5_pwd (char *user)
    1.17  {
    1.18    struct stat sbuf;
    1.19 +#ifndef QMAIL
    1.20    int fd = open (MD5ENABLE,O_RDONLY,NIL);
    1.21    unsigned char *s,*t,*buf,*lusr,*lret;
    1.22    char *r;
    1.23 @@ -214,6 +217,77 @@
    1.24      fs_give ((void **) &buf);	/* flush the buffer */
    1.25      close (fd);			/* don't need file any longer */
    1.26    }
    1.27 +#else
    1.28 +# ifndef USERAPOPFILE
    1.29 +#  define USERAPOPFILE ".apop" 
    1.30 +# endif
    1.31 +# ifndef XADDR_DELIM
    1.32 +#  ifdef POSTFIX		/* Same if-condition is in maildir.c.. sorry */
    1.33 +#   define XADDR_DELIM "+"
    1.34 +#  else
    1.35 +#   define XADDR_DELIM "-"
    1.36 +#  endif
    1.37 +# endif
    1.38 +  extern char *myMailSuffix;
    1.39 +  char mycrypt[BUFSIZ+1];
    1.40 +  char *ret = NIL, *tmp=NIL;
    1.41 +  FILE *apopfile = NIL;
    1.42 +  struct passwd *pw = getpwnam(user);
    1.43 +  if (!pw) pw = getpwnam(lcase(tmp=cpystr(user)));
    1.44 +  if (!pw && strstr(user, XADDR_DELIM)) { /* Check qmail alias */
    1.45 +    char tmp[BUFSIZ];
    1.46 +    char *s = user;
    1.47 +    memset(tmp, 0, BUFSIZ);
    1.48 +    while (*s && s && !pw) {
    1.49 +      s = strstr(s, XADDR_DELIM);
    1.50 +      if (!s) break;
    1.51 +      strncpy(tmp, user, s-user);
    1.52 +      s++;
    1.53 +      pw = getpwnam(tmp);
    1.54 +    }
    1.55 +    if (pw) {
    1.56 +      myMailSuffix = lcase(cpystr(s-1));
    1.57 +      user[strlen(tmp)] = '\0'; /* zap suffix */
    1.58 +    }
    1.59 +  }
    1.60 +  if (pw) {
    1.61 +    snprintf(mycrypt, BUFSIZ, "%s/%s", pw->pw_dir, USERAPOPFILE);
    1.62 +    if (NIL != myMailSuffix) strcat(mycrypt, myMailSuffix);
    1.63 +    if (stat(mycrypt, &sbuf) < 0) {
    1.64 +      /* printf("Cannot stat [%s]\015\n", mycrypt); */
    1.65 +      return ret;
    1.66 +    }
    1.67 +    if (sbuf.st_mode & ~(S_IFREG | S_IREAD | S_IWRITE)) {
    1.68 +      /* printf("Your apoppassword file is readable by others. Do chmod 600 %s%c\n", mycrypt, 015); */
    1.69 +      return ret;
    1.70 +    }
    1.71 +#ifdef APOPOPEN
    1.72 +    if (stat(APOPOPEN, &sbuf) >= 0) {	/* if APPOPEN exists */
    1.73 +      /* read apop password via APOPOPEN program */
    1.74 +      int bytes = 3+strlen(APOPOPEN)+strlen(mycrypt);
    1.75 +      char *aproc = (char*) fs_get(bytes);
    1.76 +      snprintf(aproc, bytes, "%s %s%c", APOPOPEN, mycrypt, '\0');
    1.77 +      apopfile = popen(aproc, "r");
    1.78 +      memset(aproc, 0, bytes);
    1.79 +      fs_give((void**)&aproc);
    1.80 +    }
    1.81 +#endif /* APOPOPEN */
    1.82 +    if ((NIL!=apopfile) || (apopfile = fopen( mycrypt, "r" ))) {
    1.83 +      fgets(mycrypt, sizeof(mycrypt) - 1, apopfile);
    1.84 +      fclose(apopfile);
    1.85 +      if (mycrypt[0]) {
    1.86 +	char p = strlen(mycrypt);
    1.87 +	while (p > 0 && (mycrypt[p-1] == '\n' || mycrypt[p-1] == '\r')) {
    1.88 +	   mycrypt[--p] = '\0'; /* zap trailing newlines */
    1.89 +	}
    1.90 +      }
    1.91 +    } else {
    1.92 +      return ret;
    1.93 +    }
    1.94 +    ret = cpystr(mycrypt);
    1.95 +    memset(mycrypt, 0, sizeof(mycrypt));
    1.96 +  }
    1.97 +#endif				/* if QMAIL */
    1.98    return ret;			/* return password */
    1.99  }
   1.100  
   1.101 @@ -231,6 +305,9 @@
   1.102    int i,j;
   1.103    char *ret = NIL;
   1.104    char *s,*authuser,tmp[MAILTMPLEN];
   1.105 +#ifdef QMAIL
   1.106 +  char *userback = cpystr(user);
   1.107 +#endif
   1.108    unsigned char digest[MD5DIGLEN];
   1.109    MD5CONTEXT ctx;
   1.110    char *hex = "0123456789abcdef";
   1.111 @@ -260,7 +337,15 @@
   1.112      memset (tmp,0,MAILTMPLEN);	/* erase sensitive information */
   1.113    }
   1.114    if (!ret) sleep (3);		/* slow down possible cracker */
   1.115 +  else {
   1.116 +    extern void permitsmtp();
   1.117 +    /* permitsmtp();*/
   1.118 +  }
   1.119 +#ifdef QMAIL
   1.120 +  return (ret) ? userback : ret;
   1.121 +#else
   1.122    return ret;
   1.123 +#endif
   1.124  }
   1.125  
   1.126  /*

UW-IMAP'd extensions by yuuji