-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscriptauth.c
More file actions
98 lines (78 loc) · 2.49 KB
/
scriptauth.c
File metadata and controls
98 lines (78 loc) · 2.49 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
#include "../../structures.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
static int already_loaded = 0;
static struct auth scriptauth;
static unsigned char *service = NULL;
static struct pluginlink *pl;
/**
* Implements scriptauthFunc()
*/
static int scriptauthFunc(struct clientparam *param) {
int rc = 0;
struct sockaddr_in sa;
SASIZETYPE sasize = sizeof(sa);
char hoststr[NI_MAXHOST];
char portstr[NI_MAXSERV];
int rc0 = getsockname(param->clisock, (struct sockaddr *) &sa, &sasize);
int rc1 = getnameinfo(
(struct sockaddr *) &sa,
sasize,
hoststr,
sizeof(hoststr),
portstr,
sizeof(portstr),
NI_NUMERICHOST | NI_NUMERICSERV
);
char addrstr[15];
snprintf(addrstr, sizeof addrstr, "%u.%u.%u.%u",
(unsigned)(((unsigned char *)(SAADDR(¶m->sincr)))[0]),
(unsigned)(((unsigned char *)(SAADDR(¶m->sincr)))[1]),
(unsigned)(((unsigned char *)(SAADDR(¶m->sincr)))[2]),
(unsigned)(((unsigned char *)(SAADDR(¶m->sincr)))[3])
);
// char * argv[] = {param->username, param->password, hoststr, portstr, addrstr, NULL};
// int status;
// status = execve((char *) service, argv, NULL);
// fprintf(stderr, "[>>>] status: %d\n", status);
char *username = "-";
if (param->username) {
username = param->username;
}
char *password = "-";
if (param->password) {
password = param->password;
}
char cmd[256];
snprintf(cmd, sizeof cmd, "%s %s %s %s %s %s", (char *) service, username, password, hoststr, portstr, addrstr);
// fprintf(stderr, "[>>>] cmd: %s\n", cmd);
int status = system(cmd);
if (status != 0) {
rc = 1;
}
return rc;
}
#ifdef WATCOM
#pragma aux start "*" parm caller [ ] value struct float struct routine [eax] modify [eax ecx edx]
#undef PLUGINCALL
#define PLUGINCALL
#endif
/**
* Init/start plugin.
*/
PLUGINAPI int PLUGINCALL start(struct pluginlink *pluginlink, int argc, unsigned char **argv) {
if (argc < 2) return 1;
pl = pluginlink;
if (service) pl->myfree(service);
service = (unsigned char *) pl->mystrdup((char *) argv[1]);
if (already_loaded) { return (0); }
already_loaded = 1;
scriptauth.authenticate = scriptauthFunc;
scriptauth.authorize = pluginlink->checkACL;
scriptauth.desc = "script";
scriptauth.next = pluginlink->authfuncs->next;
pluginlink->authfuncs->next = &scriptauth;
return 0;
}