diff -urN mldonkey/src/daemon/common/commonOptions.ml mldonkey_with_authpatch/src/daemon/common/commonOptions.ml --- mldonkey/src/daemon/common/commonOptions.ml 2007-04-23 00:31:53.000000000 +0200 +++ mldonkey_with_authpatch/src/daemon/common/commonOptions.ml 2007-04-26 18:56:37.000000000 +0200 @@ -1363,7 +1358,26 @@ "Regexp of comments to filter out, example: string1|string2|string3" string_option "http://|https://|www\\." +let auth_cmd = define_option current_section ["auth_cmd"] + "A command that is called when authorizing a user (i.e. on startup and + on auth command. The following environment variables are set: + $USERNAME - the username + $PASSWORD - the users password + + The command should return a value indicating if the authentication + is successful: + 0 - The authentication is immidiately accepted IF the user exists + 1 - The authentication is immidiately rejected + 2 - An addition check against the MD4 has is performed. + + If the user does not exist in the internal database, the authentication + will fail, also when the program returns 0. + + If this value is not set, a normal authentication against the internal + database is performed. + If this option is set and there is an error running the command the + authentication will fail." + string_option "" (*************************************************************************) diff -urN mldonkey/src/daemon/common/commonUserDb.ml mldonkey_with_authpatch/src/daemon/common/commonUserDb.ml --- mldonkey/src/daemon/common/commonUserDb.ml 2006-11-09 22:32:26.000000000 +0100 +++ mldonkey_with_authpatch/src/daemon/common/commonUserDb.ml 2007-04-26 19:04:41.177275304 +0200 @@ -313,9 +313,32 @@ let user2_user_set_password user pass_string = user.user_pass <- Md4.string pass_string -let valid_password user pass = +let valid_password user pass = try - user2_user_password user = Md4.string pass + if !!auth_cmd <> "" && user2_user_exists user + then + try + let pid = Unix.create_process_env !!auth_cmd + [|""|] + (Array.of_list (Printf.sprintf "USERNAME=%s" user :: Printf.sprintf "PASSWORD=%s" pass :: [])) + Unix.stdin Unix.stdout Unix.stderr in + + let _pid, status = Unix.waitpid [] pid in + match status with + | Unix.WEXITED exitcode -> + (match exitcode with + | 0 -> true + | 1 -> false + | _ -> user2_user_password user = Md4.string pass + ) + | Unix.WSIGNALED signal -> false + | Unix.WSTOPPED signal -> false + with Unix.Unix_error (code, f, arg) -> false + (* + Printf.sprintf "%s failed%s: %s" f (if arg = "" then "" else " on " ^ arg) (Unix.error_message code) + *) + else + user2_user_password user = Md4.string pass with Not_found -> false let has_empty_password user =