]>
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); | |
30 | printf(command); | |
14cc7eac MT |
31 | return 0; |
32 | } | |
33 | ||
44254afd | 34 | if (strcmp(argv[1], "smbuserenable")==0) |
14cc7eac | 35 | { |
44254afd MT |
36 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -e %s", argv[2]); |
37 | safe_system(command); | |
38 | printf(command); | |
14cc7eac MT |
39 | return 0; |
40 | } | |
41 | ||
44254afd | 42 | if (strcmp(argv[1], "smbuserdelete")==0) |
14cc7eac | 43 | { |
44254afd MT |
44 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -x %s", argv[2]); |
45 | safe_system(command); | |
46 | printf(command); | |
47 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/userdel %s", argv[2]); | |
48 | safe_system(command); | |
49 | printf(command); | |
14cc7eac MT |
50 | return 0; |
51 | } | |
52 | ||
44254afd | 53 | if (strcmp(argv[1], "smbsafeconf")==0) |
14cc7eac MT |
54 | { |
55 | safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf"); | |
56 | return 0; | |
57 | } | |
58 | ||
44254afd | 59 | if (strcmp(argv[1], "smbglobalreset")==0) |
14cc7eac | 60 | { |
44254afd MT |
61 | safe_system("/bin/cat /var/ipfire/samba/default.global /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf"); |
62 | safe_system("/bin/cat /var/ipfire/samba/default.settings > /var/ipfire/samba/settings"); | |
14cc7eac MT |
63 | return 0; |
64 | } | |
65 | ||
44254afd | 66 | if (strcmp(argv[1], "smbsharesreset")==0) |
14cc7eac | 67 | { |
44254afd MT |
68 | safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/default.shares > /var/ipfire/samba/smb.conf"); |
69 | safe_system("/bin/cat /var/ipfire/samba/default.shares > /var/ipfire/samba/shares"); | |
14cc7eac MT |
70 | return 0; |
71 | } | |
72 | ||
44254afd | 73 | if (strcmp(argv[1], "smbrestart")==0) |
14cc7eac MT |
74 | { |
75 | return 0; | |
76 | } | |
77 | ||
44254afd | 78 | if (strcmp(argv[1], "smbstop")==0) |
14cc7eac MT |
79 | { |
80 | return 0; | |
81 | } | |
82 | ||
44254afd | 83 | if (strcmp(argv[1], "smbstart")==0) |
14cc7eac MT |
84 | { |
85 | return 0; | |
86 | } | |
87 | ||
44254afd | 88 | if (strcmp(argv[1], "smbuseradd")==0) |
14cc7eac | 89 | { |
44254afd MT |
90 | snprintf(command, BUFFER_SIZE-1, "/usr/sbin/useradd -c 'Samba User' -d /opt/samba -g 2110 -p %s -s /bin/false %s", argv[3], argv[2]); |
91 | safe_system(command); | |
92 | printf(command); | |
93 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s", argv[3], argv[3], argv[2]); | |
94 | safe_system(command); | |
95 | printf(command); | |
14cc7eac MT |
96 | return 0; |
97 | } | |
98 | ||
44254afd | 99 | if (strcmp(argv[1], "smbchangepw")==0) |
14cc7eac | 100 | { |
44254afd MT |
101 | snprintf(command, BUFFER_SIZE-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s", argv[3], argv[3], argv[2]); |
102 | safe_system(command); | |
103 | printf(command); | |
14cc7eac MT |
104 | return 0; |
105 | } | |
106 | ||
44254afd | 107 | if (strcmp(argv[1], "readsmbpasswd")==0) |
14cc7eac MT |
108 | { |
109 | safe_system("/bin/chown root:nobody /var/ipfire/samba/private"); | |
110 | safe_system("/bin/chown root:nobody /var/ipfire/samba/private/smbpasswd"); | |
111 | safe_system("/bin/chmod 640 /var/ipfire/samba/private/smbpasswd"); | |
112 | safe_system("/bin/chmod 650 /var/ipfire/samba/private"); | |
113 | return 0; | |
114 | } | |
115 | ||
44254afd | 116 | if (strcmp(argv[1], "locksmbpasswd")==0) |
14cc7eac MT |
117 | { |
118 | safe_system("/bin/chown root:root /var/ipfire/samba/private"); | |
119 | safe_system("/bin/chown root:root /var/ipfire/samba/private/smbpasswd"); | |
120 | safe_system("/bin/chmod 600 /var/ipfire/samba/private/smbpasswd"); | |
121 | safe_system("/bin/chmod 600 /var/ipfire/samba/private"); | |
122 | return 0; | |
123 | } | |
44254afd MT |
124 | |
125 | if (strcmp(argv[1], "smbechotest")==0) | |
126 | { | |
127 | sprintf(command, BUFFER_SIZE-1, "/usr/bin/printf %s %s", argv[2], argv[3]); | |
128 | printf(command); | |
129 | safe_system(command); | |
130 | return 0; | |
131 | } | |
14cc7eac | 132 | } |