Add autogen.sh from distcc via mbp.
[kai/samba.git] / source / sam / gums.c
1 /*
2    Unix SMB/CIFS implementation.
3    Grops and Users Management System initializations.
4    Copyright (C) Simo Sorce 2002
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22
23 /*#undef DBGC_CLASS
24 #define DBGC_CLASS DBGC_GUMS*/
25
26 #define GMV_MAJOR 0
27 #define GMV_MINOR 1
28
29 GUMS_FUNCTIONS *gums_storage;
30 static void *dl_handle;
31
32 PRIVS privs[] = {
33         {PRIV_NONE,                     "no_privs",                             "No privilege"}, /* this one MUST be first */
34         {PRIV_CREATE_TOKEN,             "SeCreateToken",                        "Create Token"},
35         {PRIV_ASSIGNPRIMARYTOKEN,       "SeAssignPrimaryToken",                 "Assign Primary Token"},
36         {PRIV_LOCK_MEMORY,              "SeLockMemory",                         "Lock Memory"},
37         {PRIV_INCREASE_QUOTA,           "SeIncreaseQuotaPrivilege",             "Increase Quota Privilege"},
38         {PRIV_MACHINE_ACCOUNT,          "SeMachineAccount",                     "Machine Account"},
39         {PRIV_TCB,                      "SeTCB",                                "TCB"},
40         {PRIV_SECURITY,                 "SeSecurityPrivilege",                  "Security Privilege"},
41         {PRIV_TAKE_OWNERSHIP,           "SeTakeOwnershipPrivilege",             "Take Ownership Privilege"},
42         {PRIV_LOAD_DRIVER,              "SeLocalDriverPrivilege",               "Local Driver Privilege"},
43         {PRIV_SYSTEM_PROFILE,           "SeSystemProfilePrivilege",             "System Profile Privilege"},
44         {PRIV_SYSTEMTIME,               "SeSystemtimePrivilege",                "System Time"},
45         {PRIV_PROF_SINGLE_PROCESS,      "SeProfileSingleProcessPrivilege",      "Profile Single Process Privilege"},
46         {PRIV_INC_BASE_PRIORITY,        "SeIncreaseBasePriorityPrivilege",      "Increase Base Priority Privilege"},
47         {PRIV_CREATE_PAGEFILE,          "SeCreatePagefilePrivilege",            "Create Pagefile Privilege"},
48         {PRIV_CREATE_PERMANENT,         "SeCreatePermanent",                    "Create Permanent"},
49         {PRIV_BACKUP,                   "SeBackupPrivilege",                    "Backup Privilege"},
50         {PRIV_RESTORE,                  "SeRestorePrivilege",                   "Restore Privilege"},
51         {PRIV_SHUTDOWN,                 "SeShutdownPrivilege",                  "Shutdown Privilege"},
52         {PRIV_DEBUG,                    "SeDebugPrivilege",                     "Debug Privilege"},
53         {PRIV_AUDIT,                    "SeAudit",                              "Audit"},
54         {PRIV_SYSTEM_ENVIRONMENT,       "SeSystemEnvironmentPrivilege",         "System Environment Privilege"},
55         {PRIV_CHANGE_NOTIFY,            "SeChangeNotify",                       "Change Notify"},
56         {PRIV_REMOTE_SHUTDOWN,          "SeRemoteShutdownPrivilege",            "Remote Shutdown Privilege"},
57         {PRIV_UNDOCK,                   "SeUndock",                             "Undock"},
58         {PRIV_SYNC_AGENT,               "SeSynchronizationAgent",               "Synchronization Agent"},
59         {PRIV_ENABLE_DELEGATION,        "SeEnableDelegation",                   "Enable Delegation"},
60         {PRIV_ALL,                      "SaAllPrivs",                           "All Privileges"}
61 };
62
63 NTSTATUS gums_init(const char *module_name)
64 {
65         int (*module_version)(int);
66         NTSTATUS (*module_init)();
67 /*      gums_module_init module_init;*/
68         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
69
70         DEBUG(5, ("Opening gums module %s\n", module_name));
71         dl_handle = sys_dlopen(module_name, RTLD_NOW);
72         if (!dl_handle) {
73                 DEBUG(0, ("ERROR: Failed to load gums module %s, error: %s\n", module_name, sys_dlerror()));
74                 return NT_STATUS_UNSUCCESSFUL;
75         }
76
77         module_version = sys_dlsym(dl_handle, "gumm_version");
78         if (!module_version) {
79                 DEBUG(0, ("ERROR: Failed to find gums module version!\n"));
80                 goto error;
81         }
82
83         if (module_version(GMV_MAJOR) != GUMS_VERSION_MAJOR) {
84                 DEBUG(0, ("ERROR: Module's major version does not match gums version!\n"));
85                 goto error;
86         }
87
88         if (module_version(GMV_MINOR) != GUMS_VERSION_MINOR) {
89                 DEBUG(1, ("WARNING: Module's minor version does not match gums version!\n"));
90         }
91
92         module_init = sys_dlsym(dl_handle, "gumm_init");
93         if (!module_init) {
94                 DEBUG(0, ("ERROR: Failed to find gums module's init function!\n"));
95                 goto error;
96         }
97
98         DEBUG(5, ("Initializing module %s\n", module_name));
99
100         ret = module_init(&gums_storage);
101         goto done;
102
103 error:
104         ret = NT_STATUS_UNSUCCESSFUL;
105         sys_dlclose(dl_handle);
106
107 done:
108         return ret;
109 }
110
111 NTSTATUS gums_unload(void)
112 {
113         NSTATUS ret;
114         NTSTATUS (*module_finalize)();
115
116         if (!dl_handle)
117                 return NT_STATUS_UNSUCCESSFUL;
118
119         module_close = sys_dlsym(dl_handle, "gumm_finalize");
120         if (!module_finalize) {
121                 DEBUG(0, ("ERROR: Failed to find gums module's init function!\n"));
122                 return NT_STATUS_UNSUCCESSFUL;
123         }
124
125         DEBUG(5, ("Finalizing module %s\n", module_name));
126
127         ret = module_finalize();
128         sys_dlclose(dl_handle);
129
130         return ret;
131 }