* Makefile.am:
* acconfig.h: Added support for new MySql addition to mailutils * configure.in: * MySql/Makefile.am: * MySql/MySql.c: Mini lib to link to when mysql support * MySql/MySql.h: enabled (with --enable-mysql) * doc/Readme.mysql: Readme file for setup. * imap4d/login.c: * mailbox/mbx_default.c: The Patch pretty much works the same * mailbox/mutil.c: all around. if getpwnam() returns null * mailbox2/mutil.c: then your db is checked for the user, * pop3d/apop.c: and the struct is filled if found, * pop3d/user.c: returns null if not. If shadow support is used, then the same is done with getspnam(). * examples/mail.MysqlMailer.c: Simple sendmail backend support.
Showing
14 changed files
with
250 additions
and
2 deletions
1 | 2001-08-24 Jim Hull | ||
2 | |||
3 | * Makefile.am: | ||
4 | * acconfig.h: Added support for new MySql addition to mailutils | ||
5 | * configure.in: | ||
6 | |||
7 | * MySql/Makefile.am: | ||
8 | * MySql/MySql.c: Mini lib to link to when mysql support | ||
9 | * MySql/MySql.h: enabled (with --enable-mysql) | ||
10 | |||
11 | * doc/Readme.mysql: Readme file for setup. | ||
12 | |||
13 | * imap4d/login.c: | ||
14 | * mailbox/mbx_default.c: The Patch pretty much works the same | ||
15 | * mailbox/mutil.c: all around. if getpwnam() returns null | ||
16 | * mailbox2/mutil.c: then your db is checked for the user, | ||
17 | * pop3d/apop.c: and the struct is filled if found, | ||
18 | * pop3d/user.c: returns null if not. If shadow support | ||
19 | is used, then the same is done with getspnam(). | ||
20 | |||
21 | * examples/mail.MysqlMailer.c: Simple sendmail backend support. | ||
22 | |||
1 | 2001-08-24 Alain Magloire | 23 | 2001-08-24 Alain Magloire |
2 | 24 | ||
3 | * sieve/Makefile.am: To EXTRA_DIST add md5-rsa.{c,h}. | 25 | * sieve/Makefile.am: To EXTRA_DIST add md5-rsa.{c,h}. | ... | ... |
1 | AUTOMAKE_OPTIONS = gnu 1.4 | 1 | AUTOMAKE_OPTIONS = gnu 1.4 |
2 | ACLOCAL_AMFLAGS = -I m4 | 2 | ACLOCAL_AMFLAGS = -I m4 |
3 | 3 | ||
4 | SUBDIRS = include doc m4 lib argp mailbox frm from pop3d imap4d mail sieve \ | 4 | SUBDIRS = include doc m4 lib MySql argp mailbox frm from pop3d imap4d mail sieve \ |
5 | scripts libmu_scm guimb messages | 5 | scripts libmu_scm guimb messages |
6 | 6 | ||
7 | EXTRA_DIST = mailutils.spec mailutils.spec.in README-alpha COPYING.FDL | 7 | EXTRA_DIST = mailutils.spec mailutils.spec.in README-alpha COPYING.FDL | ... | ... |
MySql/Makefile.am
0 → 100644
MySql/MySql.c
0 → 100644
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <pwd.h> | ||
4 | |||
5 | #include <config.h> | ||
6 | |||
7 | #ifdef HAVE_MYSQL | ||
8 | |||
9 | #ifdef HAVE_SHADOW_H | ||
10 | #include <shadow.h> | ||
11 | #endif /* HAVE_SHADOW_H */ | ||
12 | |||
13 | #include <mysql/mysql.h> | ||
14 | #include "MySql.h" | ||
15 | |||
16 | struct passwd *getMpwnam (const char *username) | ||
17 | { | ||
18 | char QueryStr[1024]; | ||
19 | MYSQL *m; | ||
20 | MYSQL_RES *res; | ||
21 | MYSQL_ROW row; | ||
22 | struct passwd *tpw; | ||
23 | |||
24 | m = mysql_init(0); | ||
25 | |||
26 | if (!m) | ||
27 | return(NULL); | ||
28 | |||
29 | if (!mysql_real_connect(m, NULL, MUSER, MPASS, MDB, 0, NULL, 0)) | ||
30 | return(NULL); | ||
31 | |||
32 | memset((char *)QueryStr, '\0', 1024); | ||
33 | |||
34 | sprintf(QueryStr, "select %s,%s,%s,%s,%s from %s where %s = '%s'", Mpassword, Muid, Mgid, Mhomedir, Mshell, Mtable, Musername, username); | ||
35 | |||
36 | if (mysql_query(m, QueryStr) != 0) | ||
37 | return(NULL); | ||
38 | |||
39 | if ((res = mysql_store_result(m)) == NULL) | ||
40 | return(NULL); | ||
41 | |||
42 | if ((row = mysql_fetch_row(res)) == NULL) | ||
43 | return(NULL); | ||
44 | |||
45 | tpw = (struct passwd *)malloc(sizeof(struct passwd)); | ||
46 | |||
47 | tpw->pw_name = malloc(strlen(username)+1); | ||
48 | strcpy(tpw->pw_name, username); | ||
49 | |||
50 | tpw->pw_passwd = malloc(strlen(row[0])+1); | ||
51 | strcpy(tpw->pw_passwd, row[0]); | ||
52 | |||
53 | tpw->pw_uid = atoi(row[1]); | ||
54 | tpw->pw_gid = atoi(row[2]); | ||
55 | |||
56 | tpw->pw_gecos = malloc(strlen("Mysql User")+1); | ||
57 | strcpy(tpw->pw_gecos, "Mysql User"); | ||
58 | |||
59 | tpw->pw_dir = malloc(strlen(row[3])+1); | ||
60 | strcpy(tpw->pw_dir, row[3]); | ||
61 | |||
62 | tpw->pw_shell = malloc(strlen(row[4])+1); | ||
63 | strcpy(tpw->pw_shell, row[4]); | ||
64 | |||
65 | mysql_free_result(res); | ||
66 | return(tpw); | ||
67 | } | ||
68 | |||
69 | |||
70 | #ifdef HAVE_SHADOW_H | ||
71 | |||
72 | struct spwd *getMspnam (const char *username) | ||
73 | { | ||
74 | char QueryStr[1024]; | ||
75 | MYSQL *m; | ||
76 | MYSQL_RES *res; | ||
77 | MYSQL_ROW row; | ||
78 | struct spwd *tpw; | ||
79 | |||
80 | m = mysql_init(0); | ||
81 | |||
82 | if (!m) | ||
83 | return(NULL); | ||
84 | |||
85 | if (!mysql_real_connect(m, NULL, MUSER, MPASS, MDB, 0, NULL, 0)) | ||
86 | return(NULL); | ||
87 | |||
88 | memset((char *)QueryStr, '\0', 1024); | ||
89 | sprintf(QueryStr, "select %s from %s where %s = '%s'", Mpassword, Mtable, Musername, username); | ||
90 | |||
91 | if (mysql_query(m, QueryStr) != 0) | ||
92 | return(NULL); | ||
93 | |||
94 | if ((res = mysql_store_result(m)) == NULL) | ||
95 | return(NULL); | ||
96 | |||
97 | if ((row = mysql_fetch_row(res)) == NULL) | ||
98 | return(NULL); | ||
99 | |||
100 | tpw = (struct spwd *)malloc(sizeof(struct spwd)); | ||
101 | |||
102 | tpw->sp_namp = malloc(strlen(username)+1); | ||
103 | strcpy(tpw->sp_namp, username); | ||
104 | |||
105 | tpw->sp_pwdp = malloc(strlen(row[0])+1); | ||
106 | strcpy(tpw->sp_pwdp, row[0]); | ||
107 | |||
108 | tpw->sp_lstchg = 11428; | ||
109 | tpw->sp_min = 0; | ||
110 | tpw->sp_max = 99999; | ||
111 | tpw->sp_warn = 7; | ||
112 | |||
113 | mysql_free_result(res); | ||
114 | return(tpw); | ||
115 | } | ||
116 | |||
117 | #endif /* HAVE_SHADOW_H */ | ||
118 | |||
119 | #endif /* HAVE_MYSQL */ |
MySql/MySql.h
0 → 100644
1 | #include <config.h> | ||
2 | |||
3 | #ifdef HAVE_MYSQL | ||
4 | |||
5 | #define MUSER "accounts" /* Username for mysql access */ | ||
6 | #define MPASS "yurpass" /* Password for mysql access */ | ||
7 | #define MDB "accounts" /* Database Name */ | ||
8 | #define Mtable "users" /* Table Name */ | ||
9 | #define Musername "username" /* username field */ | ||
10 | #define Muid "uid" /* uid field */ | ||
11 | #define Mgid "gid" /* gid field */ | ||
12 | #define Mpassword "password" /* password field */ | ||
13 | #define Mhomedir "homedir" /* homedir field */ | ||
14 | #define Mshell "shell" /* shell field */ | ||
15 | #define Mcomment "comment" /* comment field */ | ||
16 | |||
17 | struct passwd *getMpwnam (const char *username); | ||
18 | struct spwd *getMspnam (const char *username); | ||
19 | |||
20 | |||
21 | #endif /* HAVE_MYSQL */ |
... | @@ -9,3 +9,4 @@ of errors. | ... | @@ -9,3 +9,4 @@ of errors. |
9 | Frank Belew <frb@wiw.org> | 9 | Frank Belew <frb@wiw.org> |
10 | Vesselin Atanasov <vesselin@bgnet.bg> | 10 | Vesselin Atanasov <vesselin@bgnet.bg> |
11 | Sergey Poznyakoff <gray@Mirddin.farlep.net> | 11 | Sergey Poznyakoff <gray@Mirddin.farlep.net> |
12 | Jim Hull <imaginos@imaginos.net> | ... | ... |
... | @@ -129,6 +129,15 @@ if test x"$ac_cv_func_argp_parse" != xyes; then | ... | @@ -129,6 +129,15 @@ if test x"$ac_cv_func_argp_parse" != xyes; then |
129 | AC_SUBST(ARGPINCS) | 129 | AC_SUBST(ARGPINCS) |
130 | fi | 130 | fi |
131 | 131 | ||
132 | dnl check if mysql support was added | ||
133 | AC_ARG_ENABLE(mysql, [ --enable-mysql enable mysql support (default no)], [use_mysql="yes"],,) | ||
134 | if test x"$use_mysql" = x"yes"; then | ||
135 | echo Enabling mysql support, be sure to edit \'MySql/MySql.h\' to change default values | ||
136 | AC_CHECK_HEADER(mysql/mysql.h, | ||
137 | LIBS="$LIBS -lmailMysql -lmysqlclient -L/usr/lib/mysql -L/usr/local/lib/mysql -L../MySql/" | ||
138 | AC_DEFINE(HAVE_MYSQL)) | ||
139 | fi | ||
140 | |||
132 | dnl Use either PAM or CRYPT, not both. | 141 | dnl Use either PAM or CRYPT, not both. |
133 | if test x"$testpam" = x"yes"; then | 142 | if test x"$testpam" = x"yes"; then |
134 | AC_CHECK_HEADERS(security/pam_appl.h) | 143 | AC_CHECK_HEADERS(security/pam_appl.h) |
... | @@ -220,4 +229,4 @@ AC_OUTPUT(Makefile mailutils.spec include/Makefile include/mailutils/Makefile | ... | @@ -220,4 +229,4 @@ AC_OUTPUT(Makefile mailutils.spec include/Makefile include/mailutils/Makefile |
220 | m4/Makefile doc/Makefile argp/Makefile lib/Makefile lib/posix/Makefile | 229 | m4/Makefile doc/Makefile argp/Makefile lib/Makefile lib/posix/Makefile |
221 | mailbox/Makefile imap4d/Makefile mailbox/include/Makefile from/Makefile | 230 | mailbox/Makefile imap4d/Makefile mailbox/include/Makefile from/Makefile |
222 | mail/Makefile pop3d/Makefile frm/Makefile sieve/Makefile messages/Makefile | 231 | mail/Makefile pop3d/Makefile frm/Makefile sieve/Makefile messages/Makefile |
223 | scripts/Makefile libmu_scm/Makefile guimb/Makefile guimb/scm/Makefile) | 232 | scripts/Makefile libmu_scm/Makefile guimb/Makefile guimb/scm/Makefile MySql/Makefile) | ... | ... |
... | @@ -17,6 +17,10 @@ | ... | @@ -17,6 +17,10 @@ |
17 | 17 | ||
18 | #include "imap4d.h" | 18 | #include "imap4d.h" |
19 | 19 | ||
20 | #ifdef HAVE_MYSQL | ||
21 | #include "../MySql/MySql.h" | ||
22 | #endif | ||
23 | |||
20 | /* | 24 | /* |
21 | * FIXME: this should support PAM, shadow, and normal password | 25 | * FIXME: this should support PAM, shadow, and normal password |
22 | */ | 26 | */ |
... | @@ -102,7 +106,15 @@ imap4d_login (struct imap4d_command *command, char *arg) | ... | @@ -102,7 +106,15 @@ imap4d_login (struct imap4d_command *command, char *arg) |
102 | 106 | ||
103 | pw = getpwnam (username); | 107 | pw = getpwnam (username); |
104 | if (pw == NULL) | 108 | if (pw == NULL) |
109 | #ifdef HAVE_MYSQL | ||
110 | { | ||
111 | pw = getMpwnam (username); | ||
112 | if (pw == NULL) | ||
113 | return util_finish (command, RESP_NO, "User name or passwd rejected"); | ||
114 | } | ||
115 | #else /* HAVE_MYSQL */ | ||
105 | return util_finish (command, RESP_NO, "User name or passwd rejected"); | 116 | return util_finish (command, RESP_NO, "User name or passwd rejected"); |
117 | #endif /* HAVE_MYSQL */ | ||
106 | 118 | ||
107 | #ifndef USE_LIBPAM | 119 | #ifndef USE_LIBPAM |
108 | if (pw->pw_uid < 1) | 120 | if (pw->pw_uid < 1) |
... | @@ -113,9 +125,18 @@ imap4d_login (struct imap4d_command *command, char *arg) | ... | @@ -113,9 +125,18 @@ imap4d_login (struct imap4d_command *command, char *arg) |
113 | struct spwd *spw; | 125 | struct spwd *spw; |
114 | spw = getspnam (username); | 126 | spw = getspnam (username); |
115 | if (spw == NULL || strcmp (spw->sp_pwdp, (char *)crypt (pass, spw->sp_pwdp))) | 127 | if (spw == NULL || strcmp (spw->sp_pwdp, (char *)crypt (pass, spw->sp_pwdp))) |
128 | #ifdef HAVE_MYSQL | ||
129 | { | ||
130 | spw = getMspnam (username); | ||
131 | if (spw == NULL || strcmp (spw->sp_pwdp, (char *)crypt (pass, spw->sp_pwdp))) | ||
132 | return util_finish (command, RESP_NO, "User name or passwd rejected"); | ||
133 | } | ||
134 | #else /* HAVE_MYSQL */ | ||
116 | #endif /* HAVE_SHADOW_H */ | 135 | #endif /* HAVE_SHADOW_H */ |
117 | return util_finish (command, RESP_NO, "User name or passwd rejected"); | 136 | return util_finish (command, RESP_NO, "User name or passwd rejected"); |
137 | #endif /* HAVE_MYSQL */ | ||
118 | } | 138 | } |
139 | |||
119 | #else /* !USE_LIBPAM */ | 140 | #else /* !USE_LIBPAM */ |
120 | _user = (char *) username; | 141 | _user = (char *) username; |
121 | _pwd = pass; | 142 | _pwd = pass; | ... | ... |
... | @@ -30,6 +30,10 @@ | ... | @@ -30,6 +30,10 @@ |
30 | # include <paths.h> | 30 | # include <paths.h> |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #ifdef HAVE_MYSQL | ||
34 | #include "../MySql/MySql.h" | ||
35 | #endif | ||
36 | |||
33 | #include <mailutils/mailbox.h> | 37 | #include <mailutils/mailbox.h> |
34 | #include <mailutils/error.h> | 38 | #include <mailutils/error.h> |
35 | 39 | ||
... | @@ -79,6 +83,12 @@ get_homedir (const char *user) | ... | @@ -79,6 +83,12 @@ get_homedir (const char *user) |
79 | if (user) | 83 | if (user) |
80 | { | 84 | { |
81 | pw = getpwnam (user); | 85 | pw = getpwnam (user); |
86 | |||
87 | #ifdef HAVE_MYSQL | ||
88 | if (!pw) | ||
89 | pw = getMpwnam(user); | ||
90 | #endif /* HAVE_MYSQL */ | ||
91 | |||
82 | if (pw) | 92 | if (pw) |
83 | homedir = pw->pw_dir; | 93 | homedir = pw->pw_dir; |
84 | } | 94 | } | ... | ... |
... | @@ -31,6 +31,10 @@ | ... | @@ -31,6 +31,10 @@ |
31 | 31 | ||
32 | #include <mailutils/mutil.h> | 32 | #include <mailutils/mutil.h> |
33 | 33 | ||
34 | #ifdef HAVE_MYSQL | ||
35 | #include "../MySql/MySql.h" | ||
36 | #endif | ||
37 | |||
34 | /* convert a sequence of hex characters into an integer */ | 38 | /* convert a sequence of hex characters into an integer */ |
35 | 39 | ||
36 | unsigned long mu_hex2ul(char hex) | 40 | unsigned long mu_hex2ul(char hex) |
... | @@ -294,6 +298,10 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) | ... | @@ -294,6 +298,10 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) |
294 | memcpy (name, p, s - p); | 298 | memcpy (name, p, s - p); |
295 | name [s - p] = '\0'; | 299 | name [s - p] = '\0'; |
296 | pw = getpwnam (name); | 300 | pw = getpwnam (name); |
301 | #ifdef HAVE_MYSQL | ||
302 | if (!pw) | ||
303 | pw = getMpwnam(name); | ||
304 | #endif /* HAVE_MYSQL */ | ||
297 | free (name); | 305 | free (name); |
298 | if (pw) | 306 | if (pw) |
299 | { | 307 | { | ... | ... |
... | @@ -32,6 +32,10 @@ | ... | @@ -32,6 +32,10 @@ |
32 | 32 | ||
33 | #include <mailutils/mutil.h> | 33 | #include <mailutils/mutil.h> |
34 | 34 | ||
35 | #ifdef HAVE_MYSQL | ||
36 | #include "../MySql/MySql.h" | ||
37 | #endif | ||
38 | |||
35 | /* convert a sequence of hex characters into an integer */ | 39 | /* convert a sequence of hex characters into an integer */ |
36 | 40 | ||
37 | unsigned long mu_hex2ul(char hex) | 41 | unsigned long mu_hex2ul(char hex) |
... | @@ -295,6 +299,10 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) | ... | @@ -295,6 +299,10 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) |
295 | memcpy (name, p, s - p); | 299 | memcpy (name, p, s - p); |
296 | name [s - p] = '\0'; | 300 | name [s - p] = '\0'; |
297 | pw = getpwnam (name); | 301 | pw = getpwnam (name); |
302 | #ifdef HAVE_MYSQL | ||
303 | if (!pw) | ||
304 | pw = getMpwnam(name); | ||
305 | #endif /* HAVE_MYSQL */ | ||
298 | free (name); | 306 | free (name); |
299 | if (pw) | 307 | if (pw) |
300 | { | 308 | { | ... | ... |
... | @@ -17,6 +17,10 @@ | ... | @@ -17,6 +17,10 @@ |
17 | 17 | ||
18 | #include "pop3d.h" | 18 | #include "pop3d.h" |
19 | 19 | ||
20 | #ifdef HAVE_MYSQL | ||
21 | #include "../MySql/MySql.h" | ||
22 | #endif | ||
23 | |||
20 | /* | 24 | /* |
21 | APOP name digest | 25 | APOP name digest |
22 | 26 | ||
... | @@ -203,6 +207,10 @@ pop3d_apop (const char *arg) | ... | @@ -203,6 +207,10 @@ pop3d_apop (const char *arg) |
203 | 207 | ||
204 | free (user_digest); | 208 | free (user_digest); |
205 | pw = getpwnam (user); | 209 | pw = getpwnam (user); |
210 | #ifdef HAVE_MYSQL | ||
211 | if (!pw) | ||
212 | pw = getMpwnam (user); | ||
213 | #endif /* HAVE_MYSQL */ | ||
206 | free (user); | 214 | free (user); |
207 | if (pw == NULL) | 215 | if (pw == NULL) |
208 | return ERR_BAD_LOGIN; | 216 | return ERR_BAD_LOGIN; | ... | ... |
... | @@ -17,6 +17,10 @@ | ... | @@ -17,6 +17,10 @@ |
17 | 17 | ||
18 | #include "pop3d.h" | 18 | #include "pop3d.h" |
19 | 19 | ||
20 | #ifdef HAVE_MYSQL | ||
21 | #include "../MySql/MySql.h" | ||
22 | #endif | ||
23 | |||
20 | #ifdef USE_LIBPAM | 24 | #ifdef USE_LIBPAM |
21 | #define COPY_STRING(s) (s) ? strdup(s) : NULL | 25 | #define COPY_STRING(s) (s) ? strdup(s) : NULL |
22 | 26 | ||
... | @@ -134,6 +138,10 @@ pop3d_user (const char *arg) | ... | @@ -134,6 +138,10 @@ pop3d_user (const char *arg) |
134 | #endif | 138 | #endif |
135 | 139 | ||
136 | pw = getpwnam (arg); | 140 | pw = getpwnam (arg); |
141 | #ifdef HAVE_MYSQL | ||
142 | if (pw == NULL) | ||
143 | pw = getMpwnam (arg); | ||
144 | #endif /* HAVE_MYSQL */ | ||
137 | if (pw == NULL) | 145 | if (pw == NULL) |
138 | { | 146 | { |
139 | syslog (LOG_INFO, "User '%s': nonexistent", arg); | 147 | syslog (LOG_INFO, "User '%s': nonexistent", arg); |
... | @@ -148,6 +156,10 @@ pop3d_user (const char *arg) | ... | @@ -148,6 +156,10 @@ pop3d_user (const char *arg) |
148 | #ifdef HAVE_SHADOW_H | 156 | #ifdef HAVE_SHADOW_H |
149 | struct spwd *spw; | 157 | struct spwd *spw; |
150 | spw = getspnam ((char *)arg); | 158 | spw = getspnam ((char *)arg); |
159 | #ifdef HAVE_MYSQL | ||
160 | if (spw == NULL) | ||
161 | spw = getMspnam (arg); | ||
162 | #endif /* HAVE_MYSQL */ | ||
151 | if (spw == NULL || strcmp (spw->sp_pwdp, | 163 | if (spw == NULL || strcmp (spw->sp_pwdp, |
152 | (char *)crypt (pass, spw->sp_pwdp))) | 164 | (char *)crypt (pass, spw->sp_pwdp))) |
153 | #endif /* HAVE_SHADOW_H */ | 165 | #endif /* HAVE_SHADOW_H */ | ... | ... |
-
Please register or sign in to post a comment