swerc

anselm's simpler werc fork
git clone git://git.suckless.org/swerc
Log | Files | Refs | README

commit 6ac98d48e63be79234d3240c0654ca90448957d8
parent 5565a8b117628ea7bdc553a5020475ee63a7e8d2
Author: uriel@engel.se.cat-v.org <unknown>
Date:   Tue, 21 Oct 2008 16:36:45 +0200

Replace debug and 'false' calls with setting $status
Diffstat:
Mbin/cgilib.rc | 44++++++++++++++------------------------------
1 file changed, 14 insertions(+), 30 deletions(-)

diff --git a/bin/cgilib.rc b/bin/cgilib.rc @@ -127,17 +127,13 @@ fn get_cookie { # Auth code # Cookie format: WERC_USER: name:timestamp:hash(name.timestamp.password) -# login_user can't be used from a template because it sets a cookie! +# login_user can't be used from a template because it sets a cookie fn login_user { get_post_args user_name user_password - if(auth_user $user_name $user_password) { - set_cookie werc_user $"user_name^':0:'^$"user_password - dprint Auth: SET COOKIE FOR USER: $user_name - } - if not { - dprint Auth: failed login for $user_name $user_password - false - } + if(auth_user $user_name $user_password) + set_cookie werc_user $"user_name^':0:'^$"user_password + if not + status='Auth: failed login for $user_name $user_password' } fn auth_user { @@ -145,36 +141,24 @@ fn auth_user { user_pass = $2 pfile = 'etc/users/'^$"user_name^'/password' - if (~ $#user_name 0 || ~ $#user_password 0) { - dprint Auth: missing user name or pass: $user_name / $user_password - false - } - if not if(! test -f $pfile) { - dprint Auth: cant find $pfile - false - } - if not if (! ~ $user_pass `{cat $pfile}) { - dprint Auth: Pass $user_pass doesnt match `{cat $pfile} - false - } - if not { + if (~ $#user_name 0 || ~ $#user_password 0) + status='Auth: missing user name or pass: '^$user_name^' / '^$user_password + if not if(! test -f $pfile) + status='Auth: cant find '^$pfile + if not if (! ~ $user_pass `{cat $pfile}) + status='Auth: Pass '$user_pass' doesnt match '^`{cat $pfile} + if not dprint Auth: success - true - } } fn user_in_group { if(~ $#logged_user 0) get_user - if(~ $#logged_user 0) { - dprint Auth: user_in_group: No logged in user + if(~ $#logged_user 0) false - } - if not if (! grep -s '^'^$logged_user^'$' etc/groups/$1) { - dprint Auth: user_in_group: Cant find $logged_user in etc/groups/$1 + if not if (! grep -s '^'^$logged_user^'$' etc/groups/$1) false - } if not true }