]> andersk Git - gssapi-openssh.git/blame - openssh/gss-serv-gsi.c
o Bump version to 2.7.
[gssapi-openssh.git] / openssh / gss-serv-gsi.c
CommitLineData
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
38#include <globus_gss_assist.h>
39
0ef028e1 40static int ssh_gssapi_gsi_userok(ssh_gssapi_client *client, char *name);
41static int ssh_gssapi_gsi_localname(ssh_gssapi_client *client, char **user);
42static void ssh_gssapi_gsi_storecreds(ssh_gssapi_client *client);
43
44ssh_gssapi_mech gssapi_gsi_mech_old = {
45 "N3+k7/4wGxHyuP8Yxi4RhA==",
46 "GSI",
47 {9, "\x2B\x06\x01\x04\x01\x9B\x50\x01\x01"},
48 NULL,
49 &ssh_gssapi_gsi_userok,
50 &ssh_gssapi_gsi_localname,
51 &ssh_gssapi_gsi_storecreds
52};
53
54ssh_gssapi_mech gssapi_gsi_mech = {
55 "dZuIebMjgUqaxvbF7hDbAw==",
56 "GSI",
57 {9, "\x2B\x06\x01\x04\x01\x9B\x50\x01\x01"},
58 NULL,
59 &ssh_gssapi_gsi_userok,
60 &ssh_gssapi_gsi_localname,
61 &ssh_gssapi_gsi_storecreds
62};
63
f4b9ce42 64/*
65 * Check if this user is OK to login under GSI. User has been authenticated
66 * as identity in global 'client_name.value' and is trying to log in as passed
67 * username in 'name'.
68 *
69 * Returns non-zero if user is authorized, 0 otherwise.
70 */
71static int
72ssh_gssapi_gsi_userok(ssh_gssapi_client *client, char *name)
73{
74 int authorized = 0;
75
0ef028e1 76#ifdef GLOBUS_GSI_GSS_ASSIST_MODULE
77 if (globus_module_activate(GLOBUS_GSI_GSS_ASSIST_MODULE) != 0) {
78 return 0;
79 }
80#endif
81
f4b9ce42 82 /* This returns 0 on success */
83 authorized = (globus_gss_assist_userok(client->name.value,
84 name) == 0);
85
0ef028e1 86 log("GSI user %s is%s authorized as target user %s",
87 (char *) client->name.value, (authorized ? "" : " not"), name);
f4b9ce42 88
89 return authorized;
90}
91
92/*
0ef028e1 93 * Return the local username associated with the GSI credentials.
94 */
95int
96ssh_gssapi_gsi_localname(ssh_gssapi_client *client, char **user)
97{
98#ifdef GLOBUS_GSI_GSS_ASSIST_MODULE
99 if (globus_module_activate(GLOBUS_GSI_GSS_ASSIST_MODULE) != 0) {
100 return 0;
101 }
102#endif
103 return(globus_gss_assist_gridmap(client->name.value, user) == 0);
104}
105
106/*
107 * Export GSI credentials to disk.
f4b9ce42 108 */
109static void
110ssh_gssapi_gsi_storecreds(ssh_gssapi_client *client)
111{
112 OM_uint32 major_status;
113 OM_uint32 minor_status;
0ef028e1 114 gss_buffer_desc export_cred = GSS_C_EMPTY_BUFFER;
115 char * p;
f4b9ce42 116
0ef028e1 117 if (!client || !client->creds) {
118 return;
119 }
f4b9ce42 120
0ef028e1 121 major_status = gss_export_cred(&minor_status,
122 client->creds,
123 GSS_C_NO_OID,
124 1,
125 &export_cred);
126 if (GSS_ERROR(major_status) && major_status != GSS_S_UNAVAILABLE) {
127 Gssctxt *ctx;
128 ssh_gssapi_build_ctx(&ctx);
129 ctx->major = major_status;
130 ctx->minor = minor_status;
131 ssh_gssapi_set_oid(ctx, &gssapi_gsi_mech.oid);
132 ssh_gssapi_error(ctx);
133 ssh_gssapi_delete_ctx(&ctx);
134 return;
135 }
136
137 p = strchr((char *) export_cred.value, '=');
138 if (p == NULL) {
139 log("Failed to parse exported credentials string '%.100s'",
140 (char *)export_cred.value);
141 gss_release_buffer(&minor_status, &export_cred);
142 return;
143 }
144 *p++ = '\0';
145 if (strcmp((char *)export_cred.value,"X509_USER_DELEG_PROXY") == 0) {
146 client->store.envvar = strdup("X509_USER_PROXY");
147 } else {
148 client->store.envvar = strdup((char *)export_cred.value);
149 }
150 client->store.envval = strdup(p);
f4b9ce42 151#ifdef USE_PAM
0ef028e1 152 do_pam_putenv(client->store.envvar, client->store.envval);
f4b9ce42 153#endif
0ef028e1 154 if (strncmp(p, "FILE:", 5) == 0) {
155 p += 5;
156 }
157 if (access(p, R_OK) == 0) {
158 client->store.filename = strdup(p);
159 }
160 gss_release_buffer(&minor_status, &export_cred);
f4b9ce42 161}
162
f4b9ce42 163#endif /* GSI */
164#endif /* GSSAPI */
This page took 0.678185 seconds and 5 git commands to generate.