1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
|
#! /bin/sh /usr/share/dpatch/dpatch-run
## 12_multiple_mailbox.dpatch by Adam D. Barratt
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Add support for multiple mailboxes per user (Bug#77711)
@DPATCH@
diff -urNad solid-pop3d~/doc/config.example solid-pop3d/doc/config.example
--- solid-pop3d~/doc/config.example 2005-11-06 15:21:34.000000000 +0100
+++ solid-pop3d/doc/config.example 2005-11-06 15:21:35.000000000 +0100
@@ -4,7 +4,9 @@
MailDropName Maildir
MailDropType maildir
UserBullFile .spop3d-blurp /* It's just an example */
+ UserMailDropDelimiter "+"
ReadExpire 0
+
</Global>
<VirtualHost 192.168.1.1>
UnreadExpire never
diff -urNad solid-pop3d~/man/dot-spop3d.5 solid-pop3d/man/dot-spop3d.5
--- solid-pop3d~/man/dot-spop3d.5 2005-11-06 15:21:30.000000000 +0100
+++ solid-pop3d/man/dot-spop3d.5 2005-11-06 15:21:35.000000000 +0100
@@ -26,30 +26,55 @@
dot-spop3d \- user configuration data for The Solid POP3 Server.
.SH DESCRIPTION
.PP
-User can specify his maildrop (location and type) and APOP secret in ~/.spop3d
-configuration file. You must set right mode (0600 - -rw-------)
-for ~/.spop3d!!!
-Maildrop specification consists of 3 parts, separated
-by white space character:
+A user can specify their maildrop location, type and associated APOP
+secret in the configuration file ~/.spop3d.
+.PP
+The file must be set to mode 0600 (-rw-------) or the server will not
+honour its content.
+.PP
+Maildrop specification consists of three parts, separated
+by white space characters:
.TP
\fIMailDrop\fP \fBpath type\fP
.PP
-\fBPath\fP argument should be specified in the same format as \fI-n\fP
-option in
+\fBPath\fP should be specified in the same format as the \fI-n\fP option in
.BR spop3d (8).
-\fBType\fP argument should be \fImailbox\fP or \fImaildir\fP.
+\fBType\fP should be \fImailbox\fP or \fImaildir\fP.
.PP
-APOP secret specification contains word \fIAPOPSecret\fP followed by encrypted
-secret. You shouldn't change this secret manually. Use
-.BR pop_auth (1)
-to do this. See
+APOP secret specification consists of the word \fIAPOPSecret\fP followed
+by an encrypted secret. You shouldn't change this secret manually. Use
.BR pop_auth (1)
-manual for more details on secret encryption!!!
+to do this.
+.PP
+Both maildrop and APOP secret specifications may optionally be followed
+by a mailbox name. This allows, for instance, user\fI+\fPboxA and user\fI+\fPboxB to
+be used as login names to access different mailboxes, where \fI+\fP
+means value of \fBUserMailDropDelimiter\fP server setting (see \fBspop3d.conf\fP(5)).
+.PP
+The APOP secret associated with a particular maildrop should be followed
+with the same mailbox name (or lack thereof). If no secret is specified
+for a maildrop then the user's standard POP password should be used to
+authenticate instead.
.SH EXAMPLE
.RS
.nf
-MailDrop Mail/bugtraq mailbox
-APOPSecret 0123456789
+MailDrop Mail/default mailbox
+APOPSecret 2345678901
+MailDrop Mail/bugtraq mailbox bugtraq
+APOPSecret 0123456789 bugtraq
+MailDrop Mail/private mailbox private
+APOPSecret 9876543210 private
+.fi
+.RE
+.PP
+To set the APOP secret for the above maildrops use the following
+.BR pop_auth (1)
+commands:
+.RS
+.nf
+pop_auth
+pop_auth bugtraq
+pop_auth private
.fi
.RE
.SH FILES
diff -urNad solid-pop3d~/man/pop_auth.1 solid-pop3d/man/pop_auth.1
--- solid-pop3d~/man/pop_auth.1 2005-11-06 15:21:34.000000000 +0100
+++ solid-pop3d/man/pop_auth.1 2005-11-06 15:21:35.000000000 +0100
@@ -27,6 +27,8 @@
.SH SYNOPSIS
.PP
.B pop_auth
+[-a]
+[\fI!\fP | \fIname\fP ...]
.SH DESCRIPTION
.PP
.B Pop_auth
@@ -34,8 +36,16 @@
in ~/.spop3d file. Used encryption is very weak and protects only from
curious system administrator who accidentialy looks at ~/.spop3d file.
Don't use your account password as the APOP secret!!!
+.PP
+.B Pop_auth
+will set APOP secret for all maildrop \fIname\fPs specified in the command line.
+You can use the special \fI!\fP name to specifiy your default maildrop.
+If called without any arguments,
+.B pop_auth
+will set APOP secret for the default maildrop.
.SH OPTIONS
-No options are recognized.
+.IP "-a"
+Set the same APOP secret for all maildrops definied in ~/.spop3d
.SH FILES
.IP "~/.spop3d"
User configuration file. APOP secret is written here.
diff -urNad solid-pop3d~/man/spop3d.conf.5 solid-pop3d/man/spop3d.conf.5
--- solid-pop3d~/man/spop3d.conf.5 2005-11-06 15:21:34.000000000 +0100
+++ solid-pop3d/man/spop3d.conf.5 2005-11-06 15:21:35.000000000 +0100
@@ -104,6 +104,13 @@
Allow users specify their maildrops (path and type) and APOP secrets.
It's enabled by default.
.TP
+.B UserMailDropDelimiter string
+Specify character used to separate different maildrops for user.
+If set, user can access different maildrops, as defined in their ~/.spop3d file,
+logging as "user_name\fIUserMailDropDelimiter\fRmaildrop_name"
+(e.g. user+private, if the \fIUserMailDropDelimiter\fR is set to \fI+\fR)
+Default is empty (disables support for multiple mailboxes per user).
+.TP
.B AllowAPOP boolean
Users can authenticate themselves with APOP scheme. It's enabled by default.
.TP
diff -urNad solid-pop3d~/src/configfile.h solid-pop3d/src/configfile.h
--- solid-pop3d~/src/configfile.h 2005-11-06 15:21:34.000000000 +0100
+++ solid-pop3d/src/configfile.h 2005-11-06 15:21:35.000000000 +0100
@@ -82,6 +82,7 @@
extern int logstatistics;
#endif
extern int allowuser;
+extern char usermd_delim[2];
struct str_option {
char *name;
diff -urNad solid-pop3d~/src/main.c solid-pop3d/src/main.c
--- solid-pop3d~/src/main.c 2005-11-06 15:21:34.000000000 +0100
+++ solid-pop3d/src/main.c 2005-11-06 15:21:35.000000000 +0100
@@ -190,6 +190,7 @@
#endif
{"LogPriority", OP_STRING, &logpriority, 64, check_logpriority},
{"AllowUser", OP_BOOLEAN, &allowuser, 0, NULL},
+ {"UserMailDropDelimiter", OP_STRING, &usermd_delim, 2, NULL},
{NULL, 0, NULL, 0, NULL}
};
@@ -197,6 +198,8 @@
int connection_state;
char username[MAXARGLN + 1];
char password[MAXARGLN + 1];
+char usersuffix[MAXARGLN + 1];
+char usermd_delim[2] = "";
char buf[MAXCMDLN + 1];
size_t count = 0;
struct str_maildrop *maildrop;
@@ -1034,8 +1037,9 @@
socklen_t addrln;
struct rlimit corelimit = {0, 0};
struct passwd *spop3d, *userentry;
- int tmp, tmp2;
+ int tmp, tmp2, tmp3;
gid_t tmpgid;
+ char *suffix;
#ifdef APOP
int useapop;
#endif
@@ -1231,6 +1235,16 @@
};
};
#endif
+ memset(usersuffix, 0, sizeof(usersuffix));
+ if (usermd_delim[0]) {
+ suffix = strchr(username, usermd_delim[0]);
+ if (suffix != NULL) {
+ tmp3 = suffix - username + 1;
+ strncpy (usersuffix, suffix + 1, sizeof(usersuffix));
+ username[tmp3-1] = 0;
+ tmp3 = 0;
+ };
+ }
#ifdef MAPPING
mapusername[0] = 0;
if (domapping) {
@@ -1369,6 +1383,16 @@
close(tunnel[0]);
wait(NULL);
check_logpriority(logpriority);
+ memset(usersuffix, 0, sizeof(usersuffix));
+ if (usermd_delim[0]) {
+ suffix = strchr(username, usermd_delim[0]);
+ if (suffix != NULL) {
+ tmp3 = suffix - username + 1;
+ strncpy (usersuffix, suffix + 1, sizeof(usersuffix));
+ username[tmp3-1] = 0;
+ tmp3 = 0;
+ };
+ }
#ifdef MAPPING
if (domapping) {
strcpy(origusername,username);
diff -urNad solid-pop3d~/src/pop_auth.c solid-pop3d/src/pop_auth.c
--- solid-pop3d~/src/pop_auth.c 2005-11-06 15:21:30.000000000 +0100
+++ solid-pop3d/src/pop_auth.c 2005-11-06 15:22:10.000000000 +0100
@@ -39,6 +39,105 @@
#include "maildrop.h"
#include "fdfgets.h"
+typedef struct suffixes {
+ char* suffix; /* maildrop suffix name */
+ char* apop_sec; /* apop secret for maildrop */
+ char* mdrop_type; /* maildrop type: mailbox or maildir */
+ char* mdrop_path; /* maildrop path */
+ int flag; /* should we set new apop secret for this maildrop */
+ struct suffixes* next; /* next maildrop */
+} suffixes;
+
+char * xstrdup( char* s ) {
+ s = strdup(s ? s : "");
+ if (!s) {
+ fprintf(stderr, "cant' allocate memory\n");
+ exit(1);
+ }
+ return s;
+}
+
+/* adds new suffix definition to list; note the list is sorted on the suffix field */
+void add_suffix(suffixes **head, char* suffix, char* apop_sec, char* mdrop_type, char* mdrop_path)
+{
+ suffixes *p, *q;
+ int r;
+
+ if (!suffix) {
+ suffix = "";
+ }
+
+ p = *head;
+ q = NULL; /* q is one before p, i.e. q->next == p */
+ r = 1;
+ while (p) {
+ r = strcmp(p->suffix, suffix);
+ if (r < 0) {
+ q = p;
+ p = p->next;
+ } else {
+ break;
+ }
+ }
+
+ if ((r == 0) && (mdrop_type && p->mdrop_type)) {
+ fprintf(stderr, "%s already set%s%s\n",
+ (mdrop_type) ? "Maildrop" : "APOP secret",
+ *suffix ? " for suffix" : "" ,
+ *suffix ? suffix : "" );
+ exit(1);
+ }
+
+ if ( r != 0 ) {
+ /* have to add new */
+ p = (suffixes*) malloc( sizeof(suffixes) );
+ if (!p) {
+ fprintf(stderr, "can't allocate memory\n");
+ exit(1);
+ }
+
+ memset(p, 0, sizeof(suffixes));
+ p->suffix = xstrdup(suffix);
+ if (!q) {
+ p->next = *head;
+ *head = p;
+ } else {
+ p->next = q->next;
+ q->next = p;
+ }
+ }
+
+ if (mdrop_type) {
+ p->mdrop_type = xstrdup(mdrop_type);
+ p->mdrop_path = xstrdup(mdrop_path);
+ } else if(apop_sec) {
+ p->apop_sec = xstrdup(apop_sec);
+ } else {
+ p->flag = 1;
+ }
+}
+
+
+void parse_args(suffixes ** head, int argc, char** argv, int * for_all)
+{
+ char * op;
+ if (argc == 1) {
+ add_suffix(head, "", NULL, NULL, NULL);
+ }
+ while (--argc) {
+ op = argv[argc];
+ if (!strcmp(op, "-a")) {
+ *for_all = 1;
+ continue;
+ } else if (!strcmp(op, "!")) {
+ op = "";
+ }
+ add_suffix(head, op, NULL, NULL, NULL);
+ }
+}
+
+
+
int main(int argc, char **argv) {
int fd, md_set = 0, linenr, fret;
ssize_t tmp;
@@ -47,12 +146,16 @@
char *pass;
char passcopy[MAXARGLN + 1];
char txtbuff[256], buf[128];
+ char apop_sec[128];;
struct rlimit corelimit = {0, 0};
char cfgfile[PATH_MAX];
struct stat stbuf;
char *tmp2;
- char tmpmaildrop_type[MAXMDTYPENAMELENGTH], tmpmaildrop_name[PATH_MAX];
+ char tmpmaildrop_type[MAXMDTYPENAMELENGTH], tmpmaildrop_name[PATH_MAX], tmpapop_sec[256];
static char digits[] = "0123456789abcdef";
+ struct suffixes * suffix_head = NULL, * p = NULL;
+ int for_all = 0;
+
if (setrlimit(RLIMIT_CORE, &corelimit) < 0) {
perror("setrlimit");
@@ -62,10 +165,14 @@
fprintf(stderr, "can't find user with UID: %u\n", getuid());
return 1;
};
+
+ parse_args(&suffix_head, argc, argv, &for_all);
+
username[0] = 0;
strncat(username, pwentry->pw_name, 8);
if (strlen(pwentry->pw_name) > 8)
fprintf(stderr, "Warning: username truncated\n");
+
snprintf(txtbuff, sizeof(txtbuff), "Enter NEW password for user %.40s: ", username);
pass = getpass(txtbuff);
passcopy[0] = 0;
@@ -80,6 +187,16 @@
fprintf(stderr, "Passwords don't match\n");
return 1;
};
+
+ memset(apop_sec, 0, sizeof(apop_sec));
+ tmp2 = apop_sec;
+ for (tmp = 0; tmp < strlen(passcopy); tmp++) {
+ passcopy[tmp] ^= 0xff;
+ tmp2[tmp * 2] = digits[(passcopy[tmp] >> 4) & 0x0f];
+ tmp2[(tmp * 2) + 1] = digits[passcopy[tmp] & 0x0f];
+ };
+ memset(passcopy, 0, strlen(passcopy));
+
if (stat(pwentry->pw_dir, &stbuf) < 0) {
memset(passcopy, 0, strlen(passcopy));
fprintf(stderr, "can't stat user home directory: %.1024s", pwentry->pw_dir);
@@ -192,47 +309,72 @@
fprintf(stderr, "no such maildrop type: %.40s", tmp2);
return 1;
};
+
strcpy(tmpmaildrop_type, tmp2);
- md_set = 1;
+ tmp2 = strtok(NULL, " \t");
+ add_suffix(&suffix_head, tmp2, NULL, tmpmaildrop_name, tmpmaildrop_type);
+
continue;
};
- if (strcasecmp(buf, "APOPSecret") == 0)
+ if (strcasecmp(buf, "APOPSecret") == 0)
+ {
+ if ((tmp2 = strtok(NULL, " \t")) != NULL) {
+ strcpy(tmpapop_sec, tmp2);
+ tmp2 = strtok(NULL, " \t");
+ add_suffix(&suffix_head, tmp2, tmpapop_sec, NULL, NULL);
+ }
+
continue;
+ }
memset(passcopy, 0, strlen(passcopy));
close(fd);
fprintf(stderr, "unknown option name, line: %u", linenr);
return 1;
};
+
if (lseek(fd, 0, SEEK_SET) < 0) {
memset(passcopy, 0, strlen(passcopy));
close(fd);
perror("lseek");
return 1;
};
- if (md_set == 1) {
- snprintf(txtbuff, sizeof(txtbuff), "MailDrop %.100s %.100s\n", tmpmaildrop_name, tmpmaildrop_type);
- if (write(fd, txtbuff, strlen(txtbuff)) < 0) {
- memset(passcopy, 0, strlen(passcopy));
- close(fd);
- perror("write");
- return 1;
+
+ p = suffix_head;
+ while (p) {
+ if (p->mdrop_type && p->mdrop_path) {
+ snprintf(txtbuff, sizeof(txtbuff), "MailDrop %.100s %.100s %.100s\n",
+ p->mdrop_type,
+ p->mdrop_path,
+ p->suffix);
+ if (write(fd, txtbuff, strlen(txtbuff)) < 0) {
+ memset(passcopy, 0, strlen(passcopy));
+ close(fd);
+ perror("write");
+ return 1;
+ };
};
- };
- memset(txtbuff, 0, sizeof(txtbuff));
- strcpy(txtbuff, "APOPSecret ");
- tmp2 = txtbuff + strlen(txtbuff);
- for (tmp = 0; tmp < strlen(passcopy); tmp++) {
- passcopy[tmp] ^= 0xff;
- tmp2[tmp * 2] = digits[(passcopy[tmp] >> 4) & 0x0f];
- tmp2[(tmp * 2) + 1] = digits[passcopy[tmp] & 0x0f];
- };
- memset(passcopy, 0, strlen(passcopy));
- strcat(txtbuff, "\n");
- if (write(fd, txtbuff, strlen(txtbuff)) < 0) {
- memset(txtbuff, 0, strlen(txtbuff));
- close(fd);
- perror("write");
- return 1;
+ p = p->next;
+ }
+
+ p = suffix_head;
+ while (p) {
+ if (for_all || p->flag || p->apop_sec) {
+ memset(txtbuff, 0, sizeof(txtbuff));
+ snprintf(txtbuff, sizeof(txtbuff), "APOPSecret %.100s %.100s\n",
+ for_all || p->flag ? apop_sec : p->apop_sec,
+ p->suffix);
+ if (*p->suffix && !p->mdrop_type)
+ fprintf(stderr, "Warning: no maildrop definition for `%.50s'\n", p->suffix);
+
+ if (write(fd, txtbuff, strlen(txtbuff)) < 0) {
+ memset(txtbuff, 0, strlen(txtbuff));
+ close(fd);
+ perror("write");
+ return 1;
+ };
+
+ };
+ p = p->next;
};
memset(txtbuff, 0, strlen(txtbuff));
if ((tmp = lseek(fd, 0, SEEK_CUR)) < 0) {
diff -urNad solid-pop3d~/src/userconfig.c solid-pop3d/src/userconfig.c
--- solid-pop3d~/src/userconfig.c 2005-11-06 15:21:30.000000000 +0100
+++ solid-pop3d/src/userconfig.c 2005-11-06 15:21:35.000000000 +0100
@@ -30,6 +30,7 @@
extern char maildrop_name[];
extern char maildrop_type[];
+extern char usersuffix[];
#ifdef APOP
extern char apop_secret[];
#endif
@@ -121,12 +122,6 @@
buf[tmp - 1] = 0;
strtok(buf, " \t");
if (strcasecmp(buf, "maildrop") == 0) {
- if (md_set == 1) {
- memset(buf, 0, sizeof(buf));
- close(fd);
- pop_log(pop_priority, "user config: maildrop already set in user config file");
- return;
- };
if ((tmp2 = strtok(NULL, " \t")) == NULL) {
memset(buf, 0, sizeof(buf));
close(fd);
@@ -165,17 +160,24 @@
return;
};
strcpy(tmpmaildrop_type, tmp2);
- md_set = 1;
+ if ((((tmp2 = strtok(NULL, " \t")) == NULL) && (usersuffix[0] == 0)) ||
+ ((tmp2 != NULL) && (usersuffix[0] != 0) && (strcasecmp(tmp2,usersuffix) == 0))) {
+ if (md_set == 1) {
+ memset(buf, 0, sizeof(buf));
+ close(fd);
+ pop_log(pop_priority, "user config: maildrop already set in user config file");
+ return;
+ };
+
+ md_set = 1;
+ strcpy(maildrop_name, tmpmaildrop_name);
+ strcpy(maildrop_type, tmpmaildrop_type);
+ };
+
continue;
};
#ifdef APOP
if (strcasecmp(buf, "APOPsecret") == 0) {
- if (as_set == 1) {
- memset(buf, 0, sizeof(buf));
- close(fd);
- pop_log(pop_priority, "user config: APOP secret already set in user config file");
- return;
- };
if ((tmp2 = strtok(NULL, " \t")) == NULL) {
memset(buf, 0, sizeof(buf));
close(fd);
@@ -215,7 +217,19 @@
tmpapop_secret[tmp3] |= (tmp2[(tmp3 * 2) + 1] - 'a' + 10);
tmpapop_secret[tmp3] ^= 0xff;
};
- as_set = 1;
+ if ((((tmp2 = strtok(NULL, " \t")) == NULL) && (usersuffix[0] == 0))
+ || ((tmp2 != NULL) && (usersuffix[0] != 0) && (strcasecmp(tmp2,usersuffix) == 0))) {
+ if (as_set == 1) {
+ memset(buf, 0, sizeof(buf));
+ close(fd);
+ pop_log(pop_priority, "user config: APOP secret already set in user config file");
+ return;
+ };
+
+ strcpy(apop_secret, tmpapop_secret);
+ as_set = 1;
+ };
+
continue;
};
memset(tmpapop_secret, 0, sizeof(tmpapop_secret));
@@ -227,12 +241,8 @@
};
close(fd);
if (md_set == 1) {
- strcpy(maildrop_name, tmpmaildrop_name);
- strcpy(maildrop_type, tmpmaildrop_type);
};
#ifdef APOP
- if (as_set == 1)
- strcpy(apop_secret, tmpapop_secret);
memset(tmpapop_secret, 0, sizeof(tmpapop_secret));
#endif
return;
|