]>
Commit | Line | Data |
---|---|---|
28f540f4 | 1 | /* |
e7fd8a39 | 2 | * svc_auth.c, Server-side rpc authenticator interface. |
28f540f4 | 3 | * |
a7ab6ec8 UD |
4 | * Copyright (c) 2010, Oracle America, Inc. |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are | |
8 | * met: | |
9 | * | |
10 | * * Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | |
12 | * * Redistributions in binary form must reproduce the above | |
13 | * copyright notice, this list of conditions and the following | |
14 | * disclaimer in the documentation and/or other materials | |
15 | * provided with the distribution. | |
16 | * * Neither the name of the "Oracle America, Inc." nor the names of its | |
17 | * contributors may be used to endorse or promote products derived | |
18 | * from this software without specific prior written permission. | |
19 | * | |
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
24 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
25 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | |
27 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28f540f4 RM |
32 | */ |
33 | ||
34 | #include <rpc/rpc.h> | |
e7fd8a39 UD |
35 | #include <rpc/svc.h> |
36 | #include <rpc/svc_auth.h> | |
28f540f4 RM |
37 | |
38 | /* | |
6d52618b UD |
39 | * svcauthsw is the bdevsw of server side authentication. |
40 | * | |
28f540f4 RM |
41 | * Server side authenticators are called from authenticate by |
42 | * using the client auth struct flavor field to index into svcauthsw. | |
6d52618b UD |
43 | * The server auth flavors must implement a routine that looks |
44 | * like: | |
45 | * | |
e7fd8a39 UD |
46 | * enum auth_stat |
47 | * flavorx_auth(rqst, msg) | |
48 | * register struct svc_req *rqst; | |
49 | * register struct rpc_msg *msg; | |
28f540f4 RM |
50 | * |
51 | */ | |
52 | ||
e7fd8a39 UD |
53 | static enum auth_stat _svcauth_null (struct svc_req *, struct rpc_msg *); |
54 | /* no authentication */ | |
55 | extern enum auth_stat _svcauth_unix (struct svc_req *, struct rpc_msg *); | |
56 | /* unix style (uid, gids) */ | |
57 | extern enum auth_stat _svcauth_short (struct svc_req *, struct rpc_msg *); | |
58 | /* short hand unix style */ | |
800d775e UD |
59 | extern enum auth_stat _svcauth_des (struct svc_req *, struct rpc_msg *); |
60 | /* des style */ | |
28f540f4 | 61 | |
e7fd8a39 UD |
62 | static const struct |
63 | { | |
64 | enum auth_stat (*authenticator) (struct svc_req *, struct rpc_msg *); | |
65 | } | |
66 | svcauthsw[] = | |
67 | { | |
68 | { _svcauth_null }, /* AUTH_NULL */ | |
69 | { _svcauth_unix }, /* AUTH_UNIX */ | |
800d775e UD |
70 | { _svcauth_short }, /* AUTH_SHORT */ |
71 | { _svcauth_des } /* AUTH_DES */ | |
28f540f4 | 72 | }; |
800d775e | 73 | #define AUTH_MAX 3 /* HIGHEST AUTH NUMBER */ |
28f540f4 RM |
74 | |
75 | ||
76 | /* | |
77 | * The call rpc message, msg has been obtained from the wire. The msg contains | |
78 | * the raw form of credentials and verifiers. authenticate returns AUTH_OK | |
79 | * if the msg is successfully authenticated. If AUTH_OK then the routine also | |
80 | * does the following things: | |
81 | * set rqst->rq_xprt->verf to the appropriate response verifier; | |
82 | * sets rqst->rq_client_cred to the "cooked" form of the credentials. | |
83 | * | |
6d52618b | 84 | * NB: rqst->rq_cxprt->verf must be pre-allocated; |
28f540f4 RM |
85 | * its length is set appropriately. |
86 | * | |
87 | * The caller still owns and is responsible for msg->u.cmb.cred and | |
88 | * msg->u.cmb.verf. The authentication system retains ownership of | |
89 | * rqst->rq_client_cred, the cooked credentials. | |
90 | * | |
91 | * There is an assumption that any flavour less than AUTH_NULL is | |
92 | * invalid. | |
93 | */ | |
94 | enum auth_stat | |
e7fd8a39 | 95 | _authenticate (register struct svc_req *rqst, struct rpc_msg *msg) |
28f540f4 | 96 | { |
e7fd8a39 | 97 | register int cred_flavor; |
28f540f4 | 98 | |
e7fd8a39 UD |
99 | rqst->rq_cred = msg->rm_call.cb_cred; |
100 | rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor; | |
101 | rqst->rq_xprt->xp_verf.oa_length = 0; | |
102 | cred_flavor = rqst->rq_cred.oa_flavor; | |
103 | if ((cred_flavor <= AUTH_MAX) && (cred_flavor >= AUTH_NULL)) | |
104 | return (*(svcauthsw[cred_flavor].authenticator)) (rqst, msg); | |
28f540f4 | 105 | |
e7fd8a39 | 106 | return AUTH_REJECTEDCRED; |
28f540f4 | 107 | } |
7b57bfe5 | 108 | libc_hidden_nolink (_authenticate, GLIBC_2_1) |
28f540f4 | 109 | |
e7fd8a39 UD |
110 | static enum auth_stat |
111 | _svcauth_null (struct svc_req *rqst, struct rpc_msg *msg) | |
28f540f4 | 112 | { |
e7fd8a39 | 113 | return AUTH_OK; |
28f540f4 | 114 | } |