#ifndef SETUP_WIN32_H
#define SETUP_WIN32_H
+#include <sys/types.h>
#include <string>
+/* Needed for some buffers etc., to have a useful replacement for MAX_PATH. */
+#define CYG_PATH_MAX 4096
+
/* Any include of <windows.h> should be through this file, which wraps it in
* various other handling. */
/* Basic Windows features only. */
#define WIN32_LEAN_AND_MEAN
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x0a00
+
/* libstdc++-v3 _really_ dislikes min & max defined as macros. */
/* As of gcc 3.3.1, it defines NOMINMAX itself, so test first,
* to avoid a redefinition error */
#define NOMINMAX
#endif
-/* In w32api 3.1, __declspec(dllimport) decoration is added to
- * certain symbols. This breaks our autoload mechanism - the symptom is
- * multiple declaration errors at link time. This define turns that off again.
- * It will default to off again in later w32api versions, but we need to work
- * with 3.1 for now. */
-#define WINBASEAPI
+/* 100ns difference between Windows and UNIX timebase. */
+#define FACTOR (0x19db1ded53e8000LL)
+/* # of 100ns intervals per second. */
+#define NSPERSEC 10000000LL
-/* Require at least Internet Explorer 3, in order to have access to
- * sufficient Windows Common Controls features from <commctrl.h> . */
-#define _WIN32_IE 0x0300
+/* Defining WINBASEAPI is required due the overloading definitions of some
+ kernel32 functions in filemanip.cc. */
+#define WINBASEAPI
#include <windows.h>
#define _access access
#endif
-/* Maximum size of a SID on NT/W2K. */
-#define MAX_SID_LEN 40
+/* When we have to check for a path delimiter, check for both, slash and
+ backslash. */
+#define isdirsep(ch) \
+ ({ \
+ char __c = (ch); \
+ ((__c) == '/' || (__c) == '\\'); \
+ })
-/* Helper function to set POSIX-like permissions on files. The fname
- is only used for printing log output. The function requires an open
- HANDLE with sufficient permissions (READ_DAC | WRITE_DAC). */
-void SetPosixPerms (const char *fname, HANDLE fh, mode_t mode);
+/* Maximum size of a SID. */
+#define MAX_SID_LEN 40
/* Computes the size of an ACL in relation to the number of ACEs it
should contain. */
#define TOKEN_ACL_SIZE(cnt) (sizeof (ACL) + \
(cnt) * (sizeof (ACCESS_ALLOWED_ACE) + MAX_SID_LEN))
+struct acl_t {
+ /* Make sure &acl is 4-byte aligned. */
+ ACL acl __attribute__ ((aligned (4)));
+ char aclbuf[TOKEN_ACL_SIZE (7)];
+};
+
class SIDWrapper {
public:
SIDWrapper () : value (NULL) {}
HANDLE value;
};
-class TokenGroupCollection {
- public:
- TokenGroupCollection (DWORD aSize, HANDLEWrapper &aHandle) :
- populated_(false), buffer(new char[aSize]),
- bufferSize(aSize), token(aHandle) {}
- ~TokenGroupCollection () { if (buffer) delete[] buffer; }
-
- /* prevent synthetics */
- TokenGroupCollection& operator= (TokenGroupCollection const &);
- TokenGroupCollection (TokenGroupCollection const &);
- bool find (SIDWrapper const &) const;
- bool populated() const { return populated_; }
- void populate();
- private:
- mutable bool populated_;
- char *buffer;
- DWORD bufferSize;
- HANDLEWrapper &token;
-};
-
class NTSecurity
{
public:
- NTSecurity () : everyOneSID (), administratorsSID (), usid (), token (),
- failed_ (false) {}
+ NTSecurity () : nullSID (), everyOneSID (), administratorsSID (), usersSID (),
+ cr_ownerSID (), cr_groupSID (), groupSID (NULL),
+ _wellKnownSIDsinitialized (false), token () {}
~NTSecurity() {}
/* prevent synthetics */
NTSecurity& operator= (NTSecurity const &);
NTSecurity (NTSecurity const &);
- SIDWrapper everyOneSID, administratorsSID;
-
- void NoteFailedAPI (const std::string &);
+ /* Set POSIX-like permissions on files. The fname is only used for printing
+ log output. The function requires an open HANDLE with sufficient
+ permissions (READ_DAC | WRITE_DAC). */
+ PSECURITY_DESCRIPTOR GetPosixPerms (const char *fname, PSID owner_sid,
+ PSID group_sid, mode_t mode,
+ SECURITY_DESCRIPTOR &out_sd, acl_t &acl);
+ void resetPrimaryGroup();
+ void setAdminGroup ();
+ void initialiseWellKnownSIDs ();
void setDefaultSecurity();
+ bool isRunAsAdmin ();
private:
- void failed (bool const &aBool) { failed_ = aBool; }
- bool const &failed () const { return failed_; }
- void initialiseEveryOneSID ();
+ void NoteFailedAPI (const std::string &);
+ bool wellKnownSIDsinitialized () const { return _wellKnownSIDsinitialized; }
+ void wellKnownSIDsinitialized (bool b) { _wellKnownSIDsinitialized = b; }
void setDefaultDACL ();
- SIDWrapper usid;
- HANDLEWrapper token;
- bool failed_;
+ void setBackupPrivileges ();
+
+ SIDWrapper nullSID, everyOneSID, administratorsSID, usersSID,
+ cr_ownerSID, cr_groupSID;
+ struct {
+ TOKEN_USER user;
+ char buf[MAX_SID_LEN];
+ } ownerSID;
+ PSID groupSID;
struct {
- PSID psid;
+ TOKEN_PRIMARY_GROUP pgrp;
char buf[MAX_SID_LEN];
- } osid;
+ } primaryGroupSID;
+
+ bool _wellKnownSIDsinitialized;
+ HANDLEWrapper token;
DWORD size;
};
extern NTSecurity nt_sec;
+#undef major
+#undef minor
class VersionInfo
{
public:
VersionInfo ();
- bool isNT () { return (v.dwPlatformId == VER_PLATFORM_WIN32_NT); }
DWORD major () const { return v.dwMajorVersion; }
DWORD minor () const { return v.dwMinorVersion; }
+ DWORD buildNumber () const { return v.dwBuildNumber; }
private:
OSVERSIONINFO v;
};
VersionInfo& GetVer ();
-#define IsWindowsNT() (GetVer ().isNT ())
#define OSMajorVersion() (GetVer ().major ())
#define OSMinorVersion() (GetVer ().minor ())
+#define OSBuildNumber() (GetVer ().buildNumber ())
+
+static inline void
+GetDlgItemRect (HWND h, int item, LPRECT r)
+{
+ GetWindowRect (GetDlgItem (h, item), r);
+ MapWindowPoints (HWND_DESKTOP, h, (LPPOINT) r, 2);
+}
+
+static inline void
+SetDlgItemRect (HWND h, int item, LPRECT r)
+{
+ MoveWindow (GetDlgItem (h, item), r->left, r->top,
+ r->right - r->left, r->bottom - r->top, TRUE);
+}
#endif /* SETUP_WIN32_H */