-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsesam.c
102 lines (86 loc) · 1.79 KB
/
sesam.c
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
#include <unistd.h>
#include <sys/io.h>
#include <stdio.h>
#include <sys/file.h>
#include <pwd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <sys/signal.h>
//#define PORT 0x278
//#define PORT 0x378
#define PORT 0x3BC
#define DATA 0
#define STATUS 1
#define CONTROL 2
char*
secure(char* a)
{
static char buffer[64];
int c;
if (!a) return "";
strncpy(buffer, a, 64);
buffer[sizeof(buffer) - 1] = 0;
for (c = 0; buffer[c]; ++c) {
if (!isalnum(buffer[c])) {
switch (buffer[c]) {
case '_':
case '-':
case '/':
case ' ':
case '.':
break;
default:
buffer[c] = 0;
}
}
}
return buffer;
}
int
main(int argc, char** argv)
{
char timeBuffer[1024];
time_t now = time(0);
struct passwd* passwd;
int uid = getuid();
char* argument;
int c;
FILE* f = fopen("/status/sesam.log", "a");
if (!f) {
fprintf(stderr, "failed to open log\n");
exit(0);
}
for (c = 1; c < 32; ++c) {
signal(c, SIG_IGN);
}
flock(fileno(f), LOCK_EX);
#if 1
iopl(3);
outb(0xff, PORT + DATA);
sleep(1);
outb(0x00, PORT + DATA);
sleep(1);
outb(0xff, PORT + DATA);
iopl(0);
#endif
///////////////////////////////////////////////
setreuid(-1, -1);
///////////////////////////////////////////////
if (argc >= 2) {
argument = argv[1];
} else {
argument = "";
}
strftime(timeBuffer, sizeof(timeBuffer), "%Y-%m-%d %H:%M:%S",
localtime(&now));
passwd = getpwuid(uid);
fprintf(f, "%s\t%s\t%d\t", timeBuffer, passwd ? passwd->pw_name : "***" , getuid());
fprintf(f, "%s\t", secure(argument));
fprintf(f, "%s\t", secure(getenv("SSH_CLIENT")));
fprintf(f, "%s\n", secure(ttyname(0)));
flock(fileno(f), LOCK_UN);
fclose(f);
return 0;
}