]>
Commit | Line | Data |
---|---|---|
a245bd6e CF |
1 | /* msg.cc: Single unix specification IPC interface for Cygwin. |
2 | ||
61522196 | 3 | Copyright 2003, 2004, 2012 Red Hat, Inc. |
a245bd6e CF |
4 | |
5 | This file is part of Cygwin. | |
6 | ||
7 | This software is a copyrighted work licensed under the terms of the | |
8 | Cygwin license. Please consult the file "CYGWIN_LICENSE" for | |
9 | details. */ | |
10 | ||
282113ba CV |
11 | #ifdef __OUTSIDE_CYGWIN__ |
12 | #include "woutsup.h" | |
a245bd6e | 13 | |
282113ba CV |
14 | #include <errno.h> |
15 | #include <pthread.h> | |
16 | #include <stdio.h> | |
17 | #include <stdlib.h> | |
18 | #include <string.h> | |
19 | #include <time.h> | |
a245bd6e | 20 | |
282113ba CV |
21 | #include "cygserver.h" |
22 | #include "process.h" | |
23 | #include "transport.h" | |
a245bd6e | 24 | |
282113ba CV |
25 | #include "cygserver_ipc.h" |
26 | #include "cygserver_msg.h" | |
a245bd6e | 27 | |
282113ba CV |
28 | client_request_msg::client_request_msg () |
29 | : client_request (CYGSERVER_REQUEST_MSG, | |
30 | &_parameters, sizeof (_parameters)) | |
31 | { | |
a245bd6e CF |
32 | } |
33 | ||
282113ba CV |
34 | void |
35 | client_request_msg::serve (transport_layer_base *const conn, | |
36 | process_cache *const cache) | |
a245bd6e | 37 | { |
282113ba CV |
38 | if (msglen () != sizeof (_parameters.in)) |
39 | { | |
40 | syscall_printf ("bad request body length: expecting %lu bytes, got %lu", | |
41 | sizeof (_parameters), msglen ()); | |
42 | error_code (EINVAL); | |
43 | msglen (0); | |
44 | return; | |
45 | } | |
46 | if (support_msgqueues == TUN_FALSE) | |
47 | { | |
48 | syscall_printf ("Message queue support not started"); | |
49 | error_code (ENOSYS); | |
50 | if (_parameters.in.msgop == MSGOP_msgrcv) | |
51 | _parameters.out.rcv = -1; | |
52 | else | |
53 | _parameters.out.ret = -1; | |
54 | msglen (sizeof (_parameters.out)); | |
55 | return; | |
56 | } | |
57 | process *const client = cache->process (_parameters.in.ipcblk.cygpid, | |
8d8f4036 | 58 | _parameters.in.ipcblk.winpid); |
282113ba CV |
59 | if (!client) |
60 | { | |
61 | error_code (EAGAIN); | |
62 | msglen (0); | |
63 | return; | |
64 | } | |
65 | if (!conn->impersonate_client ()) | |
66 | { | |
67 | client->release (); | |
68 | error_code (EACCES); | |
69 | msglen (0); | |
70 | return; | |
71 | } | |
72 | if (!adjust_identity_info (&_parameters.in.ipcblk)) | |
73 | { | |
1f8b3049 | 74 | client->release (); |
282113ba CV |
75 | conn->revert_to_self (); |
76 | error_code (EACCES); | |
77 | msglen (0); | |
78 | return; | |
79 | } | |
80 | /* Early revert_to_self since IPC code runs in kernel mode. */ | |
81 | conn->revert_to_self (); | |
1f8b3049 CV |
82 | /* sysv_msg.cc takes care of itself. */ |
83 | client->release (); | |
8d8f4036 | 84 | thread td (client, &_parameters.in.ipcblk, true); |
282113ba CV |
85 | int res; |
86 | msgop_t msgop = _parameters.in.msgop; /* Get's overwritten otherwise. */ | |
87 | switch (msgop) | |
88 | { | |
89 | case MSGOP_msgctl: | |
90 | res = msgctl (&td, &_parameters.in.ctlargs); | |
91 | break; | |
92 | case MSGOP_msgget: | |
93 | res = msgget (&td, &_parameters.in.getargs); | |
94 | break; | |
95 | case MSGOP_msgrcv: | |
96 | res = msgrcv (&td, &_parameters.in.rcvargs); | |
97 | break; | |
98 | case MSGOP_msgsnd: | |
99 | res = msgsnd (&td, &_parameters.in.sndargs); | |
100 | break; | |
c026d842 CV |
101 | default: |
102 | res = ENOSYS; | |
103 | td.td_retval[0] = -1; | |
104 | break; | |
282113ba CV |
105 | } |
106 | /* Allocated by the call to adjust_identity_info(). */ | |
107 | if (_parameters.in.ipcblk.gidlist) | |
108 | free (_parameters.in.ipcblk.gidlist); | |
282113ba CV |
109 | error_code (res); |
110 | if (msgop == MSGOP_msgrcv) | |
111 | _parameters.out.rcv = td.td_retval[0]; | |
112 | else | |
113 | _parameters.out.ret = td.td_retval[0]; | |
114 | msglen (sizeof (_parameters.out)); | |
a245bd6e | 115 | } |
282113ba | 116 | #endif /* __OUTSIDE_CYGWIN__ */ |