]> cygwin.com Git - cygwin-apps/setup.git/blob - win32.h
propsheet: drop support for Common Controls v4
[cygwin-apps/setup.git] / win32.h
1 /*
2 * Copyright (c) 2000, Red Hat, Inc.
3 *
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.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
13 * and Robert Collins <rbtcollins@hotmail.com>
14 *
15 */
16
17 #ifndef SETUP_WIN32_H
18 #define SETUP_WIN32_H
19
20 #include <sys/types.h>
21 #include <string>
22
23 /* Needed for some buffers etc., to have a useful replacement for MAX_PATH. */
24 #define CYG_PATH_MAX 4096
25
26 /* Any include of <windows.h> should be through this file, which wraps it in
27 * various other handling. */
28
29 /* Basic Windows features only. */
30 #define WIN32_LEAN_AND_MEAN
31
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 */
35 #ifndef NOMINMAX
36 #define NOMINMAX
37 #endif
38
39 /* 100ns difference between Windows and UNIX timebase. */
40 #define FACTOR (0x19db1ded53e8000LL)
41 /* # of 100ns intervals per second. */
42 #define NSPERSEC 10000000LL
43
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
50 #define WINBASEAPI
51
52 #include <windows.h>
53
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. */
56 #ifndef _access
57 #define _access access
58 #endif
59
60 /* When we have to check for a path delimiter, check for both, slash and
61 backslash. */
62 #define isdirsep(ch) \
63 ({ \
64 char __c = (ch); \
65 ((__c) == '/' || (__c) == '\\'); \
66 })
67
68 /* Maximum size of a SID. */
69 #define MAX_SID_LEN 40
70
71 /* Computes the size of an ACL in relation to the number of ACEs it
72 should contain. */
73 #define TOKEN_ACL_SIZE(cnt) (sizeof (ACL) + \
74 (cnt) * (sizeof (ACCESS_ALLOWED_ACE) + MAX_SID_LEN))
75
76 struct acl_t {
77 /* Make sure &acl is 4-byte aligned. */
78 ACL acl __attribute__ ((aligned (4)));
79 char aclbuf[TOKEN_ACL_SIZE (7)];
80 };
81
82 class SIDWrapper {
83 public:
84 SIDWrapper () : value (NULL) {}
85 /* Prevent synthetics. If assignment is needed, this should be
86 refcounting. */
87 SIDWrapper (SIDWrapper const &);
88 SIDWrapper& operator= (SIDWrapper const &);
89 ~SIDWrapper () { if (value) FreeSid (value); }
90
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; }
95 private:
96 PSID value;
97 };
98
99 class HANDLEWrapper {
100 public:
101 HANDLEWrapper () : value (NULL) {}
102 /* Prevent synthetics. If assignment is needed, we should duphandles,
103 or refcount. */
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; }
109 private:
110 HANDLE value;
111 };
112
113 class NTSecurity
114 {
115 public:
116 NTSecurity () : nullSID (), everyOneSID (), administratorsSID (), usersSID (),
117 cr_ownerSID (), cr_groupSID (), groupSID (NULL),
118 _wellKnownSIDsinitialized (false), token () {}
119 ~NTSecurity() {}
120
121 /* prevent synthetics */
122 NTSecurity& operator= (NTSecurity const &);
123 NTSecurity (NTSecurity const &);
124
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 ();
136 private:
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 ();
142
143 SIDWrapper nullSID, everyOneSID, administratorsSID, usersSID,
144 cr_ownerSID, cr_groupSID;
145 struct {
146 TOKEN_USER user;
147 char buf[MAX_SID_LEN];
148 } ownerSID;
149 PSID groupSID;
150 struct {
151 TOKEN_PRIMARY_GROUP pgrp;
152 char buf[MAX_SID_LEN];
153 } primaryGroupSID;
154
155 bool _wellKnownSIDsinitialized;
156 HANDLEWrapper token;
157 DWORD size;
158 };
159
160 extern NTSecurity nt_sec;
161
162 #undef major
163 #undef minor
164 class VersionInfo
165 {
166 public:
167 VersionInfo ();
168 DWORD major () const { return v.dwMajorVersion; }
169 DWORD minor () const { return v.dwMinorVersion; }
170 private:
171 OSVERSIONINFO v;
172 };
173
174 VersionInfo& GetVer ();
175
176 #define OSMajorVersion() (GetVer ().major ())
177 #define OSMinorVersion() (GetVer ().minor ())
178
179 static inline void
180 GetDlgItemRect (HWND h, int item, LPRECT r)
181 {
182 GetWindowRect (GetDlgItem (h, item), r);
183 MapWindowPoints (HWND_DESKTOP, h, (LPPOINT) r, 2);
184 }
185
186 static inline void
187 SetDlgItemRect (HWND h, int item, LPRECT r)
188 {
189 MoveWindow (GetDlgItem (h, item), r->left, r->top,
190 r->right - r->left, r->bottom - r->top, TRUE);
191 }
192
193 #endif /* SETUP_WIN32_H */
This page took 0.041776 seconds and 6 git commands to generate.