]>
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, | |
373a036f CV |
58 | _parameters.in.ipcblk.winpid, |
59 | _parameters.in.ipcblk.signal_arrived); | |
282113ba CV |
60 | if (!client) |
61 | { | |
62 | error_code (EAGAIN); | |
63 | msglen (0); | |
64 | return; | |
65 | } | |
66 | if (!conn->impersonate_client ()) | |
67 | { | |
68 | client->release (); | |
69 | error_code (EACCES); | |
70 | msglen (0); | |
71 | return; | |
72 | } | |
73 | if (!adjust_identity_info (&_parameters.in.ipcblk)) | |
74 | { | |
1f8b3049 | 75 | client->release (); |
282113ba CV |
76 | conn->revert_to_self (); |
77 | error_code (EACCES); | |
78 | msglen (0); | |
79 | return; | |
80 | } | |
81 | /* Early revert_to_self since IPC code runs in kernel mode. */ | |
82 | conn->revert_to_self (); | |
1f8b3049 CV |
83 | /* sysv_msg.cc takes care of itself. */ |
84 | client->release (); | |
282113ba CV |
85 | thread td = { client, &_parameters.in.ipcblk, {-1, -1} }; |
86 | int res; | |
87 | msgop_t msgop = _parameters.in.msgop; /* Get's overwritten otherwise. */ | |
88 | switch (msgop) | |
89 | { | |
90 | case MSGOP_msgctl: | |
91 | res = msgctl (&td, &_parameters.in.ctlargs); | |
92 | break; | |
93 | case MSGOP_msgget: | |
94 | res = msgget (&td, &_parameters.in.getargs); | |
95 | break; | |
96 | case MSGOP_msgrcv: | |
97 | res = msgrcv (&td, &_parameters.in.rcvargs); | |
98 | break; | |
99 | case MSGOP_msgsnd: | |
100 | res = msgsnd (&td, &_parameters.in.sndargs); | |
101 | break; | |
c026d842 CV |
102 | default: |
103 | res = ENOSYS; | |
104 | td.td_retval[0] = -1; | |
105 | break; | |
282113ba CV |
106 | } |
107 | /* Allocated by the call to adjust_identity_info(). */ | |
108 | if (_parameters.in.ipcblk.gidlist) | |
109 | free (_parameters.in.ipcblk.gidlist); | |
282113ba CV |
110 | error_code (res); |
111 | if (msgop == MSGOP_msgrcv) | |
112 | _parameters.out.rcv = td.td_retval[0]; | |
113 | else | |
114 | _parameters.out.ret = td.td_retval[0]; | |
115 | msglen (sizeof (_parameters.out)); | |
a245bd6e | 116 | } |
282113ba | 117 | #endif /* __OUTSIDE_CYGWIN__ */ |