forked from simta/simta
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimlog.c
More file actions
114 lines (93 loc) · 2.11 KB
/
simlog.c
File metadata and controls
114 lines (93 loc) · 2.11 KB
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
/*
* RFC's of interest:
*
* RFC 822 "Standard for the format of ARPA Internet text messages"
* RFC 1123 "Requirements for Internet Hosts -- Application and Support"
* RFC 2476 "Message Submission"
* RFC 2822 "Internet Message Format"
*
*/
#include "config.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/param.h>
#ifdef HAVE_LIBSSL
#include <openssl/ssl.h>
#include <openssl/rand.h>
#include <openssl/err.h>
#endif /* HAVE_LIBSSL */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#ifdef HAVE_LIBSASL
#include <sasl/sasl.h>
#endif /* HAVE_LIBSASL */
#include <snet.h>
#include "simta.h"
int
main( int argc, char *argv[] )
{
SNET *in;
SNET *out;
char *line;
int x;
struct timeval tv;
char path[ MAXPATHLEN ];
int c;
if ( simta_gettimeofday( &tv ) != 0 ) {
perror( "gettimeofday" );
return( 1 );
}
/* XXX hard path */
sprintf( path, "%s/%ld.%ld", "/var/simta/log", tv.tv_sec, tv.tv_usec );
if (( in = snet_attach( 0, 1024 * 1024 )) == NULL ) {
perror( "snet_attach" );
exit( 1 );
}
if (( out = snet_open( path, O_CREAT | O_WRONLY,
S_IRUSR | S_IRGRP | S_IROTH, 1024 * 1024 )) == NULL ) {
perror( "snet_open" );
exit( 1 );
}
snet_writef( out, "%s", argv[ 0 ] );
for ( x = 1; x < argc; x++ ) {
snet_writef( out, " %s", argv[ x ] );
}
snet_writef( out, "\n\n" );
opterr = 0;
while (( c = getopt( argc, argv, "b:" )) != -1 ) {
switch ( c ) {
case 'b':
if ( strlen( optarg ) == 1 ) {
switch ( *optarg ) {
case 'a':
/* -ba ARPANET mode */
case 'd':
/* -bd Daemon mode, background */
case 's':
/* 501 Permission denied */
printf( "501 Mode not supported\r\n" );
exit( 1 );
}
}
break;
default:
break;
}
}
while (( line = snet_getline( in, NULL )) != NULL ) {
snet_writef( out, "%s\n", line );
}
if ( snet_close( in ) != 0 ) {
perror( "snet_close" );
exit( 1 );
}
if ( snet_close( out ) != 0 ) {
perror( "snet_close" );
exit( 1 );
}
return( 0 );
}