summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorKai Blin <kai@samba.org>2008-01-16 09:52:26 +0100
committerKai Blin <kai@samba.org>2008-01-19 13:16:23 +0100
commitf22a29e1bd0c59710b1f6ab56e903fa6e1e51a46 (patch)
treeaadb0f6b0465f265e8c98f98d038377574e772ae /source3/utils
parent7b73ad2755290c5345b506dcc9c8afa04432bd5e (diff)
downloadsamba-f22a29e1bd0c59710b1f6ab56e903fa6e1e51a46.tar.gz
samba-f22a29e1bd0c59710b1f6ab56e903fa6e1e51a46.tar.bz2
samba-f22a29e1bd0c59710b1f6ab56e903fa6e1e51a46.zip
ntlm_auth: Dynamically allocate the read buffer.
This ports over my changes from Samba4 (This used to be commit 4a475baf26ba9f99bc05f13dd2745494174a00c1)
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/ntlm_auth.c71
1 files changed, 43 insertions, 28 deletions
diff --git a/source3/utils/ntlm_auth.c b/source3/utils/ntlm_auth.c
index 68bf24fec7..b0c79571d2 100644
--- a/source3/utils/ntlm_auth.c
+++ b/source3/utils/ntlm_auth.c
@@ -28,7 +28,8 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_WINBIND
-#define SQUID_BUFFER_SIZE 2010
+#define INITIAL_BUFFER_SIZE 300
+#define MAX_BUFFER_SIZE 630000
enum stdio_helper_mode {
SQUID_2_4_BASIC,
@@ -2070,46 +2071,60 @@ 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)
{
- char buf[SQUID_BUFFER_SIZE+1];
- int length;
+ char *buf;
+ char tmp[INITIAL_BUFFER_SIZE+1];
+ int length, buf_size = 0;
char *c;
- static bool err;
- /* this is not a typo - x_fgets doesn't work too well under squid */
- if (fgets(buf, sizeof(buf)-1, stdin) == NULL) {
- if (ferror(stdin)) {
- DEBUG(1, ("fgets() failed! dying..... errno=%d (%s)\n", ferror(stdin),
- strerror(ferror(stdin))));
-
- exit(1); /* BIIG buffer */
- }
- exit(0);
- }
-
- c=(char *)memchr(buf,'\n',sizeof(buf)-1);
- if (c) {
- *c = '\0';
- length = c-buf;
- } else {
- err = 1;
- return;
- }
- if (err) {
- DEBUG(2, ("Oversized message\n"));
+ buf = talloc_strdup(NULL, "");
+ if (!buf) {
+ DEBUG(0, ("Failed to allocate input buffer.\n"));
x_fprintf(x_stderr, "ERR\n");
- err = 0;
- return;
+ exit(1);
}
+ do {
+
+ /* this is not a typo - x_fgets doesn't work too well under
+ * squid */
+ if (fgets(tmp, sizeof(tmp)-1, stdin) == NULL) {
+ if (ferror(stdin)) {
+ DEBUG(1, ("fgets() failed! dying..... errno=%d "
+ "(%s)\n", ferror(stdin),
+ strerror(ferror(stdin))));
+
+ exit(1);
+ }
+ exit(0);
+ }
+
+ buf = talloc_strdup_append_buffer(buf, tmp);
+ buf_size += INITIAL_BUFFER_SIZE;
+
+ if (buf_size > MAX_BUFFER_SIZE) {
+ DEBUG(2, ("Oversized message\n"));
+ x_fprintf(x_stderr, "ERR\n");
+ talloc_free(buf);
+ return;
+ }
+
+ c = strchr(buf, '\n');
+ } while (c == NULL);
+
+ *c = '\0';
+ length = c-buf;
+
DEBUG(10, ("Got '%s' from squid (length: %d).\n",buf,length));
if (buf[0] == '\0') {
DEBUG(2, ("Invalid Request\n"));
x_fprintf(x_stderr, "ERR\n");
+ talloc_free(buf);
return;
}
-
+
fn(helper_mode, buf, length);
+ talloc_free(buf);
}