]> cygwin.com Git - cygwin-apps/setup.git/blob - win32.h
* LogFile.cc (LogFile::exit): Don't print ending message after
[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. */
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 /* Make sure &acl is 4-byte aligned. */
79 ACL acl __attribute__ ((aligned (4)));
80 char aclbuf[TOKEN_ACL_SIZE (7)];
81 };
82
83 class SIDWrapper {
84 public:
85 SIDWrapper () : value (NULL) {}
86 /* Prevent synthetics. If assignment is needed, this should be
87 refcounting. */
88 SIDWrapper (SIDWrapper const &);
89 SIDWrapper& operator= (SIDWrapper const &);
90 ~SIDWrapper () { if (value) FreeSid (value); }
91
92 /* We could look at doing weird typcast overloads here,
93 but manual access is easier for now. */
94 PSID &theSID () { return value; }
95 PSID const &theSID () const { return value; }
96 private:
97 PSID value;
98 };
99
100 class HANDLEWrapper {
101 public:
102 HANDLEWrapper () : value (NULL) {}
103 /* Prevent synthetics. If assignment is needed, we should duphandles,
104 or refcount. */
105 HANDLEWrapper (HANDLEWrapper const &);
106 HANDLEWrapper& operator= (HANDLEWrapper const &);
107 ~HANDLEWrapper () { if (value) CloseHandle (value); }
108 HANDLE &theHANDLE () { return value; }
109 HANDLE const &theHANDLE () const { return value; }
110 private:
111 HANDLE value;
112 };
113
114 class NTSecurity
115 {
116 public:
117 NTSecurity () : nullSID (), everyOneSID (), administratorsSID (), usersSID (),
118 cr_ownerSID (), cr_groupSID (), groupSID (NULL),
119 _wellKnownSIDsinitialized (false), token () {}
120 ~NTSecurity() {}
121
122 /* prevent synthetics */
123 NTSecurity& operator= (NTSecurity const &);
124 NTSecurity (NTSecurity const &);
125
126 /* Set POSIX-like permissions on files. The fname is only used for printing
127 log output. The function requires an open HANDLE with sufficient
128 permissions (READ_DAC | WRITE_DAC). */
129 PSECURITY_DESCRIPTOR GetPosixPerms (const char *fname, PSID owner_sid,
130 PSID group_sid, mode_t mode,
131 SECURITY_DESCRIPTOR &out_sd, acl_t &acl);
132 void resetPrimaryGroup();
133 void setAdminGroup ();
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 initialiseWellKnownSIDs ();
141 void setDefaultDACL ();
142 void setBackupPrivileges ();
143
144 SIDWrapper nullSID, everyOneSID, administratorsSID, usersSID,
145 cr_ownerSID, cr_groupSID;
146 struct {
147 TOKEN_USER user;
148 char buf[MAX_SID_LEN];
149 } ownerSID;
150 PSID groupSID;
151 struct {
152 TOKEN_PRIMARY_GROUP pgrp;
153 char buf[MAX_SID_LEN];
154 } primaryGroupSID;
155
156 bool _wellKnownSIDsinitialized;
157 HANDLEWrapper token;
158 DWORD size;
159 };
160
161 extern NTSecurity nt_sec;
162
163 #undef major
164 #undef minor
165 class VersionInfo
166 {
167 public:
168 VersionInfo ();
169 DWORD major () const { return v.dwMajorVersion; }
170 DWORD minor () const { return v.dwMinorVersion; }
171 private:
172 OSVERSIONINFO v;
173 };
174
175 VersionInfo& GetVer ();
176
177 #define OSMajorVersion() (GetVer ().major ())
178 #define OSMinorVersion() (GetVer ().minor ())
179
180 #endif /* SETUP_WIN32_H */
This page took 0.044558 seconds and 6 git commands to generate.