diff --git a/ChangeLog b/ChangeLog index 0b324577c..5c7a7d30e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-07-08 Jean-Sébastien Pédron + + * src/cyrsasl.erl, src/cyrsasl_anonymous.erl, src/cyrsasl_digest.erl, + src/cyrsasl_plain.erl, src/ejabberd_c2s.erl: Errors are now atoms, not + strings anymore. + 2008-07-01 Jean-Sébastien Pédron * src/ejabberd_sm.erl: Convert to exmpp. diff --git a/src/cyrsasl.erl b/src/cyrsasl.erl index 17354e21f..e942aa3e8 100644 --- a/src/cyrsasl.erl +++ b/src/cyrsasl.erl @@ -86,14 +86,14 @@ register_mechanism(Mechanism, Module, RequirePlainPassword) -> %% end. check_credentials(_State, Props) -> - User = xml:get_attr_s(username, Props), - case jlib:nodeprep(User) of - error -> - {error, "not-authorized"}; - "" -> - {error, "not-authorized"}; - _LUser -> - ok + case proplists:get_value(username, Props) of + undefined -> + {error, 'not-authorized'}; + User -> + case exmpp_stringprep:is_node(User) of + false -> {error, 'not-authorized'}; + true -> ok + end end. listmech(Host) -> @@ -133,10 +133,10 @@ server_start(State, Mech, ClientIn) -> mech_state = MechState}, ClientIn); _ -> - {error, "no-mechanism"} + {error, 'no-mechanism'} end; false -> - {error, "no-mechanism"} + {error, 'no-mechanism'} end. server_step(State, ClientIn) -> diff --git a/src/cyrsasl_anonymous.erl b/src/cyrsasl_anonymous.erl index b9cf7449c..4f1219882 100644 --- a/src/cyrsasl_anonymous.erl +++ b/src/cyrsasl_anonymous.erl @@ -50,7 +50,7 @@ mech_step(State, _ClientIn) -> %% Checks that the username is available case ejabberd_auth:is_user_exists(User, Server) of - true -> {error, "not-authorized"}; + true -> {error, 'not-authorized'}; false -> {ok, [{username, User}, {auth_module, ejabberd_auth_anonymous}]} end. diff --git a/src/cyrsasl_digest.erl b/src/cyrsasl_digest.erl index 5395205d7..c269a74bf 100644 --- a/src/cyrsasl_digest.erl +++ b/src/cyrsasl_digest.erl @@ -39,13 +39,13 @@ mech_step(#state{step = 1, nonce = Nonce} = State, _) -> mech_step(#state{step = 3, nonce = Nonce} = State, ClientIn) -> case parse(ClientIn) of bad -> - {error, "bad-protocol"}; + {error, 'bad-protocol'}; KeyVals -> UserName = xml:get_attr_s("username", KeyVals), AuthzId = xml:get_attr_s("authzid", KeyVals), case (State#state.get_password)(UserName) of {false, _} -> - {error, "not-authorized", UserName}; + {error, 'not-authorized', UserName}; {Passwd, AuthModule} -> Response = response(KeyVals, UserName, Passwd, Nonce, AuthzId, "AUTHENTICATE"), @@ -61,7 +61,7 @@ mech_step(#state{step = 3, nonce = Nonce} = State, ClientIn) -> username = UserName, authzid = AuthzId}}; _ -> - {error, "not-authorized", UserName} + {error, 'not-authorized', UserName} end end end; @@ -73,7 +73,7 @@ mech_step(#state{step = 5, {auth_module, AuthModule}]}; mech_step(A, B) -> ?DEBUG("SASL DIGEST: A ~p B ~p", [A,B]), - {error, "bad-protocol"}. + {error, 'bad-protocol'}. parse(S) -> diff --git a/src/cyrsasl_plain.erl b/src/cyrsasl_plain.erl index 1b9cddb49..c0ca708d8 100644 --- a/src/cyrsasl_plain.erl +++ b/src/cyrsasl_plain.erl @@ -51,10 +51,10 @@ mech_step(State, ClientIn) -> {ok, [{username, User}, {authzid, AuthzId}, {auth_module, AuthModule}]}; _ -> - {error, "not-authorized", User} + {error, 'not-authorized', User} end; _ -> - {error, "bad-protocol"} + {error, 'bad-protocol'} end. diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index 76e92de8d..0b3360947 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -515,15 +515,13 @@ wait_for_feature_request({xmlstreamelement, #xmlel{ns = NS, name = Name} = El}, "(~w) Failed authentication for ~s@~s", [StateData#state.socket, Username, StateData#state.server]), - % XXX OLD FORMAT: list_to_atom(Error). send_element(StateData, - exmpp_server_sasl:failure(list_to_atom(Error))), + exmpp_server_sasl:failure(Error)), {next_state, wait_for_feature_request, StateData, ?C2S_OPEN_TIMEOUT}; {error, Error} -> - % XXX OLD FORMAT: list_to_atom(Error). send_element(StateData, - exmpp_server_sasl:failure(list_to_atom(Error))), + exmpp_server_sasl:failure(Error)), fsm_next_state(wait_for_feature_request, StateData) end; {?NS_TLS, 'starttls'} when TLS == true, @@ -631,14 +629,12 @@ wait_for_sasl_response({xmlstreamelement, #xmlel{ns = NS, name = Name} = El}, "(~w) Failed authentication for ~s@~s", [StateData#state.socket, Username, StateData#state.server]), - % XXX OLD FORMAT: list_to_atom(Error). send_element(StateData, - exmpp_server_sasl:failure(list_to_atom(Error))), + exmpp_server_sasl:failure(Error)), fsm_next_state(wait_for_feature_request, StateData); {error, Error} -> - % XXX OLD FORMAT: list_to_atom(Error). send_element(StateData, - exmpp_server_sasl:failure(list_to_atom(Error))), + exmpp_server_sasl:failure(Error)), fsm_next_state(wait_for_feature_request, StateData) end; _ ->