]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/os/rpcauth.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / programs / Xserver / os / rpcauth.c
1 /* $XConsortium: rpcauth.c,v 1.9 94/04/17 20:27:06 gildea Exp $ */
2 /* $XFree86: xc/programs/Xserver/os/rpcauth.c,v 3.0 1995/07/07 15:46:07 dawes Exp $ */
3 /*
4
5 Copyright (c) 1991  X Consortium
6
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
14
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 OTHER DEALINGS IN THE SOFTWARE.
25
26 Except as contained in this notice, the name of the X Consortium shall
27 not be used in advertising or otherwise to promote the sale, use or
28 other dealings in this Software without prior written authorization
29 from the X Consortium.
30
31 */
32
33 /*
34  * SUN-DES-1 authentication mechanism
35  * Author:  Mayank Choudhary, Sun Microsystems
36  */
37
38
39 #ifdef SECURE_RPC
40
41 #include <stdlib.h>
42 #include "X.h"
43 #include "Xauth.h"
44 #include "misc.h"
45 #include "os.h"
46 #include "dixstruct.h"
47
48 #include <rpc/rpc.h>
49
50 #ifdef ultrix
51 #include <time.h>
52 #include <rpc/auth_des.h>
53 #endif
54
55 static enum auth_stat why;
56
57 static char * 
58 authdes_ezdecode(inmsg, len)
59 char *inmsg;
60 int  len;
61 {
62     struct rpc_msg  msg;
63     char            cred_area[MAX_AUTH_BYTES];
64     char            verf_area[MAX_AUTH_BYTES];
65     char            *temp_inmsg;
66     struct svc_req  r;
67     bool_t          res0, res1;
68     XDR             xdr;
69     SVCXPRT         xprt;
70
71     temp_inmsg = (char *) xalloc(len);
72     memmove(temp_inmsg, inmsg, len);
73
74     memset((char *)&msg, 0, sizeof(msg));
75     memset((char *)&r, 0, sizeof(r));
76     memset(cred_area, 0, sizeof(cred_area));
77     memset(verf_area, 0, sizeof(verf_area));
78
79     msg.rm_call.cb_cred.oa_base = cred_area;
80     msg.rm_call.cb_verf.oa_base = verf_area;
81     why = AUTH_FAILED; 
82     xdrmem_create(&xdr, temp_inmsg, len, XDR_DECODE);
83
84     if ((r.rq_clntcred = (caddr_t) xalloc(MAX_AUTH_BYTES)) == NULL)
85         goto bad1;
86     r.rq_xprt = &xprt;
87
88     /* decode into msg */
89     res0 = xdr_opaque_auth(&xdr, &(msg.rm_call.cb_cred)); 
90     res1 = xdr_opaque_auth(&xdr, &(msg.rm_call.cb_verf));
91     if ( ! (res0 && res1) )
92          goto bad2;
93
94     /* do the authentication */
95
96     r.rq_cred = msg.rm_call.cb_cred;        /* read by opaque stuff */
97     if (r.rq_cred.oa_flavor != AUTH_DES) {
98         why = AUTH_TOOWEAK;
99         goto bad2;
100     }
101 #ifdef SVR4
102     if ((why = __authenticate(&r, &msg)) != AUTH_OK) {
103 #else
104     if ((why = _authenticate(&r, &msg)) != AUTH_OK) {
105 #endif
106             goto bad2;
107     }
108     return (((struct authdes_cred *) r.rq_clntcred)->adc_fullname.name); 
109
110 bad2:
111     xfree(r.rq_clntcred);
112 bad1:
113     return ((char *)0); /* ((struct authdes_cred *) NULL); */
114 }
115
116 static XID  rpc_id = (XID) ~0L;
117
118 static Bool
119 CheckNetName (addr, len, closure)
120     unsigned char    *addr;
121     int             len;
122     pointer         closure;
123 {
124     return (len == strlen ((char *) closure) &&
125             strncmp ((char *) addr, (char *) closure, len) == 0);
126 }
127
128 static char rpc_error[MAXNETNAMELEN+50];
129
130 XID
131 SecureRPCCheck (data_length, data, client, reason)
132     register unsigned short     data_length;
133     char        *data;
134     ClientPtr client;
135     char        **reason;
136 {
137     char *fullname;
138     
139     if (rpc_id == (XID) ~0L) {
140         *reason = "Secure RPC authorization not initialized";
141     } else {
142         fullname = authdes_ezdecode(data, data_length);
143         if (fullname == (char *)0) {
144             sprintf(rpc_error, "Unable to authenticate secure RPC client (why=%d)", why);
145             *reason = rpc_error;
146         } else {
147             if (ForEachHostInFamily (FamilyNetname, CheckNetName,
148                                      (pointer) fullname))
149                 return rpc_id;
150             else {
151                 sprintf(rpc_error, "Principal \"%s\" is not authorized to connect",
152                         fullname);
153                 *reason = rpc_error;
154             }
155         }
156     }
157     return (XID) ~0L;
158 }
159     
160
161 SecureRPCInit ()
162 {
163     if (rpc_id == ~0L)
164         AddAuthorization (9, "SUN-DES-1", 0, (char *) 0);
165 }
166
167 int
168 SecureRPCAdd (data_length, data, id)
169 unsigned short  data_length;
170 char    *data;
171 XID     id;
172 {
173     if (data_length)
174         AddHost ((pointer) 0, FamilyNetname, data_length, data);
175     rpc_id = id;
176 }
177
178 int
179 SecureRPCReset ()
180 {
181     rpc_id = (XID) ~0L;
182 }
183
184 XID
185 SecureRPCToID (data_length, data)
186     unsigned short      data_length;
187     char                *data;
188 {
189     return rpc_id;
190 }
191
192 SecureRPCFromID (id, data_lenp, datap)
193      XID id;
194      unsigned short     *data_lenp;
195      char       **datap;
196 {
197     return 0;
198 }
199
200 SecureRPCRemove (data_length, data)
201      unsigned short     data_length;
202      char       *data;
203 {
204     return 0;
205 }
206 #endif /* SECURE_RPC */