mirror of
https://github.com/samba-team/samba.git
synced 2024-12-25 23:21:54 +03:00
ntlm_auth: Prepare for a deeper rewrite of the helper functions
This commit is contained in:
parent
4a475baf26
commit
f8243d1913
@ -43,6 +43,23 @@ enum stdio_helper_mode {
|
|||||||
NUM_HELPER_MODES
|
NUM_HELPER_MODES
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ntlm_auth_con_state {
|
||||||
|
CLIENT_INITIAL,
|
||||||
|
CLIENT_RESPONSE,
|
||||||
|
CLIENT_FINISHED,
|
||||||
|
CLIENT_ERROR,
|
||||||
|
SERVER_INITIAL,
|
||||||
|
SERVER_CHALLENGE,
|
||||||
|
SERVER_FINISHED,
|
||||||
|
SERVER_ERROR
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ntlm_auth_state {
|
||||||
|
TALLOC_CTX *mem_ctx;
|
||||||
|
enum stdio_helper_mode helper_mode;
|
||||||
|
enum ntlm_auth_con_state con_state;
|
||||||
|
};
|
||||||
|
|
||||||
typedef void (*stdio_helper_function)(enum stdio_helper_mode stdio_helper_mode,
|
typedef void (*stdio_helper_function)(enum stdio_helper_mode stdio_helper_mode,
|
||||||
char *buf, int length);
|
char *buf, int length);
|
||||||
|
|
||||||
@ -2069,14 +2086,15 @@ static void manage_ntlm_change_password_1_request(enum stdio_helper_mode helper_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void manage_squid_request(enum stdio_helper_mode helper_mode, stdio_helper_function fn)
|
static void manage_squid_request(struct ntlm_auth_state *state,
|
||||||
|
stdio_helper_function fn)
|
||||||
{
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
char tmp[INITIAL_BUFFER_SIZE+1];
|
char tmp[INITIAL_BUFFER_SIZE+1];
|
||||||
int length, buf_size = 0;
|
int length, buf_size = 0;
|
||||||
char *c;
|
char *c;
|
||||||
|
|
||||||
buf = talloc_strdup(NULL, "");
|
buf = talloc_strdup(state->mem_ctx, "");
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
DEBUG(0, ("Failed to allocate input buffer.\n"));
|
DEBUG(0, ("Failed to allocate input buffer.\n"));
|
||||||
x_fprintf(x_stderr, "ERR\n");
|
x_fprintf(x_stderr, "ERR\n");
|
||||||
@ -2123,17 +2141,38 @@ static void manage_squid_request(enum stdio_helper_mode helper_mode, stdio_helpe
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn(helper_mode, buf, length);
|
fn(state->helper_mode, buf, length);
|
||||||
talloc_free(buf);
|
talloc_free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void squid_stream(enum stdio_helper_mode stdio_mode, stdio_helper_function fn) {
|
static void squid_stream(enum stdio_helper_mode stdio_mode, stdio_helper_function fn) {
|
||||||
|
TALLOC_CTX *mem_ctx;
|
||||||
|
struct ntlm_auth_state *state;
|
||||||
|
|
||||||
/* initialize FDescs */
|
/* initialize FDescs */
|
||||||
x_setbuf(x_stdout, NULL);
|
x_setbuf(x_stdout, NULL);
|
||||||
x_setbuf(x_stderr, NULL);
|
x_setbuf(x_stderr, NULL);
|
||||||
|
|
||||||
|
mem_ctx = talloc_init("ntlm_auth");
|
||||||
|
if (!mem_ctx) {
|
||||||
|
DEBUG(0, ("squid_stream: Failed to create talloc context\n"));
|
||||||
|
x_fprintf(x_stderr, "ERR\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
state = talloc(mem_ctx, struct ntlm_auth_state);
|
||||||
|
if (!state) {
|
||||||
|
DEBUG(0, ("squid_stream: Failed to talloc ntlm_auth_state\n"));
|
||||||
|
x_fprintf(x_stderr, "ERR\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
state->mem_ctx = mem_ctx;
|
||||||
|
state->helper_mode = stdio_mode;
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
manage_squid_request(stdio_mode, fn);
|
manage_squid_request(state, fn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user