]> cygwin.com Git - cygwin-apps/setup.git/blob - win32.h
Use indents in category view
[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 #undef _WIN32_WINNT
33 #define _WIN32_WINNT 0x0a00
34
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 */
38 #ifndef NOMINMAX
39 #define NOMINMAX
40 #endif
41
42 /* 100ns difference between Windows and UNIX timebase. */
43 #define FACTOR (0x19db1ded53e8000LL)
44 /* # of 100ns intervals per second. */
45 #define NSPERSEC 10000000LL
46
47 /* Defining WINBASEAPI is required due the overloading definitions of some
48 kernel32 functions in filemanip.cc. */
49 #define WINBASEAPI
50
51 #include <windows.h>
52
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. */
55 #ifndef _access
56 #define _access access
57 #endif
58
59 /* When we have to check for a path delimiter, check for both, slash and
60 backslash. */
61 #define isdirsep(ch) \
62 ({ \
63 char __c = (ch); \
64 ((__c) == '/' || (__c) == '\\'); \
65 })
66
67 /* Maximum size of a SID. */
68 #define MAX_SID_LEN 40
69
70 /* Computes the size of an ACL in relation to the number of ACEs it
71 should contain. */
72 #define TOKEN_ACL_SIZE(cnt) (sizeof (ACL) + \
73 (cnt) * (sizeof (ACCESS_ALLOWED_ACE) + MAX_SID_LEN))
74
75 struct acl_t {
76 /* Make sure &acl is 4-byte aligned. */
77 ACL acl __attribute__ ((aligned (4)));
78 char aclbuf[TOKEN_ACL_SIZE (7)];
79 };
80
81 class SIDWrapper {
82 public:
83 SIDWrapper () : value (NULL) {}
84 /* Prevent synthetics. If assignment is needed, this should be
85 refcounting. */
86 SIDWrapper (SIDWrapper const &);
87 SIDWrapper& operator= (SIDWrapper const &);
88 ~SIDWrapper () { if (value) FreeSid (value); }
89
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; }
94 private:
95 PSID value;
96 };
97
98 class HANDLEWrapper {
99 public:
100 HANDLEWrapper () : value (NULL) {}
101 /* Prevent synthetics. If assignment is needed, we should duphandles,
102 or refcount. */
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; }
108 private:
109 HANDLE value;
110 };
111
112 class NTSecurity
113 {
114 public:
115 NTSecurity () : nullSID (), everyOneSID (), administratorsSID (), usersSID (),
116 cr_ownerSID (), cr_groupSID (), groupSID (NULL),
117 _wellKnownSIDsinitialized (false), token () {}
118 ~NTSecurity() {}
119
120 /* prevent synthetics */
121 NTSecurity& operator= (NTSecurity const &);
122 NTSecurity (NTSecurity const &);
123
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();
134 bool isRunAsAdmin ();
135 private:
136 void NoteFailedAPI (const std::string &);
137 bool wellKnownSIDsinitialized () const { return _wellKnownSIDsinitialized; }
138 void wellKnownSIDsinitialized (bool b) { _wellKnownSIDsinitialized = b; }
139 void setDefaultDACL ();
140 void setBackupPrivileges ();
141
142 SIDWrapper nullSID, everyOneSID, administratorsSID, usersSID,
143 cr_ownerSID, cr_groupSID;
144 struct {
145 TOKEN_USER user;
146 char buf[MAX_SID_LEN];
147 } ownerSID;
148 PSID groupSID;
149 struct {
150 TOKEN_PRIMARY_GROUP pgrp;
151 char buf[MAX_SID_LEN];
152 } primaryGroupSID;
153
154 bool _wellKnownSIDsinitialized;
155 HANDLEWrapper token;
156 DWORD size;
157 };
158
159 extern NTSecurity nt_sec;
160
161 #undef major
162 #undef minor
163 class VersionInfo
164 {
165 public:
166 VersionInfo ();
167 DWORD major () const { return v.dwMajorVersion; }
168 DWORD minor () const { return v.dwMinorVersion; }
169 DWORD buildNumber () const { return v.dwBuildNumber; }
170 private:
171 OSVERSIONINFO v;
172 };
173
174 VersionInfo& GetVer ();
175
176 #define OSMajorVersion() (GetVer ().major ())
177 #define OSMinorVersion() (GetVer ().minor ())
178 #define OSBuildNumber() (GetVer ().buildNumber ())
179
180 static inline void
181 GetDlgItemRect (HWND h, int item, LPRECT r)
182 {
183 GetWindowRect (GetDlgItem (h, item), r);
184 MapWindowPoints (HWND_DESKTOP, h, (LPPOINT) r, 2);
185 }
186
187 static inline void
188 SetDlgItemRect (HWND h, int item, LPRECT r)
189 {
190 MoveWindow (GetDlgItem (h, item), r->left, r->top,
191 r->right - r->left, r->bottom - r->top, TRUE);
192 }
193
194 #endif /* SETUP_WIN32_H */
This page took 0.045051 seconds and 5 git commands to generate.