]> git.ipfire.org Git - ipfire-2.x.git/blob - src/misc-progs/upnpctrl.c
binutils: update to 2.18.
[ipfire-2.x.git] / src / misc-progs / upnpctrl.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <fcntl.h>
7 #include "setuid.h"
8
9 #define BUFFER_SIZE 1024
10
11 char command[BUFFER_SIZE];
12
13 int main(int argc, char *argv[])
14 {
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
26 if (strcmp(argv[1], "upnpstart")==0)
27 {
28 snprintf(command, BUFFER_SIZE-1, "route add -net 239.0.0.0 netmask 255.0.0.0 %s", argv[3]);
29 safe_system(command);
30 printf(command);
31 snprintf(command, BUFFER_SIZE-1, "/usr/sbin/upnpd %s %s", argv[2], argv[3] );
32 safe_system(command);
33 printf(command);
34 return 0;
35 }
36
37 if (strcmp(argv[1], "upnpstop")==0)
38 {
39 snprintf(command, BUFFER_SIZE-1, "killall upnpd");
40 safe_system(command);
41 printf(command);
42 snprintf(command, BUFFER_SIZE-1, "route del -net 239.0.0.0 netmask 255.0.0.0 %s", argv[3]);
43 safe_system(command);
44 printf(command);
45 return 0;
46 }
47 if (strcmp(argv[1], "upnpxml")==0)
48 {
49 snprintf(command, BUFFER_SIZE-1, "sed 's/\<friendlyName\>.*\<\/friendlyName\>/\<friendlyName\>%s\<\/friendlyName\>/gi' %s/%s > tmp && mv tmp %s/%s", argv[2], argv[3], argv[4], argv[3], argv[4]);
50 safe_system(command);
51 printf(command);
52 return 0;
53 }
54 }