]>
Commit | Line | Data |
---|---|---|
1 | #include <stdio.h> | |
2 | #include <string.h> | |
3 | #include <stdlib.h> | |
4 | #include <unistd.h> | |
5 | #include <sys/types.h> | |
6 | #include <fcntl.h> | |
7 | #include "setuid.h" | |
8 | ||
9 | #define BUFFER_SIZE 1024 | |
10 | ||
11 | char command[BUFFER_SIZE]; | |
12 | ||
13 | int main(int argc, char *argv[]) | |
14 | { | |
15 | ||
16 | if (!(initsetuid())) | |
17 | exit(1); | |
18 | ||
19 | // Check what command is asked | |
20 | if (argc==1) | |
21 | { | |
22 | fprintf (stderr, "Missing smbctrl command!\n"); | |
23 | return 1; | |
24 | } | |
25 | ||
26 | if (strcmp(argv[1], "smbuserdisable")==0) | |
27 | { | |
28 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -d %s", argv[2]); | |
29 | safe_system(command); | |
30 | return 0; | |
31 | } | |
32 | ||
33 | if (strcmp(argv[1], "smbuserenable")==0) | |
34 | { | |
35 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -e %s", argv[2]); | |
36 | safe_system(command); | |
37 | return 0; | |
38 | } | |
39 | ||
40 | if (strcmp(argv[1], "smbuserdelete")==0) | |
41 | { | |
42 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -x %s", argv[2]); | |
43 | safe_system(command); | |
44 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/userdel %s", argv[2]); | |
45 | safe_system(command); | |
46 | return 0; | |
47 | } | |
48 | ||
49 | if (strcmp(argv[1], "smbsafeconf")==0) | |
50 | { | |
51 | safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf"); | |
52 | return 0; | |
53 | } | |
54 | ||
55 | if (strcmp(argv[1], "smbsafeconfpdc")==0) | |
56 | { | |
57 | safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/pdc /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf"); | |
58 | return 0; | |
59 | } | |
60 | ||
61 | if (strcmp(argv[1], "smbglobalreset")==0) | |
62 | { | |
63 | safe_system("/bin/cat /var/ipfire/samba/default.global /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf"); | |
64 | safe_system("/bin/cat /var/ipfire/samba/default.settings > /var/ipfire/samba/settings"); | |
65 | safe_system("/bin/cat /var/ipfire/samba/default.global > /var/ipfire/samba/global"); | |
66 | safe_system("/bin/cat /var/ipfire/samba/default.pdc > /var/ipfire/samba/pdc"); | |
67 | return 0; | |
68 | } | |
69 | ||
70 | if (strcmp(argv[1], "smbsharesreset")==0) | |
71 | { | |
72 | safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/default.shares > /var/ipfire/samba/smb.conf"); | |
73 | safe_system("/bin/cat /var/ipfire/samba/default.shares > /var/ipfire/samba/shares"); | |
74 | return 0; | |
75 | } | |
76 | ||
77 | if (strcmp(argv[1], "smbstop")==0) | |
78 | { | |
79 | safe_system("/etc/rc.d/init.d/samba stop"); | |
80 | printf(command); | |
81 | return 0; | |
82 | } | |
83 | ||
84 | if (strcmp(argv[1], "smbstart")==0) | |
85 | { | |
86 | safe_system("/etc/rc.d/init.d/samba start"); | |
87 | printf(command); | |
88 | return 0; | |
89 | } | |
90 | ||
91 | if (strcmp(argv[1], "smbrestart")==0) | |
92 | { | |
93 | safe_system("/etc/rc.d/init.d/samba restart"); | |
94 | printf(command); | |
95 | return 0; | |
96 | } | |
97 | ||
98 | if (strcmp(argv[1], "smbreload")==0) | |
99 | { | |
100 | safe_system("/etc/rc.d/init.d/samba reload"); | |
101 | printf(command); | |
102 | return 0; | |
103 | } | |
104 | ||
105 | if (strcmp(argv[1], "smbstatus")==0) | |
106 | { | |
107 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbstatus"); | |
108 | safe_system(command); | |
109 | return 0; | |
110 | } | |
111 | ||
112 | if (strcmp(argv[1], "smbuseradd")==0) | |
113 | { | |
114 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/groupadd sambauser"); | |
115 | safe_system(command); | |
116 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/useradd -c 'Samba User' -m -g %s -p %s -s %s %s", argv[4], argv[3], argv[5], argv[2]); | |
117 | safe_system(command); | |
118 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s", argv[3], argv[3], argv[2]); | |
119 | safe_system(command); | |
120 | return 0; | |
121 | } | |
122 | ||
123 | if (strcmp(argv[1], "smbpcadd")==0) | |
124 | { | |
125 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/groupadd sambawks"); | |
126 | safe_system(command); | |
127 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/useradd -c 'Samba Workstation' -g %s -s %s %s", argv[3], argv[4], argv[2]); | |
128 | safe_system(command); | |
129 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -a -m %s", argv[2]); | |
130 | safe_system(command); | |
131 | return 0; | |
132 | } | |
133 | ||
134 | if (strcmp(argv[1], "smbchangepw")==0) | |
135 | { | |
136 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s", argv[3], argv[3], argv[2]); | |
137 | safe_system(command); | |
138 | return 0; | |
139 | } | |
140 | ||
141 | if (strcmp(argv[1], "readsmbpasswd")==0) | |
142 | { | |
143 | safe_system("/bin/chown root:nobody /var/ipfire/samba/private"); | |
144 | safe_system("/bin/chown root:nobody /var/ipfire/samba/private/smbpasswd"); | |
145 | safe_system("/bin/chmod 640 /var/ipfire/samba/private/smbpasswd"); | |
146 | safe_system("/bin/chmod 650 /var/ipfire/samba/private"); | |
147 | return 0; | |
148 | } | |
149 | ||
150 | if (strcmp(argv[1], "locksmbpasswd")==0) | |
151 | { | |
152 | safe_system("/bin/chown root:root /var/ipfire/samba/private"); | |
153 | safe_system("/bin/chown root:root /var/ipfire/samba/private/smbpasswd"); | |
154 | safe_system("/bin/chmod 600 /var/ipfire/samba/private/smbpasswd"); | |
155 | safe_system("/bin/chmod 600 /var/ipfire/samba/private"); | |
156 | return 0; | |
157 | } | |
158 | ||
159 | if (strcmp(argv[1], "smbechotest")==0) | |
160 | { | |
161 | sprintf(command, BUFFER_SIZE-1, "/usr/bin/printf %s %s", argv[2], argv[3]); | |
162 | printf(command); | |
163 | safe_system(command); | |
164 | return 0; | |
165 | } | |
166 | } |