]> andersk Git - gssapi-openssh.git/blob - openssh/gss-serv-gsi.c
merged OPENSSH_3_8P1_GSSAPI_20040304 to gpt-branch
[gssapi-openssh.git] / openssh / gss-serv-gsi.c
1 /*
2  * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24
25 #include "includes.h"
26
27 #ifdef GSSAPI
28 #ifdef GSI
29
30 #include "auth.h"
31 #include "auth-pam.h"
32 #include "xmalloc.h"
33 #include "log.h"
34 #include "servconf.h"
35
36 #include "ssh-gss.h"
37
38 extern ServerOptions options;
39
40 #include <globus_gss_assist.h>
41
42 static int ssh_gssapi_gsi_userok(ssh_gssapi_client *client, char *name);
43 static int ssh_gssapi_gsi_localname(ssh_gssapi_client *client, char **user);
44 static void ssh_gssapi_gsi_storecreds(ssh_gssapi_client *client);
45
46 ssh_gssapi_mech gssapi_gsi_mech_old = {
47         "N3+k7/4wGxHyuP8Yxi4RhA==",
48         "GSI",
49         {9, "\x2B\x06\x01\x04\x01\x9B\x50\x01\x01"},
50         NULL,
51         &ssh_gssapi_gsi_userok,
52         &ssh_gssapi_gsi_localname,
53         &ssh_gssapi_gsi_storecreds
54 };
55
56 ssh_gssapi_mech gssapi_gsi_mech = {
57         "dZuIebMjgUqaxvbF7hDbAw==",
58         "GSI",
59         {9, "\x2B\x06\x01\x04\x01\x9B\x50\x01\x01"},
60         NULL,
61         &ssh_gssapi_gsi_userok,
62         &ssh_gssapi_gsi_localname,
63         &ssh_gssapi_gsi_storecreds
64 };
65
66 /*
67  * Check if this user is OK to login under GSI. User has been authenticated
68  * as identity in global 'client_name.value' and is trying to log in as passed
69  * username in 'name'.
70  *
71  * Returns non-zero if user is authorized, 0 otherwise.
72  */
73 static int
74 ssh_gssapi_gsi_userok(ssh_gssapi_client *client, char *name)
75 {
76     int authorized = 0;
77     
78 #ifdef GLOBUS_GSI_GSS_ASSIST_MODULE
79     if (globus_module_activate(GLOBUS_GSI_GSS_ASSIST_MODULE) != 0) {
80         return 0;
81     }
82 #endif
83
84     /* This returns 0 on success */
85     authorized = (globus_gss_assist_userok(client->displayname.value,
86                                            name) == 0);
87     
88     logit("GSI user %s is%s authorized as target user %s",
89         (char *) client->displayname.value, (authorized ? "" : " not"), name);
90     
91     return authorized;
92 }
93
94 /*
95  * Return the local username associated with the GSI credentials.
96  */
97 int
98 ssh_gssapi_gsi_localname(ssh_gssapi_client *client, char **user)
99 {
100 #ifdef GLOBUS_GSI_GSS_ASSIST_MODULE
101     if (globus_module_activate(GLOBUS_GSI_GSS_ASSIST_MODULE) != 0) {
102         return 0;
103     }
104 #endif
105     return(globus_gss_assist_gridmap(client->displayname.value, user) == 0);
106 }
107
108 /*
109  * Export GSI credentials to disk.
110  */
111 static void
112 ssh_gssapi_gsi_storecreds(ssh_gssapi_client *client)
113 {
114         OM_uint32       major_status;
115         OM_uint32       minor_status;
116         gss_buffer_desc export_cred = GSS_C_EMPTY_BUFFER;
117         char *          p;
118         
119         if (!client || !client->creds) {
120             return;
121         }
122
123         major_status = gss_export_cred(&minor_status,
124                                        client->creds,
125                                        GSS_C_NO_OID,
126                                        1,
127                                        &export_cred);
128         if (GSS_ERROR(major_status) && major_status != GSS_S_UNAVAILABLE) {
129             Gssctxt *ctx;
130             ssh_gssapi_build_ctx(&ctx);
131             ctx->major = major_status;
132             ctx->minor = minor_status;
133             ssh_gssapi_set_oid(ctx, &gssapi_gsi_mech.oid);
134             ssh_gssapi_error(ctx);
135             ssh_gssapi_delete_ctx(&ctx);
136             return;
137         }
138         
139         p = strchr((char *) export_cred.value, '=');
140         if (p == NULL) {
141             logit("Failed to parse exported credentials string '%.100s'",
142                 (char *)export_cred.value);
143             gss_release_buffer(&minor_status, &export_cred);
144             return;
145         }
146         *p++ = '\0';
147         if (strcmp((char *)export_cred.value,"X509_USER_DELEG_PROXY") == 0) {
148             client->store.envvar = strdup("X509_USER_PROXY");
149         } else {
150             client->store.envvar = strdup((char *)export_cred.value);
151         }
152         client->store.envval = strdup(p);
153 #ifdef USE_PAM
154         if (options.use_pam)
155             do_pam_putenv(client->store.envvar, client->store.envval);
156 #endif
157         if (strncmp(p, "FILE:", 5) == 0) {
158             p += 5;
159         }
160         if (access(p, R_OK) == 0) {
161             client->store.filename = strdup(p);
162         }
163         gss_release_buffer(&minor_status, &export_cred);
164 }
165
166 #endif /* GSI */
167 #endif /* GSSAPI */
This page took 0.048578 seconds and 5 git commands to generate.