-
Notifications
You must be signed in to change notification settings - Fork 1
/
csf.c
72 lines (67 loc) · 1.53 KB
/
csf.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
/*
* Copyright 2006-2019, Way to the Web Limited
* URL: http://www.configserver.com
* Email: [email protected]
*/
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <pwd.h>
main ()
{
FILE *adminFile;
FILE *resellerFile;
uid_t ruid;
char name[100];
struct passwd *pw;
int admin = 0;
int reseller = 0;
setenv("CSF_RESELLER", "", 1);
ruid = getuid();
pw = getpwuid(ruid);
adminFile=fopen ("/usr/local/directadmin/data/admin/admin.list","r");
if (adminFile!=NULL)
{
while(fgets(name,100,adminFile) != NULL)
{
int end = strlen(name) - 1;
if (end >= 0 && name[end] == '\n') name[end] = '\0';
//printf("Name [%s]\n", name);
if (strcmp(pw->pw_name, name) == 0) admin = 1;
}
fclose(adminFile);
}
if (admin == 1)
{
setuid(0);
setgid(0);
execv("/usr/local/directadmin/plugins/csf/exec/da_csf.cgi", NULL);
} else {
resellerFile=fopen ("/usr/local/directadmin/data/admin/reseller.list","r");
if (resellerFile!=NULL)
{
while(fgets(name,100,resellerFile) != NULL)
{
int end = strlen(name) - 1;
if (end >= 0 && name[end] == '\n') name[end] = '\0';
//printf("Name [%s]\n", name);
if (strcmp(pw->pw_name, name) == 0)
{
reseller = 1;
setenv("CSF_RESELLER", pw->pw_name, 1);
}
}
fclose(resellerFile);
}
if (reseller == 1)
{
setuid(0);
setgid(0);
execv("/usr/local/directadmin/plugins/csf/exec/da_csf_reseller.cgi", NULL);
} else {
printf("Permission denied [User:%s UID:%d]\n", pw->pw_name, ruid);
}
}
return 0;
}