import cyrus-sasl-2.1.23
[cyrus-sasl.git] / mac / mac_lib / xxx_client_mac_lib.c
1 /* $Id: xxx_client_mac_lib.c,v 1.3 2003/02/13 19:55:59 rjs3 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  * routines used by the sasl test programs and not provided
42  * by a mac.  see also xxx_mac_lib.c for routines needed by
43  * the sasl library and not supplied by the system runtime
44  */
45
46 #include <string.h>
47 #include <stdlib.h>
48 #include <ctype.h>
49 #include <stdio.h>
50  
51 #include <config.h>
52 #include <netinet/in.h>
53
54 char *__progname="mac";
55
56 struct hostent *gethostbyname(const char *hnam)
57 {
58         static struct hostent result;
59         int bytes[4];
60         int i;
61         unsigned int ip=0;
62         if(sscanf(hnam,"%d.%d.%d.%d",bytes,bytes+1,bytes+2,bytes+3)!=4)
63                 return 0;
64         for(i=0;i<4;i++) {
65                 ip<<=8;
66                 ip|=(bytes[i]&0x0ff);
67         }
68         memcpy(result.h_addr,&ip,4);
69         return &result;
70 }
71
72 /*
73  * ala perl chomp
74  */
75 static void xxy_chomp(char *s,const char stop_here)
76 {
77         char ch;
78         while((ch= (*s++))!=0)
79                 if(ch==stop_here) {
80                         s[-1]=0;
81                         return;
82                 }
83 }
84
85 char* getpass(const char *prompt)
86 {
87         const int max_buf=200;
88         char *buf=malloc(max_buf);
89         if(buf==0)
90                 return 0;
91         memset(buf,0,max_buf);  /* not likely to be a performance issue eheh */
92         printf("%s",prompt);
93         fgets(buf,max_buf-1,stdin);
94         xxy_chomp(buf,'\n');
95         return buf;
96 }
97
98 #ifdef TARGET_API_MAC_CARBON
99 char *strdup(const char *str)
100 {
101         if(str==0)
102                 return 0;
103         {
104                 const int len=strlen(str);
105                 char *result=malloc(len+1);
106                 strcpy(result,str);
107                 return result;
108         }
109         
110 }
111 #endif