File: rcpt.c

package info (click to toggle)
ssmtp 2.50.6.3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 720 kB
  • ctags: 111
  • sloc: ansic: 1,596; sh: 326; makefile: 116
file content (132 lines) | stat: -rw-r--r-- 2,306 bytes parent folder | download
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
/*

 $Id: rcpt.c,v 1.3 2002/04/01 12:58:54 matt Exp $

 See COPYRIGHT for the license

*/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <pwd.h>
#include "ssmtp.h"

extern char *root_user;
extern rcpt_t *rt;


/*
RCPT_parse() -- Break To|Cc|Bcc into individual addresses
*/
void RCPT_parse(char *str)
{
	bool_t in_quotes = False, got_addr = False;
	char *p, *q, *r;

#if 0
	(void)fprintf(stderr, "*** RCPT_parse(): str = [%s]\n", str);
#endif

	if((p = strdup(str)) == (char *)NULL) {
		die("RCPT_parse(): strdup() failed");
	}
	q = p;

	/* Replace <CR> and <TAB> */
	while(*q) {
		switch(*q) {
			case '\t':
			case '\n':
					*q = ' ';
		}
		q++;
	}
	q = p;
#if 0
	(void)fprintf(stderr, "*** RCPT_parse(): q = [%s]\n", q);
#endif

	r = q;
	while(*q) {
		if(*q == '"') {
			in_quotes = (in_quotes ? False : True);
		}

		/* End of string? */
		if(*(q + 1) == (char)NULL) {
			got_addr = True;
		}

		/* End of address? */
		if((*q == ',') && (in_quotes == False)) {
			got_addr = True;

			*q = (char)NULL;
		}

		if(got_addr) {
			while(*r && isspace(*r)) r++;

			RCPT_save(ADDR_parse(r));
			r = (q + 1);
#if 0
			(void)fprintf(stderr,
				"*** RCPT_parse(): r = [%s]\n", r);
#endif
			got_addr = False;
		}
		q++;
	}
	free(p);
}

/*
RCPT_save() -- Store entry into RCPT list
*/
void RCPT_save(char *str)
{
	char *p;

	/* Horrible botch for group stuff */
	p = str;
	while(*p) p++;
	if(*--p == ';') {
		return;
	}

#if 0
	(void)fprintf(stderr, "*** RCPT_save(): str = [%s]\n", str);
#endif

	if((rt->string = strdup(str)) == (char *)NULL) {
		die("RCPT_save() -- strdup() failed");
	}

	rt->next = (rcpt_t *)malloc(sizeof(rcpt_t));
	if(rt->next == (rcpt_t *)NULL) {
		die("RCPT_save() -- malloc() failed");
	}
	rt = rt->next;

	rt->next = (rcpt_t *)NULL;
}

/*
RCPT_remap() -- alias systems-level users to the person who
	reads their mail.  This is variously the owner of a workstation,
	the sysadmin of a group of stations and the postmaster otherwise.
	We don't just mail stuff off to root on the mailhub (:-))
*/
char *RCPT_remap(char *str)
{
	struct passwd *pw;

	if(strchr(str, '@') ||
		((pw = getpwnam(str)) == NULL) || (pw->pw_uid > MAXSYSUID)) {
		/* It's not a local systems-level user */
		return(append_domain(str));
	}
	else {
		return(append_domain(root_user));
	}
}