imapext-2007
diff src/osdep/unix/env_unix.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/osdep/unix/env_unix.c Thu Oct 30 00:00:57 2014 +0900 1.2 +++ b/src/osdep/unix/env_unix.c Thu Oct 30 00:03:05 2014 +0900 1.3 @@ -422,6 +422,10 @@ 1.4 case SET_DISABLEPLAINTEXT: 1.5 disablePlaintext = (long) value; 1.6 case GET_DISABLEPLAINTEXT: 1.7 +#ifdef RESTRICT_POP 1.8 + if (getenv("INTRANET") == NIL) disablePlaintext = 1; 1.9 + else disablePlaintext = NIL; 1.10 +#endif 1.11 ret = (void *) disablePlaintext; 1.12 break; 1.13 case SET_CHROOTSERVER: 1.14 @@ -665,6 +669,7 @@ 1.15 char *s; 1.16 struct passwd *pw; 1.17 struct passwd *ret = NIL; 1.18 +#ifndef QMAIL /* imapext md5 checker run previously. no need to do here */ 1.19 if (auth_md5.server) { /* using CRAM-MD5 authentication? */ 1.20 if (s = auth_md5_pwd (user)) { 1.21 if (!strcmp (s,pwd) || ((*pwd == ' ') && pwd[1] && !strcmp (s,pwd+1))) 1.22 @@ -673,7 +678,9 @@ 1.23 fs_give ((void **) &s); 1.24 } 1.25 } 1.26 - else if (pw = pwuser (user)) {/* can get user? */ 1.27 + else 1.28 +#endif 1.29 + if (pw = pwuser (user)) {/* can get user? */ 1.30 s = cpystr (pw->pw_name); /* copy returned name in case we need it */ 1.31 if (*pwd && !(ret = checkpw (pw,pwd,argc,argv)) && 1.32 (*pwd == ' ') && pwd[1] && (ret = pwuser (s))) 1.33 @@ -697,6 +704,10 @@ 1.34 struct passwd *pw = NIL; 1.35 int level = LOG_NOTICE; 1.36 char *err = "failed"; 1.37 +#ifdef QMAIL 1.38 + char usr[MAILTMPLEN], *apoppswd; 1.39 + strncpy(usr, user, MAILTMPLEN-1); 1.40 +#endif 1.41 /* cretins still haven't given up */ 1.42 if ((strlen (user) >= NETMAXUSER) || 1.43 (authuser && (strlen (authuser) >= NETMAXUSER))) { 1.44 @@ -706,6 +717,16 @@ 1.45 } 1.46 else if (logtry-- <= 0) err = "excessive login failures"; 1.47 else if (disablePlaintext) err = "disabled"; 1.48 +#ifdef QMAIL 1.49 + else if ((logtry > 0) && 1.50 + (apoppswd = auth_md5_pwd(usr)) 1.51 + && !strcmp(apoppswd, pwd) 1.52 + && (pw = getpwnam(usr))) { 1.53 + memset(apoppswd, 0, strlen(apoppswd)); 1.54 + fs_give((void**) &apoppswd); 1.55 + return pw_login(pw, usr, pw->pw_name, pw->pw_dir, argc, argv); 1.56 + } 1.57 +#endif 1.58 else if (!(authuser && *authuser)) pw = valpwd (user,pwd,argc,argv); 1.59 else if (valpwd (authuser,pwd,argc,argv)) pw = pwuser (user); 1.60 if (pw && pw_login (pw,authuser,pw->pw_name,NIL,argc,argv)) return T; 1.61 @@ -728,6 +749,34 @@ 1.62 return pw_login (pwuser (user),authuser,user,NIL,argc,argv); 1.63 } 1.64 1.65 +void permitsmtp() /* to update tcp permission */ 1.66 +{ 1.67 +#ifdef POPBEFORESMTP 1.68 + #include <sys/types.h> 1.69 + #include <sys/wait.h> 1.70 + #ifndef POP3RECORDER 1.71 + # define POP3RECORDER "/usr/local/etc/pop3-record" 1.72 + #endif 1.73 + int child; 1.74 + int wstat; 1.75 + char *permsmtp = POP3RECORDER; 1.76 + 1.77 + switch(child = fork()) 1.78 + { 1.79 + case -1: 1.80 + syslog (LOG_INFO,"Cannot exec %s", permsmtp); 1.81 + _exit(111); 1.82 + break; 1.83 + case 0: 1.84 + execl(permsmtp, permsmtp, 0); 1.85 + syslog (LOG_INFO,"Cannot exec %s", permsmtp); 1.86 + _exit(111); break; 1.87 + } 1.88 + waitpid(child, &wstat, 0); 1.89 +#endif 1.90 +} 1.91 + 1.92 + 1.93 1.94 /* Log in as anonymous daemon 1.95 * Accepts: argument count 1.96 @@ -781,8 +830,14 @@ 1.97 else fatal ("Login failed after chroot"); 1.98 } 1.99 /* normal login */ 1.100 +#ifdef QMAIL 1.101 + else if (((pw->pw_uid == geteuid ()) || (permitsmtp(), loginpw (pw,argc,argv 1.102 +))) && 1.103 + (ret = env_init (user,home))) chdir (myhomedir ()); 1.104 +#else 1.105 else if (((pw->pw_uid == geteuid ()) || loginpw (pw,argc,argv)) && 1.106 - (ret = env_init (user,home))) chdir (myhomedir ()); 1.107 + (ret = env_init (user,home))) chdir (myhomedir ()); 1.108 +#endif 1.109 fs_give ((void **) &home); /* clean up */ 1.110 if (user) fs_give ((void **) &user); 1.111 }