Erlang Mailing Lists

Author Message

<  Yaws mailing list  ~  load_yaws_auth_file error after upgrade

Guest
Posted: Sat Sep 19, 2009 7:13 am Reply with quote
Guest
Hello all,

After an upgrade from 1.81 to 1.84 in current git repository (last commit : 0efd59)
I got the following error :

** exception error: {badrecord,auth}
in function yaws_config:load_yaws_auth_file/3
in call from yaws_config:setup_auth/1
in call from yaws_config:'-add_yaws_auth/1-fun-0-'/1
in call from lists:map/2
in call from yaws_api:setconf/3


I tried to understand the difference between 1.81 and 1.84 about www-authenticate management. I added comments in the code :

In the yaws_config.erl module :


add_yaws_auth(SCs) ->
lists:map(
fun(SC) ->
SC#sconf{authdirs = setup_auth(SC)}
end, SCs).



setup_auth(SC) ->
Auth_dirs0 = get_yaws_auth_dirs(SC#sconf.docroot),

Auth_dirs1 = [#auth{dir = [X]} || X <- Auth_dirs0],

% So we add the previous authdirs from SC to a list of #auth
Auth_dirs2 = Auth_dirs1 ++ SC#sconf.authdirs,

%load_yaws_auth_file return a list of tuple : {Dir,#auth}
Auth_dirs3 = load_yaws_auth_file(SC, Auth_dirs2, []),

start_pam(Auth_dirs3),

% The result will set the authdirs field from the given SC
Auth_dirs3.





load_yaws_auth_file/3 always wait for a list of #auth as second argument
but if we call this function many times (maybe in embedded mode) we pass to load_yaws_auth_file/3
a list composed of #auth and tuple {Dir,#auth}.



A solution could be to replace in setup_auth/1 in yaws_config.erl module :

Auth_dirs2 = Auth_dirs1 ++ SC#sconf.authdirs,

by

Auth_dirs2 = Auth_dirs1 ++ [ A || {_Dir,A} <- SC#sconf.authdirs],



Thank you for your help,


wde





------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post received from mailinglist
Guest
Posted: Sat Sep 19, 2009 3:22 pm Reply with quote
Guest
My proposition to solve this issue (maybe it's not an issue, leet me see if I am wrong, maybe I need to sleep :+) ) is not correct.

What I understand is :

-> when you load a yaws configuration file, yaws_config:fload/8 set a list
of #auth records in #sconf. authdirs

-> when you call load_yaws_auth_file/3 , #sconf.authdirs takes the function result which is a list of tuples {Dir,#auth}


If you decide to set manually your #sconf records in embedded mode what you should set in your #sconf.authdirs ?
A list of #auth records (like a configure file load) or a tuples list {Directory,#auth} ?

On the other hand, the function yaws:make_www_authenticate_header/1 is called when yaws load a configuration file or when parse_yaws_auth_file/2 is called and with a "yaws_auth" file in your directory. In embedded mode, I suppose that we have to set manually and completely the headers field, even the default www_authenticate_header. But if we have a "yaws_auth" file in our directory, www_authenticate_header will be set twice, isn't it ?


For the moment, I changed the yaws_config:load_yaws_auth_file/3 :


load_yaws_auth_file(_SC, [], Acc) ->
Acc;


% handle the case where we have a tuple {Dir,#auth} in #sconf.authdirs :
load_yaws_auth_file(SC,[{_Dir,Auth}|T],Acc)->
load_yaws_auth_file(SC,[Auth|T],Acc);


load_yaws_auth_file(SC, [A|T], Acc) ->

[Dir] = A#auth.dir,
FN0=[SC#sconf.docroot, [$/|Dir], [$/|".yaws_auth"]],
FN1 = remove_multiple_slash(lists:flatten(FN0)),

A2 = case file:consult(FN1) of
{ok, TermList} ->
error_logger:info_msg("Reading .yaws_auth ~s~n",[FN1]),
Auth = parse_yaws_auth_file(TermList, A),
[Dir1] = Auth#auth.dir,
{Dir1, Auth};
{error, enoent} ->
{Dir, A};
_Err ->
error_logger:format("Bad .yaws_auth file in dir ~p~n",
[Dir]),
{Dir, A}
end,
load_yaws_auth_file(SC, T, [A2|Acc]).


let me know where are my mistakes, maybe I don't use correctly the function yaws_api:setconf(GC, Groups).



thank you


wde








======= le 19/09/2009, 09:11:57 vous
Guest
Posted: Mon Sep 28, 2009 10:37 pm Reply with quote
Guest
Commit:d5676b22c92b6f69bfe86ba0017d91663ab14f95

solve the problem






======= le 19/09/2009, 17:21:27 vous
Guest
Posted: Tue Sep 29, 2009 5:47 am Reply with quote
Guest
wde wrote:
> Commit:d5676b22c92b6f69bfe86ba0017d91663ab14f95
>
> solve the problem


I'm happy to hear that - I had a bit of bad conscience for not
replying to your mails. The auth code has been in a bit of flux
for a while - actually since I accepted the patches from
Fabian Alenius. Now Anders Dahlin has done a good code cleanup.

The only thing that is lacking now is some good docs describing
how to do the various auth(s) that are possible to do.


/klacke

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post received from mailinglist
Guest
Posted: Tue Sep 29, 2009 5:59 am Reply with quote
Guest
I was testing with something like that, maybe we could use in a doc ... :+p


-module(bla).
-compile(export_all).

-include("../include/yaws.hrl").
-include("../include/yaws_api.hrl").
-include("../include/yaws_debug.hrl").

start() ->
DocRoot = "/www",
ServerName ="bla.com",
Users = [{"user", "pass"}],
AuthDirs = [
#auth{
dir = ["/test"],
realm = "The TEST realm",
users = Users,
headers = yaws:make_www_authenticate_header({realm, "The TEST realm"})
}
],
yaws:start_embedded(DocRoot,[{servername,ServerName},{listen,{0,0,0,0}},{port,8080},{reuseaddr, true},{dir_listings, false},{authdirs, AuthDirs}]).


enable_dirlisting() ->
set_dirlisting(true).

disable_dirlisting() ->
set_dirlisting(false).

set_dirlisting(Bool) ->
{ok,GC,[[SC]]} = yaws_api:getconf(),
NSC = ?sc_set_dir_listings(SC,Bool),
yaws_api:setconf(GC,[[NSC]]).

set_new_user_realm(User,Pass) ->
{ok,GC,[[SC]]} = yaws_api:getconf(),
AuthDirs = [
#auth{
dir = ["/test"],
realm = "The TEST realm",
users = [{User, Pass}],
headers = yaws:make_www_authenticate_header({realm, "The TEST realm"})
}
],
NSC = SC#sconf{authdirs = AuthDirs},
yaws_api:setconf(GC,[[NSC]]).


add_second_authdir() ->
{ok,GC,[[SC]]} = yaws_api:getconf(),
Users = [{"css", "css"}],
NewAuthDir =
#auth{
dir = ["/css"],
realm = "The CSS realm",
users = Users,
headers = yaws:make_www_authenticate_header({realm, "The CSS realm"})
}
,
NSC = SC#sconf{authdirs = [ NewAuthDir | SC#sconf.authdirs]},
yaws_api:setconf(GC,[[NSC]]).













======= le 29/09/2009, 07:46:04 vous

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum