s/qmail
4.3.20
Next generation secure email transport
Loading...
Searching...
No Matches
4.3
sqmail-4.3.20
src
qbiff.c
Go to the documentation of this file.
1
#include <sys/types.h>
2
#include <sys/stat.h>
3
#include <unistd.h>
4
#include "hasutmp.h"
5
#ifdef HASUTMP
6
#include <utmp.h>
7
#ifndef UTMP_FILE
8
#ifdef _PATH_UTMP
9
#define UTMP_FILE _PATH_UTMP
10
#else
11
#define UTMP_FILE "/etc/utmp"
12
#endif
13
#endif
14
#else
15
#include <utmpx.h>
16
#endif
17
#include "stralloc.h"
18
#include "buffer.h"
19
#include "open.h"
20
#include "byte.h"
21
#include "str.h"
22
#include "
headerbody.h
"
23
#include "
hfield.h
"
24
#include "env.h"
25
#include "
exit.h
"
26
#include "
qmail.h
"
27
28
buffer
b
;
29
#ifdef HASUTMP
30
char
bufutmp[
sizeof
(
struct
utmp) * 16];
31
int
fdutmp;
32
#endif
33
char
buftty
[
BUFSIZE_LINE
];
34
int
fdtty
;
35
36
#ifdef HASUTMP
37
struct
utmp
ut
;
38
char
line
[
sizeof
(
ut
.ut_line) + 1];
39
#else
40
struct
utmpx *
ut
;
41
char
line
[
sizeof
(
ut
->ut_line) + 1];
42
#endif
43
44
stralloc
woof
= {0};
45
stralloc
tofrom
= {0};
46
stralloc
text
= {0};
47
48
static
void
doit(
char
*s,
int
n)
49
{
50
if
(!stralloc_catb(&
text
,s,n))
_exit
(0);
51
if
(
text
.len > 78)
text
.len = 78;
52
}
53
54
static
void
dobody(stralloc *
h
) { doit(
h
->s,
h
->len); }
55
56
static
void
doheader(stralloc *
h
)
57
{
58
int
i;
59
60
if
(
hfield_known
(
h
->s,
h
->len) ==
H_SUBJECT
) {
61
i =
hfield_skipname
(
h
->s,
h
->len);
62
doit(
h
->s + i,
h
->len - i);
63
}
64
}
65
66
static
void
finishheader() { ; }
67
68
int
main
()
69
{
70
char
*
user
;
71
char
*
sender
;
72
char
*userext;
73
struct
stat st;
74
int
i;
75
76
if
(chdir(
"/dev"
) == -1)
_exit
(0);
77
78
if
(!(
user
= env_get(
"USER"
)))
_exit
(0);
79
if
(!(
sender
= env_get(
"SENDER"
)))
_exit
(0);
80
if
(!(userext = env_get(
"LOCAL"
)))
_exit
(0);
81
#ifdef HASUTMP
82
if
(str_len(
user
) >
sizeof
(
ut
.ut_name))
_exit
(0);
83
#else
84
if
(str_len(
user
) >
sizeof
(
ut
->ut_user))
_exit
(0);
85
#endif
86
87
if
(!
stralloc_copys
(&
tofrom
,
"*** TO <"
))
_exit
(0);
88
if
(!stralloc_cats(&
tofrom
,userext))
_exit
(0);
89
if
(!stralloc_cats(&
tofrom
,
"> FROM <"
))
_exit
(0);
90
if
(!stralloc_cats(&
tofrom
,
sender
))
_exit
(0);
91
if
(!stralloc_cats(&
tofrom
,
">"
))
_exit
(0);
92
93
for
(i = 0; i <
tofrom
.len; ++i)
94
if
((
tofrom
.s[i] < 32) || (
tofrom
.s[i] > 126))
95
tofrom
.s[i] =
'_'
;
96
97
if
(!
stralloc_copys
(&
text
,
" "
))
_exit
(0);
98
if
(
headerbody
(buffer_0,doheader,finishheader,dobody) == -1)
_exit
(0);
99
100
for
(i = 0; i <
text
.len; ++i)
101
if
((
text
.s[i] < 32) || (
text
.s[i] > 126))
102
text
.s[i] =
'/'
;
103
104
if
(!
stralloc_copys
(&
woof
,
"\015\n\007"
))
_exit
(0);
105
if
(!stralloc_cat(&
woof
,&
tofrom
))
_exit
(0);
106
if
(!stralloc_cats(&
woof
,
"\015\n"
))
_exit
(0);
107
if
(!stralloc_cat(&
woof
,&
text
))
_exit
(0);
108
if
(!stralloc_cats(&
woof
,
"\015\n"
))
_exit
(0);
109
110
#ifdef HASUTMP
111
fdutmp = open_read(UTMP_FILE);
112
if
(fdutmp == -1)
_exit
(0);
113
buffer_init(&
b
,read,fdutmp,bufutmp,
sizeof
(bufutmp));
114
115
while
(buffer_get(&
b
,(
char
*)&
ut
,
sizeof
(
ut
)) ==
sizeof
(
ut
))
116
if
(!str_diffn(
ut
.ut_name,
user
,
sizeof
(
ut
.ut_name))) {
117
#else
118
while
((
ut
= getutxent()) != 0)
119
if
(
ut
->ut_type == USER_PROCESS && !str_diffn(
ut
->ut_user,
user
,
sizeof
(
ut
->ut_user))) {
120
#endif
121
#ifdef HASUTMP
122
byte_copy(
line
,
sizeof
(
ut
.ut_line),
ut
.ut_line);
123
line
[
sizeof
(
ut
.ut_line)] = 0;
124
#else
125
byte_copy(
line
,
sizeof
(
ut
->ut_line),
ut
->ut_line);
126
line
[
sizeof
(
ut
->ut_line)] = 0;
127
#endif
128
if
(
line
[0] ==
'/'
)
continue
;
129
if
(!
line
[0])
continue
;
130
if
(
line
[str_chr(
line
,
'.'
)])
continue
;
131
132
fdtty
= open_append(
line
);
133
if
(
fdtty
== -1)
continue
;
134
if
(fstat(
fdtty
,&st) == -1) { close(
fdtty
);
continue
; }
135
if
(!(st.st_mode & 0100)) { close(
fdtty
);
continue
; }
136
if
(st.st_uid != getuid()) { close(
fdtty
);
continue
; }
137
buffer_init(&
b
,
write
,
fdtty
,
buftty
,
sizeof
(
buftty
));
138
buffer_putflush(&
b
,
woof
.s,
woof
.len);
139
close(
fdtty
);
140
}
141
_exit
(0);
142
}
stralloc_copys
int stralloc_copys(stralloc *, char const *)
exit.h
_exit
void _exit(int)
sender
stralloc sender
Definition:
fastforward.c:71
headerbody
int headerbody(buffer *b, void(*dohf)(), void(*hdone)(), void(*dobl)())
Definition:
headerbody.c:21
headerbody.h
hfield_skipname
unsigned int hfield_skipname(char *s, int len)
Definition:
hfield.c:96
hfield_known
int hfield_known(char *s, int len)
Definition:
hfield.c:57
hfield.h
H_SUBJECT
#define H_SUBJECT
Definition:
hfield.h:16
h
void h(char *, char *, int, int, int)
Definition:
install.c:15
ut
struct utmpx * ut
Definition:
qbiff.c:40
b
buffer b
Definition:
qbiff.c:28
text
stralloc text
Definition:
qbiff.c:46
buftty
char buftty[BUFSIZE_LINE]
Definition:
qbiff.c:33
tofrom
stralloc tofrom
Definition:
qbiff.c:45
woof
stralloc woof
Definition:
qbiff.c:44
main
int main()
Definition:
qbiff.c:68
line
char line[sizeof(ut->ut_line)+1]
Definition:
qbiff.c:41
fdtty
int fdtty
Definition:
qbiff.c:34
user
stralloc user
Definition:
qmail-authuser.c:65
qmail.h
BUFSIZE_LINE
#define BUFSIZE_LINE
Definition:
qmail.h:8
write
void write()
Generated on Thu Jan 16 2025 17:42:04 for s/qmail by
1.9.6