Skip to content

Commit

Permalink
pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
Browse files Browse the repository at this point in the history
….com

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@941 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information
Claes Wikstrom committed Feb 14, 2006
1 parent 678f464 commit 31fdaae
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 148 deletions.
31 changes: 19 additions & 12 deletions c_src/epam.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

#include <pam_appl.h>
#include <stdio.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <pam_appl.h>
#include <pam_misc.h>
#include <unistd.h>
#include <sys/types.h>


#define get_int16(s) ((((unsigned char*) (s))[0] << 8) | \
Expand All @@ -15,10 +16,11 @@
#define put_int16(i, s) {((unsigned char*)(s))[0] = ((i) >> 8) & 0xff; \
((unsigned char*)(s))[1] = (i) & 0xff;}

#ifndef D
#define D(str) fprintf(stderr, (str))
#endif

static int interactive = 0;

static int read_fill(int fd, char *buf, int len)
static int read_fill(int fd, unsigned char *buf, int len)
{
int i, got = 0;

Expand Down Expand Up @@ -52,7 +54,7 @@ static int write_fill(int fd, char *buf, int len)
}



#if 0
/*
* These functions are for binary prompt manipulation.
* The manner in which a binary prompt is processed is application
Expand All @@ -70,6 +72,7 @@ static void pam_misc_conv_delete_binary(void *appdata,
int (*pam_binary_handler_fn)(void *appdata, pamc_bp_t *prompt_p) = NULL;
void (*pam_binary_handler_free)(void *appdata, pamc_bp_t *prompt_p)
= pam_misc_conv_delete_binary;
#endif

/*
* This conversation function is supposed to be a generic PAM one.
Expand Down Expand Up @@ -106,7 +109,6 @@ int misc_conv(int num_msg, const struct pam_message **msgm,

for (count=0; count < num_msg; ++count) {
char *string=NULL;
int nc;

switch (msgm[count]->msg_style) {
case PAM_PROMPT_ECHO_OFF:
Expand All @@ -125,6 +127,7 @@ int misc_conv(int num_msg, const struct pam_message **msgm,
goto failed_conversation;
}
break;
#if 0
case PAM_BINARY_PROMPT:
{
pamc_bp_t binary_prompt = NULL;
Expand All @@ -149,6 +152,7 @@ int misc_conv(int num_msg, const struct pam_message **msgm,

break;
}
#endif
default:
fprintf(stderr, "erroneous conversation (%d)\n"
,msgm[count]->msg_style);
Expand Down Expand Up @@ -181,13 +185,17 @@ int misc_conv(int num_msg, const struct pam_message **msgm,
switch (msgm[count]->msg_style) {
case PAM_PROMPT_ECHO_ON:
case PAM_PROMPT_ECHO_OFF:
#if 0
_pam_overwrite(reply[count].resp);
#endif
free(reply[count].resp);
break;
#if 0
case PAM_BINARY_PROMPT:
pam_binary_handler_free(appdata_ptr,
(pamc_bp_t *) &reply[count].resp);
break;
#endif
case PAM_ERROR_MSG:
case PAM_TEXT_INFO:
/* should not actually be able to get here... */
Expand Down Expand Up @@ -340,9 +348,8 @@ static void do_auth(char *service, char*user, char*pwd, char* mode, int sid)
int main(int argc, char *argv[])
{
pam_handle_t *pamh=NULL;
int retval;
unsigned char lb[2];
char buf[BUFSIZ];
unsigned char buf[BUFSIZ];
char *user;
char *pwd;
char *mode;
Expand All @@ -366,7 +373,7 @@ int main(int argc, char *argv[])
case 'a':
// auth a user
pamh = NULL;
user = &buf[1];
user = (char *)&buf[1];
pwd = user + strlen(user) + 1;
mode= pwd + strlen(pwd) + 1;
sid = atoi(mode + strlen(mode) + 1);
Expand All @@ -375,7 +382,7 @@ int main(int argc, char *argv[])
break;
case 'c':
// close session
sid = atoi(&buf[1]);
sid = atoi((char *)&buf[1]);
if ((sessp = del_session(&sessions, sid)) == NULL) {
fprintf(stderr, "Couldn't find session %d\r\n", sid);
break;
Expand Down
9 changes: 9 additions & 0 deletions include/yaws.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,12 @@
type, %% atom, pair or absolute
data}).


