1/* $Id: mac_krb_lib1.c,v 1.4 2005/01/10 19:17:33 snsimon Exp $ 2 * Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in 13 * the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * 3. The name "Carnegie Mellon University" must not be used to 17 * endorse or promote products derived from this software without 18 * prior written permission. For permission or any other legal 19 * details, please contact 20 * Office of Technology Transfer 21 * Carnegie Mellon University 22 * 5000 Forbes Avenue 23 * Pittsburgh, PA 15213-3890 24 * (412) 268-4387, fax: (412) 268-7395 25 * tech-transfer@andrew.cmu.edu 26 * 27 * 4. Redistributions of any form whatsoever must retain the following 28 * acknowledgment: 29 * "This product includes software developed by Computing Services 30 * at Carnegie Mellon University (http://www.cmu.edu/computing/)." 31 * 32 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO 33 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 34 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE 35 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 36 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 37 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 38 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 39 */ 40/* 41 * library to emulate unix kerberos on a macintosh 42 */ 43#include <config.h> 44#include <krb.h> 45#include <extra_krb.h> 46#include <kcglue_krb.h> 47 48#include <stdlib.h> 49#include <string.h> 50#include <ctype.h> 51 52#ifndef TRUE 53#define TRUE 1 54#endif 55#ifndef FALSE 56#define FALSE 0 57#endif 58 59#include <stdio.h> 60 61/* 62 * given a hostname return the kerberos realm 63 * NOT thread safe.... 64 */ 65char *krb_realmofhost(const char *s) 66{ 67 s=strchr(s,'.'); 68 if(s==0) 69 return "ANDREW.CMU.EDU"; 70 return (char *)(s+1); 71} 72 73/* 74 * return the default instance to use for a given hostname 75 * NOT thread safe... but then neathoer is the real kerberos one 76 */ 77char *krb_get_phost(const char *alias) 78{ 79#define MAX_HOST_LEN (512) 80 static char instance[MAX_HOST_LEN]; 81 char *dst=instance; 82 int remaining=MAX_HOST_LEN-10; 83 while(remaining-->0) { 84 char ch= *alias++; 85 if(ch==0) break; 86 if(isupper(ch)) 87 ch=tolower(ch); 88 if(ch=='.') 89 break; 90 *dst++=ch; 91 } 92 *dst=0; 93 return instance; 94} 95