]>
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 MT |
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 | ||
44254afd | 26 | if (strcmp(argv[1], "smbuserdisable")==0) |
14cc7eac | 27 | { |
44254afd MT |
28 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -d %s", argv[2]); |
29 | safe_system(command); | |
14cc7eac MT |
30 | return 0; |
31 | } | |
32 | ||
44254afd | 33 | if (strcmp(argv[1], "smbuserenable")==0) |
14cc7eac | 34 | { |
44254afd MT |
35 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -e %s", argv[2]); |
36 | safe_system(command); | |
14cc7eac MT |
37 | return 0; |
38 | } | |
39 | ||
44254afd | 40 | if (strcmp(argv[1], "smbuserdelete")==0) |
14cc7eac | 41 | { |
44254afd MT |
42 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -x %s", argv[2]); |
43 | safe_system(command); | |
44254afd MT |
44 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/userdel %s", argv[2]); |
45 | safe_system(command); | |
14cc7eac MT |
46 | return 0; |
47 | } | |
48 | ||
44254afd | 49 | if (strcmp(argv[1], "smbsafeconf")==0) |
14cc7eac MT |
50 | { |
51 | safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf"); | |
52 | return 0; | |
53 | } | |
54 | ||
71dfc4b7 CS |
55 | if (strcmp(argv[1], "smbsafeconfcups")==0) |
56 | { | |
57 | safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/shares /var/ipfire/samba/printer > /var/ipfire/samba/smb.conf"); | |
58 | return 0; | |
59 | } | |
60 | ||
5fd30232 MT |
61 | if (strcmp(argv[1], "smbsafeconfpdc")==0) |
62 | { | |
63 | safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/pdc /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf"); | |
64 | return 0; | |
65 | } | |
66 | ||
71dfc4b7 CS |
67 | if (strcmp(argv[1], "smbsafeconfpdccups")==0) |
68 | { | |
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"); | |
70 | return 0; | |
71 | } | |
72 | ||
44254afd | 73 | if (strcmp(argv[1], "smbglobalreset")==0) |
14cc7eac | 74 | { |
44254afd MT |
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"); | |
5fd30232 | 77 | safe_system("/bin/cat /var/ipfire/samba/default.global > /var/ipfire/samba/global"); |
fa7be659 | 78 | safe_system("/bin/cat /var/ipfire/samba/default.pdc > /var/ipfire/samba/pdc"); |
14cc7eac MT |
79 | return 0; |
80 | } | |
81 | ||
44254afd | 82 | if (strcmp(argv[1], "smbsharesreset")==0) |
14cc7eac | 83 | { |
44254afd MT |
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"); | |
14cc7eac MT |
86 | return 0; |
87 | } | |
88 | ||
71dfc4b7 CS |
89 | if (strcmp(argv[1], "smbprinterreset")==0) |
90 | { | |
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"); | |
93 | return 0; | |
94 | } | |
95 | ||
c9e1c143 | 96 | if (strcmp(argv[1], "smbstop")==0) |
14cc7eac | 97 | { |
c9e1c143 | 98 | safe_system("/etc/rc.d/init.d/samba stop"); |
14cc7eac MT |
99 | return 0; |
100 | } | |
101 | ||
c9e1c143 | 102 | if (strcmp(argv[1], "smbstart")==0) |
14cc7eac | 103 | { |
c9e1c143 | 104 | safe_system("/etc/rc.d/init.d/samba start"); |
14cc7eac MT |
105 | return 0; |
106 | } | |
107 | ||
c9e1c143 | 108 | if (strcmp(argv[1], "smbrestart")==0) |
14cc7eac | 109 | { |
c9e1c143 | 110 | safe_system("/etc/rc.d/init.d/samba restart"); |
c9e1c143 CS |
111 | return 0; |
112 | } | |
113 | ||
114 | if (strcmp(argv[1], "smbreload")==0) | |
115 | { | |
116 | safe_system("/etc/rc.d/init.d/samba reload"); | |
14cc7eac MT |
117 | return 0; |
118 | } | |
119 | ||
5fd30232 MT |
120 | if (strcmp(argv[1], "smbstatus")==0) |
121 | { | |
60124059 | 122 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbstatus"); |
5fd30232 | 123 | safe_system(command); |
5fd30232 MT |
124 | return 0; |
125 | } | |
126 | ||
44254afd | 127 | if (strcmp(argv[1], "smbuseradd")==0) |
14cc7eac | 128 | { |
5fd30232 MT |
129 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/groupadd sambauser"); |
130 | safe_system(command); | |
131 | 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]); | |
44254afd | 132 | safe_system(command); |
44254afd MT |
133 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s", argv[3], argv[3], argv[2]); |
134 | safe_system(command); | |
14cc7eac MT |
135 | return 0; |
136 | } | |
137 | ||
5fd30232 MT |
138 | if (strcmp(argv[1], "smbpcadd")==0) |
139 | { | |
140 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/groupadd sambawks"); | |
141 | safe_system(command); | |
142 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/useradd -c 'Samba Workstation' -g %s -s %s %s", argv[3], argv[4], argv[2]); | |
143 | safe_system(command); | |
5fd30232 MT |
144 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -a -m %s", argv[2]); |
145 | safe_system(command); | |
5fd30232 MT |
146 | return 0; |
147 | } | |
148 | ||
44254afd | 149 | if (strcmp(argv[1], "smbchangepw")==0) |
14cc7eac | 150 | { |
44254afd MT |
151 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s", argv[3], argv[3], argv[2]); |
152 | safe_system(command); | |
14cc7eac MT |
153 | return 0; |
154 | } | |
155 | ||
44254afd | 156 | if (strcmp(argv[1], "readsmbpasswd")==0) |
14cc7eac MT |
157 | { |
158 | safe_system("/bin/chown root:nobody /var/ipfire/samba/private"); | |
159 | safe_system("/bin/chown root:nobody /var/ipfire/samba/private/smbpasswd"); | |
160 | safe_system("/bin/chmod 640 /var/ipfire/samba/private/smbpasswd"); | |
161 | safe_system("/bin/chmod 650 /var/ipfire/samba/private"); | |
162 | return 0; | |
163 | } | |
164 | ||
44254afd | 165 | if (strcmp(argv[1], "locksmbpasswd")==0) |
14cc7eac MT |
166 | { |
167 | safe_system("/bin/chown root:root /var/ipfire/samba/private"); | |
168 | safe_system("/bin/chown root:root /var/ipfire/samba/private/smbpasswd"); | |
169 | safe_system("/bin/chmod 600 /var/ipfire/samba/private/smbpasswd"); | |
170 | safe_system("/bin/chmod 600 /var/ipfire/samba/private"); | |
171 | return 0; | |
172 | } | |
71dfc4b7 CS |
173 | return 0; |
174 | } |