]> cygwin.com Git - cygwin-apps/setup.git/blob - win32.h
* ini.h (SETUP_BZ2_FILENAME): Reflect new architecture layout in ftp.
[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 /* Any include of <windows.h> should be through this file, which wraps it in
24 * various other handling. */
25
26 /* Basic Windows features only. */
27 #define WIN32_LEAN_AND_MEAN
28
29 /* libstdc++-v3 _really_ dislikes min & max defined as macros. */
30 /* As of gcc 3.3.1, it defines NOMINMAX itself, so test first,
31 * to avoid a redefinition error */
32 #ifndef NOMINMAX
33 #define NOMINMAX
34 #endif
35
36 /* 100ns difference between Windows and UNIX timebase. */
37 #define FACTOR (0x19db1ded53e8000LL)
38 /* # of 100ns intervals per second. */
39 #define NSPERSEC 10000000LL
40
41 /* In w32api 3.1, __declspec(dllimport) decoration is added to
42 * certain symbols. This breaks our autoload mechanism - the symptom is
43 * multiple declaration errors at link time. This define turns that off again.
44 * It will default to off again in later w32api versions, but we need to work
45 * with 3.1 for now. */
46 #define DECLSPEC_IMPORT
47 #define WINBASEAPI
48
49 /* Require at least Internet Explorer 3, in order to have access to
50 * sufficient Windows Common Controls features from <commctrl.h> . */
51 #define _WIN32_IE 0x0300
52
53 #include <windows.h>
54
55 /* FIXME: The use of _access(fname, 0) as an existence check should be
56 * replaced with a more readable idiom, and this fragment removed. */
57 #ifndef _access
58 #define _access access
59 #endif
60
61 /* When we have to check for a path delimiter, check for both, slash and
62 backslash. */
63 #define isdirsep(ch) \
64 ({ \
65 char __c = (ch); \
66 ((__c) == '/' || (__c) == '\\'); \
67 })
68
69 /* Maximum size of a SID on NT/W2K. */
70 #define MAX_SID_LEN 40
71
72 /* Computes the size of an ACL in relation to the number of ACEs it
73 should contain. */
74 #define TOKEN_ACL_SIZE(cnt) (sizeof (ACL) + \
75 (cnt) * (sizeof (ACCESS_ALLOWED_ACE) + MAX_SID_LEN))
76
77 struct acl_t {
78 ACL acl;
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 setDefaultSecurity();
134 private:
135 void NoteFailedAPI (const std::string &);
136 bool wellKnownSIDsinitialized () const { return _wellKnownSIDsinitialized; }
137 void wellKnownSIDsinitialized (bool b) { _wellKnownSIDsinitialized = b; }
138 void initialiseWellKnownSIDs ();
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 private:
170 OSVERSIONINFO v;
171 };
172
173 VersionInfo& GetVer ();
174
175 #define OSMajorVersion() (GetVer ().major ())
176 #define OSMinorVersion() (GetVer ().minor ())
177
178 #endif /* SETUP_WIN32_H */
This page took 0.045092 seconds and 5 git commands to generate.