]> cygwin.com Git - cygwin-apps/setup.git/blame - win32.h
Support xz and lzma decompression via liblzma
[cygwin-apps/setup.git] / win32.h
CommitLineData
23c9e63c
DD
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>
ad3c7385 13 * and Robert Collins <rbtcollins@hotmail.com>
23c9e63c
DD
14 *
15 */
16
c93bc6d0
MB
17#ifndef SETUP_WIN32_H
18#define SETUP_WIN32_H
19
5072c0bb
BD
20#include <string>
21
4875ac88
MB
22/* Any include of <windows.h> should be through this file, which wraps it in
23 * various other handling. */
23c9e63c 24
4875ac88 25/* Basic Windows features only. */
ed96c6da 26#define WIN32_LEAN_AND_MEAN
46d04e97 27
666bf37d 28/* libstdc++-v3 _really_ dislikes min & max defined as macros. */
587a67fc
MB
29/* As of gcc 3.3.1, it defines NOMINMAX itself, so test first,
30 * to avoid a redefinition error */
31#ifndef NOMINMAX
666bf37d 32#define NOMINMAX
587a67fc 33#endif
46d04e97 34
6c7aee70 35/* In w32api 3.1, __declspec(dllimport) decoration is added to
46d04e97
MB
36 * certain symbols. This breaks our autoload mechanism - the symptom is
37 * multiple declaration errors at link time. This define turns that off again.
38 * It will default to off again in later w32api versions, but we need to work
39 * with 3.1 for now. */
40#define WINBASEAPI
41
30718d6f 42/* Require at least Internet Explorer 3, in order to have access to
4875ac88
MB
43 * sufficient Windows Common Controls features from <commctrl.h> . */
44#define _WIN32_IE 0x0300
46d04e97 45
4875ac88 46#include <windows.h>
46d04e97 47
4875ac88
MB
48/* FIXME: The use of _access(fname, 0) as an existence check should be
49 * replaced with a more readable idiom, and this fragment removed. */
45e01f23
RC
50#ifndef _access
51#define _access access
52#endif
ed96c6da 53
4d10ec8c
CV
54/* When we have to check for a path delimiter, check for both, slash and
55 backslash. */
56#define isdirsep(ch) \
57 ({ \
58 char __c = (ch); \
59 ((__c) == '/' || (__c) == '\\'); \
60 })
61
5072c0bb
BD
62/* Maximum size of a SID on NT/W2K. */
63#define MAX_SID_LEN 40
64
65/* Computes the size of an ACL in relation to the number of ACEs it
66 should contain. */
67#define TOKEN_ACL_SIZE(cnt) (sizeof (ACL) + \
68 (cnt) * (sizeof (ACCESS_ALLOWED_ACE) + MAX_SID_LEN))
69
26922cd2
CV
70struct acl_t {
71 ACL acl;
72 char aclbuf[TOKEN_ACL_SIZE (7)];
73};
74
5072c0bb
BD
75class SIDWrapper {
76 public:
77 SIDWrapper () : value (NULL) {}
78 /* Prevent synthetics. If assignment is needed, this should be
79 refcounting. */
80 SIDWrapper (SIDWrapper const &);
81 SIDWrapper& operator= (SIDWrapper const &);
82 ~SIDWrapper () { if (value) FreeSid (value); }
83
84 /* We could look at doing weird typcast overloads here,
85 but manual access is easier for now. */
86 PSID &theSID () { return value; }
87 PSID const &theSID () const { return value; }
88 private:
89 PSID value;
90};
91
92class HANDLEWrapper {
93 public:
94 HANDLEWrapper () : value (NULL) {}
95 /* Prevent synthetics. If assignment is needed, we should duphandles,
96 or refcount. */
97 HANDLEWrapper (HANDLEWrapper const &);
98 HANDLEWrapper& operator= (HANDLEWrapper const &);
99 ~HANDLEWrapper () { if (value) CloseHandle (value); }
100 HANDLE &theHANDLE () { return value; }
101 HANDLE const &theHANDLE () const { return value; }
102 private:
103 HANDLE value;
104};
105
5072c0bb
BD
106class NTSecurity
107{
108public:
be617b59 109 NTSecurity () : nullSID (), everyOneSID (), administratorsSID (), usersSID (),
26922cd2 110 cr_ownerSID (), cr_groupSID (), groupSID (NULL),
be617b59 111 _wellKnownSIDsinitialized (false), token () {}
5072c0bb
BD
112 ~NTSecurity() {}
113
114 /* prevent synthetics */
115 NTSecurity& operator= (NTSecurity const &);
116 NTSecurity (NTSecurity const &);
117
be617b59
CV
118 /* Set POSIX-like permissions on files. The fname is only used for printing
119 log output. The function requires an open HANDLE with sufficient
120 permissions (READ_DAC | WRITE_DAC). */
26922cd2
CV
121 PSECURITY_DESCRIPTOR GetPosixPerms (const char *fname, PSID owner_sid,
122 PSID group_sid, mode_t mode,
123 SECURITY_DESCRIPTOR &out_sd, acl_t &acl);
770e3aed 124 void resetPrimaryGroup();
d29a864d 125 void setAdminGroup ();
5072c0bb
BD
126 void setDefaultSecurity();
127private:
be617b59
CV
128 void NoteFailedAPI (const std::string &);
129 bool wellKnownSIDsinitialized () const { return _wellKnownSIDsinitialized; }
130 void wellKnownSIDsinitialized (bool b) { _wellKnownSIDsinitialized = b; }
131 void initialiseWellKnownSIDs ();
5072c0bb 132 void setDefaultDACL ();
be617b59
CV
133 void setBackupPrivileges ();
134
89cc2408 135 SIDWrapper nullSID, everyOneSID, administratorsSID, usersSID,
26922cd2
CV
136 cr_ownerSID, cr_groupSID;
137 struct {
138 TOKEN_USER user;
139 char buf[MAX_SID_LEN];
140 } ownerSID;
141 PSID groupSID;
5072c0bb 142 struct {
d29a864d 143 TOKEN_PRIMARY_GROUP pgrp;
5072c0bb 144 char buf[MAX_SID_LEN];
d29a864d
CV
145 } primaryGroupSID;
146
147 bool _wellKnownSIDsinitialized;
148 HANDLEWrapper token;
5072c0bb
BD
149 DWORD size;
150};
151
b41c2908
CV
152extern NTSecurity nt_sec;
153
f26f525f
CF
154#undef major
155#undef minor
5072c0bb
BD
156class VersionInfo
157{
158 public:
159 VersionInfo ();
160 bool isNT () { return (v.dwPlatformId == VER_PLATFORM_WIN32_NT); }
53d33c5d
CV
161 DWORD major () const { return v.dwMajorVersion; }
162 DWORD minor () const { return v.dwMinorVersion; }
5072c0bb
BD
163 private:
164 OSVERSIONINFO v;
165};
166
167VersionInfo& GetVer ();
168
169#define IsWindowsNT() (GetVer ().isNT ())
53d33c5d
CV
170#define OSMajorVersion() (GetVer ().major ())
171#define OSMinorVersion() (GetVer ().minor ())
ad3c7385 172
c93bc6d0 173#endif /* SETUP_WIN32_H */
This page took 0.072231 seconds and 5 git commands to generate.