17c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 27c478bd9Sstevel@tonic-gate 37c478bd9Sstevel@tonic-gate /* 47c478bd9Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 57c478bd9Sstevel@tonic-gate * 67c478bd9Sstevel@tonic-gate * Openvision retains the copyright to derivative works of 77c478bd9Sstevel@tonic-gate * this source code. Do *NOT* create a derivative of this 87c478bd9Sstevel@tonic-gate * source code before consulting with your legal department. 97c478bd9Sstevel@tonic-gate * Do *NOT* integrate *ANY* of this source code into another 107c478bd9Sstevel@tonic-gate * product before consulting with your legal department. 117c478bd9Sstevel@tonic-gate * 127c478bd9Sstevel@tonic-gate * For further information, read the top-level Openvision 137c478bd9Sstevel@tonic-gate * copyright which is contained in the top-level MIT Kerberos 147c478bd9Sstevel@tonic-gate * copyright. 157c478bd9Sstevel@tonic-gate * 167c478bd9Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 177c478bd9Sstevel@tonic-gate * 187c478bd9Sstevel@tonic-gate */ 197c478bd9Sstevel@tonic-gate 207c478bd9Sstevel@tonic-gate 217c478bd9Sstevel@tonic-gate /* 227c478bd9Sstevel@tonic-gate * admin/edit/util.c 237c478bd9Sstevel@tonic-gate * 247c478bd9Sstevel@tonic-gate * Copyright 1992 by the Massachusetts Institute of Technology. 257c478bd9Sstevel@tonic-gate * All Rights Reserved. 267c478bd9Sstevel@tonic-gate * 277c478bd9Sstevel@tonic-gate * Export of this software from the United States of America may 287c478bd9Sstevel@tonic-gate * require a specific license from the United States Government. 297c478bd9Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating 307c478bd9Sstevel@tonic-gate * export to obtain such a license before exporting. 317c478bd9Sstevel@tonic-gate * 327c478bd9Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 337c478bd9Sstevel@tonic-gate * distribute this software and its documentation for any purpose and 347c478bd9Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright 357c478bd9Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and 367c478bd9Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that 377c478bd9Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining 387c478bd9Sstevel@tonic-gate * to distribution of the software without specific, written prior 39*56a424ccSmp153739 * permission. Furthermore if you modify this software you must label 40*56a424ccSmp153739 * your software as modified software and not distribute it in such a 41*56a424ccSmp153739 * fashion that it might be confused with the original M.I.T. software. 42*56a424ccSmp153739 * M.I.T. makes no representations about the suitability of 437c478bd9Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express 447c478bd9Sstevel@tonic-gate * or implied warranty. 457c478bd9Sstevel@tonic-gate * 467c478bd9Sstevel@tonic-gate * Utilities for kdb5_edit. 477c478bd9Sstevel@tonic-gate * 487c478bd9Sstevel@tonic-gate * Some routines derived from code contributed by the Sandia National 497c478bd9Sstevel@tonic-gate * Laboratories. Sandia National Laboratories also makes no 507c478bd9Sstevel@tonic-gate * representations about the suitability of the modifications, or 517c478bd9Sstevel@tonic-gate * additions to this software for any purpose. It is provided "as is" 527c478bd9Sstevel@tonic-gate * without express or implied warranty. 537c478bd9Sstevel@tonic-gate * 547c478bd9Sstevel@tonic-gate */ 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate #include <k5-int.h> 577c478bd9Sstevel@tonic-gate #include "./kdb5_edit.h" 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate #ifndef HAVE_STRSTR 607c478bd9Sstevel@tonic-gate char * 617c478bd9Sstevel@tonic-gate strstr(s1, s2) 627c478bd9Sstevel@tonic-gate char *s1; 637c478bd9Sstevel@tonic-gate char *s2; 647c478bd9Sstevel@tonic-gate { 657c478bd9Sstevel@tonic-gate int s2len; 667c478bd9Sstevel@tonic-gate int i; 677c478bd9Sstevel@tonic-gate char *temp_ptr; 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate temp_ptr = s1; 707c478bd9Sstevel@tonic-gate for ( i = 0; i < strlen(s1); i++) { 71*56a424ccSmp153739 if (memcmp(temp_ptr, s2, strlen(s2)) == 0) return(temp_ptr); 727c478bd9Sstevel@tonic-gate temp_ptr += 1; 737c478bd9Sstevel@tonic-gate } 747c478bd9Sstevel@tonic-gate return ((char *) 0); 757c478bd9Sstevel@tonic-gate } 767c478bd9Sstevel@tonic-gate #endif /* HAVE_STRSTR */ 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate void 797c478bd9Sstevel@tonic-gate parse_token(token_in, must_be_first_char, num_tokens, tokens_out) 807c478bd9Sstevel@tonic-gate char *token_in; 817c478bd9Sstevel@tonic-gate int *must_be_first_char; 827c478bd9Sstevel@tonic-gate int *num_tokens; 837c478bd9Sstevel@tonic-gate char *tokens_out; 847c478bd9Sstevel@tonic-gate { 857c478bd9Sstevel@tonic-gate int i, j; 867c478bd9Sstevel@tonic-gate int token_count = 0; 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate i = 0; 897c478bd9Sstevel@tonic-gate j = 0; 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* Eliminate Up Front Asterisks */ 927c478bd9Sstevel@tonic-gate *must_be_first_char = 1; 937c478bd9Sstevel@tonic-gate for (i = 0; token_in[i] == '*'; i++) { 947c478bd9Sstevel@tonic-gate *must_be_first_char = 0; 957c478bd9Sstevel@tonic-gate } 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate if (i == strlen(token_in)) { 987c478bd9Sstevel@tonic-gate *num_tokens = 0; 997c478bd9Sstevel@tonic-gate return; 1007c478bd9Sstevel@tonic-gate } 101*56a424ccSmp153739 1027c478bd9Sstevel@tonic-gate /* Fill first token_out */ 1037c478bd9Sstevel@tonic-gate token_count++; 1047c478bd9Sstevel@tonic-gate while ((token_in[i] != '*') && (token_in[i] != '\0')) { 1057c478bd9Sstevel@tonic-gate tokens_out[j] = token_in[i]; 1067c478bd9Sstevel@tonic-gate j++; 1077c478bd9Sstevel@tonic-gate i++; 1087c478bd9Sstevel@tonic-gate } 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate if (i == strlen(token_in)) { 1117c478bd9Sstevel@tonic-gate tokens_out[j] = '\0'; 1127c478bd9Sstevel@tonic-gate *num_tokens = token_count; 1137c478bd9Sstevel@tonic-gate return; 1147c478bd9Sstevel@tonic-gate } 115*56a424ccSmp153739 1167c478bd9Sstevel@tonic-gate /* Then All Subsequent Tokens */ 1177c478bd9Sstevel@tonic-gate while (i < strlen(token_in)) { 1187c478bd9Sstevel@tonic-gate if (token_in[i] == '*') { 1197c478bd9Sstevel@tonic-gate token_count++; 1207c478bd9Sstevel@tonic-gate tokens_out[j] = '\t'; 1217c478bd9Sstevel@tonic-gate } else { 1227c478bd9Sstevel@tonic-gate tokens_out[j] = token_in[i]; 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate i++; 1257c478bd9Sstevel@tonic-gate j++; 1267c478bd9Sstevel@tonic-gate } 1277c478bd9Sstevel@tonic-gate tokens_out[j] = '\0'; 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate if (tokens_out[j - 1] == '\t') { 1307c478bd9Sstevel@tonic-gate token_count--; 1317c478bd9Sstevel@tonic-gate tokens_out[j - 1] = '\0'; 1327c478bd9Sstevel@tonic-gate } 133*56a424ccSmp153739 1347c478bd9Sstevel@tonic-gate *num_tokens = token_count; 135*56a424ccSmp153739 return; 1367c478bd9Sstevel@tonic-gate } 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate int 1397c478bd9Sstevel@tonic-gate check_for_match(search_field, must_be_first_character, chk_entry, 1407c478bd9Sstevel@tonic-gate num_tokens, type) 1417c478bd9Sstevel@tonic-gate int must_be_first_character; 1427c478bd9Sstevel@tonic-gate char *search_field; 1437c478bd9Sstevel@tonic-gate krb5_db_entry *chk_entry; 1447c478bd9Sstevel@tonic-gate int num_tokens; 1457c478bd9Sstevel@tonic-gate int type; 1467c478bd9Sstevel@tonic-gate { 1477c478bd9Sstevel@tonic-gate char token1[256]; 1487c478bd9Sstevel@tonic-gate char *found1; 1497c478bd9Sstevel@tonic-gate char token2[256]; 1507c478bd9Sstevel@tonic-gate char *found2; 1517c478bd9Sstevel@tonic-gate char token3[256]; 1527c478bd9Sstevel@tonic-gate char *found3; 1537c478bd9Sstevel@tonic-gate char *local_entry; 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate local_entry = chk_entry->princ->data[type].data; 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate token1[0] = token2[0] = token3[0] = '\0'; 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate (void) sscanf(search_field, "%s\t%s\t%s", token1, token2, token3); 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate found1 = strstr(local_entry, token1); 1627c478bd9Sstevel@tonic-gate 163*56a424ccSmp153739 if (must_be_first_character && (found1 != local_entry)) return(0); 1647c478bd9Sstevel@tonic-gate 165*56a424ccSmp153739 if (found1 && (num_tokens == 1)) return(1); 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate if (found1 && (num_tokens > 1)) { 1687c478bd9Sstevel@tonic-gate found2 = strstr(local_entry, token2); 169*56a424ccSmp153739 if (found2 && (found2 > found1) && (num_tokens == 2)) return(1); 1707c478bd9Sstevel@tonic-gate } 171*56a424ccSmp153739 1727c478bd9Sstevel@tonic-gate if ((found2 > found1) && (num_tokens == 3)) { 1737c478bd9Sstevel@tonic-gate found3 = strstr(local_entry, token3); 174*56a424ccSmp153739 if (found3 && (found3 > found2) && (found2 > found1)) return(1); 1757c478bd9Sstevel@tonic-gate } 1767c478bd9Sstevel@tonic-gate return(0); 1777c478bd9Sstevel@tonic-gate } 178*56a424ccSmp153739 179