1*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gate /* 4*0Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 5*0Sstevel@tonic-gate * 6*0Sstevel@tonic-gate * Openvision retains the copyright to derivative works of 7*0Sstevel@tonic-gate * this source code. Do *NOT* create a derivative of this 8*0Sstevel@tonic-gate * source code before consulting with your legal department. 9*0Sstevel@tonic-gate * Do *NOT* integrate *ANY* of this source code into another 10*0Sstevel@tonic-gate * product before consulting with your legal department. 11*0Sstevel@tonic-gate * 12*0Sstevel@tonic-gate * For further information, read the top-level Openvision 13*0Sstevel@tonic-gate * copyright which is contained in the top-level MIT Kerberos 14*0Sstevel@tonic-gate * copyright. 15*0Sstevel@tonic-gate * 16*0Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 17*0Sstevel@tonic-gate * 18*0Sstevel@tonic-gate */ 19*0Sstevel@tonic-gate 20*0Sstevel@tonic-gate 21*0Sstevel@tonic-gate /* 22*0Sstevel@tonic-gate * admin/edit/util.c 23*0Sstevel@tonic-gate * 24*0Sstevel@tonic-gate * Copyright 1992 by the Massachusetts Institute of Technology. 25*0Sstevel@tonic-gate * All Rights Reserved. 26*0Sstevel@tonic-gate * 27*0Sstevel@tonic-gate * Export of this software from the United States of America may 28*0Sstevel@tonic-gate * require a specific license from the United States Government. 29*0Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating 30*0Sstevel@tonic-gate * export to obtain such a license before exporting. 31*0Sstevel@tonic-gate * 32*0Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 33*0Sstevel@tonic-gate * distribute this software and its documentation for any purpose and 34*0Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright 35*0Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and 36*0Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that 37*0Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining 38*0Sstevel@tonic-gate * to distribution of the software without specific, written prior 39*0Sstevel@tonic-gate * permission. M.I.T. makes no representations about the suitability of 40*0Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express 41*0Sstevel@tonic-gate * or implied warranty. 42*0Sstevel@tonic-gate * 43*0Sstevel@tonic-gate * Utilities for kdb5_edit. 44*0Sstevel@tonic-gate * 45*0Sstevel@tonic-gate * Some routines derived from code contributed by the Sandia National 46*0Sstevel@tonic-gate * Laboratories. Sandia National Laboratories also makes no 47*0Sstevel@tonic-gate * representations about the suitability of the modifications, or 48*0Sstevel@tonic-gate * additions to this software for any purpose. It is provided "as is" 49*0Sstevel@tonic-gate * without express or implied warranty. 50*0Sstevel@tonic-gate * 51*0Sstevel@tonic-gate */ 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate #define KDB5_DISPATCH 54*0Sstevel@tonic-gate #define KRB5_KDB5_DBM__ 55*0Sstevel@tonic-gate #include <k5-int.h> 56*0Sstevel@tonic-gate /* #define these to avoid an indirection function; for future implementations, 57*0Sstevel@tonic-gate these may be redirected from a dispatch table/routine */ 58*0Sstevel@tonic-gate #define krb5_dbm_db_set_name krb5_db_set_name 59*0Sstevel@tonic-gate #define krb5_dbm_db_set_nonblocking krb5_db_set_nonblocking 60*0Sstevel@tonic-gate #define krb5_dbm_db_init krb5_db_init 61*0Sstevel@tonic-gate #define krb5_dbm_db_get_age krb5_db_get_age 62*0Sstevel@tonic-gate #define krb5_dbm_db_create krb5_db_create 63*0Sstevel@tonic-gate #define krb5_dbm_db_rename krb5_db_rename 64*0Sstevel@tonic-gate #define krb5_dbm_db_get_principal krb5_db_get_principal 65*0Sstevel@tonic-gate #define krb5_dbm_db_free_principal krb5_db_free_principal 66*0Sstevel@tonic-gate #define krb5_dbm_db_put_principal krb5_db_put_principal 67*0Sstevel@tonic-gate #define krb5_dbm_db_delete_principal krb5_db_delete_principal 68*0Sstevel@tonic-gate #define krb5_dbm_db_lock krb5_db_lock 69*0Sstevel@tonic-gate #define krb5_dbm_db_unlock krb5_db_unlock 70*0Sstevel@tonic-gate #define krb5_dbm_db_set_lockmode krb5_db_set_lockmode 71*0Sstevel@tonic-gate #define krb5_dbm_db_close_database krb5_db_close_database 72*0Sstevel@tonic-gate #define krb5_dbm_db_open_database krb5_db_open_database 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate #include <kadm5/admin.h> 75*0Sstevel@tonic-gate #include "./kdb5_edit.h" 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate #ifndef HAVE_STRSTR 78*0Sstevel@tonic-gate char * 79*0Sstevel@tonic-gate strstr(s1, s2) 80*0Sstevel@tonic-gate char *s1; 81*0Sstevel@tonic-gate char *s2; 82*0Sstevel@tonic-gate { 83*0Sstevel@tonic-gate int s2len; 84*0Sstevel@tonic-gate int i; 85*0Sstevel@tonic-gate char *temp_ptr; 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate temp_ptr = s1; 88*0Sstevel@tonic-gate for (i = 0; i < strlen(s1); i++) { 89*0Sstevel@tonic-gate if (memcmp(temp_ptr, s2, strlen(s2)) == 0) 90*0Sstevel@tonic-gate return (temp_ptr); 91*0Sstevel@tonic-gate temp_ptr += 1; 92*0Sstevel@tonic-gate } 93*0Sstevel@tonic-gate return ((char *) 0); 94*0Sstevel@tonic-gate } 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate #endif /* HAVE_STRSTR */ 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate void 99*0Sstevel@tonic-gate parse_token(token_in, must_be_first_char, num_tokens, tokens_out) 100*0Sstevel@tonic-gate char *token_in; 101*0Sstevel@tonic-gate int *must_be_first_char; 102*0Sstevel@tonic-gate int *num_tokens; 103*0Sstevel@tonic-gate char *tokens_out; 104*0Sstevel@tonic-gate { 105*0Sstevel@tonic-gate int i, j; 106*0Sstevel@tonic-gate int token_count = 0; 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gate i = 0; 109*0Sstevel@tonic-gate j = 0; 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate /* Eliminate Up Front Asterisks */ 112*0Sstevel@tonic-gate *must_be_first_char = 1; 113*0Sstevel@tonic-gate for (i = 0; token_in[i] == '*'; i++) { 114*0Sstevel@tonic-gate *must_be_first_char = 0; 115*0Sstevel@tonic-gate } 116*0Sstevel@tonic-gate 117*0Sstevel@tonic-gate if (i == strlen(token_in)) { 118*0Sstevel@tonic-gate *num_tokens = 0; 119*0Sstevel@tonic-gate return; 120*0Sstevel@tonic-gate } 121*0Sstevel@tonic-gate /* Fill first token_out */ 122*0Sstevel@tonic-gate token_count++; 123*0Sstevel@tonic-gate while ((token_in[i] != '*') && (token_in[i] != '\0')) { 124*0Sstevel@tonic-gate tokens_out[j] = token_in[i]; 125*0Sstevel@tonic-gate j++; 126*0Sstevel@tonic-gate i++; 127*0Sstevel@tonic-gate } 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate if (i == strlen(token_in)) { 130*0Sstevel@tonic-gate tokens_out[j] = '\0'; 131*0Sstevel@tonic-gate *num_tokens = token_count; 132*0Sstevel@tonic-gate return; 133*0Sstevel@tonic-gate } 134*0Sstevel@tonic-gate /* Then All Subsequent Tokens */ 135*0Sstevel@tonic-gate while (i < strlen(token_in)) { 136*0Sstevel@tonic-gate if (token_in[i] == '*') { 137*0Sstevel@tonic-gate token_count++; 138*0Sstevel@tonic-gate tokens_out[j] = '\t'; 139*0Sstevel@tonic-gate } else { 140*0Sstevel@tonic-gate tokens_out[j] = token_in[i]; 141*0Sstevel@tonic-gate } 142*0Sstevel@tonic-gate i++; 143*0Sstevel@tonic-gate j++; 144*0Sstevel@tonic-gate } 145*0Sstevel@tonic-gate tokens_out[j] = '\0'; 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate if (tokens_out[j - 1] == '\t') { 148*0Sstevel@tonic-gate token_count--; 149*0Sstevel@tonic-gate tokens_out[j - 1] = '\0'; 150*0Sstevel@tonic-gate } 151*0Sstevel@tonic-gate *num_tokens = token_count; 152*0Sstevel@tonic-gate } 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate int 155*0Sstevel@tonic-gate check_for_match(search_field, must_be_first_character, chk_entry, 156*0Sstevel@tonic-gate num_tokens, type) 157*0Sstevel@tonic-gate int must_be_first_character; 158*0Sstevel@tonic-gate char *search_field; 159*0Sstevel@tonic-gate krb5_db_entry *chk_entry; 160*0Sstevel@tonic-gate int num_tokens; 161*0Sstevel@tonic-gate int type; 162*0Sstevel@tonic-gate { 163*0Sstevel@tonic-gate char token1[256]; 164*0Sstevel@tonic-gate char *found1; 165*0Sstevel@tonic-gate char token2[256]; 166*0Sstevel@tonic-gate char *found2; 167*0Sstevel@tonic-gate char token3[256]; 168*0Sstevel@tonic-gate char *found3; 169*0Sstevel@tonic-gate char *local_entry; 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate local_entry = chk_entry->princ->data[type].data; 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate token1[0] = token2[0] = token3[0] = '\0'; 174*0Sstevel@tonic-gate 175*0Sstevel@tonic-gate (void) sscanf(search_field, "%s\t%s\t%s", token1, token2, token3); 176*0Sstevel@tonic-gate 177*0Sstevel@tonic-gate found1 = strstr(local_entry, token1); 178*0Sstevel@tonic-gate 179*0Sstevel@tonic-gate if (must_be_first_character && (found1 != local_entry)) 180*0Sstevel@tonic-gate return (0); 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate if (found1 && (num_tokens == 1)) 183*0Sstevel@tonic-gate return (1); 184*0Sstevel@tonic-gate 185*0Sstevel@tonic-gate if (found1 && (num_tokens > 1)) { 186*0Sstevel@tonic-gate found2 = strstr(local_entry, token2); 187*0Sstevel@tonic-gate if (found2 && (found2 > found1) && (num_tokens == 2)) 188*0Sstevel@tonic-gate return (1); 189*0Sstevel@tonic-gate } 190*0Sstevel@tonic-gate if ((found2 > found1) && (num_tokens == 3)) { 191*0Sstevel@tonic-gate found3 = strstr(local_entry, token3); 192*0Sstevel@tonic-gate if (found3 && (found3 > found2) && (found2 > found1)) 193*0Sstevel@tonic-gate return (1); 194*0Sstevel@tonic-gate } 195*0Sstevel@tonic-gate return (0); 196*0Sstevel@tonic-gate } 197