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 assert(strncmp(pipename, "\\\\.\\pipe\\", 9) == 0);
31 assert(strchr(pipename + 9, '\\') == NULL);
33 pipehandle = CreateFile(pipename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
34 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
36 if (pipehandle == INVALID_HANDLE_VALUE) {
37 err = dupprintf("Unable to open named pipe '%s': %s",
38 pipename, win_strerror(GetLastError()));
39 ret = new_error_socket(err, plug);
44 if ((usersid = get_user_sid()) == NULL) {
45 CloseHandle(pipehandle);
46 err = dupprintf("Unable to get user SID");
47 ret = new_error_socket(err, plug);
52 if (GetSecurityInfo(pipehandle, SE_KERNEL_OBJECT,
53 OWNER_SECURITY_INFORMATION,
54 &pipeowner, NULL, NULL, NULL,
55 &psd) != ERROR_SUCCESS) {
56 err = dupprintf("Unable to get named pipe security information: %s",
57 win_strerror(GetLastError()));
58 ret = new_error_socket(err, plug);
60 CloseHandle(pipehandle);
65 if (!EqualSid(pipeowner, usersid)) {
66 err = dupprintf("Owner of named pipe '%s' is not us", pipename);
67 ret = new_error_socket(err, plug);
69 CloseHandle(pipehandle);
78 return make_handle_socket(pipehandle, pipehandle, plug, TRUE);
81 #endif /* !defined NO_SECURITY */