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