passdb-passwd.c revision 0373a24e97602b4c394e93a70b75f45e5869fa51
742N/A/* Copyright (C) 2002-2003 Timo Sirainen */
742N/A
742N/A#include "config.h"
742N/A#undef HAVE_CONFIG_H
742N/A
742N/A#ifdef PASSDB_PASSWD
742N/A
742N/A#include "common.h"
742N/A#include "safe-memset.h"
742N/A#include "passdb.h"
742N/A#include "mycrypt.h"
742N/A
742N/A#include <pwd.h>
742N/A
742N/Astatic void
742N/Apasswd_verify_plain(struct auth_request *request, const char *password,
742N/A verify_plain_callback_t *callback)
742N/A{
742N/A struct passwd *pw;
742N/A int result;
742N/A
2603N/A pw = getpwnam(request->user);
742N/A if (pw == NULL) {
742N/A if (verbose) {
742N/A i_info("passwd(%s): unknown user",
1116N/A get_log_prefix(request));
1116N/A }
1116N/A callback(PASSDB_RESULT_USER_UNKNOWN, request);
742N/A return;
742N/A }
742N/A
1117N/A if (!IS_VALID_PASSWD(pw->pw_passwd)) {
1117N/A if (verbose) {
1117N/A i_info("passwd(%s): invalid password field '%s'",
1117N/A get_log_prefix(request), pw->pw_passwd);
758N/A }
758N/A callback(PASSDB_RESULT_USER_DISABLED, request);
758N/A return;
758N/A }
758N/A
758N/A /* check if the password is valid */
758N/A result = strcmp(mycrypt(password, pw->pw_passwd), pw->pw_passwd) == 0;
758N/A
758N/A /* clear the passwords from memory */
758N/A safe_memset(pw->pw_passwd, 0, strlen(pw->pw_passwd));
742N/A
742N/A if (!result) {
742N/A if (verbose) {
742N/A i_info("passwd(%s): password mismatch",
742N/A get_log_prefix(request));
758N/A }
742N/A callback(PASSDB_RESULT_PASSWORD_MISMATCH, request);
742N/A return;
742N/A }
758N/A
742N/A callback(PASSDB_RESULT_OK, request);
742N/A}
758N/A
742N/Astatic void passwd_deinit(void)
742N/A{
742N/A endpwent();
742N/A}
742N/A
742N/Astruct passdb_module passdb_passwd = {
742N/A NULL,
742N/A passwd_deinit,
742N/A
742N/A passwd_verify_plain,
742N/A NULL
742N/A};
742N/A
742N/A#endif
742N/A