]> git.ipfire.org Git - ipfire-2.x.git/blame - src/misc-progs/sambactrl.c
Netzwerkbeta-Bugfixes...
[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
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
5fd30232
MT
55 if (strcmp(argv[1], "smbsafeconfpdc")==0)
56 {
57 safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/pdc /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf");
58 return 0;
59 }
60
44254afd 61 if (strcmp(argv[1], "smbglobalreset")==0)
14cc7eac 62 {
44254afd
MT
63 safe_system("/bin/cat /var/ipfire/samba/default.global /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf");
64 safe_system("/bin/cat /var/ipfire/samba/default.settings > /var/ipfire/samba/settings");
5fd30232 65 safe_system("/bin/cat /var/ipfire/samba/default.global > /var/ipfire/samba/global");
14cc7eac
MT
66 return 0;
67 }
68
44254afd 69 if (strcmp(argv[1], "smbsharesreset")==0)
14cc7eac 70 {
44254afd
MT
71 safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/default.shares > /var/ipfire/samba/smb.conf");
72 safe_system("/bin/cat /var/ipfire/samba/default.shares > /var/ipfire/samba/shares");
14cc7eac
MT
73 return 0;
74 }
75
44254afd 76 if (strcmp(argv[1], "smbrestart")==0)
14cc7eac
MT
77 {
78 return 0;
79 }
80
44254afd 81 if (strcmp(argv[1], "smbstop")==0)
14cc7eac
MT
82 {
83 return 0;
84 }
85
44254afd 86 if (strcmp(argv[1], "smbstart")==0)
14cc7eac
MT
87 {
88 return 0;
89 }
90
5fd30232
MT
91 if (strcmp(argv[1], "smbstatus")==0)
92 {
93 snprintf(command, BUFFER_SIZE-1, "/usr/sbin/smbstatus");
94 safe_system(command);
95 printf(command);
96 return 0;
97 }
98
44254afd 99 if (strcmp(argv[1], "smbuseradd")==0)
14cc7eac 100 {
5fd30232
MT
101 snprintf(command, BUFFER_SIZE-1, "/usr/sbin/groupadd sambauser");
102 safe_system(command);
103 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
MT
104 safe_system(command);
105 printf(command);
106 snprintf(command, BUFFER_SIZE-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s", argv[3], argv[3], argv[2]);
107 safe_system(command);
108 printf(command);
14cc7eac
MT
109 return 0;
110 }
111
5fd30232
MT
112 if (strcmp(argv[1], "smbpcadd")==0)
113 {
114 snprintf(command, BUFFER_SIZE-1, "/usr/sbin/groupadd sambawks");
115 safe_system(command);
116 snprintf(command, BUFFER_SIZE-1, "/usr/sbin/useradd -c 'Samba Workstation' -g %s -s %s %s", argv[3], argv[4], argv[2]);
117 safe_system(command);
118 printf(command);
119 snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -a -m %s", argv[2]);
120 safe_system(command);
121 printf(command);
122 return 0;
123 }
124
44254afd 125 if (strcmp(argv[1], "smbchangepw")==0)
14cc7eac 126 {
44254afd
MT
127 snprintf(command, BUFFER_SIZE-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s", argv[3], argv[3], argv[2]);
128 safe_system(command);
129 printf(command);
14cc7eac
MT
130 return 0;
131 }
132
44254afd 133 if (strcmp(argv[1], "readsmbpasswd")==0)
14cc7eac
MT
134 {
135 safe_system("/bin/chown root:nobody /var/ipfire/samba/private");
136 safe_system("/bin/chown root:nobody /var/ipfire/samba/private/smbpasswd");
137 safe_system("/bin/chmod 640 /var/ipfire/samba/private/smbpasswd");
138 safe_system("/bin/chmod 650 /var/ipfire/samba/private");
139 return 0;
140 }
141
44254afd 142 if (strcmp(argv[1], "locksmbpasswd")==0)
14cc7eac
MT
143 {
144 safe_system("/bin/chown root:root /var/ipfire/samba/private");
145 safe_system("/bin/chown root:root /var/ipfire/samba/private/smbpasswd");
146 safe_system("/bin/chmod 600 /var/ipfire/samba/private/smbpasswd");
147 safe_system("/bin/chmod 600 /var/ipfire/samba/private");
148 return 0;
149 }
44254afd
MT
150
151 if (strcmp(argv[1], "smbechotest")==0)
152 {
153 sprintf(command, BUFFER_SIZE-1, "/usr/bin/printf %s %s", argv[2], argv[3]);
154 printf(command);
155 safe_system(command);
156 return 0;
157 }
14cc7eac 158}