51303cbd0c
* cygserver.h (CYGWIN_SERVER_VERSION_API): Bump. (request_code_t): Define CYGSERVER_REQUEST_SETPWD request type. * cygserver_msg.h (client_request_msg::retval): Use default value of -1 for retval if msglen is 0. * cygserver_sem.h (client_request_sem::retval): Ditto. * cygserver_shm.h (client_request_shm::retval): Ditto. * cygserver_setpwd.h: New file. * external.cc (cygwin_internal): Implement new CW_SET_PRIV_KEY type. * sec_auth.cc (open_local_policy): Make externally available. Get ACCESS_MASK as argument. (create_token): Accommodate change to open_local_policy. (lsaauth): Ditto. (lsaprivkeyauth): New function fetching token by retrieving password stored in Cygwin or Interix LSA private data area and calling LogonUser with it. * security.h (lsaprivkeyauth): Declare. (open_local_policy): Declare. * setlsapwd.cc: New file implementing setting LSA private data password using LsaStorePrivateData or by calling cygserver if available. * syscalls.cc (seteuid32): Add workaround to get the original token when switching back to the original privileged user, even if setgroups group list is still active. Add long comment to explain why. Call lsaprivkeyauth first, only if that fails call lsaauth or create_token. * include/cygwin/version.h: Bump API minor number. * include/sys/cygwin.h (cygwin_getinfo_types): Add CW_SET_PRIV_KEY.
192 lines
4.4 KiB
C++
192 lines
4.4 KiB
C++
/* cygserver.h
|
|
|
|
Copyright 2001, 2002, 2003, 2004, 2008 Red Hat Inc.
|
|
|
|
Written by Egor Duda <deo@logos-m.ru>
|
|
|
|
This file is part of Cygwin.
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
details. */
|
|
|
|
#ifndef _CYGSERVER_H_
|
|
#define _CYGSERVER_H_
|
|
|
|
#ifdef __GNUC__
|
|
#define CYGSERVER_PACKED __attribute__ ((packed))
|
|
#else
|
|
#define CYGSERVER_PACKED
|
|
#endif
|
|
|
|
#define CYGWIN_SERVER_VERSION_MAJOR 1
|
|
#define CYGWIN_SERVER_VERSION_API 4
|
|
#define CYGWIN_SERVER_VERSION_MINOR 0
|
|
#define CYGWIN_SERVER_VERSION_PATCH 0
|
|
|
|
typedef enum {
|
|
CYGSERVER_UNKNOWN = 0,
|
|
CYGSERVER_OK,
|
|
CYGSERVER_UNAVAIL
|
|
} cygserver_states;
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
* class client_request
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
class transport_layer_base;
|
|
|
|
#ifndef __INSIDE_CYGWIN__
|
|
class process_cache;
|
|
#endif
|
|
|
|
class client_request
|
|
{
|
|
protected:
|
|
typedef enum {
|
|
CYGSERVER_REQUEST_INVALID,
|
|
CYGSERVER_REQUEST_GET_VERSION,
|
|
CYGSERVER_REQUEST_SHUTDOWN,
|
|
CYGSERVER_REQUEST_ATTACH_TTY,
|
|
CYGSERVER_REQUEST_MSG,
|
|
CYGSERVER_REQUEST_SEM,
|
|
CYGSERVER_REQUEST_SHM,
|
|
CYGSERVER_REQUEST_SETPWD,
|
|
CYGSERVER_REQUEST_LAST
|
|
} request_code_t;
|
|
|
|
struct header_t
|
|
{
|
|
size_t msglen;
|
|
union
|
|
{
|
|
request_code_t request_code;
|
|
ssize_t error_code;
|
|
};
|
|
|
|
header_t () {};
|
|
header_t (request_code_t, size_t);
|
|
} CYGSERVER_PACKED;
|
|
|
|
public:
|
|
#ifndef __INSIDE_CYGWIN__
|
|
static void handle_request (transport_layer_base *, process_cache *);
|
|
#endif
|
|
|
|
client_request (request_code_t request_code,
|
|
void *buf = NULL,
|
|
size_t bufsiz = 0);
|
|
virtual ~client_request ();
|
|
|
|
request_code_t request_code () const { return _header.request_code; }
|
|
|
|
ssize_t error_code () const { return _header.error_code; };
|
|
void error_code (ssize_t error_code) { _header.error_code = error_code; };
|
|
|
|
size_t msglen () const { return _header.msglen; };
|
|
void msglen (size_t len) { _header.msglen = len; };
|
|
|
|
int make_request ();
|
|
|
|
protected:
|
|
virtual void send (transport_layer_base *);
|
|
|
|
private:
|
|
header_t _header;
|
|
void * const _buf;
|
|
const size_t _buflen;
|
|
|
|
#ifndef __INSIDE_CYGWIN__
|
|
void handle (transport_layer_base *, process_cache *);
|
|
virtual void serve (transport_layer_base *, process_cache *) = 0;
|
|
#endif
|
|
};
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
* class client_request_get_version
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
class client_request_get_version : public client_request
|
|
{
|
|
private:
|
|
struct request_get_version
|
|
{
|
|
DWORD major, api, minor, patch;
|
|
} CYGSERVER_PACKED;
|
|
|
|
public:
|
|
client_request_get_version ();
|
|
bool check_version () const;
|
|
|
|
private:
|
|
struct request_get_version version;
|
|
|
|
#ifndef __INSIDE_CYGWIN__
|
|
virtual void serve (transport_layer_base *, process_cache *);
|
|
#endif
|
|
};
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
* class client_request_shutdown
|
|
*
|
|
* Nb. This whole class is only !__INSIDE_CYGWIN__ since it is used
|
|
* solely by cygserver itself.
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
#ifndef __INSIDE_CYGWIN__
|
|
|
|
class client_request_shutdown : public client_request
|
|
{
|
|
public:
|
|
client_request_shutdown ();
|
|
|
|
private:
|
|
virtual void serve (transport_layer_base *, process_cache *);
|
|
};
|
|
|
|
#endif /* !__INSIDE_CYGWIN__ */
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
* class client_request_attach_tty
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
class client_request_attach_tty : public client_request
|
|
{
|
|
private:
|
|
struct request_attach_tty
|
|
{
|
|
DWORD pid, master_pid;
|
|
HANDLE from_master, to_master;
|
|
} CYGSERVER_PACKED;
|
|
|
|
public:
|
|
#ifdef __INSIDE_CYGWIN__
|
|
client_request_attach_tty (DWORD nmaster_pid,
|
|
HANDLE nfrom_master, HANDLE nto_master);
|
|
#else
|
|
client_request_attach_tty ();
|
|
#endif
|
|
|
|
HANDLE from_master () const { return req.from_master; };
|
|
HANDLE to_master () const { return req.to_master; };
|
|
|
|
protected:
|
|
virtual void send (transport_layer_base *);
|
|
|
|
private:
|
|
struct request_attach_tty req;
|
|
|
|
#ifndef __INSIDE_CYGWIN__
|
|
virtual void serve (transport_layer_base *, process_cache *);
|
|
#endif
|
|
};
|
|
|
|
#ifndef __INSIDE_CYGWIN__
|
|
extern PSID admininstrator_group_sid;
|
|
#endif
|
|
|
|
extern bool check_cygserver_available ();
|
|
extern void cygserver_init ();
|
|
|
|
#endif /* _CYGSERVER_H_ */
|