]>
Commit | Line | Data |
---|---|---|
14cc7eac MT |
1 | #include <stdio.h> |
2 | #include <string.h> | |
3 | #include <stdlib.h> | |
44254afd MT |
4 | #include <unistd.h> |
5 | #include <sys/types.h> | |
6 | #include <fcntl.h> | |
14cc7eac MT |
7 | #include "setuid.h" |
8 | ||
44254afd MT |
9 | #define BUFFER_SIZE 1024 |
10 | ||
11 | char command[BUFFER_SIZE]; | |
12 | ||
13 | int main(int argc, char *argv[]) | |
14cc7eac | 14 | { |
14cc7eac | 15 | |
88932936 CS |
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 | { | |
c41c2eb4 | 28 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -d %s >/dev/null", argv[2]); |
88932936 CS |
29 | safe_system(command); |
30 | return 0; | |
31 | } | |
32 | ||
33 | if (strcmp(argv[1], "smbuserenable")==0) | |
34 | { | |
c41c2eb4 | 35 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -e %s >/dev/null", argv[2]); |
88932936 CS |
36 | safe_system(command); |
37 | return 0; | |
38 | } | |
39 | ||
40 | if (strcmp(argv[1], "smbuserdelete")==0) | |
41 | { | |
c41c2eb4 | 42 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -x %s >/dev/null", argv[2]); |
88932936 | 43 | safe_system(command); |
c41c2eb4 | 44 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/userdel %s >/dev/null", argv[2]); |
88932936 CS |
45 | safe_system(command); |
46 | return 0; | |
47 | } | |
48 | ||
49 | if (strcmp(argv[1], "smbsafeconf")==0) | |
50 | { | |
63d4db83 | 51 | safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf"); |
88932936 CS |
52 | return 0; |
53 | } | |
54 | ||
55 | if (strcmp(argv[1], "smbsafeconfcups")==0) | |
56 | { | |
63d4db83 | 57 | safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/shares /var/ipfire/samba/printer > /var/ipfire/samba/smb.conf"); |
88932936 CS |
58 | return 0; |
59 | } | |
60 | ||
61 | if (strcmp(argv[1], "smbsafeconfpdc")==0) | |
62 | { | |
63d4db83 | 63 | safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/pdc /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf"); |
88932936 CS |
64 | return 0; |
65 | } | |
66 | ||
67 | if (strcmp(argv[1], "smbsafeconfpdccups")==0) | |
68 | { | |
63d4db83 | 69 | safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/pdc /var/ipfire/samba/shares /var/ipfire/samba/printer > /var/ipfire/samba/smb.conf"); |
88932936 CS |
70 | return 0; |
71 | } | |
72 | ||
73 | if (strcmp(argv[1], "smbglobalreset")==0) | |
74 | { | |
63d4db83 CS |
75 | safe_system("/bin/cat /var/ipfire/samba/default.global /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf"); |
76 | safe_system("/bin/cat /var/ipfire/samba/default.settings > /var/ipfire/samba/settings"); | |
77 | safe_system("/bin/cat /var/ipfire/samba/default.global > /var/ipfire/samba/global"); | |
78 | safe_system("/bin/cat /var/ipfire/samba/default.pdc > /var/ipfire/samba/pdc"); | |
88932936 CS |
79 | return 0; |
80 | } | |
81 | ||
82 | if (strcmp(argv[1], "smbsharesreset")==0) | |
83 | { | |
63d4db83 CS |
84 | safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/default.shares > /var/ipfire/samba/smb.conf"); |
85 | safe_system("/bin/cat /var/ipfire/samba/default.shares > /var/ipfire/samba/shares"); | |
88932936 CS |
86 | return 0; |
87 | } | |
88 | ||
89 | if (strcmp(argv[1], "smbprinterreset")==0) | |
90 | { | |
63d4db83 CS |
91 | safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/shares /var/default.printer > /var/ipfire/samba/smb.conf"); |
92 | safe_system("/bin/cat /var/ipfire/samba/default.printer > /var/ipfire/samba/printer"); | |
88932936 CS |
93 | return 0; |
94 | } | |
95 | ||
96 | if (strcmp(argv[1], "smbstop")==0) | |
97 | { | |
c41c2eb4 | 98 | safe_system("/etc/rc.d/init.d/samba stop >/dev/null"); |
c0b839c4 | 99 | safe_system("rm -rf /etc/rc.d/rc*.d/*samba"); |
88932936 CS |
100 | return 0; |
101 | } | |
102 | ||
103 | if (strcmp(argv[1], "smbstart")==0) | |
104 | { | |
c41c2eb4 | 105 | safe_system("/etc/rc.d/init.d/samba start >/dev/null"); |
c0b839c4 CS |
106 | safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc3.d/S45samba"); |
107 | safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc0.d/K48samba"); | |
108 | safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc6.d/K48samba"); | |
88932936 CS |
109 | return 0; |
110 | } | |
111 | ||
112 | if (strcmp(argv[1], "smbrestart")==0) | |
113 | { | |
c41c2eb4 | 114 | safe_system("/etc/rc.d/init.d/samba restart >/dev/null"); |
88932936 CS |
115 | return 0; |
116 | } | |
117 | ||
118 | if (strcmp(argv[1], "smbreload")==0) | |
119 | { | |
c41c2eb4 | 120 | safe_system("/etc/rc.d/init.d/samba reload >/dev/null"); |
88932936 CS |
121 | return 0; |
122 | } | |
123 | ||
124 | if (strcmp(argv[1], "smbstatus")==0) | |
125 | { | |
c41c2eb4 | 126 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbstatus 2>/dev/null"); |
88932936 CS |
127 | safe_system(command); |
128 | return 0; | |
129 | } | |
130 | ||
131 | if (strcmp(argv[1], "smbuseradd")==0) | |
132 | { | |
c41c2eb4 | 133 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/groupadd sambauser >/dev/null"); |
88932936 | 134 | safe_system(command); |
63d4db83 CS |
135 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/useradd -c 'Samba User' -m -g %s -s %s %s >/dev/null", argv[4], argv[5], argv[2]); |
136 | safe_system(command); | |
137 | snprintf(command, BUFFER_SIZE-1, "echo %s:%s | chpasswd", argv[2], argv[3]); | |
88932936 | 138 | safe_system(command); |
c41c2eb4 | 139 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s >/dev/null", argv[3], argv[3], argv[2]); |
88932936 CS |
140 | safe_system(command); |
141 | return 0; | |
142 | } | |
143 | ||
144 | if (strcmp(argv[1], "smbpcadd")==0) | |
145 | { | |
c41c2eb4 | 146 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/groupadd sambawks >/dev/null"); |
88932936 | 147 | safe_system(command); |
c41c2eb4 | 148 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/useradd -c 'Samba Workstation' -g %s -s %s %s >/dev/null", argv[3], argv[4], argv[2]); |
88932936 | 149 | safe_system(command); |
c41c2eb4 | 150 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -a -m %s >/dev/null", argv[2]); |
88932936 CS |
151 | safe_system(command); |
152 | return 0; | |
153 | } | |
154 | ||
155 | if (strcmp(argv[1], "smbchangepw")==0) | |
156 | { | |
63d4db83 CS |
157 | snprintf(command, BUFFER_SIZE-1, "echo %s:%s | chpasswd", argv[2], argv[3]); |
158 | safe_system(command); | |
c41c2eb4 | 159 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s >/dev/null", argv[3], argv[3], argv[2]); |
88932936 CS |
160 | safe_system(command); |
161 | return 0; | |
162 | } | |
163 | ||
164 | if (strcmp(argv[1], "readsmbpasswd")==0) | |
165 | { | |
c41c2eb4 CS |
166 | safe_system("/bin/chown root:nobody /var/ipfire/samba/private >/dev/null"); |
167 | safe_system("/bin/chown root:nobody /var/ipfire/samba/private/smbpasswd >/dev/null"); | |
168 | safe_system("/bin/chmod 640 /var/ipfire/samba/private/smbpasswd >/dev/null"); | |
169 | safe_system("/bin/chmod 650 /var/ipfire/samba/private >/dev/null"); | |
88932936 CS |
170 | return 0; |
171 | } | |
172 | ||
173 | if (strcmp(argv[1], "locksmbpasswd")==0) | |
174 | { | |
c41c2eb4 CS |
175 | safe_system("/bin/chown root:root /var/ipfire/samba/private >/dev/null"); |
176 | safe_system("/bin/chown root:root /var/ipfire/samba/private/smbpasswd >/dev/null"); | |
177 | safe_system("/bin/chmod 600 /var/ipfire/samba/private/smbpasswd >/dev/null"); | |
178 | safe_system("/bin/chmod 600 /var/ipfire/samba/private >/dev/null"); | |
88932936 CS |
179 | return 0; |
180 | } | |
181 | if (strcmp(argv[1], "enable")==0) | |
182 | { | |
183 | safe_system("touch /var/ipfire/samba/enable"); | |
51f3b7f5 | 184 | safe_system("/etc/rc.d/init.d/samba start"); |
186e3d2c MT |
185 | safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc3.d/S45samba"); |
186 | safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc0.d/K48samba"); | |
187 | safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc6.d/K48samba"); | |
88932936 CS |
188 | return 0; |
189 | } | |
190 | ||
191 | if (strcmp(argv[1], "disable")==0) | |
192 | { | |
63d4db83 | 193 | safe_system("unlink /var/ipfire/samba/enable"); |
88932936 | 194 | safe_system("/etc/rc.d/init.d/samba stop"); |
186e3d2c | 195 | safe_system("rm -rf /etc/rc.d/rc*.d/*samba"); |
88932936 CS |
196 | return 0; |
197 | } | |
71dfc4b7 | 198 | return 0; |
c41c2eb4 | 199 | } |