]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/misc-progs/sambactrl.c
c598cb0e3dbff4142279d8cd5b921a7b34ead0f7
9 #define BUFFER_SIZE 1024
11 char command
[BUFFER_SIZE
];
13 int main(int argc
, char *argv
[])
19 // Check what command is asked
22 fprintf (stderr
, "Missing smbctrl command!\n");
26 if (strcmp(argv
[1], "smbuserdisable")==0)
28 snprintf(command
, BUFFER_SIZE
-1, "/usr/bin/smbpasswd -d %s", argv
[2]);
33 if (strcmp(argv
[1], "smbuserenable")==0)
35 snprintf(command
, BUFFER_SIZE
-1, "/usr/bin/smbpasswd -e %s", argv
[2]);
40 if (strcmp(argv
[1], "smbuserdelete")==0)
42 snprintf(command
, BUFFER_SIZE
-1, "/usr/bin/smbpasswd -x %s", argv
[2]);
44 snprintf(command
, BUFFER_SIZE
-1, "/usr/sbin/userdel %s", argv
[2]);
49 if (strcmp(argv
[1], "smbsafeconf")==0)
51 safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf");
55 if (strcmp(argv
[1], "smbsafeconfpdc")==0)
57 safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/pdc /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf");
61 if (strcmp(argv
[1], "smbglobalreset")==0)
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");
65 safe_system("/bin/cat /var/ipfire/samba/default.global > /var/ipfire/samba/global");
66 safe_system("/bin/cat /var/ipfire/samba/default.pdc > /var/ipfire/samba/pdc");
70 if (strcmp(argv
[1], "smbsharesreset")==0)
72 safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/default.shares > /var/ipfire/samba/smb.conf");
73 safe_system("/bin/cat /var/ipfire/samba/default.shares > /var/ipfire/samba/shares");
77 if (strcmp(argv
[1], "smbstop")==0)
79 safe_system("/etc/rc.d/init.d/samba stop");
84 if (strcmp(argv
[1], "smbstart")==0)
86 safe_system("/etc/rc.d/init.d/samba start");
91 if (strcmp(argv
[1], "smbrestart")==0)
93 safe_system("/etc/rc.d/init.d/samba restart");
98 if (strcmp(argv
[1], "smbreload")==0)
100 safe_system("/etc/rc.d/init.d/samba reload");
105 if (strcmp(argv
[1], "smbstatus")==0)
107 snprintf(command
, BUFFER_SIZE
-1, "/usr/sbin/smbstatus");
108 safe_system(command
);
112 if (strcmp(argv
[1], "smbuseradd")==0)
114 snprintf(command
, BUFFER_SIZE
-1, "/usr/sbin/groupadd sambauser");
115 safe_system(command
);
116 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]);
117 safe_system(command
);
119 snprintf(command
, BUFFER_SIZE
-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s", argv
[3], argv
[3], argv
[2]);
120 safe_system(command
);
125 if (strcmp(argv
[1], "smbpcadd")==0)
127 snprintf(command
, BUFFER_SIZE
-1, "/usr/sbin/groupadd sambawks");
128 safe_system(command
);
129 snprintf(command
, BUFFER_SIZE
-1, "/usr/sbin/useradd -c 'Samba Workstation' -g %s -s %s %s", argv
[3], argv
[4], argv
[2]);
130 safe_system(command
);
132 snprintf(command
, BUFFER_SIZE
-1, "/usr/bin/smbpasswd -a -m %s", argv
[2]);
133 safe_system(command
);
138 if (strcmp(argv
[1], "smbchangepw")==0)
140 snprintf(command
, BUFFER_SIZE
-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s", argv
[3], argv
[3], argv
[2]);
141 safe_system(command
);
146 if (strcmp(argv
[1], "readsmbpasswd")==0)
148 safe_system("/bin/chown root:nobody /var/ipfire/samba/private");
149 safe_system("/bin/chown root:nobody /var/ipfire/samba/private/smbpasswd");
150 safe_system("/bin/chmod 640 /var/ipfire/samba/private/smbpasswd");
151 safe_system("/bin/chmod 650 /var/ipfire/samba/private");
155 if (strcmp(argv
[1], "locksmbpasswd")==0)
157 safe_system("/bin/chown root:root /var/ipfire/samba/private");
158 safe_system("/bin/chown root:root /var/ipfire/samba/private/smbpasswd");
159 safe_system("/bin/chmod 600 /var/ipfire/samba/private/smbpasswd");
160 safe_system("/bin/chmod 600 /var/ipfire/samba/private");
164 if (strcmp(argv
[1], "smbechotest")==0)
166 sprintf(command
, BUFFER_SIZE
-1, "/usr/bin/printf %s %s", argv
[2], argv
[3]);
168 safe_system(command
);