00001 /*****************************************************************************\ 00002 * * 00003 * Name : run_as_service * 00004 * Author : Chris Koeritz * 00005 * * 00006 ******************************************************************************* 00007 * Copyright (c) 2000-$now By Author. This program is free software; you can * 00008 * redistribute it and/or modify it under the terms of the GNU General Public * 00009 * License as published by the Free Software Foundation; either version 2 of * 00010 * the License or (at your option) any later version. This is online at: * 00011 * http://www.fsf.org/copyleft/gpl.html * 00012 * Please send any updates to: fred@gruntose.com * 00013 \*****************************************************************************/ 00014 00015 #include <loggers/console_logger.h> 00016 #include <opsystem/filename.h> 00017 #include <data_struct/static_memory_gremlin.h> 00018 #include <security/nt_security.h> 00019 00020 HOOPLE_STARTUP_CODE; 00021 00023 00024 bool run_as_service(char *user, log_base &out) 00025 { 00026 #ifdef __WIN32__ 00027 // ensure that the user has the "logon as a service" right. 00028 nt_security secu; 00029 long err = secu.SetPrivilegeOnUser("", user, "SeServiceLogonRight", true); 00030 if (err) { 00031 // that didn't work; probably the user name is bad? 00032 out.log(istring(istring::SPRINTF, "There was a problem giving " 00033 "\"%s\" the \"Logon as a Service\" right:\r\n%s", user, 00034 portable::system_error_text(err).s())); 00035 return false; 00036 } 00037 #else 00038 istring junk = user; 00039 out.eol(); 00040 junk += ""; 00041 #endif 00042 return true; 00043 } 00044 00045 int main(int argc, char *argv[]) 00046 { 00047 console_logger out; 00048 if (argc < 2) { 00049 out.log(filename(argv[0]).rootname() + " usage:\n\ 00050 The first parameter must be a user name that will be given the\n\ 00051 \"login as a service\" access rights.\n"); 00052 return 1; 00053 } 00054 bool did_it = run_as_service(argv[1], out); 00055 if (did_it) 00056 out.log(istring("Success giving \"") + argv[1] + "\" the 'login as service' rights."); 00057 else 00058 out.log(istring("Failed in giving \"") + argv[1] + "\" the 'login as service' rights!"); 00059 return !did_it; 00060 } 00061 00062 #ifdef __BUILD_STATIC_APPLICATION__ 00063 // static dependencies found by buildor_gen_deps.sh: 00064 #include <basis/array.cpp> 00065 #include <basis/byte_array.cpp> 00066 #include <basis/callstack_tracker.cpp> 00067 #include <basis/chaos.cpp> 00068 #include <basis/convert_utf.cpp> 00069 #include <basis/definitions.cpp> 00070 #include <basis/earth_time.cpp> 00071 #include <basis/guards.cpp> 00072 #include <basis/istring.cpp> 00073 #include <basis/log_base.cpp> 00074 #include <basis/memory_checker.cpp> 00075 #include <basis/mutex.cpp> 00076 #include <basis/object_base.cpp> 00077 #include <basis/outcome.cpp> 00078 #include <basis/packable.cpp> 00079 #include <basis/portable.cpp> 00080 #include <basis/sequence.cpp> 00081 #include <basis/set.cpp> 00082 #include <basis/utility.cpp> 00083 #include <basis/version_record.cpp> 00084 #include <data_struct/amorph.cpp> 00085 #include <data_struct/bit_vector.cpp> 00086 #include <data_struct/byte_hasher.cpp> 00087 #include <data_struct/configurator.cpp> 00088 #include <data_struct/hash_table.cpp> 00089 #include <data_struct/pointer_hash.cpp> 00090 #include <data_struct/stack.cpp> 00091 #include <data_struct/static_memory_gremlin.cpp> 00092 #include <data_struct/string_hash.cpp> 00093 #include <data_struct/string_hasher.cpp> 00094 #include <data_struct/string_table.cpp> 00095 #include <data_struct/symbol_table.cpp> 00096 #include <data_struct/table_configurator.cpp> 00097 #include <loggers/console_logger.cpp> 00098 #include <loggers/file_logger.cpp> 00099 #include <loggers/locked_logger.cpp> 00100 #include <loggers/null_logger.cpp> 00101 #include <loggers/program_wide_logger.cpp> 00102 #include <opsystem/byte_filer.cpp> 00103 #include <opsystem/command_line.cpp> 00104 #include <opsystem/critical_events.cpp> 00105 #include <opsystem/directory.cpp> 00106 #include <opsystem/filename.cpp> 00107 #include <opsystem/ini_config.cpp> 00108 #include <opsystem/ini_parser.cpp> 00109 #include <opsystem/path_configuration.cpp> 00110 #include <opsystem/rendezvous.cpp> 00111 #include <security/nt_security.cpp> 00112 #include <security/win32_security.cpp> 00113 #include <textual/byte_format.cpp> 00114 #include <textual/parser_bits.cpp> 00115 #include <textual/string_manipulation.cpp> 00116 #include <textual/tokenizer.cpp> 00117 #endif // __BUILD_STATIC_APPLICATION__ 00118
1.5.1