3 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
5 * Openvision retains the copyright to derivative works of
6 * this source code. Do *NOT* create a derivative of this
7 * source code before consulting with your legal department.
8 * Do *NOT* integrate *ANY* of this source code into another
9 * product before consulting with your legal department.
11 * For further information, read the top-level Openvision
12 * copyright which is contained in the top-level MIT Kerberos
15 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
21 * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
26 #if !defined(lint) && !defined(__CODECENTER__)
27 static char *rcsid
= "$Header$";
30 #include <sys/types.h>
36 #include "server_internal.h"
37 #include <kadm5/admin.h>
44 #include "adm_proto.h"
48 static char **word_list
= NULL
; /* list of word pointers */
49 static char *word_block
= NULL
; /* actual word data */
50 static unsigned int word_count
= 0; /* number of words */
54 * Function: word_compare
56 * Purpose: compare two words in the dictionary.
59 * w1 (input) pointer to first word
60 * w2 (input) pointer to second word
61 * <return value> result of strcmp
64 * w1 and w2 to point to valid memory
69 word_compare(const void *s1
, const void *s2
)
71 return (strcasecmp(*(const char **)s1
, *(const char **)s2
));
77 * Purpose: Initialize in memory word dictionary
81 * <return value> KADM5_OK on success errno on failure;
82 * (but success on ENOENT)
85 * If WORDFILE exists, it must contain a list of words,
89 * If WORDFILE exists, it is read into memory sorted for future
90 * use. If it does not exist, it syslogs an error message and returns
94 * word_list to point to a chunck of allocated memory containing
96 * word_block to contain the dictionary.
100 int init_dict(kadm5_config_params
*params
)
109 if(word_list
!= NULL
&& word_block
!= NULL
)
111 if (! (params
->mask
& KADM5_CONFIG_DICT_FILE
)) {
112 /* Solaris Kerberos */
113 krb5_klog_syslog(LOG_INFO
,
114 dgettext(TEXT_DOMAIN
,
115 "No dictionary file specified, continuing "
119 if ((fd
= open(params
->dict_file
, O_RDONLY
)) == -1) {
120 if (errno
== ENOENT
) {
121 /* Solaris Kerberos */
122 krb5_klog_syslog(LOG_ERR
,
123 dgettext(TEXT_DOMAIN
,
124 "WARNING! Cannot find dictionary file %s, "
125 "continuing without one."), params
->dict_file
);
130 if (fstat(fd
, &sb
) == -1)
132 if ((word_block
= (char *) malloc(sb
.st_size
+ 1)) == NULL
)
134 if (read(fd
, word_block
, sb
.st_size
) != sb
.st_size
)
137 word_block
[sb
.st_size
] = '\0';
141 while(len
> 0 && (t
= memchr(p
, '\n', len
)) != NULL
) {
147 if ((word_list
= (char **) malloc(word_count
* sizeof(char *))) == NULL
)
150 for (i
= 0; i
< word_count
; i
++) {
154 qsort(word_list
, word_count
, sizeof(char *), word_compare
);
159 * Function: find_word
161 * Purpose: See if the specified word exists in the in-core dictionary
164 * word (input) word to search for.
165 * <return value> WORD_NOT_FOUND if not in dictionary,
166 * KADM5_OK if if found word
167 * errno if init needs to be called and returns an
171 * word to be a null terminated string.
172 * That word_list and word_block besetup
175 * finds word in dictionary.
182 find_word(const char *word
)
186 if(word_list
== NULL
|| word_block
== NULL
)
187 return WORD_NOT_FOUND
;
188 if ((value
= (char **) bsearch(&word
, word_list
, word_count
, sizeof(char *),
189 word_compare
)) == NULL
)
190 return WORD_NOT_FOUND
;
196 * Function: destroy_dict
198 * Purpose: destroy in-core copy of dictionary.
202 * <return value> none
206 * frees up memory occupied by word_list and word_block
207 * sets count back to 0, and resets the pointers to NULL
210 * word_list, word_block, and word_count.