dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / krb5 / kadm5 / srv / server_misc.c
blob6f1eb5caff49a92b4674d2018c81a1ee61eb93bd
2 /*
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
13 * copyright.
15 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
21 * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
23 * $Header$
26 static char *rcsid = "$Header$";
28 #include "k5-int.h"
29 #include <krb5/kdb.h>
30 #include <ctype.h>
31 #include <pwd.h>
33 /* for strcasecmp */
34 #include <string.h>
36 #include "server_internal.h"
38 kadm5_ret_t
39 adb_policy_init(kadm5_server_handle_t handle)
41 /* now policy is initialized as part of database. No seperate call needed */
42 /* Solaris Kerberos: krb5_db_inited returns 0 when db has been inited */
43 if( krb5_db_inited( handle->context ) == 0 )
44 return KADM5_OK;
46 return krb5_db_open( handle->context, NULL,
47 KRB5_KDB_OPEN_RW | KRB5_KDB_SRV_TYPE_ADMIN );
50 kadm5_ret_t
51 adb_policy_close(kadm5_server_handle_t handle)
53 /* will be taken care by database close */
54 return KADM5_OK;
57 #ifdef HESIOD
58 /* stolen from v4sever/kadm_funcs.c */
59 static char *
60 reverse(str)
61 char *str;
63 static char newstr[80];
64 char *p, *q;
65 int i;
67 i = strlen(str);
68 if (i >= sizeof(newstr))
69 i = sizeof(newstr)-1;
70 p = str+i-1;
71 q = newstr;
72 q[i]='\0';
73 for(; i > 0; i--)
74 *q++ = *p--;
76 return(newstr);
78 #endif /* HESIOD */
80 #if 0
81 static int
82 lower(str)
83 char *str;
85 register char *cp;
86 int effect=0;
88 for (cp = str; *cp; cp++) {
89 if (isupper(*cp)) {
90 *cp = tolower(*cp);
91 effect++;
94 return(effect);
96 #endif
98 #ifdef HESIOD
99 static int
100 str_check_gecos(gecos, pwstr)
101 char *gecos;
102 char *pwstr;
104 char *cp, *ncp, *tcp;
106 for (cp = gecos; *cp; ) {
107 /* Skip past punctuation */
108 for (; *cp; cp++)
109 if (isalnum(*cp))
110 break;
111 /* Skip to the end of the word */
112 for (ncp = cp; *ncp; ncp++)
113 if (!isalnum(*ncp) && *ncp != '\'')
114 break;
115 /* Delimit end of word */
116 if (*ncp)
117 *ncp++ = '\0';
118 /* Check word to see if it's the password */
119 if (*cp) {
120 if (!strcasecmp(pwstr, cp))
121 return 1;
122 tcp = reverse(cp);
123 if (!strcasecmp(pwstr, tcp))
124 return 1;
125 cp = ncp;
126 } else
127 break;
129 return 0;
131 #endif /* HESIOD */
133 /* some of this is stolen from gatekeeper ... */
134 kadm5_ret_t
135 passwd_check(kadm5_server_handle_t handle,
136 char *password, int use_policy, kadm5_policy_ent_t pol,
137 krb5_principal principal)
139 int nupper = 0,
140 nlower = 0,
141 ndigit = 0,
142 npunct = 0,
143 nspec = 0;
144 char c, *s, *cp;
145 #ifdef HESIOD
146 extern struct passwd *hes_getpwnam();
147 struct passwd *ent;
148 #endif
150 if(use_policy) {
151 if(strlen(password) < pol->pw_min_length)
152 return KADM5_PASS_Q_TOOSHORT;
153 s = password;
154 while ((c = *s++)) {
155 if (islower((unsigned char) c)) {
156 nlower = 1;
157 continue;
159 else if (isupper((unsigned char) c)) {
160 nupper = 1;
161 continue;
162 } else if (isdigit((unsigned char) c)) {
163 ndigit = 1;
164 continue;
165 } else if (ispunct((unsigned char) c)) {
166 npunct = 1;
167 continue;
168 } else {
169 nspec = 1;
170 continue;
173 if ((nupper + nlower + ndigit + npunct + nspec) < pol->pw_min_classes)
174 return KADM5_PASS_Q_CLASS;
175 if((find_word(password) == KADM5_OK))
176 return KADM5_PASS_Q_DICT;
177 else {
178 int i, n = krb5_princ_size(handle->context, principal);
179 cp = krb5_princ_realm(handle->context, principal)->data;
180 if (strcasecmp(cp, password) == 0)
181 return KADM5_PASS_Q_DICT;
182 for (i = 0; i < n ; i++) {
183 cp = krb5_princ_component(handle->context, principal, i)->data;
184 if (strcasecmp(cp, password) == 0)
185 return KADM5_PASS_Q_DICT;
186 #ifdef HESIOD
187 ent = hes_getpwnam(cp);
188 if (ent && ent->pw_gecos)
189 if (str_check_gecos(ent->pw_gecos, password))
190 return KADM5_PASS_Q_DICT; /* XXX new error code? */
191 #endif
193 return KADM5_OK;
195 } else {
196 if (strlen(password) < 1)
197 return KADM5_PASS_Q_TOOSHORT;
199 return KADM5_OK;
202 void
203 trunc_name(size_t *len, char **dots)
205 *dots = *len > MAXPRINCLEN ? "..." : "";
206 *len = *len > MAXPRINCLEN ? MAXPRINCLEN : *len;