working on getting the run as service tool to work again.
[feisty_meow.git] / nucleus / tools / simple_utilities / run_as_service.cpp
1 /*****************************************************************************\
2 *                                                                             *
3 *  Name   : run_as_service                                                    *
4 *  Author : Chris Koeritz                                                     *
5 *                                                                             *
6 *******************************************************************************
7 * Copyright (c) 2000-$now By Author.  This program is free software; you can  *
8 * redistribute it and/or modify it under the terms of the GNU General Public  *
9 * License as published by the Free Software Foundation; either version 2 of   *
10 * the License or (at your option) any later version.  This is online at:      *
11 *     http://www.fsf.org/copyleft/gpl.html                                    *
12 * Please send any updates to: fred@gruntose.com                               *
13 \*****************************************************************************/
14
15 #include <loggers/console_logger.h>
16 #include <filesystem/filename.h>
17 #include <structures/static_memory_gremlin.h>
18 #include <security/nt_security.h>
19
20 HOOPLE_STARTUP_CODE;
21
22 //////////////
23
24 bool run_as_service(char *user, log_base &out)
25 {
26 #ifdef __WIN32__
27   // ensure that the user has the "logon as a service" right.
28   nt_security secu;
29   long err = secu.SetPrivilegeOnUser("", user, "SeServiceLogonRight", true);
30   if (err) {
31     // that didn't work; probably the user name is bad?
32     out.log(astring(astring::SPRINTF, "There was a problem giving "
33         "\"%s\" the \"Logon as a Service\" right:\r\n%s", user,
34         critical_events::system_error_text(err).s()));
35     return false;
36   }
37 #else
38   astring junk = user;
39   out.eol();
40   junk += "";
41 #endif
42   return true;
43 }
44
45 int main(int argc, char *argv[])
46 {
47   console_logger out;
48   if (argc < 2) {
49     out.log(filename(argv[0]).rootname() + " usage:\n\
50 The first parameter must be a user name that will be given the\n\
51 \"login as a service\" access rights.\n");
52     return 1;
53   }
54   bool did_it = run_as_service(argv[1], out);
55   if (did_it)
56     out.log(astring("Success giving \"") + argv[1] + "\" the 'login as service' rights.");
57   else
58     out.log(astring("Failed in giving \"") + argv[1] + "\" the 'login as service' rights!");
59   return !did_it;
60 }
61
62 #ifdef __BUILD_STATIC_APPLICATION__
63   // static dependencies found by buildor_gen_deps.sh:
64   #include <basis/byte_array.cpp>
65   #include <basis/callstack_tracker.cpp>
66   #include <basis/utf_conversion.cpp>
67   #include <basis/definitions.cpp>
68   #include <basis/earth_time.cpp>
69   #include <basis/guards.cpp>
70   #include <basis/astring.cpp>
71   #include <basis/log_base.cpp>
72   #include <basis/memory_checker.cpp>
73   #include <basis/mutex.cpp>
74   #include <basis/contracts.h>
75   #include <basis/outcome.cpp>
76   #include <basis/packable.cpp>
77   #include <basis/portable.cpp>
78   #include <basis/trap_new.addin>
79   #include <basis/untrap_new.addin>
80   #include <basis/utility.cpp>
81   #include <basis/version_record.cpp>
82   #include <structures/bit_vector.cpp>
83   #include <structures/byte_hasher.cpp>
84   #include <structures/configurator.cpp>
85   #include <structures/hash_table.h>
86   #include <structures/pointer_hash.h>
87   #include <structures/stack.h>
88   #include <structures/static_memory_gremlin.cpp>
89   #include <structures/string_hash.h>
90   #include <structures/string_hasher.cpp>
91   #include <structures/string_table.cpp>
92   #include <structures/symbol_table.h>
93   #include <structures/table_configurator.cpp>
94   #include <loggers/console_logger.cpp>
95   #include <loggers/file_logger.cpp>
96   #include <loggers/locked_logger.cpp>
97   #include <loggers/null_logger.cpp>
98   #include <loggers/program_wide_logger.cpp>
99   #include <filesystem/byte_filer.cpp>
100   #include <application/command_line.cpp>
101   #include <opsystem/critical_events.cpp>
102   #include <filesystem/directory.cpp>
103   #include <filesystem/filename.cpp>
104   #include <configuration/ini_configurator.cpp>
105   #include <opsystem/ini_parser.cpp>
106   #include <configuration/application_configuration.cpp>
107   #include <application/rendezvous.cpp>
108   #include <security/nt_security.cpp>
109   #include <security/win32_security.cpp>
110   #include <textual/byte_formatter.cpp>
111   #include <textual/parser_bits.cpp>
112   #include <textual/string_manipulation.cpp>
113   #include <configuration/variable_tokenizer.cpp>
114 #endif // __BUILD_STATIC_APPLICATION__
115