dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / krb5 / kadmin / dbutil / util.c
blobee151180b83a570a83e898a3beb75d0e9bea9332
1 #pragma ident "%Z%%M% %I% %E% SMI"
3 /*
4 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
6 * Openvision retains the copyright to derivative works of
7 * this source code. Do *NOT* create a derivative of this
8 * source code before consulting with your legal department.
9 * Do *NOT* integrate *ANY* of this source code into another
10 * product before consulting with your legal department.
12 * For further information, read the top-level Openvision
13 * copyright which is contained in the top-level MIT Kerberos
14 * copyright.
16 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
22 * admin/edit/util.c
24 * Copyright 1992 by the Massachusetts Institute of Technology.
25 * All Rights Reserved.
27 * Export of this software from the United States of America may
28 * require a specific license from the United States Government.
29 * It is the responsibility of any person or organization contemplating
30 * export to obtain such a license before exporting.
32 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
33 * distribute this software and its documentation for any purpose and
34 * without fee is hereby granted, provided that the above copyright
35 * notice appear in all copies and that both that copyright notice and
36 * this permission notice appear in supporting documentation, and that
37 * the name of M.I.T. not be used in advertising or publicity pertaining
38 * to distribution of the software without specific, written prior
39 * permission. Furthermore if you modify this software you must label
40 * your software as modified software and not distribute it in such a
41 * fashion that it might be confused with the original M.I.T. software.
42 * M.I.T. makes no representations about the suitability of
43 * this software for any purpose. It is provided "as is" without express
44 * or implied warranty.
46 * Utilities for kdb5_edit.
48 * Some routines derived from code contributed by the Sandia National
49 * Laboratories. Sandia National Laboratories also makes no
50 * representations about the suitability of the modifications, or
51 * additions to this software for any purpose. It is provided "as is"
52 * without express or implied warranty.
56 #include <k5-int.h>
57 #include "./kdb5_edit.h"
59 #ifndef HAVE_STRSTR
60 char *
61 strstr(s1, s2)
62 char *s1;
63 char *s2;
65 int s2len;
66 int i;
67 char *temp_ptr;
69 temp_ptr = s1;
70 for ( i = 0; i < strlen(s1); i++) {
71 if (memcmp(temp_ptr, s2, strlen(s2)) == 0) return(temp_ptr);
72 temp_ptr += 1;
74 return ((char *) 0);
76 #endif /* HAVE_STRSTR */
78 void
79 parse_token(token_in, must_be_first_char, num_tokens, tokens_out)
80 char *token_in;
81 int *must_be_first_char;
82 int *num_tokens;
83 char *tokens_out;
85 int i, j;
86 int token_count = 0;
88 i = 0;
89 j = 0;
91 /* Eliminate Up Front Asterisks */
92 *must_be_first_char = 1;
93 for (i = 0; token_in[i] == '*'; i++) {
94 *must_be_first_char = 0;
97 if (i == strlen(token_in)) {
98 *num_tokens = 0;
99 return;
102 /* Fill first token_out */
103 token_count++;
104 while ((token_in[i] != '*') && (token_in[i] != '\0')) {
105 tokens_out[j] = token_in[i];
106 j++;
107 i++;
110 if (i == strlen(token_in)) {
111 tokens_out[j] = '\0';
112 *num_tokens = token_count;
113 return;
116 /* Then All Subsequent Tokens */
117 while (i < strlen(token_in)) {
118 if (token_in[i] == '*') {
119 token_count++;
120 tokens_out[j] = '\t';
121 } else {
122 tokens_out[j] = token_in[i];
124 i++;
125 j++;
127 tokens_out[j] = '\0';
129 if (tokens_out[j - 1] == '\t') {
130 token_count--;
131 tokens_out[j - 1] = '\0';
134 *num_tokens = token_count;
135 return;
139 check_for_match(search_field, must_be_first_character, chk_entry,
140 num_tokens, type)
141 int must_be_first_character;
142 char *search_field;
143 krb5_db_entry *chk_entry;
144 int num_tokens;
145 int type;
147 char token1[256];
148 char *found1;
149 char token2[256];
150 char *found2;
151 char token3[256];
152 char *found3;
153 char *local_entry;
155 local_entry = chk_entry->princ->data[type].data;
157 token1[0] = token2[0] = token3[0] = '\0';
159 (void) sscanf(search_field, "%s\t%s\t%s", token1, token2, token3);
161 found1 = strstr(local_entry, token1);
163 if (must_be_first_character && (found1 != local_entry)) return(0);
165 if (found1 && (num_tokens == 1)) return(1);
167 if (found1 && (num_tokens > 1)) {
168 found2 = strstr(local_entry, token2);
169 if (found2 && (found2 > found1) && (num_tokens == 2)) return(1);
172 if ((found2 > found1) && (num_tokens == 3)) {
173 found3 = strstr(local_entry, token3);
174 if (found3 && (found3 > found2) && (found2 > found1)) return(1);
176 return(0);