]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/misc-progs/sambactrl.c
Tripwire fertig fuer die BETA
[people/pmueller/ipfire-2.x.git] / src / misc-progs / sambactrl.c
CommitLineData
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
11char command[BUFFER_SIZE];
12
13int main(int argc, char *argv[])
14cc7eac 14{
14cc7eac 15
88932936
CS
16if (!(initsetuid()))
17exit(1);
18
19// Check what command is asked
20if (argc==1)
21{
22fprintf (stderr, "Missing smbctrl command!\n");
23return 1;
24}
25
26if (strcmp(argv[1], "smbuserdisable")==0)
27{
28snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -d %s", argv[2]);
29safe_system(command);
30return 0;
31}
32
33if (strcmp(argv[1], "smbuserenable")==0)
34{
35snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -e %s", argv[2]);
36safe_system(command);
37return 0;
38}
39
40if (strcmp(argv[1], "smbuserdelete")==0)
41{
42snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -x %s", argv[2]);
43safe_system(command);
44snprintf(command, BUFFER_SIZE-1, "/usr/sbin/userdel %s", argv[2]);
45safe_system(command);
46return 0;
47}
48
49if (strcmp(argv[1], "smbsafeconf")==0)
50{
51safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf");
52return 0;
53}
54
55if (strcmp(argv[1], "smbsafeconfcups")==0)
56{
57safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/shares /var/ipfire/samba/printer > /var/ipfire/samba/smb.conf");
58return 0;
59}
60
61if (strcmp(argv[1], "smbsafeconfpdc")==0)
62{
63safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/pdc /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf");
64return 0;
65}
66
67if (strcmp(argv[1], "smbsafeconfpdccups")==0)
68{
69safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/pdc /var/ipfire/samba/shares /var/ipfire/samba/printer > /var/ipfire/samba/smb.conf");
70return 0;
71}
72
73if (strcmp(argv[1], "smbglobalreset")==0)
74{
75safe_system("/bin/cat /var/ipfire/samba/default.global /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf");
76safe_system("/bin/cat /var/ipfire/samba/default.settings > /var/ipfire/samba/settings");
77safe_system("/bin/cat /var/ipfire/samba/default.global > /var/ipfire/samba/global");
78safe_system("/bin/cat /var/ipfire/samba/default.pdc > /var/ipfire/samba/pdc");
79return 0;
80}
81
82if (strcmp(argv[1], "smbsharesreset")==0)
83{
84safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/default.shares > /var/ipfire/samba/smb.conf");
85safe_system("/bin/cat /var/ipfire/samba/default.shares > /var/ipfire/samba/shares");
86return 0;
87}
88
89if (strcmp(argv[1], "smbprinterreset")==0)
90{
91safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/shares /var/default.printer > /var/ipfire/samba/smb.conf");
92safe_system("/bin/cat /var/ipfire/samba/default.printer > /var/ipfire/samba/printer");
93return 0;
94}
95
96if (strcmp(argv[1], "smbstop")==0)
97{
98safe_system("/etc/rc.d/init.d/samba stop");
99return 0;
100}
101
102if (strcmp(argv[1], "smbstart")==0)
103{
104safe_system("/etc/rc.d/init.d/samba start");
105return 0;
106}
107
108if (strcmp(argv[1], "smbrestart")==0)
109{
110safe_system("/etc/rc.d/init.d/samba restart");
111return 0;
112}
113
114if (strcmp(argv[1], "smbreload")==0)
115{
116safe_system("/etc/rc.d/init.d/samba reload");
117return 0;
118}
119
120if (strcmp(argv[1], "smbstatus")==0)
121{
122snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbstatus");
123safe_system(command);
124return 0;
125}
126
127if (strcmp(argv[1], "smbuseradd")==0)
128{
129snprintf(command, BUFFER_SIZE-1, "/usr/sbin/groupadd sambauser");
130safe_system(command);
131snprintf(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]);
132safe_system(command);
133snprintf(command, BUFFER_SIZE-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s", argv[3], argv[3], argv[2]);
134safe_system(command);
135return 0;
136}
137
138if (strcmp(argv[1], "smbpcadd")==0)
139{
140snprintf(command, BUFFER_SIZE-1, "/usr/sbin/groupadd sambawks");
141safe_system(command);
142snprintf(command, BUFFER_SIZE-1, "/usr/sbin/useradd -c 'Samba Workstation' -g %s -s %s %s", argv[3], argv[4], argv[2]);
143safe_system(command);
144snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -a -m %s", argv[2]);
145safe_system(command);
146return 0;
147}
148
149if (strcmp(argv[1], "smbchangepw")==0)
150{
151snprintf(command, BUFFER_SIZE-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s", argv[3], argv[3], argv[2]);
152safe_system(command);
153return 0;
154}
155
156if (strcmp(argv[1], "readsmbpasswd")==0)
157{
158safe_system("/bin/chown root:nobody /var/ipfire/samba/private");
159safe_system("/bin/chown root:nobody /var/ipfire/samba/private/smbpasswd");
160safe_system("/bin/chmod 640 /var/ipfire/samba/private/smbpasswd");
161safe_system("/bin/chmod 650 /var/ipfire/samba/private");
162return 0;
163}
164
165if (strcmp(argv[1], "locksmbpasswd")==0)
166{
167safe_system("/bin/chown root:root /var/ipfire/samba/private");
168safe_system("/bin/chown root:root /var/ipfire/samba/private/smbpasswd");
169safe_system("/bin/chmod 600 /var/ipfire/samba/private/smbpasswd");
170safe_system("/bin/chmod 600 /var/ipfire/samba/private");
171return 0;
172}
173if (strcmp(argv[1], "enable")==0)
174{
175safe_system("touch /var/ipfire/samba/enable");
176safe_system("/etc/rc.d/init.d/samba start");
177safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc2.d/S50samba");
178safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc2.d/K50samba");
179safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc3.d/S50samba");
180safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc3.d/K50samba");
181return 0;
182}
183
184if (strcmp(argv[1], "disable")==0)
185{
186safe_system("unlink /var/ipfire/samba/enable");
187safe_system("/etc/rc.d/init.d/samba stop");
188safe_system("unlink /etc/rc.d/rc2.d/S50samba");
189safe_system("unlink /etc/rc.d/rc2.d/K50samba");
190safe_system("unlink /etc/rc.d/rc3.d/S50samba");
191safe_system("unlink /etc/rc.d/rc3.d/K50samba");
192return 0;
193}
71dfc4b7
CS
194return 0;
195}