10Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
20Sstevel@tonic-gate
30Sstevel@tonic-gate /*
40Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
50Sstevel@tonic-gate *
60Sstevel@tonic-gate * Openvision retains the copyright to derivative works of
70Sstevel@tonic-gate * this source code. Do *NOT* create a derivative of this
80Sstevel@tonic-gate * source code before consulting with your legal department.
90Sstevel@tonic-gate * Do *NOT* integrate *ANY* of this source code into another
100Sstevel@tonic-gate * product before consulting with your legal department.
110Sstevel@tonic-gate *
120Sstevel@tonic-gate * For further information, read the top-level Openvision
130Sstevel@tonic-gate * copyright which is contained in the top-level MIT Kerberos
140Sstevel@tonic-gate * copyright.
150Sstevel@tonic-gate *
160Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
170Sstevel@tonic-gate *
180Sstevel@tonic-gate */
190Sstevel@tonic-gate
200Sstevel@tonic-gate
210Sstevel@tonic-gate /*
220Sstevel@tonic-gate * admin/edit/util.c
230Sstevel@tonic-gate *
240Sstevel@tonic-gate * Copyright 1992 by the Massachusetts Institute of Technology.
250Sstevel@tonic-gate * All Rights Reserved.
260Sstevel@tonic-gate *
270Sstevel@tonic-gate * Export of this software from the United States of America may
280Sstevel@tonic-gate * require a specific license from the United States Government.
290Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating
300Sstevel@tonic-gate * export to obtain such a license before exporting.
31*2881Smp153739 *
320Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
330Sstevel@tonic-gate * distribute this software and its documentation for any purpose and
340Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright
350Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and
360Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that
370Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining
380Sstevel@tonic-gate * to distribution of the software without specific, written prior
39*2881Smp153739 * permission. Furthermore if you modify this software you must label
40*2881Smp153739 * your software as modified software and not distribute it in such a
41*2881Smp153739 * fashion that it might be confused with the original M.I.T. software.
42*2881Smp153739 * M.I.T. makes no representations about the suitability of
430Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express
440Sstevel@tonic-gate * or implied warranty.
45*2881Smp153739 *
460Sstevel@tonic-gate * Utilities for kdb5_edit.
47*2881Smp153739 *
480Sstevel@tonic-gate * Some routines derived from code contributed by the Sandia National
490Sstevel@tonic-gate * Laboratories. Sandia National Laboratories also makes no
500Sstevel@tonic-gate * representations about the suitability of the modifications, or
510Sstevel@tonic-gate * additions to this software for any purpose. It is provided "as is"
520Sstevel@tonic-gate * without express or implied warranty.
53*2881Smp153739 *
540Sstevel@tonic-gate */
550Sstevel@tonic-gate
560Sstevel@tonic-gate #include <k5-int.h>
570Sstevel@tonic-gate #include "./kdb5_edit.h"
580Sstevel@tonic-gate
590Sstevel@tonic-gate #ifndef HAVE_STRSTR
600Sstevel@tonic-gate char *
strstr(s1,s2)610Sstevel@tonic-gate strstr(s1, s2)
620Sstevel@tonic-gate char *s1;
630Sstevel@tonic-gate char *s2;
640Sstevel@tonic-gate {
65*2881Smp153739 int s2len;
66*2881Smp153739 int i;
67*2881Smp153739 char *temp_ptr;
680Sstevel@tonic-gate
69*2881Smp153739 temp_ptr = s1;
70*2881Smp153739 for ( i = 0; i < strlen(s1); i++) {
71*2881Smp153739 if (memcmp(temp_ptr, s2, strlen(s2)) == 0) return(temp_ptr);
72*2881Smp153739 temp_ptr += 1;
73*2881Smp153739 }
74*2881Smp153739 return ((char *) 0);
750Sstevel@tonic-gate }
76*2881Smp153739 #endif /* HAVE_STRSTR */
770Sstevel@tonic-gate
780Sstevel@tonic-gate void
parse_token(token_in,must_be_first_char,num_tokens,tokens_out)790Sstevel@tonic-gate parse_token(token_in, must_be_first_char, num_tokens, tokens_out)
800Sstevel@tonic-gate char *token_in;
81*2881Smp153739 int *must_be_first_char;
82*2881Smp153739 int *num_tokens;
830Sstevel@tonic-gate char *tokens_out;
840Sstevel@tonic-gate {
85*2881Smp153739 int i, j;
86*2881Smp153739 int token_count = 0;
870Sstevel@tonic-gate
88*2881Smp153739 i = 0;
89*2881Smp153739 j = 0;
900Sstevel@tonic-gate
910Sstevel@tonic-gate /* Eliminate Up Front Asterisks */
92*2881Smp153739 *must_be_first_char = 1;
93*2881Smp153739 for (i = 0; token_in[i] == '*'; i++) {
94*2881Smp153739 *must_be_first_char = 0;
95*2881Smp153739 }
960Sstevel@tonic-gate
97*2881Smp153739 if (i == strlen(token_in)) {
98*2881Smp153739 *num_tokens = 0;
99*2881Smp153739 return;
100*2881Smp153739 }
101*2881Smp153739
1020Sstevel@tonic-gate /* Fill first token_out */
103*2881Smp153739 token_count++;
104*2881Smp153739 while ((token_in[i] != '*') && (token_in[i] != '\0')) {
105*2881Smp153739 tokens_out[j] = token_in[i];
106*2881Smp153739 j++;
107*2881Smp153739 i++;
108*2881Smp153739 }
1090Sstevel@tonic-gate
110*2881Smp153739 if (i == strlen(token_in)) {
111*2881Smp153739 tokens_out[j] = '\0';
112*2881Smp153739 *num_tokens = token_count;
113*2881Smp153739 return;
114*2881Smp153739 }
115*2881Smp153739
1160Sstevel@tonic-gate /* Then All Subsequent Tokens */
117*2881Smp153739 while (i < strlen(token_in)) {
118*2881Smp153739 if (token_in[i] == '*') {
119*2881Smp153739 token_count++;
120*2881Smp153739 tokens_out[j] = '\t';
121*2881Smp153739 } else {
122*2881Smp153739 tokens_out[j] = token_in[i];
1230Sstevel@tonic-gate }
124*2881Smp153739 i++;
125*2881Smp153739 j++;
126*2881Smp153739 }
127*2881Smp153739 tokens_out[j] = '\0';
1280Sstevel@tonic-gate
129*2881Smp153739 if (tokens_out[j - 1] == '\t') {
130*2881Smp153739 token_count--;
131*2881Smp153739 tokens_out[j - 1] = '\0';
132*2881Smp153739 }
133*2881Smp153739
134*2881Smp153739 *num_tokens = token_count;
135*2881Smp153739 return;
1360Sstevel@tonic-gate }
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate int
check_for_match(search_field,must_be_first_character,chk_entry,num_tokens,type)139*2881Smp153739 check_for_match(search_field, must_be_first_character, chk_entry,
140*2881Smp153739 num_tokens, type)
1410Sstevel@tonic-gate int must_be_first_character;
1420Sstevel@tonic-gate char *search_field;
1430Sstevel@tonic-gate krb5_db_entry *chk_entry;
1440Sstevel@tonic-gate int num_tokens;
1450Sstevel@tonic-gate int type;
1460Sstevel@tonic-gate {
147*2881Smp153739 char token1[256];
148*2881Smp153739 char *found1;
149*2881Smp153739 char token2[256];
150*2881Smp153739 char *found2;
151*2881Smp153739 char token3[256];
152*2881Smp153739 char *found3;
153*2881Smp153739 char *local_entry;
1540Sstevel@tonic-gate
155*2881Smp153739 local_entry = chk_entry->princ->data[type].data;
1560Sstevel@tonic-gate
157*2881Smp153739 token1[0] = token2[0] = token3[0] = '\0';
1580Sstevel@tonic-gate
159*2881Smp153739 (void) sscanf(search_field, "%s\t%s\t%s", token1, token2, token3);
1600Sstevel@tonic-gate
161*2881Smp153739 found1 = strstr(local_entry, token1);
1620Sstevel@tonic-gate
163*2881Smp153739 if (must_be_first_character && (found1 != local_entry)) return(0);
1640Sstevel@tonic-gate
165*2881Smp153739 if (found1 && (num_tokens == 1)) return(1);
1660Sstevel@tonic-gate
167*2881Smp153739 if (found1 && (num_tokens > 1)) {
168*2881Smp153739 found2 = strstr(local_entry, token2);
169*2881Smp153739 if (found2 && (found2 > found1) && (num_tokens == 2)) return(1);
170*2881Smp153739 }
171*2881Smp153739
172*2881Smp153739 if ((found2 > found1) && (num_tokens == 3)) {
173*2881Smp153739 found3 = strstr(local_entry, token3);
174*2881Smp153739 if (found3 && (found3 > found2) && (found2 > found1)) return(1);
175*2881Smp153739 }
176*2881Smp153739 return(0);
1770Sstevel@tonic-gate }
178*2881Smp153739
179