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 static char *rcsid
= "$Header$";
28 #include <sys/types.h>
34 #include "server_internal.h"
35 #include <kadm5/admin.h>
42 #include "adm_proto.h"
46 static char **word_list
= NULL
; /* list of word pointers */
47 static char *word_block
= NULL
; /* actual word data */
48 static unsigned int word_count
= 0; /* number of words */
52 * Function: word_compare
54 * Purpose: compare two words in the dictionary.
57 * w1 (input) pointer to first word
58 * w2 (input) pointer to second word
59 * <return value> result of strcmp
62 * w1 and w2 to point to valid memory
67 word_compare(const void *s1
, const void *s2
)
69 return (strcasecmp(*(const char **)s1
, *(const char **)s2
));
75 * Purpose: Initialize in memory word dictionary
79 * <return value> KADM5_OK on success errno on failure;
80 * (but success on ENOENT)
83 * If WORDFILE exists, it must contain a list of words,
87 * If WORDFILE exists, it is read into memory sorted for future
88 * use. If it does not exist, it syslogs an error message and returns
92 * word_list to point to a chunck of allocated memory containing
94 * word_block to contain the dictionary.
98 int init_dict(kadm5_config_params
*params
)
107 if(word_list
!= NULL
&& word_block
!= NULL
)
109 if (! (params
->mask
& KADM5_CONFIG_DICT_FILE
)) {
110 /* Solaris Kerberos */
111 krb5_klog_syslog(LOG_INFO
,
112 dgettext(TEXT_DOMAIN
,
113 "No dictionary file specified, continuing "
117 if ((fd
= open(params
->dict_file
, O_RDONLY
)) == -1) {
118 if (errno
== ENOENT
) {
119 /* Solaris Kerberos */
120 krb5_klog_syslog(LOG_ERR
,
121 dgettext(TEXT_DOMAIN
,
122 "WARNING! Cannot find dictionary file %s, "
123 "continuing without one."), params
->dict_file
);
128 if (fstat(fd
, &sb
) == -1)
130 if ((word_block
= (char *) malloc(sb
.st_size
+ 1)) == NULL
)
132 if (read(fd
, word_block
, sb
.st_size
) != sb
.st_size
)
135 word_block
[sb
.st_size
] = '\0';
139 while(len
> 0 && (t
= memchr(p
, '\n', len
)) != NULL
) {
145 if ((word_list
= (char **) malloc(word_count
* sizeof(char *))) == NULL
)
148 for (i
= 0; i
< word_count
; i
++) {
152 qsort(word_list
, word_count
, sizeof(char *), word_compare
);
157 * Function: find_word
159 * Purpose: See if the specified word exists in the in-core dictionary
162 * word (input) word to search for.
163 * <return value> WORD_NOT_FOUND if not in dictionary,
164 * KADM5_OK if if found word
165 * errno if init needs to be called and returns an
169 * word to be a null terminated string.
170 * That word_list and word_block besetup
173 * finds word in dictionary.
180 find_word(const char *word
)
184 if(word_list
== NULL
|| word_block
== NULL
)
185 return WORD_NOT_FOUND
;
186 if ((value
= (char **) bsearch(&word
, word_list
, word_count
, sizeof(char *),
187 word_compare
)) == NULL
)
188 return WORD_NOT_FOUND
;
194 * Function: destroy_dict
196 * Purpose: destroy in-core copy of dictionary.
200 * <return value> none
204 * frees up memory occupied by word_list and word_block
205 * sets count back to 0, and resets the pointers to NULL
208 * word_list, word_block, and word_count.