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>
22 /* Any include of <windows.h> should be through this file, which wraps it in
23 * various other handling. */
25 /* Basic Windows features only. */
26 #define WIN32_LEAN_AND_MEAN
28 /* libstdc++-v3 _really_ dislikes min & max defined as macros. */
29 /* As of gcc 3.3.1, it defines NOMINMAX itself, so test first,
30 * to avoid a redefinition error */
35 /* In w32api 3.1, __declspec(dllimport) decoration is added to
36 * certain symbols. This breaks our autoload mechanism - the symptom is
37 * multiple declaration errors at link time. This define turns that off again.
38 * It will default to off again in later w32api versions, but we need to work
39 * with 3.1 for now. */
42 /* Require at least Internet Explorer 3, in order to have access to
43 * sufficient Windows Common Controls features from <commctrl.h> . */
44 #define _WIN32_IE 0x0300
48 /* FIXME: The use of _access(fname, 0) as an existence check should be
49 * replaced with a more readable idiom, and this fragment removed. */
51 #define _access access
54 /* When we have to check for a path delimiter, check for both, slash and
56 #define isdirsep(ch) \
59 ((__c) == '/' || (__c) == '\\'); \
62 /* Maximum size of a SID on NT/W2K. */
63 #define MAX_SID_LEN 40
65 /* Computes the size of an ACL in relation to the number of ACEs it
67 #define TOKEN_ACL_SIZE(cnt) (sizeof (ACL) + \
68 (cnt) * (sizeof (ACCESS_ALLOWED_ACE) + MAX_SID_LEN))
72 char aclbuf
[TOKEN_ACL_SIZE (7)];
77 SIDWrapper () : value (NULL
) {}
78 /* Prevent synthetics. If assignment is needed, this should be
80 SIDWrapper (SIDWrapper
const &);
81 SIDWrapper
& operator= (SIDWrapper
const &);
82 ~SIDWrapper () { if (value
) FreeSid (value
); }
84 /* We could look at doing weird typcast overloads here,
85 but manual access is easier for now. */
86 PSID
&theSID () { return value
; }
87 PSID
const &theSID () const { return value
; }
94 HANDLEWrapper () : value (NULL
) {}
95 /* Prevent synthetics. If assignment is needed, we should duphandles,
97 HANDLEWrapper (HANDLEWrapper
const &);
98 HANDLEWrapper
& operator= (HANDLEWrapper
const &);
99 ~HANDLEWrapper () { if (value
) CloseHandle (value
); }
100 HANDLE
&theHANDLE () { return value
; }
101 HANDLE
const &theHANDLE () const { return value
; }
109 NTSecurity () : nullSID (), everyOneSID (), administratorsSID (), usersSID (),
110 cr_ownerSID (), cr_groupSID (), groupSID (NULL
),
111 _wellKnownSIDsinitialized (false), token () {}
114 /* prevent synthetics */
115 NTSecurity
& operator= (NTSecurity
const &);
116 NTSecurity (NTSecurity
const &);
118 /* Set POSIX-like permissions on files. The fname is only used for printing
119 log output. The function requires an open HANDLE with sufficient
120 permissions (READ_DAC | WRITE_DAC). */
121 PSECURITY_DESCRIPTOR
GetPosixPerms (const char *fname
, PSID owner_sid
,
122 PSID group_sid
, mode_t mode
,
123 SECURITY_DESCRIPTOR
&out_sd
, acl_t
&acl
);
124 void SetPosixPerms (const char *fname
, HANDLE fh
, mode_t mode
);
125 void resetPrimaryGroup();
126 void setAdminGroup ();
127 void setDefaultSecurity();
129 void NoteFailedAPI (const std::string
&);
130 bool wellKnownSIDsinitialized () const { return _wellKnownSIDsinitialized
; }
131 void wellKnownSIDsinitialized (bool b
) { _wellKnownSIDsinitialized
= b
; }
132 void initialiseWellKnownSIDs ();
133 void setDefaultDACL ();
134 void setBackupPrivileges ();
136 SIDWrapper nullSID
, everyOneSID
, administratorsSID
, usersSID
,
137 cr_ownerSID
, cr_groupSID
;
140 char buf
[MAX_SID_LEN
];
144 TOKEN_PRIMARY_GROUP pgrp
;
145 char buf
[MAX_SID_LEN
];
148 bool _wellKnownSIDsinitialized
;
153 extern NTSecurity nt_sec
;
161 bool isNT () { return (v
.dwPlatformId
== VER_PLATFORM_WIN32_NT
); }
162 DWORD
major () const { return v
.dwMajorVersion
; }
163 DWORD
minor () const { return v
.dwMinorVersion
; }
168 VersionInfo
& GetVer ();
170 #define IsWindowsNT() (GetVer ().isNT ())
171 #define OSMajorVersion() (GetVer ().major ())
172 #define OSMinorVersion() (GetVer ().minor ())
174 #endif /* SETUP_WIN32_H */