]>
Commit | Line | Data |
---|---|---|
f4b9ce42 | 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 | ||
3b7a7049 | 38 | extern ServerOptions options; |
39 | ||
f4b9ce42 | 40 | #include <globus_gss_assist.h> |
41 | ||
0ef028e1 | 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 | ||
0ef028e1 | 46 | ssh_gssapi_mech gssapi_gsi_mech = { |
47 | "dZuIebMjgUqaxvbF7hDbAw==", | |
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 | ||
f4b9ce42 | 56 | /* |
57 | * Check if this user is OK to login under GSI. User has been authenticated | |
58 | * as identity in global 'client_name.value' and is trying to log in as passed | |
59 | * username in 'name'. | |
60 | * | |
61 | * Returns non-zero if user is authorized, 0 otherwise. | |
62 | */ | |
63 | static int | |
64 | ssh_gssapi_gsi_userok(ssh_gssapi_client *client, char *name) | |
65 | { | |
66 | int authorized = 0; | |
67 | ||
0ef028e1 | 68 | #ifdef GLOBUS_GSI_GSS_ASSIST_MODULE |
69 | if (globus_module_activate(GLOBUS_GSI_GSS_ASSIST_MODULE) != 0) { | |
70 | return 0; | |
71 | } | |
72 | #endif | |
73 | ||
f4b9ce42 | 74 | /* This returns 0 on success */ |
7cac2b65 | 75 | authorized = (globus_gss_assist_userok(client->displayname.value, |
f4b9ce42 | 76 | name) == 0); |
77 | ||
7cac2b65 | 78 | logit("GSI user %s is%s authorized as target user %s", |
79 | (char *) client->displayname.value, (authorized ? "" : " not"), name); | |
f4b9ce42 | 80 | |
81 | return authorized; | |
82 | } | |
83 | ||
84 | /* | |
0ef028e1 | 85 | * Return the local username associated with the GSI credentials. |
86 | */ | |
87 | int | |
88 | ssh_gssapi_gsi_localname(ssh_gssapi_client *client, char **user) | |
89 | { | |
90 | #ifdef GLOBUS_GSI_GSS_ASSIST_MODULE | |
91 | if (globus_module_activate(GLOBUS_GSI_GSS_ASSIST_MODULE) != 0) { | |
92 | return 0; | |
93 | } | |
94 | #endif | |
7cac2b65 | 95 | return(globus_gss_assist_gridmap(client->displayname.value, user) == 0); |
0ef028e1 | 96 | } |
97 | ||
98 | /* | |
99 | * Export GSI credentials to disk. | |
f4b9ce42 | 100 | */ |
101 | static void | |
102 | ssh_gssapi_gsi_storecreds(ssh_gssapi_client *client) | |
103 | { | |
104 | OM_uint32 major_status; | |
105 | OM_uint32 minor_status; | |
0ef028e1 | 106 | gss_buffer_desc export_cred = GSS_C_EMPTY_BUFFER; |
107 | char * p; | |
f4b9ce42 | 108 | |
0ef028e1 | 109 | if (!client || !client->creds) { |
110 | return; | |
111 | } | |
f4b9ce42 | 112 | |
0ef028e1 | 113 | major_status = gss_export_cred(&minor_status, |
114 | client->creds, | |
115 | GSS_C_NO_OID, | |
116 | 1, | |
117 | &export_cred); | |
118 | if (GSS_ERROR(major_status) && major_status != GSS_S_UNAVAILABLE) { | |
119 | Gssctxt *ctx; | |
120 | ssh_gssapi_build_ctx(&ctx); | |
121 | ctx->major = major_status; | |
122 | ctx->minor = minor_status; | |
123 | ssh_gssapi_set_oid(ctx, &gssapi_gsi_mech.oid); | |
124 | ssh_gssapi_error(ctx); | |
125 | ssh_gssapi_delete_ctx(&ctx); | |
126 | return; | |
127 | } | |
128 | ||
129 | p = strchr((char *) export_cred.value, '='); | |
130 | if (p == NULL) { | |
7cac2b65 | 131 | logit("Failed to parse exported credentials string '%.100s'", |
0ef028e1 | 132 | (char *)export_cred.value); |
133 | gss_release_buffer(&minor_status, &export_cred); | |
134 | return; | |
135 | } | |
136 | *p++ = '\0'; | |
137 | if (strcmp((char *)export_cred.value,"X509_USER_DELEG_PROXY") == 0) { | |
138 | client->store.envvar = strdup("X509_USER_PROXY"); | |
139 | } else { | |
140 | client->store.envvar = strdup((char *)export_cred.value); | |
141 | } | |
142 | client->store.envval = strdup(p); | |
f4b9ce42 | 143 | #ifdef USE_PAM |
308180eb | 144 | if (options.use_pam) |
145 | do_pam_putenv(client->store.envvar, client->store.envval); | |
f4b9ce42 | 146 | #endif |
0ef028e1 | 147 | if (strncmp(p, "FILE:", 5) == 0) { |
148 | p += 5; | |
149 | } | |
150 | if (access(p, R_OK) == 0) { | |
151 | client->store.filename = strdup(p); | |
152 | } | |
153 | gss_release_buffer(&minor_status, &export_cred); | |
f4b9ce42 | 154 | } |
155 | ||
f4b9ce42 | 156 | #endif /* GSI */ |
157 | #endif /* GSSAPI */ |