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 /* Needed for some buffers etc., to have a useful replacement for MAX_PATH. */
24 #define CYG_PATH_MAX 4096
26 /* Any include of <windows.h> should be through this file, which wraps it in
27 * various other handling. */
29 /* Basic Windows features only. */
30 #define WIN32_LEAN_AND_MEAN
32 /* libstdc++-v3 _really_ dislikes min & max defined as macros. */
33 /* As of gcc 3.3.1, it defines NOMINMAX itself, so test first,
34 * to avoid a redefinition error */
39 /* 100ns difference between Windows and UNIX timebase. */
40 #define FACTOR (0x19db1ded53e8000LL)
41 /* # of 100ns intervals per second. */
42 #define NSPERSEC 10000000LL
44 /* In w32api 3.1, __declspec(dllimport) decoration is added to
45 * certain symbols. This breaks our autoload mechanism - the symptom is
46 * multiple declaration errors at link time. This define turns that off again.
47 * It will default to off again in later w32api versions, but we need to work
48 * with 3.1 for now. */
49 #define DECLSPEC_IMPORT
54 /* FIXME: The use of _access(fname, 0) as an existence check should be
55 * replaced with a more readable idiom, and this fragment removed. */
57 #define _access access
60 /* When we have to check for a path delimiter, check for both, slash and
62 #define isdirsep(ch) \
65 ((__c) == '/' || (__c) == '\\'); \
68 /* Maximum size of a SID. */
69 #define MAX_SID_LEN 40
71 /* Computes the size of an ACL in relation to the number of ACEs it
73 #define TOKEN_ACL_SIZE(cnt) (sizeof (ACL) + \
74 (cnt) * (sizeof (ACCESS_ALLOWED_ACE) + MAX_SID_LEN))
77 /* Make sure &acl is 4-byte aligned. */
78 ACL acl
__attribute__ ((aligned (4)));
79 char aclbuf
[TOKEN_ACL_SIZE (7)];
84 SIDWrapper () : value (NULL
) {}
85 /* Prevent synthetics. If assignment is needed, this should be
87 SIDWrapper (SIDWrapper
const &);
88 SIDWrapper
& operator= (SIDWrapper
const &);
89 ~SIDWrapper () { if (value
) FreeSid (value
); }
91 /* We could look at doing weird typcast overloads here,
92 but manual access is easier for now. */
93 PSID
&theSID () { return value
; }
94 PSID
const &theSID () const { return value
; }
101 HANDLEWrapper () : value (NULL
) {}
102 /* Prevent synthetics. If assignment is needed, we should duphandles,
104 HANDLEWrapper (HANDLEWrapper
const &);
105 HANDLEWrapper
& operator= (HANDLEWrapper
const &);
106 ~HANDLEWrapper () { if (value
) CloseHandle (value
); }
107 HANDLE
&theHANDLE () { return value
; }
108 HANDLE
const &theHANDLE () const { return value
; }
116 NTSecurity () : nullSID (), everyOneSID (), administratorsSID (), usersSID (),
117 cr_ownerSID (), cr_groupSID (), groupSID (NULL
),
118 _wellKnownSIDsinitialized (false), token () {}
121 /* prevent synthetics */
122 NTSecurity
& operator= (NTSecurity
const &);
123 NTSecurity (NTSecurity
const &);
125 /* Set POSIX-like permissions on files. The fname is only used for printing
126 log output. The function requires an open HANDLE with sufficient
127 permissions (READ_DAC | WRITE_DAC). */
128 PSECURITY_DESCRIPTOR
GetPosixPerms (const char *fname
, PSID owner_sid
,
129 PSID group_sid
, mode_t mode
,
130 SECURITY_DESCRIPTOR
&out_sd
, acl_t
&acl
);
131 void resetPrimaryGroup();
132 void setAdminGroup ();
133 void initialiseWellKnownSIDs ();
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 setDefaultDACL ();
141 void setBackupPrivileges ();
143 SIDWrapper nullSID
, everyOneSID
, administratorsSID
, usersSID
,
144 cr_ownerSID
, cr_groupSID
;
147 char buf
[MAX_SID_LEN
];
151 TOKEN_PRIMARY_GROUP pgrp
;
152 char buf
[MAX_SID_LEN
];
155 bool _wellKnownSIDsinitialized
;
160 extern NTSecurity nt_sec
;
168 DWORD
major () const { return v
.dwMajorVersion
; }
169 DWORD
minor () const { return v
.dwMinorVersion
; }
174 VersionInfo
& GetVer ();
176 #define OSMajorVersion() (GetVer ().major ())
177 #define OSMinorVersion() (GetVer ().minor ())
180 GetDlgItemRect (HWND h
, int item
, LPRECT r
)
182 GetWindowRect (GetDlgItem (h
, item
), r
);
183 MapWindowPoints (HWND_DESKTOP
, h
, (LPPOINT
) r
, 2);
187 SetDlgItemRect (HWND h
, int item
, LPRECT r
)
189 MoveWindow (GetDlgItem (h
, item
), r
->left
, r
->top
,
190 r
->right
- r
->left
, r
->bottom
- r
->top
, TRUE
);
193 #endif /* SETUP_WIN32_H */