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.
12 __RCSID("$Heimdal: pop_pass.c 19078 2006-11-20 18:12:41Z lha $"
17 krb4_verify_password (POP
*p
)
20 char lrealm
[REALM_SZ
];
23 status
= krb_get_lrealm(lrealm
,1);
24 if (status
== KFAILURE
) {
25 pop_log(p
, POP_PRIORITY
, "%s: (%s.%s@%s) %s", p
->client
,
26 p
->kdata
.pname
, p
->kdata
.pinst
, p
->kdata
.prealm
,
27 krb_get_err_text(status
));
30 snprintf(tkt
, sizeof(tkt
), "%s_popper.%u", TKT_ROOT
, (unsigned)getpid());
31 krb_set_tkt_string (tkt
);
33 status
= krb_verify_user(p
->user
, "", lrealm
,
34 p
->pop_parm
[1], KRB_VERIFY_SECURE
, "pop");
35 dest_tkt(); /* no point in keeping the tickets */
42 krb5_verify_password (POP
*p
)
44 krb5_preauthtype pre_auth_types
[] = {KRB5_PADATA_ENC_TIMESTAMP
};
45 krb5_get_init_creds_opt
*get_options
;
46 krb5_verify_init_creds_opt verify_options
;
48 krb5_principal client
, server
;
51 ret
= krb5_get_init_creds_opt_alloc (p
->context
, &get_options
);
53 pop_log(p
, POP_PRIORITY
, "krb5_get_init_creds_opt_init: %s",
54 krb5_get_err_text (p
->context
, ret
));
58 krb5_get_init_creds_opt_set_preauth_list (get_options
,
62 krb5_verify_init_creds_opt_init (&verify_options
);
64 ret
= krb5_parse_name (p
->context
, p
->user
, &client
);
66 pop_log(p
, POP_PRIORITY
, "krb5_parse_name: %s",
67 krb5_get_err_text (p
->context
, ret
));
71 ret
= krb5_get_init_creds_password (p
->context
,
80 krb5_get_init_creds_opt_free(p
->context
, get_options
);
82 pop_log(p
, POP_PRIORITY
,
83 "krb5_get_init_creds_password: %s",
84 krb5_get_err_text (p
->context
, ret
));
88 ret
= krb5_sname_to_principal (p
->context
,
94 pop_log(p
, POP_PRIORITY
,
95 "krb5_get_init_creds_password: %s",
96 krb5_get_err_text (p
->context
, ret
));
100 ret
= krb5_verify_init_creds (p
->context
,
106 krb5_free_principal (p
->context
, client
);
107 krb5_free_principal (p
->context
, server
);
108 krb5_free_cred_contents (p
->context
, &creds
);
113 * pass: Obtain the user password from a POP client
122 /* Look for the user in the password file */
123 if ((pw
= k_getpwnam(p
->user
)) == NULL
) {
124 pop_log(p
, POP_PRIORITY
, "user %s (from %s) not found",
126 return pop_msg(p
, POP_FAILURE
, "Login incorrect.");
129 pop_log(p
, POP_INFO
, "login from %s as %s", p
->ipaddr
, p
->user
);
131 /* Build the name of the user's maildrop */
132 snprintf(p
->drop_name
, sizeof(p
->drop_name
), "%s/%s", POP_MAILDIR
, p
->user
);
133 if(stat(p
->drop_name
, &st
) < 0 || !S_ISDIR(st
.st_mode
)){
134 /* Make a temporary copy of the user's maildrop */
135 /* and set the group and user id */
136 if (pop_dropcopy(p
, pw
) != POP_SUCCESS
) return (POP_FAILURE
);
138 /* Get information about the maildrop */
139 if (pop_dropinfo(p
) != POP_SUCCESS
) return(POP_FAILURE
);
141 if(changeuser(p
, pw
) != POP_SUCCESS
) return POP_FAILURE
;
142 if(pop_maildir_info(p
) != POP_SUCCESS
) return POP_FAILURE
;
144 /* Initialize the last-message-accessed number */
156 /* Make one string of all these parameters */
158 for (i
= 1; i
< p
->parm_count
; ++i
)
159 p
->pop_parm
[i
][strlen(p
->pop_parm
[i
])] = ' ';
161 /* Look for the user in the password file */
162 if ((pw
= k_getpwnam(p
->user
)) == NULL
)
163 return (pop_msg(p
,POP_FAILURE
,
164 "Password supplied for \"%s\" is incorrect.",
169 if (p
->version
== 4) {
170 if(kuserok (&p
->kdata
, p
->user
)) {
171 pop_log(p
, POP_PRIORITY
,
172 "%s: (%s.%s@%s) tried to retrieve mail for %s.",
173 p
->client
, p
->kdata
.pname
, p
->kdata
.pinst
,
174 p
->kdata
.prealm
, p
->user
);
175 return(pop_msg(p
,POP_FAILURE
,
176 "Popping not authorized"));
178 pop_log(p
, POP_INFO
, "%s: %s.%s@%s -> %s",
180 p
->kdata
.pname
, p
->kdata
.pinst
, p
->kdata
.prealm
,
185 if (p
->version
== 5) {
188 if (!krb5_kuserok (p
->context
, p
->principal
, p
->user
)) {
189 pop_log (p
, POP_PRIORITY
,
190 "krb5 permission denied");
191 return pop_msg(p
, POP_FAILURE
,
192 "Popping not authorized");
194 if(krb5_unparse_name (p
->context
, p
->principal
, &name
) == 0) {
195 pop_log(p
, POP_INFO
, "%s: %s -> %s",
196 p
->ipaddr
, name
, p
->user
);
200 pop_log (p
, POP_PRIORITY
, "kerberos authentication failed");
201 return pop_msg (p
, POP_FAILURE
,
202 "kerberos authentication failed");
207 /* We don't accept connections from users with null passwords */
208 if (pw
->pw_passwd
== NULL
)
211 "Password supplied for \"%s\" is incorrect.",
215 if (otp_verify_user (&p
->otp_ctx
, p
->pop_parm
[1]) == 0)
219 /* Compare the supplied password with the password file entry */
220 if (p
->auth_level
!= AUTH_NONE
)
221 return pop_msg(p
, POP_FAILURE
,
222 "Password supplied for \"%s\" is incorrect.",
224 else if (!strcmp(crypt(p
->pop_parm
[1], pw
->pw_passwd
), pw
->pw_passwd
))
229 ret
= krb4_verify_password (p
);
233 ret
= krb5_verify_password (p
);
236 return pop_msg(p
, POP_FAILURE
,
237 "Password incorrect");
240 status
= login_user(p
);
241 if(status
!= POP_SUCCESS
)
244 /* Authorization completed successfully */
245 return (pop_msg (p
, POP_SUCCESS
,
246 "%s has %d message(s) (%ld octets).",
247 p
->user
, p
->msg_count
, p
->drop_size
));