]> git.ipfire.org Git - ipfire-2.x.git/blame - src/misc-progs/upnpctrl.c
binutils: update to 2.18.
[ipfire-2.x.git] / src / misc-progs / upnpctrl.c
CommitLineData
5fd30232
MT
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
11char command[BUFFER_SIZE];
12
13int 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 {
7654ad59 22 fprintf (stderr, "Missing smbctrl command!\n");
5fd30232
MT
23 return 1;
24 }
25
7654ad59 26 if (strcmp(argv[1], "upnpstart")==0)
5fd30232 27 {
7654ad59 28 snprintf(command, BUFFER_SIZE-1, "route add -net 239.0.0.0 netmask 255.0.0.0 %s", argv[3]);
5fd30232
MT
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
7654ad59 37 if (strcmp(argv[1], "upnpstop")==0)
5fd30232
MT
38 {
39 snprintf(command, BUFFER_SIZE-1, "killall upnpd");
40 safe_system(command);
41 printf(command);
7654ad59 42 snprintf(command, BUFFER_SIZE-1, "route del -net 239.0.0.0 netmask 255.0.0.0 %s", argv[3]);
5fd30232
MT
43 safe_system(command);
44 printf(command);
45 return 0;
46 }
7654ad59
CS
47 if (strcmp(argv[1], "upnpxml")==0)
48 {
13211b21 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]);
7654ad59
CS
50 safe_system(command);
51 printf(command);
52 return 0;
53 }
13211b21 54}