]> git.ipfire.org Git - ipfire-2.x.git/blame - src/misc-progs/ipfirereboot.c
suricata: Change midstream policy to "pass-flow"
[ipfire-2.x.git] / src / misc-progs / ipfirereboot.c
CommitLineData
12938118
MT
1/*
2 * This file is part of the IPCop Firewall.
3 *
4 * IPCop is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * IPCop is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with IPCop; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Copyright (C) 2005-10-25 Franck Bourdonnec
19 *
20 * $Id: ipcopreboot.c,v 1.1.2.2 2005/10/24 23:05:50 franck78 Exp $
21 *
22 */
23
24#include <stdio.h>
25#include <string.h>
26#include <stdlib.h>
27#include "setuid.h"
28
29
30/* define operations */
31#define OP_REBOOT "boot"
ab1bdf34 32#define OP_REBOOT_FS "bootfs"
12938118 33#define OP_SHUTDOWN "down"
12938118
MT
34
35int main(int argc, char**argv)
36{
37
38 if (!(initsetuid()))
39 return 1;
40
41 // Check what command is asked
42 if (argc==1)
66c36198 43 {
12938118
MT
44 fprintf (stderr, "Missing reboot command!\n");
45 return 1;
46 }
47
48 if (argc==2 && strcmp(argv[1], OP_SHUTDOWN)==0)
49 {
50 safe_system("/sbin/shutdown -h now");
51 return 0;
52 }
53
54 if (argc==2 && strcmp(argv[1], OP_REBOOT)==0)
55 {
56 safe_system("/sbin/shutdown -r now");
57 return 0;
58 }
59
60 if (argc==2 && strcmp(argv[1], OP_REBOOT_FS)==0)
61 {
62 safe_system("/sbin/shutdown -F -r now");
63 return 0;
64 }
65
12938118
MT
66 fprintf (stderr, "Bad reboot command!\n");
67 return 1;
68}