215991560e69f01c125b228947c554e1f148c001
[krb5.git] / src / lib / krb5 / krb / chk_trans.c
1 /*
2  * Copyright (c) 1994 CyberSAFE Corporation.
3  * All rights reserved.
4  *
5  * Export of this software from the United States of America may
6  *   require a specific license from the United States Government.
7  *   It is the responsibility of any person or organization contemplating
8  *   export to obtain such a license before exporting.
9  *
10  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
11  * distribute this software and its documentation for any purpose and
12  * without fee is hereby granted, provided that the above copyright
13  * notice appear in all copies and that both that copyright notice and
14  * this permission notice appear in supporting documentation, and that
15  * the name of M.I.T. not be used in advertising or publicity pertaining
16  * to distribution of the software without specific, written prior
17  * permission.  Neither M.I.T., the Open Computing Security Group, nor
18  * CyberSAFE Corporation make any representations about the suitability of
19  * this software for any purpose.  It is provided "as is" without express
20  * or implied warranty.
21  */
22
23 #include <stdio.h>
24 #include "k5-int.h"
25
26 #define MAX_REALM_LN 500
27
28 krb5_error_code INTERFACE
29 krb5_check_transited_list(context, trans, realm1, realm2)
30     krb5_context context;
31 krb5_data      *trans;
32 krb5_data      *realm1;
33 krb5_data      *realm2;
34 {
35   char            prev[MAX_REALM_LN+1];
36   char            next[MAX_REALM_LN+1];
37   char            *nextp;
38   int             i, j;
39   int             trans_length;
40   krb5_error_code retval = 0;
41   krb5_principal  *tgs_list;
42
43   if (!trans || !trans->data)  return(0);
44   trans_length = trans->data[trans->length-1] ?
45                  trans->length : trans->length - 1;
46
47   if (retval = krb5_walk_realm_tree(context, realm1, realm2, &tgs_list,
48                                     KRB5_REALM_BRANCH_CHAR)) {
49     return(retval);
50   }
51
52   memset(prev, 0, MAX_REALM_LN + 1);
53   memset(next, 0, MAX_REALM_LN + 1), nextp = next;
54   for (i = 0; i <= trans_length; i++) {
55     if (i < trans_length-1 && trans->data[i] == '\\') {
56       i++;
57       *nextp++ = trans->data[i];
58       continue;
59     }
60     if (i < trans_length && trans->data[i] != ',') {
61       *nextp++ = trans->data[i];
62       continue;
63     }
64     if (strlen(next) > 0) {
65       if (next[0] != '/') {
66         if (*(nextp-1) == '.')  strcat(next, prev);
67         retval = KRB5KRB_AP_ERR_ILL_CR_TKT;
68         for (j = 0; tgs_list[j]; j++) {
69           if (strlen(next) == (size_t) krb5_princ_realm(context, tgs_list[j])->length &&
70               !memcmp(next, krb5_princ_realm(context, tgs_list[j])->data,
71                       strlen(next))) {
72             retval = 0;
73             break; 
74           }
75         }
76         if (retval)  goto finish;
77       }
78       if (i+1 < trans_length && trans->data[i+1] == ' ') {
79         i++;
80         memset(next, 0, MAX_REALM_LN + 1), nextp = next;
81         continue;
82       }
83       if (i+1 < trans_length && trans->data[i+1] != '/') {
84         strcpy(prev, next);
85         memset(next, 0, MAX_REALM_LN + 1), nextp = next;
86         continue;
87       }
88     }
89   }
90
91 finish:
92   krb5_free_realm_tree(context, tgs_list);
93   return(retval);
94 }