]>
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"); |
88932936 CS |
99 | return 0; |
100 | } | |
101 | ||
102 | if (strcmp(argv[1], "smbstart")==0) | |
103 | { | |
c41c2eb4 | 104 | safe_system("/etc/rc.d/init.d/samba start >/dev/null"); |
88932936 CS |
105 | return 0; |
106 | } | |
107 | ||
108 | if (strcmp(argv[1], "smbrestart")==0) | |
109 | { | |
c41c2eb4 | 110 | safe_system("/etc/rc.d/init.d/samba restart >/dev/null"); |
88932936 CS |
111 | return 0; |
112 | } | |
113 | ||
114 | if (strcmp(argv[1], "smbreload")==0) | |
115 | { | |
c41c2eb4 | 116 | safe_system("/etc/rc.d/init.d/samba reload >/dev/null"); |
88932936 CS |
117 | return 0; |
118 | } | |
119 | ||
120 | if (strcmp(argv[1], "smbstatus")==0) | |
121 | { | |
c41c2eb4 | 122 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbstatus 2>/dev/null"); |
88932936 CS |
123 | safe_system(command); |
124 | return 0; | |
125 | } | |
126 | ||
127 | if (strcmp(argv[1], "smbuseradd")==0) | |
128 | { | |
c41c2eb4 | 129 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/groupadd sambauser >/dev/null"); |
88932936 | 130 | safe_system(command); |
63d4db83 CS |
131 | 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]); |
132 | safe_system(command); | |
133 | snprintf(command, BUFFER_SIZE-1, "echo %s:%s | chpasswd", argv[2], argv[3]); | |
88932936 | 134 | safe_system(command); |
c41c2eb4 | 135 | 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 |
136 | safe_system(command); |
137 | return 0; | |
138 | } | |
139 | ||
140 | if (strcmp(argv[1], "smbpcadd")==0) | |
141 | { | |
c41c2eb4 | 142 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/groupadd sambawks >/dev/null"); |
88932936 | 143 | safe_system(command); |
c41c2eb4 | 144 | 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 | 145 | safe_system(command); |
c41c2eb4 | 146 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -a -m %s >/dev/null", argv[2]); |
88932936 CS |
147 | safe_system(command); |
148 | return 0; | |
149 | } | |
150 | ||
151 | if (strcmp(argv[1], "smbchangepw")==0) | |
152 | { | |
63d4db83 CS |
153 | snprintf(command, BUFFER_SIZE-1, "echo %s:%s | chpasswd", argv[2], argv[3]); |
154 | safe_system(command); | |
c41c2eb4 | 155 | 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 |
156 | safe_system(command); |
157 | return 0; | |
158 | } | |
159 | ||
160 | if (strcmp(argv[1], "readsmbpasswd")==0) | |
161 | { | |
c41c2eb4 CS |
162 | safe_system("/bin/chown root:nobody /var/ipfire/samba/private >/dev/null"); |
163 | safe_system("/bin/chown root:nobody /var/ipfire/samba/private/smbpasswd >/dev/null"); | |
164 | safe_system("/bin/chmod 640 /var/ipfire/samba/private/smbpasswd >/dev/null"); | |
165 | safe_system("/bin/chmod 650 /var/ipfire/samba/private >/dev/null"); | |
88932936 CS |
166 | return 0; |
167 | } | |
168 | ||
169 | if (strcmp(argv[1], "locksmbpasswd")==0) | |
170 | { | |
c41c2eb4 CS |
171 | safe_system("/bin/chown root:root /var/ipfire/samba/private >/dev/null"); |
172 | safe_system("/bin/chown root:root /var/ipfire/samba/private/smbpasswd >/dev/null"); | |
173 | safe_system("/bin/chmod 600 /var/ipfire/samba/private/smbpasswd >/dev/null"); | |
174 | safe_system("/bin/chmod 600 /var/ipfire/samba/private >/dev/null"); | |
88932936 CS |
175 | return 0; |
176 | } | |
177 | if (strcmp(argv[1], "enable")==0) | |
178 | { | |
179 | safe_system("touch /var/ipfire/samba/enable"); | |
c41c2eb4 | 180 | safe_system("/etc/rc.d/init.d/samba start "); |
63d4db83 CS |
181 | safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc2.d/S50samba"); |
182 | safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc2.d/K50samba"); | |
88932936 CS |
183 | safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc3.d/S50samba"); |
184 | safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc3.d/K50samba"); | |
185 | return 0; | |
186 | } | |
187 | ||
188 | if (strcmp(argv[1], "disable")==0) | |
189 | { | |
63d4db83 | 190 | safe_system("unlink /var/ipfire/samba/enable"); |
88932936 | 191 | safe_system("/etc/rc.d/init.d/samba stop"); |
63d4db83 CS |
192 | safe_system("unlink /etc/rc.d/rc2.d/S50samba"); |
193 | safe_system("unlink /etc/rc.d/rc2.d/K50samba"); | |
194 | safe_system("unlink /etc/rc.d/rc3.d/S50samba"); | |
195 | safe_system("unlink /etc/rc.d/rc3.d/K50samba"); | |
88932936 CS |
196 | return 0; |
197 | } | |
71dfc4b7 | 198 | return 0; |
c41c2eb4 | 199 | } |