2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
16 krb5_verify_password (POP
*p
)
18 krb5_preauthtype pre_auth_types
[] = {KRB5_PADATA_ENC_TIMESTAMP
};
19 krb5_get_init_creds_opt
*get_options
;
20 krb5_verify_init_creds_opt verify_options
;
22 krb5_principal client
, server
;
25 ret
= krb5_get_init_creds_opt_alloc (p
->context
, &get_options
);
27 pop_log(p
, POP_PRIORITY
, "krb5_get_init_creds_opt_alloc: %s",
28 krb5_get_err_text (p
->context
, ret
));
32 krb5_get_init_creds_opt_set_preauth_list (get_options
,
36 krb5_verify_init_creds_opt_init (&verify_options
);
38 ret
= krb5_parse_name (p
->context
, p
->user
, &client
);
40 krb5_get_init_creds_opt_free(p
->context
, get_options
);
41 pop_log(p
, POP_PRIORITY
, "krb5_parse_name: %s",
42 krb5_get_err_text (p
->context
, ret
));
46 ret
= krb5_get_init_creds_password (p
->context
,
55 krb5_get_init_creds_opt_free(p
->context
, get_options
);
57 pop_log(p
, POP_PRIORITY
,
58 "krb5_get_init_creds_password: %s",
59 krb5_get_err_text (p
->context
, ret
));
63 ret
= krb5_sname_to_principal (p
->context
,
69 pop_log(p
, POP_PRIORITY
,
70 "krb5_get_init_creds_password: %s",
71 krb5_get_err_text (p
->context
, ret
));
75 ret
= krb5_verify_init_creds (p
->context
,
81 krb5_free_principal (p
->context
, client
);
82 krb5_free_principal (p
->context
, server
);
83 krb5_free_cred_contents (p
->context
, &creds
);
88 * pass: Obtain the user password from a POP client
97 /* Look for the user in the password file */
98 if ((pw
= k_getpwnam(p
->user
)) == NULL
) {
99 pop_log(p
, POP_PRIORITY
, "user %s (from %s) not found",
101 return pop_msg(p
, POP_FAILURE
, "Login incorrect.");
104 pop_log(p
, POP_INFO
, "login from %s as %s", p
->ipaddr
, p
->user
);
106 /* Build the name of the user's maildrop */
107 snprintf(p
->drop_name
, sizeof(p
->drop_name
), "%s/%s", POP_MAILDIR
, p
->user
);
108 if(stat(p
->drop_name
, &st
) < 0 || !S_ISDIR(st
.st_mode
)){
109 /* Make a temporary copy of the user's maildrop */
110 /* and set the group and user id */
111 if (pop_dropcopy(p
, pw
) != POP_SUCCESS
) return (POP_FAILURE
);
113 /* Get information about the maildrop */
114 if (pop_dropinfo(p
) != POP_SUCCESS
) return(POP_FAILURE
);
116 if(changeuser(p
, pw
) != POP_SUCCESS
) return POP_FAILURE
;
117 if(pop_maildir_info(p
) != POP_SUCCESS
) return POP_FAILURE
;
119 /* Initialize the last-message-accessed number */
131 /* Make one string of all these parameters */
133 for (i
= 1; i
< p
->parm_count
; ++i
)
134 p
->pop_parm
[i
][strlen(p
->pop_parm
[i
])] = ' ';
136 /* Look for the user in the password file */
137 if ((pw
= k_getpwnam(p
->user
)) == NULL
)
138 return (pop_msg(p
,POP_FAILURE
,
139 "Password supplied for \"%s\" is incorrect.",
144 if (p
->version
== 5) {
147 if (!krb5_kuserok (p
->context
, p
->principal
, p
->user
)) {
148 pop_log (p
, POP_PRIORITY
,
149 "krb5 permission denied");
150 return pop_msg(p
, POP_FAILURE
,
151 "Popping not authorized");
153 if(krb5_unparse_name (p
->context
, p
->principal
, &name
) == 0) {
154 pop_log(p
, POP_INFO
, "%s: %s -> %s",
155 p
->ipaddr
, name
, p
->user
);
159 pop_log (p
, POP_PRIORITY
, "kerberos authentication failed");
160 return pop_msg (p
, POP_FAILURE
,
161 "kerberos authentication failed");
166 /* We don't accept connections from users with null passwords */
167 if (pw
->pw_passwd
== NULL
)
170 "Password supplied for \"%s\" is incorrect.",
174 if (otp_verify_user (&p
->otp_ctx
, p
->pop_parm
[1]) == 0)
178 /* Compare the supplied password with the password file entry */
179 if (p
->auth_level
!= AUTH_NONE
)
180 return pop_msg(p
, POP_FAILURE
,
181 "Password supplied for \"%s\" is incorrect.",
183 else if (!strcmp(crypt(p
->pop_parm
[1], pw
->pw_passwd
), pw
->pw_passwd
))
189 ret
= krb5_verify_password (p
);
192 return pop_msg(p
, POP_FAILURE
,
193 "Password incorrect");
196 status
= login_user(p
);
197 if(status
!= POP_SUCCESS
)
200 /* Authorization completed successfully */
201 return (pop_msg (p
, POP_SUCCESS
,
202 "%s has %d message(s) (%ld octets).",
203 p
->user
, p
->msg_count
, p
->drop_size
));