%% as read by application:get_env()
-record(env, {debug,
trace,
traceoutput,
conf,
runmod,
embedded}).

4 changes: 3 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ yaws_vsn.erl: yaws_vsn.template ../vsn.mk


charset.def:
echo $(DEFAULT_CHARSET) > charset.def
if [ ! -z "$(DEFAULT_CHARSET)" ]; then \
echo $(DEFAULT_CHARSET) > charset.def; \
else rm charset.def; touch charset.def; fi

mime_types.erl: mime.types mime_type_c.erl charset.def
$(ERL) -noshell -pa ../ebin -s mime_type_c compile
Expand Down
2 changes: 1 addition & 1 deletion src/mime_type_c.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ c() ->
{ok, F} = file:open("mime.types", [read]),
io:format("Compiling mime.types ... > mime_types.erl ~n", []),
{ok, B} = file:read_file("charset.def"),
case string:tokens(binary_to_list(B)," \r\n\t") of
case string:tokens(binary_to_list(B)," \r\n\t" ++ [0, 12]) of
[] ->
put(charset, []);
[CharSet0] ->
Expand Down
23 changes: 13 additions & 10 deletions src/yaws_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-compile(export_all).
%%-export([Function/Arity, ...]).

-export([load/4,
-export([load/1,
toks/1,
make_default_gconf/1]).

Expand All @@ -41,25 +41,26 @@ paths() ->

%% load the config

load(false, Trace, TraceOutput, Debug) ->
load(E = #env{conf = false}) ->
case yaws:first(fun(F) -> yaws:exists(F) end, paths()) of
false ->
{error, "Can't find no config file "};
{ok, _, File} ->
load({file, File}, Trace, TraceOutput, Debug)
load(E#env{conf = {file, File}})
end;
load({file, File}, Trace, TraceOutput, Debug) ->
load(E) ->
{file, File} = E#env.conf,
error_logger:info_msg("Yaws: Using config file ~s~n", [File]),
case file:open(File, [read]) of
{ok, FD} ->
GC = make_default_gconf(Debug),
GC2 = if TraceOutput == undefined ->
GC = make_default_gconf(E#env.debug),
GC2 = if E#env.traceoutput == undefined ->
GC;
true ->
?gc_set_tty_trace(GC,true)
end,
GC3 = ?gc_set_debug(GC2, Debug),
GC4 = GC3#gconf{trace = Trace},
GC3 = ?gc_set_debug(GC2, E#env.debug),
GC4 = GC3#gconf{trace = E#env.trace},
R = (catch fload(FD, globals, GC4, undefined,
[], 1, io:get_line(FD, ''))),
?Debug("FLOAD: ~p", [R]),
Expand Down Expand Up @@ -497,8 +498,10 @@ fload(FD, server, GC, C, Cs, Lno, Chars) ->
"true" ->
C2 = ?sc_set_dir_listings(C, true),
C3 = ?sc_set_dir_all_zip(C2, true),
AllAppMod = {"all.zip", yaws_ls},
C4 = C3#sconf{appmods = [AllAppMod | C3#sconf.appmods]},
C4 = C3#sconf{appmods = [ {"all.zip", yaws_ls},
{"all.tgz", yaws_ls},
{"all.tbz2", yaws_ls}|
C3#sconf.appmods]},
fload(FD, server, GC, C4, Cs, Lno+1, Next);
"true_nozip" ->
C2 = ?sc_set_dir_listings(C, true),
Expand Down
4 changes: 0 additions & 4 deletions src/yaws_ctl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ start(GC, true) ->
end.


%% syncronous start,
%% If we're later supposed
%% to change uid, we're still root here.

run(GC) ->
%% First check if there is already a Yaws system running
%% with the same sid.
Expand Down
Loading

0 comments on commit 31fdaae

Please sign in to comment.