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
33 #define _WIN32_WINNT 0x0a00
35 /* libstdc++-v3 _really_ dislikes min & max defined as macros. */
36 /* As of gcc 3.3.1, it defines NOMINMAX itself, so test first,
37 * to avoid a redefinition error */
42 /* 100ns difference between Windows and UNIX timebase. */
43 #define FACTOR (0x19db1ded53e8000LL)
44 /* # of 100ns intervals per second. */
45 #define NSPERSEC 10000000LL
47 /* Defining WINBASEAPI is required due the overloading definitions of some
48 kernel32 functions in filemanip.cc. */
53 /* FIXME: The use of _access(fname, 0) as an existence check should be
54 * replaced with a more readable idiom, and this fragment removed. */
56 #define _access access
59 /* When we have to check for a path delimiter, check for both, slash and
61 #define isdirsep(ch) \
64 ((__c) == '/' || (__c) == '\\'); \
67 /* Maximum size of a SID. */
68 #define MAX_SID_LEN 40
70 /* Computes the size of an ACL in relation to the number of ACEs it
72 #define TOKEN_ACL_SIZE(cnt) (sizeof (ACL) + \
73 (cnt) * (sizeof (ACCESS_ALLOWED_ACE) + MAX_SID_LEN))
76 /* Make sure &acl is 4-byte aligned. */
77 ACL acl
__attribute__ ((aligned (4)));
78 char aclbuf
[TOKEN_ACL_SIZE (7)];
83 SIDWrapper () : value (NULL
) {}
84 /* Prevent synthetics. If assignment is needed, this should be
86 SIDWrapper (SIDWrapper
const &);
87 SIDWrapper
& operator= (SIDWrapper
const &);
88 ~SIDWrapper () { if (value
) FreeSid (value
); }
90 /* We could look at doing weird typcast overloads here,
91 but manual access is easier for now. */
92 PSID
&theSID () { return value
; }
93 PSID
const &theSID () const { return value
; }
100 HANDLEWrapper () : value (NULL
) {}
101 /* Prevent synthetics. If assignment is needed, we should duphandles,
103 HANDLEWrapper (HANDLEWrapper
const &);
104 HANDLEWrapper
& operator= (HANDLEWrapper
const &);
105 ~HANDLEWrapper () { if (value
) CloseHandle (value
); }
106 HANDLE
&theHANDLE () { return value
; }
107 HANDLE
const &theHANDLE () const { return value
; }
115 NTSecurity () : nullSID (), everyOneSID (), administratorsSID (), usersSID (),
116 cr_ownerSID (), cr_groupSID (), groupSID (NULL
),
117 _wellKnownSIDsinitialized (false), token () {}
120 /* prevent synthetics */
121 NTSecurity
& operator= (NTSecurity
const &);
122 NTSecurity (NTSecurity
const &);
124 /* Set POSIX-like permissions on files. The fname is only used for printing
125 log output. The function requires an open HANDLE with sufficient
126 permissions (READ_DAC | WRITE_DAC). */
127 PSECURITY_DESCRIPTOR
GetPosixPerms (const char *fname
, PSID owner_sid
,
128 PSID group_sid
, mode_t mode
,
129 SECURITY_DESCRIPTOR
&out_sd
, acl_t
&acl
);
130 void resetPrimaryGroup();
131 void setAdminGroup ();
132 void initialiseWellKnownSIDs ();
133 void setDefaultSecurity(bool isAdmin
);
134 bool isRunAsAdmin ();
135 bool hasSymlinkCreationRights ();
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
; }
170 DWORD
buildNumber () const { return v
.dwBuildNumber
; }
175 VersionInfo
& GetVer ();
177 #define OSMajorVersion() (GetVer ().major ())
178 #define OSMinorVersion() (GetVer ().minor ())
179 #define OSBuildNumber() (GetVer ().buildNumber ())
181 USHORT
WowNativeMachine ();
184 GetDlgItemRect (HWND h
, int item
, LPRECT r
)
186 GetWindowRect (GetDlgItem (h
, item
), r
);
187 MapWindowPoints (HWND_DESKTOP
, h
, (LPPOINT
) r
, 2);
191 SetDlgItemRect (HWND h
, int item
, LPRECT r
)
193 MoveWindow (GetDlgItem (h
, item
), r
->left
, r
->top
,
194 r
->right
- r
->left
, r
->bottom
- r
->top
, TRUE
);
197 const std::string
LoadStringUtf8(unsigned int uID
);
198 const std::wstring
LoadStringW(unsigned int uID
);
199 const std::wstring
LoadStringWEx(UINT uID
, UINT langId
);
201 bool is_developer_mode(void);
203 #endif /* SETUP_WIN32_H */