2 * Copyright (c) 2000, Red Hat, Inc.
4 * This program 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.
9 * A copy of the GNU General Public License can be found at
12 * Written by DJ Delorie <dj@cygnus.com>
13 * and Robert Collins <rbtcollins@hotmail.com>
20 #include <sys/types.h>
23 /* Any include of <windows.h> should be through this file, which wraps it in
24 * various other handling. */
26 /* Basic Windows features only. */
27 #define WIN32_LEAN_AND_MEAN
29 /* libstdc++-v3 _really_ dislikes min & max defined as macros. */
30 /* As of gcc 3.3.1, it defines NOMINMAX itself, so test first,
31 * to avoid a redefinition error */
36 /* 100ns difference between Windows and UNIX timebase. */
37 #define FACTOR (0x19db1ded53e8000LL)
38 /* # of 100ns intervals per second. */
39 #define NSPERSEC 10000000LL
41 /* In w32api 3.1, __declspec(dllimport) decoration is added to
42 * certain symbols. This breaks our autoload mechanism - the symptom is
43 * multiple declaration errors at link time. This define turns that off again.
44 * It will default to off again in later w32api versions, but we need to work
45 * with 3.1 for now. */
46 #define DECLSPEC_IMPORT
49 /* Require at least Internet Explorer 3, in order to have access to
50 * sufficient Windows Common Controls features from <commctrl.h> . */
51 #define _WIN32_IE 0x0300
55 /* FIXME: The use of _access(fname, 0) as an existence check should be
56 * replaced with a more readable idiom, and this fragment removed. */
58 #define _access access
61 /* When we have to check for a path delimiter, check for both, slash and
63 #define isdirsep(ch) \
66 ((__c) == '/' || (__c) == '\\'); \
69 /* Maximum size of a SID. */
70 #define MAX_SID_LEN 40
72 /* Computes the size of an ACL in relation to the number of ACEs it
74 #define TOKEN_ACL_SIZE(cnt) (sizeof (ACL) + \
75 (cnt) * (sizeof (ACCESS_ALLOWED_ACE) + MAX_SID_LEN))
78 /* Make sure &acl is 4-byte aligned. */
79 ACL acl
__attribute__ ((aligned (4)));
80 char aclbuf
[TOKEN_ACL_SIZE (7)];
85 SIDWrapper () : value (NULL
) {}
86 /* Prevent synthetics. If assignment is needed, this should be
88 SIDWrapper (SIDWrapper
const &);
89 SIDWrapper
& operator= (SIDWrapper
const &);
90 ~SIDWrapper () { if (value
) FreeSid (value
); }
92 /* We could look at doing weird typcast overloads here,
93 but manual access is easier for now. */
94 PSID
&theSID () { return value
; }
95 PSID
const &theSID () const { return value
; }
100 class HANDLEWrapper
{
102 HANDLEWrapper () : value (NULL
) {}
103 /* Prevent synthetics. If assignment is needed, we should duphandles,
105 HANDLEWrapper (HANDLEWrapper
const &);
106 HANDLEWrapper
& operator= (HANDLEWrapper
const &);
107 ~HANDLEWrapper () { if (value
) CloseHandle (value
); }
108 HANDLE
&theHANDLE () { return value
; }
109 HANDLE
const &theHANDLE () const { return value
; }
117 NTSecurity () : nullSID (), everyOneSID (), administratorsSID (), usersSID (),
118 cr_ownerSID (), cr_groupSID (), groupSID (NULL
),
119 _wellKnownSIDsinitialized (false), token () {}
122 /* prevent synthetics */
123 NTSecurity
& operator= (NTSecurity
const &);
124 NTSecurity (NTSecurity
const &);
126 /* Set POSIX-like permissions on files. The fname is only used for printing
127 log output. The function requires an open HANDLE with sufficient
128 permissions (READ_DAC | WRITE_DAC). */
129 PSECURITY_DESCRIPTOR
GetPosixPerms (const char *fname
, PSID owner_sid
,
130 PSID group_sid
, mode_t mode
,
131 SECURITY_DESCRIPTOR
&out_sd
, acl_t
&acl
);
132 void resetPrimaryGroup();
133 void setAdminGroup ();
134 void setDefaultSecurity();
135 bool isRunAsAdmin ();
137 void NoteFailedAPI (const std::string
&);
138 bool wellKnownSIDsinitialized () const { return _wellKnownSIDsinitialized
; }
139 void wellKnownSIDsinitialized (bool b
) { _wellKnownSIDsinitialized
= b
; }
140 void initialiseWellKnownSIDs ();
141 void setDefaultDACL ();
142 void setBackupPrivileges ();
144 SIDWrapper nullSID
, everyOneSID
, administratorsSID
, usersSID
,
145 cr_ownerSID
, cr_groupSID
;
148 char buf
[MAX_SID_LEN
];
152 TOKEN_PRIMARY_GROUP pgrp
;
153 char buf
[MAX_SID_LEN
];
156 bool _wellKnownSIDsinitialized
;
161 extern NTSecurity nt_sec
;
169 DWORD
major () const { return v
.dwMajorVersion
; }
170 DWORD
minor () const { return v
.dwMinorVersion
; }
175 VersionInfo
& GetVer ();
177 #define OSMajorVersion() (GetVer ().major ())
178 #define OSMinorVersion() (GetVer ().minor ())
180 #endif /* SETUP_WIN32_H */