2
* Copyright 1999-2006 University of Chicago
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
#ifndef GLOBUS_DONT_DOCUMENT_INTERNAL
20
* GSSAPI module activation code
22
* $RCSfile: gridmap.c,v $
23
* $Revision: 1.23.4.1 $
28
#include "globus_i_gss_assist.h"
29
#include "globus_gsi_system_config.h"
30
#include "globus_gsi_cert_utils.h"
31
#include "globus_callout.h"
35
typedef struct _gridmap_line_s {
38
} globus_i_gss_assist_gridmap_line_t;
40
#define WHITESPACE_CHARS " \t\n"
41
#define QUOTING_CHARS "\""
42
#define ESCAPING_CHARS "\\"
43
#define COMMENT_CHARS "#"
44
/* Characters seperating user ids in the gridmap file */
45
#define USERID_SEP_CHARS ","
47
* Characters that terminate a user id in the gridmap file. This
48
* is a combination of whitespace and seperators.
50
#define USERID_TERMINATOR_CHARS USERID_SEP_CHARS WHITESPACE_CHARS
56
#define GLOBUS_GENERIC_MAPPING_TYPE "globus_mapping"
57
#define GLOBUS_GENERIC_AUTHZ_TYPE "globus_authorization"
60
* Number of user id slots to allocate at a time
61
* Arbitraty value, but must be >= 2.
63
#define USERID_CHUNK_SIZE 4
65
#ifndef GLOBUS_DONT_DOCUMENT_INTERNAL
69
globus_i_gss_assist_gridmap_find_dn(
70
const char * const dn,
71
globus_i_gss_assist_gridmap_line_t **
76
globus_i_gss_assist_gridmap_find_local_user(
77
const char * const local_user,
78
globus_i_gss_assist_gridmap_line_t **
83
globus_i_gss_assist_gridmap_parse_line(
85
globus_i_gss_assist_gridmap_line_t **
89
globus_i_gss_assist_gridmap_line_free(
90
globus_i_gss_assist_gridmap_line_t *
95
globus_i_gss_assist_gridmap_parse_globusid(
100
globus_i_gss_assist_xdigit_to_value(
105
globus_l_gss_assist_gridmap_lookup(
106
gss_ctx_id_t context,
108
char * desired_identity,
109
char * identity_buffer,
110
unsigned int identity_buffer_length);
120
* @ingroup globus_gsi_gss_assist
122
* Routines callable from globus based code to
123
* map a globusID to a local unix user
125
* GRIDMAP environment variable pointing at the
126
* map file. Defaults to ~/.gridmap
128
* A gridmap file is required if being run as root.
129
* if being run as a user,it is not required, and defaults to
130
* the current user who is running the command.
132
* This is the same file used by the gssapi_cleartext
133
* but will be used with other gssapi implementations which
134
* do not use the gridmap file.
137
* the GSSAPI name from the client who requested
140
* the resulting user ID name for the local system
144
* -1 if bad arguments
148
globus_gss_assist_gridmap(
152
globus_result_t result = GLOBUS_SUCCESS;
153
globus_i_gss_assist_gridmap_line_t *
156
static char * _function_name_ =
157
"globus_gss_assist_gridmap";
158
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_ENTER;
160
/* Check arguments */
161
if ((globusidp == NULL) || (useridp == NULL))
163
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
165
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_ARGUMENTS,
166
(_GASL("Params passed to function are NULL")));
172
result = globus_i_gss_assist_gridmap_find_dn(globusidp, &gline);
173
if(result != GLOBUS_SUCCESS)
175
GLOBUS_GSI_GSS_ASSIST_ERROR_CHAIN_RESULT(
177
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP);
183
if ((gline->user_ids == NULL) ||
184
(gline->user_ids[0] == NULL))
187
* If we get here then something in this code is broken
188
* or the gridmap file is badly formatted or, most likely,
191
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
193
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP,
194
(_GASL("Invalid (NULL) user id values")));
198
/* First user id is default */
199
*useridp = strdup(gline->user_ids[0]);
201
globus_i_gss_assist_gridmap_line_free(gline);
203
if (*useridp == NULL)
205
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
207
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP,
208
(_GASL("Duplicate string operation failed")));
214
char * gridmap_filename = NULL;
216
GLOBUS_GSI_SYSCONFIG_GET_GRIDMAP_FILENAME(&gridmap_filename);
218
/* No entry found in gridmap file for this user */
219
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
221
GLOBUS_GSI_GSS_ASSIST_ERROR_IN_GRIDMAP_NO_USER_ENTRY,
222
(_GASL("The DN: %s could not be mapped to a valid user in the "
223
"gridmap file: %s."),
225
gridmap_filename != NULL ? gridmap_filename : "(NULL)"));
227
free(gridmap_filename);
233
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_EXIT;
234
if(result == GLOBUS_SUCCESS)
240
globus_object_t * error_obj;
241
error_obj = globus_error_get(result);
242
globus_object_free(error_obj);
247
/* globus_gss_assist_gridmap() */
255
* @ingroup globus_gsi_gss_assist
256
* Check to see if a particular globusid is authorized to access
257
* the given local user account.
260
* the globus id in string form - this should be the user's subject
262
* the local account that access is sought for
265
* 0 on success (authorization allowed)
266
* -1 if bad arguments
270
globus_gss_assist_userok(
274
char * gridmap_filename = NULL;
275
globus_result_t result = GLOBUS_SUCCESS;
276
globus_i_gss_assist_gridmap_line_t *
279
static char * _function_name_ =
280
"globus_gss_assist_userok";
281
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_ENTER;
283
/* Check arguments */
284
if ((globusid == NULL) ||
287
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
289
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_ARGUMENTS,
290
(_GASL("Arguments passed to function are NULL")));
294
result = globus_i_gss_assist_gridmap_find_dn(globusid, &gline);
295
if(result != GLOBUS_SUCCESS)
297
GLOBUS_GSI_GSS_ASSIST_ERROR_CHAIN_RESULT(
299
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP);
305
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
307
GLOBUS_GSI_GSS_ASSIST_ERROR_IN_GRIDMAP_NO_USER_ENTRY,
308
(_GASL("The DN: %s does not map to the username: %s"),
313
if (gline->user_ids == NULL)
315
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
317
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP,
318
(_GASL("The gridmap is malformated. No user id's could be be found.")));
322
for (useridp = gline->user_ids; *useridp != NULL; useridp++)
324
if (strcmp(*useridp, userid) == 0)
330
GLOBUS_GSI_SYSCONFIG_GET_GRIDMAP_FILENAME(&gridmap_filename);
331
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
333
GLOBUS_GSI_GSS_ASSIST_ERROR_USER_ID_DOESNT_MATCH,
334
(_GASL("The user id: %s, doesn't match the the DN: %s, in the "
338
gridmap_filename != NULL ? gridmap_filename : "(NULL)"));
339
free(gridmap_filename);
345
globus_i_gss_assist_gridmap_line_free(gline);
348
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_EXIT;
349
if(result == GLOBUS_SUCCESS)
355
globus_object_t * error_obj;
356
error_obj = globus_error_get(result);
357
globus_object_free(error_obj);
362
/* globus_gss_assist_userok() */
366
* @name Map Local User
370
* @ingroup globus_gsi_gss_assist
371
* Routine for returning the default globus ID associated with
372
* a local user name. This is somewhat of a hack since there is
373
* not a guarenteed one-to-one mapping. What we do is look for
374
* the first entry in the gridmap file that has the local
375
* user as the default login. If the user is not a default on any
376
* entry, we find the first entry in which the user exists as a
380
* the local username to find the DN for
382
* the first DN found that reverse maps from the local_user
385
* 0 on success, otherwise an error object identifier is returned.
386
* use globus_error_get to get the error object from the id. The
387
* resulting error object must be freed using globus_object_free
388
* when it is no longer needed.
390
* @see globus_error_get
391
* @see globus_object_free
394
globus_gss_assist_map_local_user(
398
char * gridmap_filename = NULL;
399
globus_result_t result = GLOBUS_SUCCESS;
400
globus_i_gss_assist_gridmap_line_t *
402
static char * _function_name_ =
403
"globus_gss_assist_map_local_user";
404
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_ENTER;
406
/* Check arguments */
407
if ((local_user == NULL) ||
410
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
412
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_ARGUMENTS,
413
(_GASL("Arguments passed to the function are NULL.")));
419
result = globus_i_gss_assist_gridmap_find_local_user(local_user, &gline);
420
if(result != GLOBUS_SUCCESS)
423
* We failed to open the gridmap file.
425
GLOBUS_GSI_GSS_ASSIST_ERROR_CHAIN_RESULT(
427
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP);
433
if (gline->dn == NULL)
435
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
437
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP,
438
(_GASL("The gridmap file: %s is formatted incorrectly. No "
439
"distinguished names could be found.")));
443
/* First user id is default */
444
*globusidp = strdup(gline->dn);
446
if (*globusidp == NULL)
448
/* strdup() failed */
449
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
451
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP,
452
(_GASL("The string duplication operation failed.")));
458
GLOBUS_GSI_SYSCONFIG_GET_GRIDMAP_FILENAME(&gridmap_filename);
459
/* No entry found in gridmap file for this user */
460
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
462
GLOBUS_GSI_GSS_ASSIST_ERROR_IN_GRIDMAP_NO_USER_ENTRY,
463
(_GASL("No DN entry found for user: %s in gridmap file: %s"),
465
gridmap_filename != NULL ? gridmap_filename : "(NULL)"));
466
free(gridmap_filename);
474
globus_i_gss_assist_gridmap_line_free(gline);
477
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_EXIT;
478
if(result == GLOBUS_SUCCESS)
484
globus_object_t * error_obj;
485
error_obj = globus_error_get(result);
486
globus_object_free(error_obj);
491
/* globus_gss_assist_map_local_user() */
494
#ifndef GLOBUS_DONT_DOCUMENT_INTERNAL
497
* @name Gridmap Find DN
501
* @ingroup globus_i_gsi_gss_assist
502
* Locate the entry for the given DN in the default gridmap file
505
* the distinguished name to search for
507
* gives the line information
510
* 0 on success, otherwise an error object identifier is returned.
511
* use globus_error_get to get the error object from the id. The
512
* resulting error object must be freed using globus_object_free
513
* when it is no longer needed.
515
* @see globus_error_get
516
* @see globus_object_free
520
globus_i_gss_assist_gridmap_find_dn(
521
const char * const dn,
522
globus_i_gss_assist_gridmap_line_t **
525
char * gridmap_filename = NULL;
526
globus_result_t result = GLOBUS_SUCCESS;
527
char * open_mode = "r";
528
FILE * gmap_stream = NULL;
530
globus_i_gss_assist_gridmap_line_t *
532
static char * _function_name_ =
533
"globus_i_gss_assist_gridmap_find_dn";
534
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_ENTER;
537
/* Check arguments */
540
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
542
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_ARGUMENTS,
543
(_GASL("The DN passed to function is NULL.")));
547
result = GLOBUS_GSI_SYSCONFIG_GET_GRIDMAP_FILENAME(&gridmap_filename);
548
if(result != GLOBUS_SUCCESS)
550
gridmap_filename = NULL;
551
GLOBUS_GSI_GSS_ASSIST_ERROR_CHAIN_RESULT(
553
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP);
557
gmap_stream = fopen(gridmap_filename, open_mode);
559
if (gmap_stream == NULL)
561
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
563
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP,
564
(_GASL("Couldn't open gridmap file: %s for reading."),
569
free(gridmap_filename);
570
gridmap_filename = NULL;
576
if (fgets(line, sizeof(line), gmap_stream) == NULL)
578
break; /* EOF or error */
581
result = globus_i_gss_assist_gridmap_parse_line(line, &gline_tmp);
582
if (result != GLOBUS_SUCCESS)
584
GLOBUS_GSI_GSS_ASSIST_ERROR_CHAIN_RESULT(
586
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP);
587
continue; /* Parse error */
590
if ((gline_tmp != NULL) &&
591
(globus_i_gsi_cert_utils_dn_cmp(dn, gline_tmp->dn) == 0))
597
globus_i_gss_assist_gridmap_line_free(gline_tmp);
616
if (gridmap_filename != NULL)
618
free(gridmap_filename);
621
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_EXIT;
624
/* gridmap_find_dn() */
628
* @name Find Local User
632
* @ingroup globus_i_gsi_gss_assist
633
* Locate the first entry with the given local user as the default in the
634
* default gridmap file. If the user is not a default on any entry, locate the
635
* first entry in which the user exists as a secondary mapping.
638
* the name to search for
640
* the resulting gridmap_line_t contianing the user and DN information
643
* 0 on success, otherwise an error object identifier is returned.
644
* use globus_error_get to get the error object from the id. The
645
* resulting error object must be freed using globus_object_free
646
* when it is no longer needed.
648
* @see globus_error_get
649
* @see globus_object_free
653
globus_i_gss_assist_gridmap_find_local_user(
654
const char * const local_user,
655
globus_i_gss_assist_gridmap_line_t **
658
char * gridmap_filename = NULL;
659
char * open_mode = "r";
660
FILE * gmap_stream = NULL;
662
globus_i_gss_assist_gridmap_line_t *
665
char * nondefault_line = NULL;
666
globus_result_t result = GLOBUS_SUCCESS;
667
static char * _function_name_ =
668
"globus_i_gss_assist_gridmap_find_local_user";
669
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_ENTER;
671
/* Check arguments */
672
if (local_user == NULL)
674
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
676
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_ARGUMENTS,
677
(_GASL("Arguments passed to function are NULL.")));
681
result = GLOBUS_GSI_SYSCONFIG_GET_GRIDMAP_FILENAME(&gridmap_filename);
682
if(result != GLOBUS_SUCCESS)
684
gridmap_filename = NULL;
685
GLOBUS_GSI_GSS_ASSIST_ERROR_CHAIN_RESULT(
687
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP);
691
gmap_stream = fopen(gridmap_filename, open_mode);
693
if (gmap_stream == NULL)
695
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
697
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP,
698
(_GASL("Can't open the file: %s"), gridmap_filename));
705
char save_line[1024];
707
if (fgets(line, sizeof(line), gmap_stream) == NULL)
709
break; /* EOF or error */
712
strncpy(save_line, line, sizeof(save_line));
714
result = globus_i_gss_assist_gridmap_parse_line(line, &gline_tmp);
715
if(result != GLOBUS_SUCCESS)
717
continue; /* Parse error */
720
if (gline_tmp == NULL)
726
for(useridp = gline_tmp->user_ids;
727
*useridp != NULL && !found;
730
if(strcmp(local_user, *useridp) == 0)
732
/* check all names, but only stop looking if we match a
733
* default name. save the first nondefault match til
734
* we've checked all the defaults */
735
if(*useridp == gline_tmp->user_ids[0])
739
else if(nondefault_line == NULL)
741
nondefault_line = strdup(save_line);
747
globus_i_gss_assist_gridmap_line_free(gline_tmp);
752
if(nondefault_line != NULL)
754
result = globus_i_gss_assist_gridmap_parse_line(
755
nondefault_line, &gline_tmp);
756
free(nondefault_line);
757
if(result != GLOBUS_SUCCESS)
774
if (gridmap_filename)
776
free(gridmap_filename);
782
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_EXIT;
785
/* gridmap_find_local_user() */
789
* @name Gridmap Parse Line
793
* @ingroup globus_i_gsi_gss_assist
795
* Given a line from the gridmap file, parse it returning
796
* a gridmap_line_t structure. line is modified during parsing.
797
* The format of the line is expected to be:
798
* <DN> <userid>[,<userid>[,<userid>...]]
799
* Leading and trailing whitespace is ignored.
800
* userids must only have a comma between them, no whitespace.
801
* Anything after the userids is ignored.
802
* Anything after an unescaped comment character is ignored.
807
* the resulting parsed gridmap line structure
810
* 0 on success, otherwise an error object identifier is returned.
811
* use globus_error_get to get the error object from the id. The
812
* resulting error object must be freed using globus_object_free
813
* when it is no longer needed.
815
* @see globus_error_get
816
* @see globus_object_free
820
globus_i_gss_assist_gridmap_parse_line(
822
globus_i_gss_assist_gridmap_line_t **
826
char * parsed_dn = NULL;
827
char ** userids = NULL;
829
int userid_slots = 0;
830
globus_i_gss_assist_gridmap_line_t *
832
globus_result_t result = GLOBUS_SUCCESS;
833
static char * _function_name_ =
834
"globus_i_gss_assist_gridmap_parse_line";
835
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_ENTER;
837
/* Check arguments */
838
if ((line == NULL) ||
841
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
843
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP,
844
(_GASL("Arguments passed to function are NULL.")));
848
/* Skip over leading whitespace */
849
line += strspn(line, WHITESPACE_CHARS);
851
/* Check for comment at start of line and ignore line if present */
852
if (strchr(COMMENT_CHARS, *line) != NULL)
854
/* Ignore line, return NULL gline */
859
/* Check for empty line */
862
/* Empty line, return NULL gline. */
868
if (strchr(QUOTING_CHARS, *line) != NULL)
871
* Yes, skip over opening quote and look for unescaped
872
* closing double quote
879
/* If loop below resolves bug 4979 */
880
if (strchr(ESCAPING_CHARS, *(dn_end - 1)))
885
dn_end += strcspn(dn_end, QUOTING_CHARS);
889
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
891
GLOBUS_GSI_GSS_ASSIST_ERROR_INVALID_GRIDMAP_FORMAT,
892
(_GASL("A closing quote is missing in the gridmap file, "
893
"on the line:\n%s\n"),
898
/* Make sure it's not escaped */
900
while (strchr(ESCAPING_CHARS, *(dn_end - 1)) != NULL);
904
/* No, just find next whitespace */
905
dn_end = line + strcspn(line, WHITESPACE_CHARS);
909
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
911
GLOBUS_GSI_GSS_ASSIST_ERROR_INVALID_GRIDMAP_FORMAT,
912
(_GASL("Nothing follows the DN on the line:\n%s\n"),
918
/* NUL terminate DN and parse */
921
result = globus_i_gss_assist_gridmap_parse_globusid(line, &parsed_dn);
922
if(result != GLOBUS_SUCCESS)
924
GLOBUS_GSI_GSS_ASSIST_ERROR_CHAIN_RESULT(
926
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP);
930
/* Skip over closing delim and any whitespace after DN */
932
line += strspn(line, WHITESPACE_CHARS);
934
/* Parse list of unix user ID seperated by USERID_SEP_CHARS */
939
/* Find end of this userid */
940
userid_len = strcspn(line, USERID_TERMINATOR_CHARS);
942
/* Make sure we have a slot and if not allocate it */
943
if ((num_userids + 1 /* new entry */+ 1 /* for NULL */) > userid_slots)
946
userid_slots += USERID_CHUNK_SIZE;
947
userids_tmp = realloc(userids, userid_slots * sizeof(char *));
951
result = globus_error_put(globus_error_wrap_errno_error(
952
GLOBUS_GSI_GSS_ASSIST_MODULE,
954
GLOBUS_GSI_GSS_ASSIST_ERROR_ERRNO,
958
_GASL("Could not allocate enough memory")));
962
userids = userids_tmp;
965
userids[num_userids] = malloc(userid_len + 1 /* for NUL */);
967
if (!userids[num_userids])
969
result = globus_error_put(globus_error_wrap_errno_error(
970
GLOBUS_GSI_GSS_ASSIST_MODULE,
972
GLOBUS_GSI_GSS_ASSIST_ERROR_ERRNO,
976
_GASL("Could not allocate enough memory")));
980
strncpy(userids[num_userids], line, userid_len);
981
userids[num_userids][userid_len] = NUL;
984
userids[num_userids] = NULL;
987
line += strspn(line, USERID_TERMINATOR_CHARS);
990
/* Ok, build our gridmap_line_t structure */
991
gline_tmp = malloc(sizeof(*gline_tmp));
993
if (gline_tmp == NULL)
995
result = globus_error_put(globus_error_wrap_errno_error(
996
GLOBUS_GSI_GSS_ASSIST_MODULE,
998
GLOBUS_GSI_GSS_ASSIST_ERROR_ERRNO,
1002
_GASL("Could not allocate enough memory")));
1006
gline_tmp->dn = parsed_dn;
1007
gline_tmp->user_ids = userids;
1022
char **userids_tmp = userids;
1024
while (*userids_tmp != NULL)
1026
free(*userids_tmp++);
1034
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_EXIT;
1037
/* gridmap_parse_line() */
1041
* @name globus_i_gsi_gss_assist
1045
* @ingroup globus_i_gsi_gss_assist
1046
* Frees all memory allocated to a gridmap_line_t structure.
1049
* pointer to structure to be freed.
1056
globus_i_gss_assist_gridmap_line_free(
1057
globus_i_gss_assist_gridmap_line_t *
1060
static char * _function_name_ =
1061
"globus_i_gss_assist_gridmap_line_free";
1062
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_ENTER;
1066
if (gline->dn != NULL)
1071
if (gline->user_ids != NULL)
1073
char ** userids_tmp = gline->user_ids;
1075
while (*userids_tmp != NULL)
1077
free(*userids_tmp++);
1080
free(gline->user_ids);
1086
/* gridmap_free_gridmap_line() */
1090
* @name Gridmap Parse Globusid
1094
* @ingroup globus_i_gsi_gss_assist
1095
* Given a pointer to a string containing the globusid from the
1096
* gridmap file, return a pointer to a string containing the
1097
* parsed from of the id.
1099
* Specifically handle backslashed characters - e.g. '\\',
1103
* the unparsed globusid
1105
* the resulting parsed string - this should be freed when
1108
* 0 on success, otherwise an error object identifier is returned.
1109
* use globus_error_get to get the error object from the id. The
1110
* resulting error object must be freed using globus_object_free
1111
* when it is no longer needed.
1113
* @see globus_error_get
1114
* @see globus_object_free
1118
globus_i_gss_assist_gridmap_parse_globusid(
1119
const char * unparsed,
1122
/* Is the current character escaped? (Previous char was backslash) */
1125
/* Buffer we are putting resulting name into */
1126
char * buffer = NULL;
1128
/* Buffer's length in bytes */
1131
/* And our current position in buffer */
1132
int buffer_index = 0;
1134
/* Character we're currently looking at */
1137
globus_result_t result = GLOBUS_SUCCESS;
1138
static char * _function_name_ =
1139
"globus_i_gss_assist_gridmap_parse_globusid";
1140
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_ENTER;
1143
* Check input parameters for legality
1145
if ((unparsed == NULL) ||
1148
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
1150
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_ARGUMENTS,
1151
(_GASL("Arguments passed to function are NULL.")));
1155
buffer_len = strlen(unparsed);
1156
buffer = malloc(buffer_len);
1160
globus_error_put(globus_error_wrap_errno_error(
1161
GLOBUS_GSI_GSS_ASSIST_MODULE,
1163
GLOBUS_GSI_GSS_ASSIST_ERROR_ERRNO,
1167
_GASL("Could not allocate enough memory")));
1172
* Walk through the name, parsing as we go
1174
while ((unparsed_char = *(unparsed++)) != NUL)
1176
/* Unescaped backslash */
1177
if (strchr(ESCAPING_CHARS, unparsed_char) && !escaped)
1183
/* Escaped hex character - e.g. '\xfe' */
1184
if ((unparsed_char == 'x') && escaped)
1186
if (isxdigit(*unparsed) &&
1187
isxdigit(*(unparsed + 1)))
1189
/* Set unparsed_char to value represented by hex value */
1191
(globus_i_gss_assist_xdigit_to_value(*unparsed) << 4) +
1192
globus_i_gss_assist_xdigit_to_value(*(unparsed + 1));
1196
/* else just fall through */
1200
* Ok, we now have the character in unparsed_char to be appended
1201
* to our output string.
1203
* First, make sure we have enough room in our output buffer.
1206
if ((buffer_index + 1 /* for NUL */) >= buffer_len)
1213
tmp_buffer = realloc(buffer, buffer_len);
1215
if (tmp_buffer == NULL)
1218
globus_error_put(globus_error_wrap_errno_error(
1219
GLOBUS_GSI_GSS_ASSIST_MODULE,
1221
GLOBUS_GSI_GSS_ASSIST_ERROR_ERRNO,
1225
_GASL("Could not allocate enough memory")));
1229
buffer = tmp_buffer;
1232
buffer[buffer_index++] = unparsed_char;
1233
buffer[buffer_index] = NUL;
1238
/* XXX What if escaped == 1 here? */
1245
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_EXIT;
1248
/* gridmap_parse_globusid() */
1252
* @name Hexadecimal Digit to Integer
1256
* @ingroup globus_i_gsi_gss_assist
1257
* Convert an ascii character representing a hexadecimal digit
1261
* character contianing the hexidecimal digit
1264
* the value in the xdigit, or -1 if error
1267
globus_i_gss_assist_xdigit_to_value(
1270
if ((xdigit >= '0') && (xdigit <= '9'))
1271
return (xdigit - '0');
1273
if ((xdigit >= 'a') && (xdigit <= 'f'))
1274
return (xdigit - 'a' + 0xa);
1276
if ((xdigit >= 'A') && (xdigit <= 'F'))
1277
return (xdigit - 'A' + 0xa);
1282
/* xdigit_to_value() */
1285
#endif /* GLOBUS_DONT_DOCUMENT_INTERNAL */
1289
* @ingroup globus_i_gsi_gss_assist
1290
* Look up all globus ids associated with a given user id.
1293
* The local username on which we are preforming the lookup.
1296
* a pointer to an array of strings. On entrance it should be
1297
* unitialized. Upon return from this function it will point
1298
* to an array of strings. The user should use the macro
1299
* GlobusGssAssistFreeDNArray to clean up this memory.
1302
* The number of globus_ids returned in dns.
1305
* the value in the xdigit, or -1 if error
1308
globus_gss_assist_lookup_all_globusid(
1317
globus_i_gss_assist_gridmap_line_t * gline;
1318
char * gridmap_filename = NULL;
1319
globus_result_t res = GLOBUS_SUCCESS;
1320
FILE * gmap_stream = NULL;
1321
static char * _function_name_ =
1322
"globus_gss_assist_lookup_all_globusid";
1324
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_ENTER;
1326
/* Check arguments */
1331
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
1333
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_ARGUMENTS,
1334
(_GASL("An argument passed to function is NULL.")));
1339
res = GLOBUS_GSI_SYSCONFIG_GET_GRIDMAP_FILENAME(&gridmap_filename);
1340
if(res != GLOBUS_SUCCESS)
1342
gridmap_filename = NULL;
1343
GLOBUS_GSI_GSS_ASSIST_ERROR_CHAIN_RESULT(
1345
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP);
1350
gmap_stream = fopen(gridmap_filename, "r");
1352
if (gmap_stream == NULL)
1354
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
1356
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_GRIDMAP,
1357
(_GASL("Couldn't open gridmap file: %s for reading."),
1364
l_dns = (char **)globus_malloc(sizeof(char *) * max_ndx);
1366
while(fgets(line, sizeof(line), gmap_stream) != NULL)
1368
res = globus_i_gss_assist_gridmap_parse_line(line, &gline);
1370
if(res == GLOBUS_SUCCESS &&
1372
gline->user_ids != NULL &&
1373
gline->user_ids[0] != NULL)
1375
if(strcmp(gline->user_ids[0], username) == 0)
1377
l_dns[ndx] = strdup(gline->dn);
1382
l_dns = (char **)globus_libc_realloc(l_dns,
1383
sizeof(char *) * max_ndx);
1392
fclose(gmap_stream);
1397
if(gridmap_filename != NULL)
1399
free(gridmap_filename);
1402
GLOBUS_I_GSI_GSS_ASSIST_DEBUG_EXIT;
1406
/* globus_gss_assist_lookup_all_globusid() */
1410
globus_gss_assist_map_and_authorize(
1411
gss_ctx_id_t context,
1413
char * desired_identity,
1414
char * identity_buffer,
1415
unsigned int identity_buffer_length)
1417
globus_object_t * error;
1418
globus_result_t result = GLOBUS_SUCCESS;
1419
static globus_bool_t initialized = GLOBUS_FALSE;
1420
static globus_callout_handle_t authz_handle = NULL;
1422
static char * _function_name_ =
1423
"globus_gss_assist_map_and_authorize";
1425
globus_mutex_lock(&globus_i_gsi_gss_assist_mutex);
1427
if(initialized == GLOBUS_FALSE)
1430
result = GLOBUS_GSI_SYSCONFIG_GET_AUTHZ_CONF_FILENAME(&filename);
1432
if(result != GLOBUS_SUCCESS)
1434
error = globus_error_get(result);
1436
if(globus_error_match(
1438
GLOBUS_GSI_SYSCONFIG_MODULE,
1439
GLOBUS_GSI_SYSCONFIG_ERROR_GETTING_AUTHZ_FILENAME)
1442
globus_object_free(error);
1446
result = globus_error_put(error);
1447
globus_mutex_unlock(&globus_i_gsi_gss_assist_mutex);
1453
result = globus_callout_handle_init(&authz_handle);
1455
if(result != GLOBUS_SUCCESS)
1458
GLOBUS_GSI_GSS_ASSIST_ERROR_CHAIN_RESULT(
1460
GLOBUS_GSI_GSS_ASSIST_ERROR_WITH_CALLOUT_CONFIG);
1461
globus_mutex_unlock(&globus_i_gsi_gss_assist_mutex);
1465
result = globus_callout_read_config(authz_handle, filename);
1469
if(result != GLOBUS_SUCCESS)
1471
GLOBUS_GSI_GSS_ASSIST_ERROR_CHAIN_RESULT(
1473
GLOBUS_GSI_GSS_ASSIST_ERROR_INITIALIZING_CALLOUT_HANDLE);
1474
globus_callout_handle_destroy(authz_handle);
1475
globus_mutex_unlock(&globus_i_gsi_gss_assist_mutex);
1479
initialized = GLOBUS_TRUE;
1482
globus_mutex_unlock(&globus_i_gsi_gss_assist_mutex);
1485
if(authz_handle == NULL)
1487
return globus_l_gss_assist_gridmap_lookup(
1492
identity_buffer_length);
1496
result = globus_callout_call_type(authz_handle,
1497
GLOBUS_GENERIC_MAPPING_TYPE,
1502
identity_buffer_length);
1504
if(result != GLOBUS_SUCCESS)
1506
error = globus_error_get(result);
1508
if(globus_error_match(
1510
GLOBUS_CALLOUT_MODULE,
1511
GLOBUS_CALLOUT_ERROR_TYPE_NOT_REGISTERED)
1514
globus_object_free(error);
1515
result = globus_l_gss_assist_gridmap_lookup(
1520
identity_buffer_length);
1525
result = globus_error_put(error);
1526
GLOBUS_GSI_GSS_ASSIST_ERROR_CHAIN_RESULT(
1528
GLOBUS_GSI_GSS_ASSIST_CALLOUT_ERROR);
1533
result = globus_callout_call_type(authz_handle,
1534
GLOBUS_GENERIC_AUTHZ_TYPE,
1537
if(result != GLOBUS_SUCCESS)
1539
error = globus_error_get(result);
1541
if(globus_error_match(
1543
GLOBUS_CALLOUT_MODULE,
1544
GLOBUS_CALLOUT_ERROR_TYPE_NOT_REGISTERED)
1547
result = globus_error_put(error);
1548
GLOBUS_GSI_GSS_ASSIST_ERROR_CHAIN_RESULT(
1550
GLOBUS_GSI_GSS_ASSIST_CALLOUT_ERROR);
1555
result = GLOBUS_SUCCESS;
1558
globus_object_free(error);
1566
/* globus_gss_assist_map_and_authorize */
1568
#ifndef GLOBUS_DONT_DOCUMENT_INTERNAL
1571
globus_l_gss_assist_gridmap_lookup(
1572
gss_ctx_id_t context,
1574
char * desired_identity,
1575
char * identity_buffer,
1576
unsigned int identity_buffer_length)
1579
gss_buffer_desc peer_name_buffer;
1580
OM_uint32 major_status;
1581
OM_uint32 minor_status;
1583
globus_result_t result = GLOBUS_SUCCESS;
1585
char * local_identity;
1586
static char * _function_name_ =
1587
"globus_l_gss_assist_gridmap_lookup";
1589
major_status = gss_inquire_context(&minor_status,
1599
if(GSS_ERROR(major_status))
1601
result = minor_status;
1602
GLOBUS_GSI_GSS_ASSIST_ERROR_CHAIN_RESULT(
1604
GLOBUS_GSI_GSS_ASSIST_GSSAPI_ERROR);
1608
major_status = gss_inquire_context(&minor_status,
1610
initiator ? GLOBUS_NULL : &peer,
1611
initiator ? &peer : GLOBUS_NULL,
1618
if(GSS_ERROR(major_status))
1620
result = minor_status;
1621
GLOBUS_GSI_GSS_ASSIST_ERROR_CHAIN_RESULT(
1623
GLOBUS_GSI_GSS_ASSIST_GSSAPI_ERROR);
1627
major_status = gss_display_name(&minor_status,
1631
if(GSS_ERROR(major_status))
1633
result = minor_status;
1634
GLOBUS_GSI_GSS_ASSIST_ERROR_CHAIN_RESULT(
1636
GLOBUS_GSI_GSS_ASSIST_GSSAPI_ERROR);
1637
gss_release_name(&minor_status, &peer);
1641
gss_release_name(&minor_status, &peer);
1643
if(desired_identity == NULL)
1645
rc = globus_gss_assist_gridmap(
1646
peer_name_buffer.value,
1651
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
1653
GLOBUS_GSI_GSS_ASSIST_GRIDMAP_LOOKUP_FAILED,
1654
(_GASL("Could not map %s\n"), peer_name_buffer.value));
1655
gss_release_buffer(&minor_status, &peer_name_buffer);
1659
if(strlen(local_identity) + 1 > identity_buffer_length)
1661
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
1663
GLOBUS_GSI_GSS_ASSIST_BUFFER_TOO_SMALL,
1664
(_GASL("Local identity length: %d Buffer length: %d\n"),
1665
strlen(local_identity), identity_buffer_length));
1669
strcpy(identity_buffer, local_identity);
1671
free(local_identity);
1675
rc = globus_gss_assist_userok(peer_name_buffer.value,
1679
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
1681
GLOBUS_GSI_GSS_ASSIST_GRIDMAP_LOOKUP_FAILED,
1682
(_GASL("Could not map %s to %s\n"),
1683
peer_name_buffer.value,
1688
if(strlen(desired_identity) + 1 > identity_buffer_length)
1690
GLOBUS_GSI_GSS_ASSIST_ERROR_RESULT(
1692
GLOBUS_GSI_GSS_ASSIST_BUFFER_TOO_SMALL,
1693
(_GASL("Desired identity length: %d Buffer length: %d\n"),
1694
strlen(desired_identity), identity_buffer_length));
1698
strcpy(identity_buffer, desired_identity);
1702
gss_release_buffer(&minor_status, &peer_name_buffer);
1707
#endif /* GLOBUS_DONT_DOCUMENT_INTERNAL */