Missing doc/Readme.mysql and examples/mail.MysqlMailer.c
Showing
2 changed files
with
170 additions
and
0 deletions
doc/Readme.mysql
0 → 100644
1 | Author: Jim Hull (8-24-2001) | ||
2 | imaginos@imaginos.net | ||
3 | |||
4 | Mysql support for mailutils .... | ||
5 | |||
6 | This addition to mailutils allows you to have complete email support | ||
7 | without actually having the users on the systems. This would allow you to | ||
8 | have complete web based account management for users while still | ||
9 | maintaining system security as the users can not access the box directly. | ||
10 | The setup is designed to work with the same table definitions as ProFtpd | ||
11 | thus granting you the ability to grant complete web/ftp/email based system | ||
12 | all authenticated by a database running in mysql. A current running system | ||
13 | for this exists at http://www.linuxrocket.net/freeweb.cgi. | ||
14 | |||
15 | |||
16 | Setup: | ||
17 | |||
18 | Mysql: | ||
19 | create database mail; | ||
20 | grant all privileges on mail.* to user@localhost identified by | ||
21 | 'foobar'; | ||
22 | |||
23 | create table users (username VARCHAR(20) UNIQUE NOT NULL, | ||
24 | uid INT(5) NOT NULL DEFAULT 99, | ||
25 | gid INT(5) NOT NULL DEFAULT 99, | ||
26 | password VARCHAR(15) NOT NULL, | ||
27 | homedir VARCHAR(128) NOT NULL, | ||
28 | shell VARCHAR(64) NOT NULL, | ||
29 | comment TEXT); | ||
30 | |||
31 | |||
32 | When you are done, it should look like .... | ||
33 | |||
34 | +----------+--------------+------+-----+---------+-------+ | ||
35 | | Field | Type | Null | Key | Default | Extra | | ||
36 | +----------+--------------+------+-----+---------+-------+ | ||
37 | | username | varchar(20) | | PRI | | | | ||
38 | | uid | int(5) | | | 99 | | | ||
39 | | gid | int(5) | | | 99 | | | ||
40 | | password | varchar(15) | | | | | | ||
41 | | homedir | varchar(128) | | | | | | ||
42 | | shell | varchar(64) | | | | | | ||
43 | | comment | text | YES | | NULL | | | ||
44 | +----------+--------------+------+-----+---------+-------+ | ||
45 | |||
46 | System Setup: | ||
47 | |||
48 | After modifying MySql/MySql.h with your appropriate defines, compile and | ||
49 | install. | ||
50 | |||
51 | Add a user with no possibility of a pass, with its own gid, shell should | ||
52 | be /bin/false and dir should be /dev/null. Something like ... | ||
53 | |||
54 | monly:x:3002:805:Mail Only:/dev/null:/bin/false | ||
55 | monly:x:805: | ||
56 | |||
57 | When you enter new users into your table, you want to be sure they all | ||
58 | have the same uid/gid in the table as that one user on the system. If you | ||
59 | use the mailer thats in examples/mail.MysqlMailer.c then you will be all | ||
60 | ready to go. It explains in the source for its setup and installation. | ||
61 | |||
62 | an example entry would be ... | ||
63 | +----------+------+------+---------------+-------------------------+------------+----------+ | ||
64 | | username | uid | gid | password | homedir | shell | comment | | ||
65 | +----------+------+------+---------------+-------------------------+------------+----------+ | ||
66 | | foobar | 3002 | 805 | JahUAjwjhAJha | /home/foobar | /bin/false | F. Bar | | ||
67 | +----------+------+------+---------------+-------------------------+------------+----------+ | ||
68 | |||
69 | 1) make sure /var/spool/foobar is uid '3002', gid 'mail' and 0660 | ||
70 | 2) make sure /home/foobar is uid '3002', gid '805' so when you set up | ||
71 | proftpd it works in unison |
examples/mail.MysqlMailer.c
0 → 100644
1 | #include <stdlib.h> | ||
2 | #include <stdio.h> | ||
3 | #include <mysql/mysql.h> | ||
4 | #include <unistd.h> | ||
5 | #include <string.h> | ||
6 | #include <sysexits.h> | ||
7 | #include <sys/types.h> | ||
8 | #include <sys/stat.h> | ||
9 | |||
10 | /********************************************************************** | ||
11 | ** mailer to go with gnu-pop3d patch, works with sendmail | ||
12 | ** add the following in sendmail.cf right after virtusertable ruleset | ||
13 | ** R$* < $* @ yourdomain . net . > $#MysqlMailer $: $1 | ||
14 | ** | ||
15 | ** Then after local mailer, add the following | ||
16 | ** MMysqlMailer, P=/usr/local/bin/mail.MysqlMailer, F=lsDFMoqeu9, S=10/30, R=20/40, | ||
17 | ** A=mail.MysqlMailer $u | ||
18 | ** | ||
19 | ** compile with gcc -o mail.MysqlMailer mail.MysqlMailer.c -lmysqlclient | ||
20 | ** | ||
21 | ** chown it so it is owned by same owner of your psuedo mails (mine is monly) | ||
22 | ** and same group as owner sendmail runs as | ||
23 | ** then chmod 4711. If you have local users on your box (shell accounts) you may want | ||
24 | ** to declare AGENT as read-only in /etc/profile (declare -r AGENT). | ||
25 | ** | ||
26 | ** Author: Jim Hull (08-24-2001) | ||
27 | ** imaginos@imaginos.net | ||
28 | **********************************************************************/ | ||
29 | |||
30 | #define USERNAME "username" /* username field */ | ||
31 | #define TABLE "table" /* table name */ | ||
32 | #define Muser "user" /* Mysql username */ | ||
33 | #define Mpass "password" /* Mysql password */ | ||
34 | #define Mdb "db" /* Mysql Database Name */ | ||
35 | |||
36 | int main(int argc, char **argv) | ||
37 | { | ||
38 | FILE *f; | ||
39 | char QueryStr[1024], *user, path[128], output[1024], *agent; | ||
40 | MYSQL *m; | ||
41 | MYSQL_RES *res; | ||
42 | MYSQL_ROW row; | ||
43 | int i; | ||
44 | |||
45 | if (argc != 2) | ||
46 | exit(EX_NOUSER); | ||
47 | |||
48 | agent = getenv("AGENT"); | ||
49 | |||
50 | if (!agent) | ||
51 | exit(EX_NOUSER); | ||
52 | |||
53 | if (strcmp(getenv("AGENT"), "sendmail") != 0) | ||
54 | exit(EX_NOUSER); | ||
55 | |||
56 | user = strdup(argv[1]); | ||
57 | |||
58 | memset((char *)QueryStr, '\0', 1024); | ||
59 | memset((char *)path, '\0', 128); | ||
60 | |||
61 | m = mysql_init(0); | ||
62 | |||
63 | if (!m) | ||
64 | exit(EX_NOUSER); | ||
65 | |||
66 | if (!mysql_real_connect(m, NULL, Muser, Mpass, Mdb, 0, NULL, 0)) | ||
67 | exit(EX_NOUSER); | ||
68 | |||
69 | sprintf(QueryStr, "select %s from %s where %s = '%s' limit 1", USERNAME, TABLE, USERNAME, user); | ||
70 | |||
71 | if (mysql_query(m, QueryStr) != 0) | ||
72 | exit(EX_NOUSER); | ||
73 | |||
74 | if ((res = mysql_store_result(m)) == NULL) | ||
75 | exit(EX_NOUSER); | ||
76 | |||
77 | if ((row = mysql_fetch_row(res)) == NULL) | ||
78 | exit(EX_NOUSER); | ||
79 | |||
80 | sprintf(path, "/var/spool/mail/%s", row[0]); | ||
81 | |||
82 | f = fopen(path, "a"); | ||
83 | |||
84 | if (!f) | ||
85 | exit(EX_NOUSER); | ||
86 | |||
87 | while (!feof(stdin)) | ||
88 | { | ||
89 | memset((char *)output, '\0', 1024); | ||
90 | fgets(output, 1024, stdin); | ||
91 | fprintf(f, "%s", output); | ||
92 | } | ||
93 | chmod(path, S_IWUSR|S_IRUSR|S_IRGRP|S_IWGRP); | ||
94 | fclose(f); | ||
95 | exit(0); | ||
96 | } | ||
97 | |||
98 | |||
99 |
-
Please register or sign in to post a comment