]> git.ipfire.org Git - ipfire-2.x.git/blame - src/misc-progs/sambactrl.c
misc-progs: sambactrl: Remove unused smbsafeconfpdc command
[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
a8e327cd
MT
13int main(int argc, char *argv[]) {
14 if (!(initsetuid()))
15 exit(1);
14cc7eac 16
a8e327cd
MT
17 // Check what command is asked
18 if (argc == 1) {
19 fprintf (stderr, "Missing smbctrl command!\n");
20 return 1;
88932936 21
a8e327cd
MT
22 } else if (strcmp(argv[1], "smbuserdisable") == 0) {
23 snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -d %s >/dev/null", argv[2]);
24 safe_system(command);
25
26 } else if (strcmp(argv[1], "smbuserenable") == 0) {
27 snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -e %s >/dev/null", argv[2]);
28 safe_system(command);
29
30 } else if (strcmp(argv[1], "smbuserdelete") == 0) {
31 snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbpasswd -x %s >/dev/null", argv[2]);
32 safe_system(command);
33
34 snprintf(command, BUFFER_SIZE-1, "/usr/sbin/userdel %s >/dev/null", argv[2]);
35 safe_system(command);
36
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");
39
a8e327cd
MT
40 } else if (strcmp(argv[1], "smbstop") == 0) {
41 safe_system("/etc/rc.d/init.d/samba stop >/dev/null");
42 safe_system("/usr/local/bin/sambactrl disable");
43
44 } else if (strcmp(argv[1], "smbstart") == 0) {
45 safe_system("/etc/rc.d/init.d/samba start >/dev/null");
46 safe_system("/usr/local/bin/sambactrl enable");
47
48 } else if (strcmp(argv[1], "smbrestart") == 0) {
49 safe_system("/etc/rc.d/init.d/samba restart >/dev/null");
50
51 } else if (strcmp(argv[1], "smbreload") == 0) {
52 safe_system("/etc/rc.d/init.d/samba reload >/dev/null");
53
54 } else if (strcmp(argv[1], "smbstatus") == 0) {
55 snprintf(command, BUFFER_SIZE-1, "/usr/bin/smbstatus 2>/dev/null");
56 safe_system(command);
57
58 } else if (strcmp(argv[1], "smbuseradd") == 0) {
59 snprintf(command, BUFFER_SIZE-1, "/usr/sbin/groupadd sambauser >/dev/null");
60 safe_system(command);
61
62 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]);
63 safe_system(command);
64
65 snprintf(command, BUFFER_SIZE-1, "echo %s:%s | chpasswd", argv[2], argv[3]);
66 safe_system(command);
67
68 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]);
69 safe_system(command);
70
a8e327cd
MT
71 } else if (strcmp(argv[1], "smbchangepw") == 0) {
72 snprintf(command, BUFFER_SIZE-1, "echo %s:%s | chpasswd", argv[2], argv[3]);
73 safe_system(command);
74
75 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]);
76 safe_system(command);
77
78 } else if (strcmp(argv[1], "readsmbpasswd") == 0) {
79 safe_system("/bin/chown root:nobody /var/ipfire/samba/private >/dev/null");
80 safe_system("/bin/chown root:nobody /var/ipfire/samba/private/smbpasswd >/dev/null");
81 safe_system("/bin/chmod 640 /var/ipfire/samba/private/smbpasswd >/dev/null");
82 safe_system("/bin/chmod 650 /var/ipfire/samba/private >/dev/null");
83
84 } else if (strcmp(argv[1], "locksmbpasswd") == 0) {
85 safe_system("/bin/chown root:root /var/ipfire/samba/private >/dev/null");
86 safe_system("/bin/chown root:root /var/ipfire/samba/private/smbpasswd >/dev/null");
87 safe_system("/bin/chmod 600 /var/ipfire/samba/private/smbpasswd >/dev/null");
88 safe_system("/bin/chmod 600 /var/ipfire/samba/private >/dev/null");
89
90 } else if (strcmp(argv[1], "enable") == 0) {
91 safe_system("touch /var/ipfire/samba/enable");
92 safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc3.d/S45samba");
93 safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc0.d/K48samba");
94 safe_system("ln -snf /etc/rc.d/init.d/samba /etc/rc.d/rc6.d/K48samba");
95
96 } else if (strcmp(argv[1], "disable") == 0) {
97 safe_system("unlink /var/ipfire/samba/enable");
98 safe_system("rm -rf /etc/rc.d/rc*.d/*samba");
0ffbb688
MT
99
100 } else if (strcmp(argv[1], "join") == 0) {
101 if (argc == 4) {
102 snprintf(command, BUFFER_SIZE - 1, "/usr/bin/net join -U \"%s%%%s\"",
103 argv[2], argv[3]);
104 return safe_system(command);
105 } else {
106 fprintf(stderr, "Wrong number of arguments. Need username and password.\n");
107 return 1;
108 }
a8e327cd
MT
109 }
110
111 return 0;
c41c2eb4 112}