2 * Windows support module which deals with being a named-pipe client.
8 #define DEFINE_PLUG_METHOD_MACROS
15 #if !defined NO_SECURITY
19 Socket make_handle_socket(HANDLE send_H, HANDLE recv_H, Plug plug,
22 Socket new_named_pipe_client(const char *pipename, Plug plug)
25 PSID usersid, pipeowner;
26 PSECURITY_DESCRIPTOR psd;
30 extern int advapi_initialised;
31 init_advapi(); /* for get_user_sid. FIXME: do better. */
33 assert(strncmp(pipename, "\\\\.\\pipe\\", 9) == 0);
34 assert(strchr(pipename + 9, '\\') == NULL);
36 pipehandle = CreateFile(pipename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
37 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
39 if (pipehandle == INVALID_HANDLE_VALUE) {
40 err = dupprintf("Unable to open named pipe '%s': %s",
41 pipename, win_strerror(GetLastError()));
42 ret = new_error_socket(err, plug);
47 if ((usersid = get_user_sid()) == NULL) {
48 CloseHandle(pipehandle);
49 err = dupprintf("Unable to get user SID");
50 ret = new_error_socket(err, plug);
55 if (GetSecurityInfo(pipehandle, SE_KERNEL_OBJECT,
56 OWNER_SECURITY_INFORMATION,
57 &pipeowner, NULL, NULL, NULL,
58 &psd) != ERROR_SUCCESS) {
59 err = dupprintf("Unable to get named pipe security information: %s",
60 win_strerror(GetLastError()));
61 ret = new_error_socket(err, plug);
63 CloseHandle(pipehandle);
68 if (!EqualSid(pipeowner, usersid)) {
69 err = dupprintf("Owner of named pipe '%s' is not us", pipename);
70 ret = new_error_socket(err, plug);
72 CloseHandle(pipehandle);
81 return make_handle_socket(pipehandle, pipehandle, plug, TRUE);
84 #endif /* !defined NO_SECURITY */