]>
git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blob - src/misc-progs/sambactrl.c
9 #define BUFFER_SIZE 1024
11 char command
[BUFFER_SIZE
];
13 int main(int argc
, char *argv
[]) {
17 // Check what command is asked
19 fprintf (stderr
, "Missing smbctrl command!\n");
22 } else if (strcmp(argv
[1], "smbuserdisable") == 0) {
23 snprintf(command
, BUFFER_SIZE
-1, "/usr/bin/smbpasswd -d %s >/dev/null", argv
[2]);
26 } else if (strcmp(argv
[1], "smbuserenable") == 0) {
27 snprintf(command
, BUFFER_SIZE
-1, "/usr/bin/smbpasswd -e %s >/dev/null", argv
[2]);
30 } else if (strcmp(argv
[1], "smbuserdelete") == 0) {
31 snprintf(command
, BUFFER_SIZE
-1, "/usr/bin/smbpasswd -x %s >/dev/null", argv
[2]);
34 snprintf(command
, BUFFER_SIZE
-1, "/usr/sbin/userdel %s >/dev/null", argv
[2]);
37 } else if (strcmp(argv
[1], "smbsafeconf") == 0) {
38 safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf");
40 } else if (strcmp(argv
[1], "smbsafeconfcups") == 0) {
41 safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/shares /var/ipfire/samba/printer > /var/ipfire/samba/smb.conf");
43 } else if (strcmp(argv
[1], "smbsafeconfpdc") == 0) {
44 safe_system("/bin/cat /var/ipfire/samba/global /var/ipfire/samba/pdc /var/ipfire/samba/shares > /var/ipfire/samba/smb.conf");
46 } else if (strcmp(argv
[1], "smbsafeconfpdccups") == 0) {
47 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");
49 } else if (strcmp(argv
[1], "smbstop") == 0) {
50 safe_system("/etc/rc.d/init.d/samba stop >/dev/null");
51 safe_system("/usr/local/bin/sambactrl disable");
53 } else if (strcmp(argv
[1], "smbstart") == 0) {
54 safe_system("/etc/rc.d/init.d/samba start >/dev/null");
55 safe_system("/usr/local/bin/sambactrl enable");
57 } else if (strcmp(argv
[1], "smbrestart") == 0) {
58 safe_system("/etc/rc.d/init.d/samba restart >/dev/null");
60 } else if (strcmp(argv
[1], "smbreload") == 0) {
61 safe_system("/etc/rc.d/init.d/samba reload >/dev/null");
63 } else if (strcmp(argv
[1], "smbstatus") == 0) {
64 snprintf(command
, BUFFER_SIZE
-1, "/usr/bin/smbstatus 2>/dev/null");
67 } else if (strcmp(argv
[1], "smbuseradd") == 0) {
68 snprintf(command
, BUFFER_SIZE
-1, "/usr/sbin/groupadd sambauser >/dev/null");
71 snprintf(command
, BUFFER_SIZE
-1, "/usr/sbin/useradd -c 'Samba User' -m -g %s -s %s %s >/dev/null", argv
[4], argv
[5], argv
[2]);
74 snprintf(command
, BUFFER_SIZE
-1, "echo %s:%s | chpasswd", argv
[2], argv
[3]);
77 snprintf(command
, BUFFER_SIZE
-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s >/dev/null", argv
[3], argv
[3], argv
[2]);
80 } else if (strcmp(argv
[1], "smbpcadd") == 0) {
81 snprintf(command
, BUFFER_SIZE
-1, "/usr/sbin/groupadd sambawks >/dev/null");
84 snprintf(command
, BUFFER_SIZE
-1, "/usr/sbin/useradd -c 'Samba Workstation' -g %s -s %s %s >/dev/null", argv
[3], argv
[4], argv
[2]);
87 snprintf(command
, BUFFER_SIZE
-1, "/usr/bin/smbpasswd -a -m %s >/dev/null", argv
[2]);
90 } else if (strcmp(argv
[1], "smbchangepw") == 0) {
91 snprintf(command
, BUFFER_SIZE
-1, "echo %s:%s | chpasswd", argv
[2], argv
[3]);
94 snprintf(command
, BUFFER_SIZE
-1, "/usr/bin/printf '%s\n%s\n' | /usr/bin/smbpasswd -as %s >/dev/null", argv
[3], argv
[3], argv
[2]);
97 } else if (strcmp(argv
[1], "readsmbpasswd") == 0) {
98 safe_system("/bin/chown root:nobody /var/ipfire/samba/private >/dev/null");
99 safe_system("/bin/chown root:nobody /var/ipfire/samba/private/smbpasswd >/dev/null");
100 safe_system("/bin/chmod 640 /var/ipfire/samba/private/smbpasswd >/dev/null");
101 safe_system("/bin/chmod 650 /var/ipfire/samba/private >/dev/null");
103 } else if (strcmp(argv
[1], "locksmbpasswd") == 0) {
104 safe_system("/bin/chown root:root /var/ipfire/samba/private >/dev/null");
105 safe_system("/bin/chown root:root /var/ipfire/samba/private/smbpasswd >/dev/null");
106 safe_system("/bin/chmod 600 /var/ipfire/samba/private/smbpasswd >/dev/null");
107 safe_system("/bin/chmod 600 /var/ipfire/samba/private >/dev/null");
109 } else if (strcmp(argv
[1], "enable") == 0) {
110 safe_system("touch /var/ipfire/samba/enable");
111 safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc3.d/S45samba");
112 safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc0.d/K48samba");
113 safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc6.d/K48samba");
115 } else if (strcmp(argv
[1], "disable") == 0) {
116 safe_system("unlink /var/ipfire/samba/enable");
117 safe_system("rm -rf /etc/rc.d/rc*.d/*samba");
119 } else if (strcmp(argv
[1], "join") == 0) {
121 snprintf(command
, BUFFER_SIZE
- 1, "/usr/bin/net join -U \"%s%%%s\"",
123 return safe_system(command
);
125 fprintf(stderr
, "Wrong number of arguments. Need username and password.\n");