From 163a855d26106ac9c6eaf945a31a6495204de990 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 13 Apr 2002 09:35:52 +0000 Subject: Better handling of uid/gid -> RID and RID -> uid/gid code. All uids and gids must create valid RIDs, becouse other code expects this, and can't handle the failure case. (ACL code in particular) Allow admins to adjust the base of the RID algorithm, so avoid clashes with users brought in from NT (for example). Put all the algorithm code back in one place, so that this change is global. Better coping with NULL sid pointers - but it still breaks a lot of stuff. BONUS: manpage entry for new paramater :-) counter based rids for normal users in tdbsam is disabled for the timebeing, idra and I will work out some things here soon I hope. Andrew Bartlett (This used to be commit 5275c94cdf0c64f347d4282f47088d084b1a7ea5) --- source3/lib/util_sid.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c index cd7b64bb70..100324a047 100644 --- a/source3/lib/util_sid.c +++ b/source3/lib/util_sid.c @@ -197,7 +197,7 @@ void generate_wellknown_sids(void) Turns a domain SID into a name, returned in the nt_domain argument. ***************************************************************************/ -BOOL map_domain_sid_to_name(DOM_SID *sid, char *nt_domain) +BOOL map_domain_sid_to_name(DOM_SID *sid, fstring nt_domain) { fstring sid_str; int i = 0; @@ -344,11 +344,18 @@ char *sid_to_string(fstring sidstr_out, DOM_SID *sid) { char subauth[16]; int i; + uint32 ia; + + if (!sid) { + fstrcpy(sidstr_out, "(NULL SID)"); + return sidstr_out; + } + /* BIG NOTE: this function only does SIDS where the identauth is not >= 2^32 */ - uint32 ia = (sid->id_auth[5]) + - (sid->id_auth[4] << 8 ) + - (sid->id_auth[3] << 16) + - (sid->id_auth[2] << 24); + ia = (sid->id_auth[5]) + + (sid->id_auth[4] << 8 ) + + (sid->id_auth[3] << 16) + + (sid->id_auth[2] << 24); slprintf(sidstr_out, sizeof(fstring) - 1, "S-%u-%lu", (unsigned int)sid->sid_rev_num, (unsigned long)ia); -- cgit From 07e6ff5fcfe337bb65a7c3a4493a92a7761cf2ed Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 14 Apr 2002 09:44:16 +0000 Subject: Partly based on the work by mimir (Rafal Szczesniak ) this patch allows samba to correctly enumerate its trusted domains - by exaimining the keys in the secrets.tdb file. This patch has been tested with both NT4 and rpcclient/wbinfo, and adds some extra functionality to talloc and rpc_parse to allow it to deal with already unicode strings. Finally, this cleans up some const warnings that were in net_rpc.c by pushing another dash of const into the rpc client code. Andrew Bartlett (This used to be commit 0bdd94cb992b40942aaf2e5e0efd2868b4686296) --- source3/lib/talloc.c | 9 +++++++++ source3/lib/util_unistr.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/talloc.c b/source3/lib/talloc.c index 6ac784a929..b50e451b95 100644 --- a/source3/lib/talloc.c +++ b/source3/lib/talloc.c @@ -287,6 +287,15 @@ char *talloc_strdup(TALLOC_CTX *t, const char *p) return NULL; } +/** strdup_w with a talloc */ +smb_ucs2_t *talloc_strdup_w(TALLOC_CTX *t, const smb_ucs2_t *p) +{ + if (p) + return talloc_memdup(t, p, (strlen_w(p) + 1) * sizeof(smb_ucs2_t)); + else + return NULL; +} + /** * Perform string formatting, and return a pointer to newly allocated * memory holding the result, inside a memory pool. diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index a1cff26169..ba02819bdc 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -775,3 +775,44 @@ int unistrcpy(uint16 *dst, uint16 *src) return num_wchars; } + +/** + * Samba ucs2 type to UNISTR2 conversion + * + * @param ctx Talloc context to create the dst strcture (if null) and the + * contents of the unicode string. + * @param dst UNISTR2 destination. If equals null, then it's allocated. + * @param src smb_ucs2_t source. + * @param max_len maximum number of unicode characters to copy. If equals + * null, then null-termination of src is taken + * + * @return copied UNISTR2 destination + **/ +UNISTR2* ucs2_to_unistr2(TALLOC_CTX *ctx, UNISTR2* dst, smb_ucs2_t* src) +{ + size_t len; + + if (!src) return NULL; + len = strlen_w(src); + + /* allocate UNISTR2 destination if not given */ + if (!dst) { + dst = (UNISTR2*) talloc(ctx, sizeof(UNISTR2)); + if (!dst) return NULL; + } + if (!dst->buffer) { + dst->buffer = (uint16*) talloc(ctx, sizeof(uint16) * (len + 1)); + if (!dst->buffer) return NULL; + } + + /* set UNISTR2 parameters */ + dst->uni_max_len = len + 1; + dst->undoc = 0; + dst->uni_str_len = len; + + /* copy the actual unicode string */ + strncpy_w(dst->buffer, src, dst->uni_max_len); + + return dst; +}; + -- cgit From 36514b65eed055282f2f391d18128536026d9485 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 15 Apr 2002 01:55:57 +0000 Subject: Fixed incorrect debug. (This used to be commit 3b6df44ddc80d728c01511529ccb05c1ba3d414b) --- source3/lib/username.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/username.c b/source3/lib/username.c index 1504fd6a06..da603949bc 100644 --- a/source3/lib/username.c +++ b/source3/lib/username.c @@ -493,7 +493,7 @@ BOOL user_in_list(const char *user,char **list) while (*list) { - DEBUG(10,("user_in_list: checking user |%s| in group |%s|\n", user, *list)); + DEBUG(10,("user_in_list: checking user |%s| against |%s|\n", user, *list)); /* * Check raw username. -- cgit From 02f84c6bd0c06c3dacc93d6413d6645367f42744 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 16 Apr 2002 10:40:23 +0000 Subject: i forgot to commit these parts of the string handling patch earlier. Sorry. (This used to be commit bac0093a9713416b1679d1bc167b70f02b06ef78) --- source3/lib/charcnv.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index cdfca8eb97..be7701237e 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -354,7 +354,7 @@ int pull_ascii(char *dest, const void *src, int dest_len, int src_len, int flags dest_len = sizeof(pstring); } - if (flags & STR_TERMINATE) src_len = strlen(src)+1; + if (src_len == -1 && (flags & STR_TERMINATE)) src_len = strlen(src)+1; ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len); @@ -525,7 +525,7 @@ copy a string from a ucs2 source to a unix char* destination flags can have: STR_TERMINATE means the string in src is null terminated STR_NOALIGN means don't try to align -if STR_TERMINATE is set then src_len is ignored +if STR_TERMINATE is set then src_len is ignored if it is -1 src_len is the length of the source area in bytes return the number of bytes occupied by the string in src the resulting string in "dest" is always null terminated @@ -543,7 +543,7 @@ int pull_ucs2(const void *base_ptr, char *dest, const void *src, int dest_len, i if (src_len > 0) src_len--; } - if (flags & STR_TERMINATE) src_len = strlen_w(src)*2+2; + if (src_len == -1 && (flags & STR_TERMINATE)) src_len = strlen_w(src)*2+2; /* ucs2 is always a multiple of 2 bytes */ src_len &= ~1; @@ -609,7 +609,7 @@ int pull_utf8(char *dest, const void *src, int dest_len, int src_len, int flags) dest_len = sizeof(pstring); } - if (flags & STR_TERMINATE) src_len = strlen(src)+1; + if (src_len == -1 && (flags & STR_TERMINATE)) src_len = strlen(src)+1; ret = convert_string(CH_UTF8, CH_UNIX, src, src_len, dest, dest_len); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; @@ -687,7 +687,7 @@ flags can have: STR_UNICODE means to force as unicode STR_ASCII use ascii even with unicode packet STR_NOALIGN means don't do alignment -if STR_TERMINATE is set then src_len is ignored +if STR_TERMINATE is set then src_len is ignored is it is -1 src_len is the length of the source area in bytes return the number of bytes occupied by the string in src the resulting string in "dest" is always null terminated -- cgit From b66932e1a5dc3a368474e6e110c5a88a251465f5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 16 Apr 2002 12:07:12 +0000 Subject: fixed the handling of STR_TERMINATE (This used to be commit dbc6b137a83cf9fe0558625dd32f92f15296fba6) --- source3/lib/charcnv.c | 24 +++++++++++++++++++++--- source3/lib/util_str.c | 12 ++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index be7701237e..803cda36c8 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -354,7 +354,13 @@ int pull_ascii(char *dest, const void *src, int dest_len, int src_len, int flags dest_len = sizeof(pstring); } - if (src_len == -1 && (flags & STR_TERMINATE)) src_len = strlen(src)+1; + if (flags & STR_TERMINATE) { + if (src_len == -1) { + src_len = strlen(src)+1; + } else { + src_len = strnlen(src, src_len) + 1; + } + } ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len); @@ -543,7 +549,13 @@ int pull_ucs2(const void *base_ptr, char *dest, const void *src, int dest_len, i if (src_len > 0) src_len--; } - if (src_len == -1 && (flags & STR_TERMINATE)) src_len = strlen_w(src)*2+2; + if (flags & STR_TERMINATE) { + if (src_len == -1) { + src_len = strlen_w(src)*2+2; + } else { + src_len = strnlen_w(src, src_len/2)*2+2; + } + } /* ucs2 is always a multiple of 2 bytes */ src_len &= ~1; @@ -609,7 +621,13 @@ int pull_utf8(char *dest, const void *src, int dest_len, int src_len, int flags) dest_len = sizeof(pstring); } - if (src_len == -1 && (flags & STR_TERMINATE)) src_len = strlen(src)+1; + if (flags & STR_TERMINATE) { + if (src_len == -1) { + src_len = strlen(src)+1; + } else { + src_len = strnlen(src, src_len) + 1; + } + } ret = convert_string(CH_UTF8, CH_UNIX, src, src_len, dest, dest_len); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 6fdca658cd..9a841a36b3 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -1001,3 +1001,15 @@ some platforms don't have strndup return ret; } #endif + +#ifndef HAVE_STRNLEN +/******************************************************************* +some platforms don't have strndup +********************************************************************/ + size_t strnlen(const char *s, size_t n) +{ + int i; + for (i=0; s[i] && i Date: Tue, 16 Apr 2002 22:38:04 +0000 Subject: Fix incorrect zpadlen handling in fmtfp. Thanks to Ollie Oldham for spotting it. few mods to make it easier to compile the tests. addedd the "Ollie" test to the floating point ones. (This used to be commit 415f9d92bc0a37d38b81a653a4b4c5f0fefa2fe8) --- source3/lib/snprintf.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/snprintf.c b/source3/lib/snprintf.c index 9a9dcdbae1..3034dfaaf6 100644 --- a/source3/lib/snprintf.c +++ b/source3/lib/snprintf.c @@ -57,6 +57,12 @@ #ifndef NO_CONFIG_H /* for some tests */ #include "config.h" +#else +#define NULL 0 +#endif + +#ifdef TEST_SNPRINTF /* need math library headers for testing */ +#include #endif #ifdef HAVE_STRING_H @@ -656,9 +662,8 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, /* Convert integer part */ do { - temp = intpart; - my_modf(intpart*0.1, &intpart); - temp = temp*0.1; + temp = intpart*0.1; + my_modf(temp, &intpart); index = (int) ((temp -intpart +0.05)* 10.0); /* index = (int) (((double)(temp*0.1) -intpart +0.05) *10.0); */ /* printf ("%llf, %f, %x\n", temp, intpart, index); */ @@ -672,9 +677,8 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, if (fracpart) { do { - temp = fracpart; - my_modf(fracpart*0.1, &fracpart); - temp = temp*0.1; + temp = fracpart*0.1; + my_modf(temp, &fracpart); index = (int) ((temp -fracpart +0.05)* 10.0); /* index = (int) ((((temp/10) -fracpart) +0.05) *10); */ /* printf ("%lf, %lf, %ld\n", temp, fracpart, index); */ @@ -726,14 +730,14 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, if (max > 0) { dopr_outch (buffer, currlen, maxlen, '.'); + while (zpadlen > 0) { + dopr_outch (buffer, currlen, maxlen, '0'); + --zpadlen; + } + while (fplace > 0) dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]); } - - while (zpadlen > 0) { - dopr_outch (buffer, currlen, maxlen, '0'); - --zpadlen; - } while (padlen < 0) { dopr_outch (buffer, currlen, maxlen, ' '); @@ -853,7 +857,7 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) NULL }; double fp_nums[] = { 6442452944.1234, -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996, - 0.9996, 1.996, 4.136, 0}; + 0.9996, 1.996, 4.136, 5.030201, 0}; char *int_fmt[] = { "%-1.5d", "%1.5d", @@ -948,8 +952,10 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) { double v0 = 0.12345678901234567890123456789012345678901; for (x=0; x<100; x++) { - snprintf(buf1, sizeof(buf1), "%1.1f", v0*pow(10, x)); - sprintf(buf2, "%1.1f", v0*pow(10, x)); + double p = pow(10, x); + double r = v0*p; + snprintf(buf1, sizeof(buf1), "%1.1f", r); + sprintf(buf2, "%1.1f", r); if (strcmp(buf1, buf2)) { printf("we seem to support %d digits\n", x-1); break; -- cgit From 7c0301d100885f3d4ee48a973158d1aa0036af1c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 16 Apr 2002 22:55:39 +0000 Subject: stricter conditions on termination in strings this was a very nasty bug with filename corruption and NT4 clients. The exact termination conditions are quite critical ... (This used to be commit a538efe7d00e7a61df194ca1c22e0583dcbb7a4a) --- source3/lib/charcnv.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 803cda36c8..cd32779594 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -356,9 +356,9 @@ int pull_ascii(char *dest, const void *src, int dest_len, int src_len, int flags if (flags & STR_TERMINATE) { if (src_len == -1) { - src_len = strlen(src)+1; + src_len = strlen(src); } else { - src_len = strnlen(src, src_len) + 1; + src_len = strnlen(src, src_len); } } @@ -551,9 +551,9 @@ int pull_ucs2(const void *base_ptr, char *dest, const void *src, int dest_len, i if (flags & STR_TERMINATE) { if (src_len == -1) { - src_len = strlen_w(src)*2+2; + src_len = strlen_w(src)*2; } else { - src_len = strnlen_w(src, src_len/2)*2+2; + src_len = strnlen_w(src, src_len/2)*2; } } @@ -623,9 +623,9 @@ int pull_utf8(char *dest, const void *src, int dest_len, int src_len, int flags) if (flags & STR_TERMINATE) { if (src_len == -1) { - src_len = strlen(src)+1; + src_len = strlen(src); } else { - src_len = strnlen(src, src_len) + 1; + src_len = strnlen(src, src_len); } } -- cgit From 1416106736adb6190ac788ee27c2a4bf4eb1790f Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 16 Apr 2002 22:56:08 +0000 Subject: sync with 2.2 (This used to be commit 18d5ffd835165d2570443c979d9157e2388b37d8) --- source3/lib/snprintf.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/snprintf.c b/source3/lib/snprintf.c index 3034dfaaf6..2733626108 100644 --- a/source3/lib/snprintf.c +++ b/source3/lib/snprintf.c @@ -100,6 +100,11 @@ #define LLONG long #endif +/* free memory if the pointer is valid and zero the pointer */ +#ifndef SAFE_FREE +#define SAFE_FREE(x) do { if ((x) != NULL) {free((x)); (x)=NULL;} } while(0) +#endif + static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args); static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, @@ -822,10 +827,10 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) { char *msg = NULL; vasprintf(&msg, format, arglist); - if (!msg) - return; - syslog(facility_priority, "%s", msg); - free(msg); + if (!msg) + return; + syslog(facility_priority, "%s", msg); + SAFE_FREE(msg); } #endif /* HAVE_SYSLOG */ #endif /* HAVE_VSYSLOG */ -- cgit From e35ac78c49c3bd2aeb871cf1ebee43cf73477c6a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 17 Apr 2002 02:37:46 +0000 Subject: make suure we get the return value from the pull_*() functions right for both null terminated and buffer length terminated strings (This used to be commit e8fbf853e0eed61bb7405be731f18fb2426f8dc4) --- source3/lib/charcnv.c | 18 ++++++++++++------ source3/lib/util_str.c | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index cd32779594..a6db286134 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -356,9 +356,11 @@ int pull_ascii(char *dest, const void *src, int dest_len, int src_len, int flags if (flags & STR_TERMINATE) { if (src_len == -1) { - src_len = strlen(src); + src_len = strlen(src) + 1; } else { - src_len = strnlen(src, src_len); + int len = strnlen(src, src_len); + if (len < src_len) len++; + src_len = len; } } @@ -551,9 +553,11 @@ int pull_ucs2(const void *base_ptr, char *dest, const void *src, int dest_len, i if (flags & STR_TERMINATE) { if (src_len == -1) { - src_len = strlen_w(src)*2; + src_len = strlen_w(src)*2 + 2; } else { - src_len = strnlen_w(src, src_len/2)*2; + int len = strnlen_w(src, src_len/2); + if (len < src_len/2) len++; + src_len = len*2; } } @@ -623,9 +627,11 @@ int pull_utf8(char *dest, const void *src, int dest_len, int src_len, int flags) if (flags & STR_TERMINATE) { if (src_len == -1) { - src_len = strlen(src); + src_len = strlen(src) + 1; } else { - src_len = strnlen(src, src_len); + int len = strnlen(src, src_len); + if (len < src_len) len++; + src_len = len; } } diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 9a841a36b3..f6e579ddba 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -1004,7 +1004,7 @@ some platforms don't have strndup #ifndef HAVE_STRNLEN /******************************************************************* -some platforms don't have strndup +some platforms don't have strnlen ********************************************************************/ size_t strnlen(const char *s, size_t n) { -- cgit From 6a9bc86d62cc9ba532392af02a5d71e50b6b0411 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 18 Apr 2002 03:59:02 +0000 Subject: nicer strndup() function (This used to be commit 546764f3cbbefaad312386280dd2ebbbe5b4446d) --- source3/lib/util_str.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index f6e579ddba..ff3559ce14 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -991,13 +991,13 @@ some platforms don't have strndup char *strndup(const char *s, size_t n) { char *ret; - int i; - for (i=0;s[i] && i Date: Fri, 19 Apr 2002 02:08:52 +0000 Subject: First cut at fix for the EINTR problem... More needs to be done I think. Jeremy. (This used to be commit 48475a7a697242b9fd7b1aec24389afb112569c4) --- source3/lib/system.c | 45 ++++++++ source3/lib/util.c | 9 +- source3/lib/util_sock.c | 266 +++++++++++++++++++++++------------------------- 3 files changed, 180 insertions(+), 140 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/system.c b/source3/lib/system.c index 8c7eec939e..d97751eb4b 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -72,6 +72,51 @@ int sys_usleep(long usecs) #endif /* HAVE_USLEEP */ } +/******************************************************************* +A read wrapper that will deal with EINTR. +********************************************************************/ + +ssize_t sys_read(int fd, void *buf, size_t count) +{ + ssize_t ret; + + do { + errno = 0; + ret = read(fd, buf, count); + } while (ret == -1 && errno == EINTR); + return ret; +} + +/******************************************************************* +A write wrapper that will deal with EINTR. +********************************************************************/ + +ssize_t sys_write(int fd, const void *buf, size_t count) +{ + ssize_t ret; + + do { + errno = 0; + ret = write(fd, buf, count); + } while (ret == -1 && errno == EINTR); + return ret; +} + +/******************************************************************* +A send wrapper that will deal with EINTR. +********************************************************************/ + +int sys_send(int s, const void *msg, size_t len, int flags) +{ + ssize_t ret; + + do { + errno = 0; + ret = send(s, msg, len, flags); + } while (ret == -1 && errno == EINTR); + return ret; +} + /******************************************************************* A stat() wrapper that will deal with 64 bit filesizes. ********************************************************************/ diff --git a/source3/lib/util.c b/source3/lib/util.c index 7e2ad49639..c524adaa7a 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1353,11 +1353,12 @@ BOOL fcntl_lock(int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type) lock.l_len = count; lock.l_pid = 0; - errno = 0; + do { + errno = 0; + ret = fcntl(fd,op,&lock); + } while (ret == -1 && errno == EINTR); - ret = fcntl(fd,op,&lock); - - if (errno != 0) + if (ret == -1 && errno != 0) DEBUG(3,("fcntl_lock: fcntl lock gave errno %d (%s)\n",errno,strerror(errno))); /* a lock query */ diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index af3182264d..1c7f9ce115 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -247,10 +247,10 @@ static ssize_t read_socket_with_timeout(int fd,char *buf,size_t mincnt,size_t ma if (fd == sslFd) { readret = SSL_read(ssl, buf + nread, maxcnt - nread); } else { - readret = read(fd, buf + nread, maxcnt - nread); + readret = sys_read(fd, buf + nread, maxcnt - nread); } #else /* WITH_SSL */ - readret = read(fd, buf + nread, maxcnt - nread); + readret = sys_read(fd, buf + nread, maxcnt - nread); #endif /* WITH_SSL */ if (readret == 0) { @@ -304,10 +304,10 @@ static ssize_t read_socket_with_timeout(int fd,char *buf,size_t mincnt,size_t ma if (fd == sslFd) { readret = SSL_read(ssl, buf + nread, maxcnt - nread); }else{ - readret = read(fd, buf + nread, maxcnt - nread); + readret = sys_read(fd, buf + nread, maxcnt - nread); } #else /* WITH_SSL */ - readret = read(fd, buf+nread, maxcnt-nread); + readret = sys_read(fd, buf+nread, maxcnt-nread); #endif /* WITH_SSL */ if (readret == 0) { @@ -357,10 +357,10 @@ ssize_t read_with_timeout(int fd, char *buf, size_t mincnt, size_t maxcnt, if(fd == sslFd){ readret = SSL_read(ssl, buf + nread, maxcnt - nread); }else{ - readret = read(fd, buf + nread, maxcnt - nread); + readret = sys_read(fd, buf + nread, maxcnt - nread); } #else /* WITH_SSL */ - readret = read(fd, buf + nread, maxcnt - nread); + readret = sys_read(fd, buf + nread, maxcnt - nread); #endif /* WITH_SSL */ if (readret <= 0) @@ -387,10 +387,10 @@ ssize_t read_with_timeout(int fd, char *buf, size_t mincnt, size_t maxcnt, if(fd == sslFd){ readret = SSL_read(ssl, buf + nread, maxcnt - nread); }else{ - readret = read(fd, buf + nread, maxcnt - nread); + readret = sys_read(fd, buf + nread, maxcnt - nread); } #else /* WITH_SSL */ - readret = read(fd, buf+nread, maxcnt-nread); + readret = sys_read(fd, buf+nread, maxcnt-nread); #endif /* WITH_SSL */ if (readret <= 0) @@ -409,12 +409,12 @@ send a keepalive packet (rfc1002) BOOL send_keepalive(int client) { - unsigned char buf[4]; + unsigned char buf[4]; - buf[0] = SMBkeepalive; - buf[1] = buf[2] = buf[3] = 0; + buf[0] = SMBkeepalive; + buf[1] = buf[2] = buf[3] = 0; - return(write_socket_data(client,(char *)buf,4) == 4); + return(write_socket_data(client,(char *)buf,4) == 4); } /**************************************************************************** @@ -423,38 +423,36 @@ BOOL send_keepalive(int client) ssize_t read_data(int fd,char *buffer,size_t N) { - ssize_t ret; - size_t total=0; + ssize_t ret; + size_t total=0; - smb_read_error = 0; + smb_read_error = 0; - while (total < N) - { + while (total < N) { #ifdef WITH_SSL - if(fd == sslFd){ - ret = SSL_read(ssl, buffer + total, N - total); - }else{ - ret = read(fd,buffer + total,N - total); - } + if(fd == sslFd){ + ret = SSL_read(ssl, buffer + total, N - total); + }else{ + ret = sys_read(fd,buffer + total,N - total); + } #else /* WITH_SSL */ - ret = read(fd,buffer + total,N - total); + ret = sys_read(fd,buffer + total,N - total); #endif /* WITH_SSL */ - if (ret == 0) - { - DEBUG(10,("read_data: read of %d returned 0. Error = %s\n", (int)(N - total), strerror(errno) )); - smb_read_error = READ_EOF; - return 0; - } - if (ret == -1) - { - DEBUG(0,("read_data: read failure for %d. Error = %s\n", (int)(N - total), strerror(errno) )); - smb_read_error = READ_ERROR; - return -1; - } - total += ret; - } - return (ssize_t)total; + if (ret == 0) { + DEBUG(10,("read_data: read of %d returned 0. Error = %s\n", (int)(N - total), strerror(errno) )); + smb_read_error = READ_EOF; + return 0; + } + + if (ret == -1) { + DEBUG(0,("read_data: read failure for %d. Error = %s\n", (int)(N - total), strerror(errno) )); + smb_read_error = READ_ERROR; + return -1; + } + total += ret; + } + return (ssize_t)total; } /**************************************************************************** @@ -463,38 +461,36 @@ ssize_t read_data(int fd,char *buffer,size_t N) static ssize_t read_socket_data(int fd,char *buffer,size_t N) { - ssize_t ret; - size_t total=0; + ssize_t ret; + size_t total=0; - smb_read_error = 0; + smb_read_error = 0; - while (total < N) - { + while (total < N) { #ifdef WITH_SSL - if(fd == sslFd){ - ret = SSL_read(ssl, buffer + total, N - total); - }else{ - ret = read(fd,buffer + total,N - total); + if(fd == sslFd){ + ret = SSL_read(ssl, buffer + total, N - total); + }else{ + ret = sys_read(fd,buffer + total,N - total); } #else /* WITH_SSL */ - ret = read(fd,buffer + total,N - total); + ret = sys_read(fd,buffer + total,N - total); #endif /* WITH_SSL */ - if (ret == 0) - { - DEBUG(10,("read_socket_data: recv of %d returned 0. Error = %s\n", (int)(N - total), strerror(errno) )); - smb_read_error = READ_EOF; - return 0; - } - if (ret == -1) - { - DEBUG(0,("read_socket_data: recv failure for %d. Error = %s\n", (int)(N - total), strerror(errno) )); - smb_read_error = READ_ERROR; - return -1; - } - total += ret; - } - return (ssize_t)total; + if (ret == 0) { + DEBUG(10,("read_socket_data: recv of %d returned 0. Error = %s\n", (int)(N - total), strerror(errno) )); + smb_read_error = READ_EOF; + return 0; + } + + if (ret == -1) { + DEBUG(0,("read_socket_data: recv failure for %d. Error = %s\n", (int)(N - total), strerror(errno) )); + smb_read_error = READ_ERROR; + return -1; + } + total += ret; + } + return (ssize_t)total; } /**************************************************************************** @@ -503,30 +499,30 @@ static ssize_t read_socket_data(int fd,char *buffer,size_t N) ssize_t write_data(int fd,char *buffer,size_t N) { - size_t total=0; - ssize_t ret; + size_t total=0; + ssize_t ret; - while (total < N) - { + while (total < N) { #ifdef WITH_SSL - if(fd == sslFd){ - ret = SSL_write(ssl,buffer + total,N - total); - }else{ - ret = write(fd,buffer + total,N - total); - } + if(fd == sslFd){ + ret = SSL_write(ssl,buffer + total,N - total); + }else{ + ret = sys_write(fd,buffer + total,N - total); + } #else /* WITH_SSL */ - ret = write(fd,buffer + total,N - total); + ret = sys_write(fd,buffer + total,N - total); #endif /* WITH_SSL */ - if (ret == -1) { - DEBUG(0,("write_data: write failure. Error = %s\n", strerror(errno) )); - return -1; - } - if (ret == 0) return total; + if (ret == -1) { + DEBUG(0,("write_data: write failure. Error = %s\n", strerror(errno) )); + return -1; + } + if (ret == 0) + return total; - total += ret; - } - return (ssize_t)total; + total += ret; + } + return (ssize_t)total; } /**************************************************************************** @@ -535,30 +531,30 @@ ssize_t write_data(int fd,char *buffer,size_t N) ssize_t write_socket_data(int fd,char *buffer,size_t N) { - size_t total=0; - ssize_t ret; + size_t total=0; + ssize_t ret; - while (total < N) - { + while (total < N) { #ifdef WITH_SSL - if(fd == sslFd){ - ret = SSL_write(ssl,buffer + total,N - total); - }else{ - ret = send(fd,buffer + total,N - total, 0); + if(fd == sslFd){ + ret = SSL_write(ssl,buffer + total,N - total); + }else{ + ret = sys_send(fd,buffer + total,N - total, 0); } #else /* WITH_SSL */ - ret = send(fd,buffer + total,N - total,0); + ret = sys_send(fd,buffer + total,N - total,0); #endif /* WITH_SSL */ - if (ret == -1) { - DEBUG(0,("write_socket_data: write failure. Error = %s\n", strerror(errno) )); - return -1; - } - if (ret == 0) return total; + if (ret == -1) { + DEBUG(0,("write_socket_data: write failure. Error = %s\n", strerror(errno) )); + return -1; + } + if (ret == 0) + return total; - total += ret; - } - return (ssize_t)total; + total += ret; + } + return (ssize_t)total; } /**************************************************************************** @@ -567,17 +563,17 @@ write to a socket ssize_t write_socket(int fd,char *buf,size_t len) { - ssize_t ret=0; + ssize_t ret=0; - DEBUG(6,("write_socket(%d,%d)\n",fd,(int)len)); - ret = write_socket_data(fd,buf,len); + DEBUG(6,("write_socket(%d,%d)\n",fd,(int)len)); + ret = write_socket_data(fd,buf,len); - DEBUG(6,("write_socket(%d,%d) wrote %d\n",fd,(int)len,(int)ret)); - if(ret <= 0) - DEBUG(0,("write_socket: Error writing %d bytes to socket %d: ERRNO = %s\n", - (int)len, fd, strerror(errno) )); + DEBUG(6,("write_socket(%d,%d) wrote %d\n",fd,(int)len,(int)ret)); + if(ret <= 0) + DEBUG(0,("write_socket: Error writing %d bytes to socket %d: ERRNO = %s\n", + (int)len, fd, strerror(errno) )); - return(ret); + return(ret); } /**************************************************************************** @@ -590,30 +586,29 @@ timeout is in milliseconds. static ssize_t read_smb_length_return_keepalive(int fd,char *inbuf,unsigned int timeout) { - ssize_t len=0; - int msg_type; - BOOL ok = False; + ssize_t len=0; + int msg_type; + BOOL ok = False; - while (!ok) - { - if (timeout > 0) - ok = (read_socket_with_timeout(fd,inbuf,4,4,timeout) == 4); - else - ok = (read_socket_data(fd,inbuf,4) == 4); + while (!ok) { + if (timeout > 0) + ok = (read_socket_with_timeout(fd,inbuf,4,4,timeout) == 4); + else + ok = (read_socket_data(fd,inbuf,4) == 4); - if (!ok) - return(-1); + if (!ok) + return(-1); - len = smb_len(inbuf); - msg_type = CVAL(inbuf,0); + len = smb_len(inbuf); + msg_type = CVAL(inbuf,0); - if (msg_type == SMBkeepalive) - DEBUG(5,("Got keepalive packet\n")); - } + if (msg_type == SMBkeepalive) + DEBUG(5,("Got keepalive packet\n")); + } - DEBUG(10,("got smb length of %d\n",len)); + DEBUG(10,("got smb length of %d\n",len)); - return(len); + return(len); } /**************************************************************************** @@ -625,23 +620,22 @@ timeout is in milliseconds. ssize_t read_smb_length(int fd,char *inbuf,unsigned int timeout) { - ssize_t len; + ssize_t len; - for(;;) - { - len = read_smb_length_return_keepalive(fd, inbuf, timeout); + for(;;) { + len = read_smb_length_return_keepalive(fd, inbuf, timeout); - if(len < 0) - return len; + if(len < 0) + return len; - /* Ignore session keepalives. */ - if(CVAL(inbuf,0) != SMBkeepalive) - break; - } + /* Ignore session keepalives. */ + if(CVAL(inbuf,0) != SMBkeepalive) + break; + } - DEBUG(10,("read_smb_length: got smb length of %d\n",len)); + DEBUG(10,("read_smb_length: got smb length of %d\n",len)); - return len; + return len; } /**************************************************************************** -- cgit From e41915d7c802566f598ac844514913fb230f4f7d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Apr 2002 02:15:10 +0000 Subject: Fix send and recvfrom. Jeremy. (This used to be commit 8cbc24c3bd0e2d2349625c3b5d2e12ac092ec5a8) --- source3/lib/system.c | 17 ++++++++++++++++- source3/lib/util_sock.c | 22 +++++++++++----------- 2 files changed, 27 insertions(+), 12 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/system.c b/source3/lib/system.c index d97751eb4b..61f93dd6a5 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -106,7 +106,7 @@ ssize_t sys_write(int fd, const void *buf, size_t count) A send wrapper that will deal with EINTR. ********************************************************************/ -int sys_send(int s, const void *msg, size_t len, int flags) +ssize_t sys_send(int s, const void *msg, size_t len, int flags) { ssize_t ret; @@ -117,6 +117,21 @@ int sys_send(int s, const void *msg, size_t len, int flags) return ret; } +/******************************************************************* +A recvfrom wrapper that will deal with EINTR. +********************************************************************/ + +ssize_t sys_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen) +{ + ssize_t ret; + + do { + errno = 0; + ret = recvfrom(s, buf, len, flags, from, fromlen); + } while (ret == -1 && errno == EINTR); + return ret; +} + /******************************************************************* A stat() wrapper that will deal with 64 bit filesizes. ********************************************************************/ diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index 1c7f9ce115..27336cefa2 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -42,20 +42,19 @@ int smb_read_error = 0; BOOL is_a_socket(int fd) { - int v,l; - l = sizeof(int); - return(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&v, &l) == 0); + int v,l; + l = sizeof(int); + return(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&v, &l) == 0); } enum SOCK_OPT_TYPES {OPT_BOOL,OPT_INT,OPT_ON}; -typedef struct smb_socket_option -{ - char *name; - int level; - int option; - int value; - int opttype; +typedef struct smb_socket_option { + char *name; + int level; + int option; + int value; + int opttype; } smb_socket_option; smb_socket_option socket_options[] = { @@ -97,6 +96,7 @@ smb_socket_option socket_options[] = { /**************************************************************************** Print socket options. ****************************************************************************/ + static void print_socket_options(int s) { int value, vlen = 4; @@ -178,7 +178,7 @@ ssize_t read_udp_socket(int fd,char *buf,size_t len) memset((char *)&sock,'\0',socklen); memset((char *)&lastip,'\0',sizeof(lastip)); - ret = (ssize_t)recvfrom(fd,buf,len,0,(struct sockaddr *)&sock,&socklen); + ret = (ssize_t)sys_recvfrom(fd,buf,len,0,(struct sockaddr *)&sock,&socklen); if (ret <= 0) { DEBUG(2,("read socket failed. ERRNO=%s\n",strerror(errno))); return(0); -- cgit From e762f93821a21f460fecf7452d2363574ab04dad Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Apr 2002 02:20:04 +0000 Subject: Fixed sendto in oplock code. Jeremy. (This used to be commit 64974fa334fd757ff5cfd1bd32d7300bf8a6208c) --- source3/lib/system.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/system.c b/source3/lib/system.c index 61f93dd6a5..7734328795 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -117,6 +117,21 @@ ssize_t sys_send(int s, const void *msg, size_t len, int flags) return ret; } +/******************************************************************* +A sendto wrapper that will deal with EINTR. +********************************************************************/ + +ssize_t sys_sendto(int s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen) +{ + ssize_t ret; + + do { + errno = 0; + ret = sendto(s, msg, len, flags, to, tolen); + } while (ret == -1 && errno == EINTR); + return ret; +} + /******************************************************************* A recvfrom wrapper that will deal with EINTR. ********************************************************************/ -- cgit From b63be4e1abf419f68755c6b4def8d960c32e70cb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Apr 2002 03:05:38 +0000 Subject: Added sys_fcntl (not to be used everywhere). Added sys_read/sys_write for transfer_file. Jeremy. (This used to be commit c7ff521bab838c070931f2b0ece4be3371fbcdbf) --- source3/lib/system.c | 15 +++++++++++++++ source3/lib/util.c | 11 ++++------- source3/lib/util_file.c | 1 + 3 files changed, 20 insertions(+), 7 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/system.c b/source3/lib/system.c index 7734328795..eaaa76743a 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -147,6 +147,21 @@ ssize_t sys_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *f return ret; } +/******************************************************************* +A fcntl wrapper that will deal with EINTR. +********************************************************************/ + +int sys_fcntl(int fd, int cmd, void *arg) +{ + int ret; + + do { + errno = 0; + ret = fcntl(fd, cmd, arg); + } while (ret == -1 && errno == EINTR); + return ret; +} + /******************************************************************* A stat() wrapper that will deal with 64 bit filesizes. ********************************************************************/ diff --git a/source3/lib/util.c b/source3/lib/util.c index c524adaa7a..1ee1a9c06a 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -552,13 +552,13 @@ int set_blocking(int fd, BOOL set) #endif #endif - if((val = fcntl(fd, F_GETFL, 0)) == -1) + if((val = sys_fcntl(fd, F_GETFL, 0)) == -1) return -1; if(set) /* Turn blocking on - ie. clear nonblock flag */ val &= ~FLAG_TO_SET; else val |= FLAG_TO_SET; - return fcntl( fd, F_SETFL, val); + return sys_fcntl( fd, F_SETFL, val); #undef FLAG_TO_SET } @@ -620,7 +620,7 @@ ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn) SMB_OFF_T transfer_file(int infd,int outfd,SMB_OFF_T n) { - return (SMB_OFF_T)transfer_file_internal(infd, outfd, (size_t)n, read, write); + return (SMB_OFF_T)transfer_file_internal(infd, outfd, (size_t)n, sys_read, sys_write); } /******************************************************************* @@ -1353,10 +1353,7 @@ BOOL fcntl_lock(int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type) lock.l_len = count; lock.l_pid = 0; - do { - errno = 0; - ret = fcntl(fd,op,&lock); - } while (ret == -1 && errno == EINTR); + ret = sys_fcntl(fd,op,&lock); if (ret == -1 && errno != 0) DEBUG(3,("fcntl_lock: fcntl lock gave errno %d (%s)\n",errno,strerror(errno))); diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c index e80267f84b..fd3aeb99d9 100644 --- a/source3/lib/util_file.c +++ b/source3/lib/util_file.c @@ -51,6 +51,7 @@ BOOL do_file_lock(int fd, int waitsecs, int type) lock.l_pid = 0; alarm(waitsecs); + /* Note we must *NOT* use sys_fcntl here ! JRA */ ret = fcntl(fd, SMB_F_SETLKW, &lock); alarm(0); CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN); -- cgit From 8bc0e73a4366d79e292c21bebf671a2a2a6e5531 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Apr 2002 17:22:32 +0000 Subject: Fixed one more sendto. Jeremy. (This used to be commit 7adcc930ca56bf879b5e73b74bca19ac2353f1c0) --- source3/lib/util_sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index 27336cefa2..5bdfb24be4 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -789,7 +789,7 @@ BOOL send_one_packet(char *buf,int len,struct in_addr ip,int port,int type) len,inet_ntoa(ip),port,type==SOCK_DGRAM?"DGRAM":"STREAM")); /* send it */ - ret = (sendto(out_fd,buf,len,0,(struct sockaddr *)&sock_out,sizeof(sock_out)) >= 0); + ret = (sys_sendto(out_fd,buf,len,0,(struct sockaddr *)&sock_out,sizeof(sock_out)) >= 0); if (!ret) DEBUG(0,("Packet send to %s(%d) failed ERRNO=%s\n", -- cgit From 4f4d25d3e14a297f8ee31917f4307667f7b8a46b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Apr 2002 17:30:27 +0000 Subject: Fix different args to sys_fcntl without going varargs.... Jeremy. (This used to be commit 65742067e07195048edcee46dae95a58a4a50950) --- source3/lib/system.c | 17 ++++++++++++++++- source3/lib/util.c | 6 +++--- 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/system.c b/source3/lib/system.c index eaaa76743a..d9a4bbd83b 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -151,7 +151,22 @@ ssize_t sys_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *f A fcntl wrapper that will deal with EINTR. ********************************************************************/ -int sys_fcntl(int fd, int cmd, void *arg) +int sys_fcntl_ptr(int fd, int cmd, void *arg) +{ + int ret; + + do { + errno = 0; + ret = fcntl(fd, cmd, arg); + } while (ret == -1 && errno == EINTR); + return ret; +} + +/******************************************************************* +A fcntl wrapper that will deal with EINTR. +********************************************************************/ + +int sys_fcntl_long(int fd, int cmd, long arg) { int ret; diff --git a/source3/lib/util.c b/source3/lib/util.c index 1ee1a9c06a..ea1670ea27 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -552,13 +552,13 @@ int set_blocking(int fd, BOOL set) #endif #endif - if((val = sys_fcntl(fd, F_GETFL, 0)) == -1) + if((val = sys_fcntl_long(fd, F_GETFL, 0)) == -1) return -1; if(set) /* Turn blocking on - ie. clear nonblock flag */ val &= ~FLAG_TO_SET; else val |= FLAG_TO_SET; - return sys_fcntl( fd, F_SETFL, val); + return sys_fcntl_long( fd, F_SETFL, val); #undef FLAG_TO_SET } @@ -1353,7 +1353,7 @@ BOOL fcntl_lock(int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type) lock.l_len = count; lock.l_pid = 0; - ret = sys_fcntl(fd,op,&lock); + ret = sys_fcntl_ptr(fd,op,&lock); if (ret == -1 && errno != 0) DEBUG(3,("fcntl_lock: fcntl lock gave errno %d (%s)\n",errno,strerror(errno))); -- cgit From ca2e14ddc3d753f79319060f3024a0c9b3a57b98 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Apr 2002 21:45:02 +0000 Subject: We cannot set errno=0 in any of the wrapper calls as this breaks UNIX error returns to the client. Jeremy. (This used to be commit 1d66e53a64ec2878293e6d74a852b736ddab8f21) --- source3/lib/system.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/system.c b/source3/lib/system.c index d9a4bbd83b..dfd206027e 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -81,7 +81,6 @@ ssize_t sys_read(int fd, void *buf, size_t count) ssize_t ret; do { - errno = 0; ret = read(fd, buf, count); } while (ret == -1 && errno == EINTR); return ret; @@ -96,7 +95,6 @@ ssize_t sys_write(int fd, const void *buf, size_t count) ssize_t ret; do { - errno = 0; ret = write(fd, buf, count); } while (ret == -1 && errno == EINTR); return ret; @@ -111,7 +109,6 @@ ssize_t sys_send(int s, const void *msg, size_t len, int flags) ssize_t ret; do { - errno = 0; ret = send(s, msg, len, flags); } while (ret == -1 && errno == EINTR); return ret; @@ -126,7 +123,6 @@ ssize_t sys_sendto(int s, const void *msg, size_t len, int flags, const struct ssize_t ret; do { - errno = 0; ret = sendto(s, msg, len, flags, to, tolen); } while (ret == -1 && errno == EINTR); return ret; @@ -141,7 +137,6 @@ ssize_t sys_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *f ssize_t ret; do { - errno = 0; ret = recvfrom(s, buf, len, flags, from, fromlen); } while (ret == -1 && errno == EINTR); return ret; @@ -156,7 +151,6 @@ int sys_fcntl_ptr(int fd, int cmd, void *arg) int ret; do { - errno = 0; ret = fcntl(fd, cmd, arg); } while (ret == -1 && errno == EINTR); return ret; @@ -171,7 +165,6 @@ int sys_fcntl_long(int fd, int cmd, long arg) int ret; do { - errno = 0; ret = fcntl(fd, cmd, arg); } while (ret == -1 && errno == EINTR); return ret; -- cgit From 193225dd424c72209b54d867fac64b7415cff529 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 Apr 2002 11:43:02 +0000 Subject: patch from Alexander Bokovoy needed for dlopen on bsd systems (This used to be commit 38fd99e84176106ed700f637e9292d2a4c1385b4) --- source3/lib/system.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/system.c b/source3/lib/system.c index dfd206027e..9953df7058 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -1269,7 +1269,7 @@ int sys_pclose(int fd) void *sys_dlopen(const char *name, int flags) { -#if defined(HAVE_LIBDL) || defined(HAVE_DLOPEN) +#if defined(HAVE_DLOPEN) return dlopen(name, flags); #else return NULL; @@ -1278,7 +1278,7 @@ void *sys_dlopen(const char *name, int flags) void *sys_dlsym(void *handle, char *symbol) { -#if defined(HAVE_LIBDL) || defined(HAVE_DLSYM) +#if defined(HAVE_DLSYM) return dlsym(handle, symbol); #else return NULL; @@ -1287,7 +1287,7 @@ void *sys_dlsym(void *handle, char *symbol) int sys_dlclose (void *handle) { -#if defined(HAVE_LIBDL) || defined(HAVE_DLCLOSE) +#if defined(HAVE_DLCLOSE) return dlclose(handle); #else return 0; @@ -1296,7 +1296,7 @@ int sys_dlclose (void *handle) const char *sys_dlerror(void) { -#if defined(HAVE_LIBDL) || defined(HAVE_DLERROR) +#if defined(HAVE_DLERROR) return dlerror(); #else return NULL; -- cgit From 6337369a903b07ef42c050f77d439d8b11b7f6bf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 8 May 2002 23:15:42 +0000 Subject: Merge in Jerry's called name fix. Jeremy. (This used to be commit 6d957924579d64407bdd94d7e78088fb1ea5c9ce) --- source3/lib/util.c | 124 ++++++++++++++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 58 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util.c b/source3/lib/util.c index ea1670ea27..dcb42bbfc4 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1389,20 +1389,39 @@ BOOL fcntl_lock(int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type) } /******************************************************************* -is the name specified one of my netbios names -returns true is it is equal, false otherwise + Is the name specified one of my netbios names. + Returns true if it is equal, false otherwise. ********************************************************************/ + BOOL is_myname(char *s) { - int n; - BOOL ret = False; + int n; + BOOL ret = False; - for (n=0; my_netbios_names[n]; n++) { - if (strequal(my_netbios_names[n], s)) - ret=True; - } - DEBUG(8, ("is_myname(\"%s\") returns %d\n", s, ret)); - return(ret); + for (n=0; my_netbios_names[n]; n++) { + if (strequal(my_netbios_names[n], s)) + ret=True; + } + DEBUG(8, ("is_myname(\"%s\") returns %d\n", s, ret)); + return(ret); +} + +/******************************************************************** + Return only the first IP address of our configured interfaces + as a string. + ********************************************************************/ + +const char *get_my_primary_ip (void) +{ + static fstring ip_string; + int n; + struct iface_struct nics[MAX_INTERFACES]; + + if ((n=get_interfaces(nics, MAX_INTERFACES)) <= 0) + return NULL; + + fstrcpy(ip_string, inet_ntoa(nics[0].ip)); + return ip_string; } BOOL is_myname_or_ipaddr(char *s) @@ -1414,8 +1433,7 @@ BOOL is_myname_or_ipaddr(char *s) return True; /* maybe its an IP address? */ - if (is_ipaddress(s)) - { + if (is_ipaddress(s)) { struct iface_struct nics[MAX_INTERFACES]; int i, n; uint32 ip; @@ -1433,59 +1451,56 @@ BOOL is_myname_or_ipaddr(char *s) /* check for an alias */ ptr = lp_netbios_aliases(); - for ( ; *ptr; ptr++ ) - { + for ( ; *ptr; ptr++ ) { if (StrCaseCmp(s, *ptr) == 0) return True; } - /* no match */ return False; - } - /******************************************************************* -set the horrid remote_arch string based on an enum. + Set the horrid remote_arch string based on an enum. ********************************************************************/ + void set_remote_arch(enum remote_arch_types type) { - extern fstring remote_arch; - ra_type = type; - switch( type ) - { - case RA_WFWG: - fstrcpy(remote_arch, "WfWg"); - return; - case RA_OS2: - fstrcpy(remote_arch, "OS2"); - return; - case RA_WIN95: - fstrcpy(remote_arch, "Win95"); - return; - case RA_WINNT: - fstrcpy(remote_arch, "WinNT"); - return; - case RA_WIN2K: - fstrcpy(remote_arch, "Win2K"); - return; - case RA_SAMBA: - fstrcpy(remote_arch,"Samba"); - return; - default: - ra_type = RA_UNKNOWN; - fstrcpy(remote_arch, "UNKNOWN"); - break; - } + extern fstring remote_arch; + ra_type = type; + switch( type ) { + case RA_WFWG: + fstrcpy(remote_arch, "WfWg"); + return; + case RA_OS2: + fstrcpy(remote_arch, "OS2"); + return; + case RA_WIN95: + fstrcpy(remote_arch, "Win95"); + return; + case RA_WINNT: + fstrcpy(remote_arch, "WinNT"); + return; + case RA_WIN2K: + fstrcpy(remote_arch, "Win2K"); + return; + case RA_SAMBA: + fstrcpy(remote_arch,"Samba"); + return; + default: + ra_type = RA_UNKNOWN; + fstrcpy(remote_arch, "UNKNOWN"); + break; + } } /******************************************************************* Get the remote_arch type. ********************************************************************/ + enum remote_arch_types get_remote_arch(void) { - return ra_type; + return ra_type; } @@ -1493,42 +1508,35 @@ void out_ascii(FILE *f, unsigned char *buf,int len) { int i; for (i=0;i(per_line/2)) fprintf(f, " "); - while (n--) - { + while (n--) { fprintf(f, " "); } n = MIN(per_line/2,i%per_line); -- cgit From 4db4e95ab2140e179d0f15ad390b7a994b6642f2 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 9 May 2002 04:08:00 +0000 Subject: pidfile merge from SAMBA_2_2 (including --with-fhs) and a few other minor things; compiles and shouldnt break, but needs testing (This used to be commit 19b9b50d9039afe614284aaf379f9f1078e2e307) --- source3/lib/pidfile.c | 9 +++------ source3/lib/util.c | 53 +++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 20 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/pidfile.c b/source3/lib/pidfile.c index 28fd959b54..b98259fe5e 100644 --- a/source3/lib/pidfile.c +++ b/source3/lib/pidfile.c @@ -35,7 +35,7 @@ pid_t pidfile_pid(char *name) unsigned ret; pstring pidFile; - slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_lockdir(), name); + slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_piddir(), name); fd = sys_open(pidFile, O_NONBLOCK | O_RDONLY, 0644); if (fd == -1) { @@ -68,10 +68,7 @@ pid_t pidfile_pid(char *name) return 0; } -/* Create a pid file in the lock directory. open it and leave it locked. - This must be done after a call to lp_load() as it uses the lp_lockdir() - function to generate the path to the pidfile. */ - +/* create a pid file in the pid directory. open it and leave it locked */ void pidfile_create(char *name) { int fd; @@ -79,7 +76,7 @@ void pidfile_create(char *name) pstring pidFile; pid_t pid; - slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_lockdir(), name); + slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_piddir(), name); pid = pidfile_pid(name); if (pid != 0) { diff --git a/source3/lib/util.c b/source3/lib/util.c index dcb42bbfc4..5f80fa6757 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -91,9 +91,10 @@ char **my_netbios_names; /**************************************************************************** - find a suitable temporary directory. The result should be copied immediately + Find a suitable temporary directory. The result should be copied immediately as it may be overwritten by a subsequent call. - ****************************************************************************/ +****************************************************************************/ + char *tmpdir(void) { char *p; @@ -190,7 +191,7 @@ BOOL file_exist(const char *fname,SMB_STRUCT_STAT *sbuf) if (sys_stat(fname,sbuf) != 0) return(False); - return(S_ISREG(sbuf->st_mode)); + return((S_ISREG(sbuf->st_mode)) || (S_ISFIFO(sbuf->st_mode))); } /******************************************************************* @@ -689,7 +690,7 @@ void become_daemon(void) /**************************************************************************** -put up a yes/no prompt + Put up a yes/no prompt ****************************************************************************/ BOOL yesno(char *p) { @@ -862,7 +863,7 @@ struct in_addr *interpret_addr2(const char *str) } /******************************************************************* - check if an IP is the 0.0.0.0 + Check if an IP is the 0.0.0.0 ******************************************************************/ BOOL is_zero_ip(struct in_addr ip) { @@ -871,7 +872,9 @@ BOOL is_zero_ip(struct in_addr ip) return(a == 0); } -/* Set an IP to 0.0.0.0 */ +/******************************************************************* + Set an IP to 0.0.0.0 + ******************************************************************/ void zero_ip(struct in_addr *ip) { @@ -1062,7 +1065,8 @@ char *uidtoname(uid_t uid) struct passwd *pass; pass = sys_getpwuid(uid); - if (pass) return(pass->pw_name); + if (pass) + return(pass->pw_name); slprintf(name, sizeof(name) - 1, "%d",(int)uid); return(name); } @@ -1078,7 +1082,8 @@ char *gidtoname(gid_t gid) struct group *grp; grp = getgrgid(gid); - if (grp) return(grp->gr_name); + if (grp) + return(grp->gr_name); slprintf(name,sizeof(name) - 1, "%d",(int)gid); return(name); } @@ -1408,10 +1413,10 @@ BOOL is_myname(char *s) /******************************************************************** Return only the first IP address of our configured interfaces - as a string. - ********************************************************************/ + as a string + *******************************************************************/ -const char *get_my_primary_ip (void) +const char* get_my_primary_ip (void) { static fstring ip_string; int n; @@ -1775,10 +1780,10 @@ int smb_mkstemp(char *template) #endif } - -/** +/***************************************************************** malloc that aborts with smb_panic on fail or zero size. -**/ + *****************************************************************/ + void *smb_xmalloc(size_t size) { void *p; @@ -1870,6 +1875,26 @@ char *lock_path(char *name) return fname; } +/***************************************************************** +a useful function for returning a path in the Samba pid directory + *****************************************************************/ +char *pid_path(char *name) +{ + static pstring fname; + + pstrcpy(fname,lp_piddir()); + trim_string(fname,"","/"); + + if (!directory_exist(fname,NULL)) { + mkdir(fname,0755); + } + + pstrcat(fname,"/"); + pstrcat(fname,name); + + return fname; +} + /** * @brief Returns an absolute path to a file in the Samba lib directory. -- cgit From 27cd004bf2a6a76a16a7741f7aa97c1f30b3de50 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 9 May 2002 17:35:42 +0000 Subject: merge from SAMBA_2_2 (This used to be commit c26ce496e88a9a1f93a51fa626f222c98892746f) --- source3/lib/access.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/access.c b/source3/lib/access.c index f12ee92799..62d47b82cf 100644 --- a/source3/lib/access.c +++ b/source3/lib/access.c @@ -30,7 +30,7 @@ static int masked_match(char *tok, char *slash, char *s) if (strlen(slash + 1) > 2) { mask = interpret_addr(slash + 1); } else { - mask = (uint32)((ALLONES >> atoi(slash + 1)) ^ ALLONES); + mask = (uint32)((ALLONES << atoi(slash + 1)) ^ ALLONES); } if (net == INADDR_NONE || mask == INADDR_NONE) { -- cgit From 30c80f90ade5f0b6aee777d3da4135ae94e43a60 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 9 May 2002 17:38:23 +0000 Subject: We were mapping the open of name1/name2 where name1 wasn't a directory (ie. ENOTDIR) to the NT status code NT_STATUS_NOT_A_DIRECTORY. NT seems to use NT_STATUS_OBJECT_PATH_NOT_FOUND. I'm hoping this will fix the access binaries served from a Samba share bug... Jeremy. (This used to be commit 6f2b76c2394e305e5a282f459b84f94f8ed2082a) --- source3/lib/error.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/error.c b/source3/lib/error.c index 22ac1cb2d7..78db04ecc5 100644 --- a/source3/lib/error.c +++ b/source3/lib/error.c @@ -26,7 +26,7 @@ const struct unix_error_map unix_dos_nt_errmap[] = { { EPERM, ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED }, { EACCES, ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED }, { ENOENT, ERRDOS, ERRbadfile, NT_STATUS_NO_SUCH_FILE }, - { ENOTDIR, ERRDOS, ERRbadpath, NT_STATUS_NOT_A_DIRECTORY }, + { ENOTDIR, ERRDOS, ERRbadpath, NT_STATUS_OBJECT_PATH_NOT_FOUND }, { EIO, ERRHRD, ERRgeneral, NT_STATUS_IO_DEVICE_ERROR }, { EBADF, ERRSRV, ERRsrverror, NT_STATUS_INVALID_HANDLE }, { EINVAL, ERRSRV, ERRsrverror, NT_STATUS_INVALID_HANDLE }, -- cgit From 1bd3da9aef6624325a049cc84a7e6882c072a898 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 9 May 2002 17:44:42 +0000 Subject: NT uses NT_STATUS_OBJECT_NAME_NOT_FOUND not NT_STATUS_NO_SUCH_FILE for ENOENT. Jeremy. (This used to be commit 2b49d727b061f87d5022e7ee75b66dc851265fd5) --- source3/lib/error.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/error.c b/source3/lib/error.c index 78db04ecc5..608d2b89ba 100644 --- a/source3/lib/error.c +++ b/source3/lib/error.c @@ -25,7 +25,7 @@ const struct unix_error_map unix_dos_nt_errmap[] = { { EPERM, ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED }, { EACCES, ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED }, - { ENOENT, ERRDOS, ERRbadfile, NT_STATUS_NO_SUCH_FILE }, + { ENOENT, ERRDOS, ERRbadfile, NT_STATUS_OBJECT_NAME_NOT_FOUND }, { ENOTDIR, ERRDOS, ERRbadpath, NT_STATUS_OBJECT_PATH_NOT_FOUND }, { EIO, ERRHRD, ERRgeneral, NT_STATUS_IO_DEVICE_ERROR }, { EBADF, ERRSRV, ERRsrverror, NT_STATUS_INVALID_HANDLE }, -- cgit From 282d069ff4d6a9d06788e11caab67c47e4bb927b Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 11 May 2002 16:55:59 +0000 Subject: move vsyslog() from snprintf.c to replace.c tx Elrond for prosecuting cleanness :) (This used to be commit 2f30c2edfd6373864f5bd0c4f8d70625495da7eb) --- source3/lib/replace.c | 14 ++++++++++++++ source3/lib/snprintf.c | 14 -------------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/replace.c b/source3/lib/replace.c index dd50ff035e..2cc7d48adb 100644 --- a/source3/lib/replace.c +++ b/source3/lib/replace.c @@ -414,3 +414,17 @@ char *rep_inet_ntoa(struct in_addr ip) return setvbuf(stream, (char *)NULL, _IOLBF, 0); } #endif /* HAVE_SETLINEBUF */ + +#ifndef HAVE_VSYSLOG +#ifdef HAVE_SYSLOG + void vsyslog (int facility_priority, char *format, va_list arglist) +{ + char *msg = NULL; + vasprintf(&msg, format, arglist); + if (!msg) + return; + syslog(facility_priority, "%s", msg); + SAFE_FREE(msg); +} +#endif /* HAVE_SYSLOG */ +#endif /* HAVE_VSYSLOG */ diff --git a/source3/lib/snprintf.c b/source3/lib/snprintf.c index 2733626108..ee0d302b0f 100644 --- a/source3/lib/snprintf.c +++ b/source3/lib/snprintf.c @@ -821,20 +821,6 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) } #endif -#ifndef HAVE_VSYSLOG -#ifdef HAVE_SYSLOG - void vsyslog (int facility_priority, char *format, va_list arglist) -{ - char *msg = NULL; - vasprintf(&msg, format, arglist); - if (!msg) - return; - syslog(facility_priority, "%s", msg); - SAFE_FREE(msg); -} -#endif /* HAVE_SYSLOG */ -#endif /* HAVE_VSYSLOG */ - #ifdef TEST_SNPRINTF int sprintf(char *str,const char *fmt,...); -- cgit From 276e1928c4557da1fd7ca8e1232a652331f3a488 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Thu, 16 May 2002 20:06:00 +0000 Subject: Add __va_copy to talloc functions. talloc_asprintf was causing all kinds of problems on Linux/390 systems... (This used to be commit 2605e483b309e62b4c5d39a2ac6d8b2257bb5a87) --- source3/lib/talloc.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/talloc.c b/source3/lib/talloc.c index b50e451b95..b66d674dd5 100644 --- a/source3/lib/talloc.c +++ b/source3/lib/talloc.c @@ -316,12 +316,22 @@ smb_ucs2_t *talloc_strdup_w(TALLOC_CTX *t, const smb_ucs2_t *p) { int len; char *ret; + va_list ap2; - len = vsnprintf(NULL, 0, fmt, ap); +#ifdef HAVE_VA_COPY + __va_copy(ap2, ap); /* for systems were va_list is a struct */ +#else + ap2 = ap; +#endif + len = vsnprintf(NULL, 0, fmt, ap2); ret = talloc(t, len+1); - if (ret) - vsnprintf(ret, len+1, fmt, ap); + if (ret) { +#ifdef HAVE_VA_COPY + __va_copy(ap2, ap); +#endif + vsnprintf(ret, len+1, fmt, ap2); + } return ret; } @@ -354,14 +364,23 @@ smb_ucs2_t *talloc_strdup_w(TALLOC_CTX *t, const smb_ucs2_t *p) const char *fmt, va_list ap) { int len, s_len; + va_list ap2; +#ifdef HAVE_VA_COPY + __va_copy(ap2, ap); +#else + ap2 = ap; +#endif s_len = strlen(s); - len = vsnprintf(NULL, 0, fmt, ap); + len = vsnprintf(NULL, 0, fmt, ap2); s = talloc_realloc(t, s, s_len + len+1); if (!s) return NULL; - vsnprintf(s+s_len, len+1, fmt, ap); +#ifdef HAVE_VA_COPY + __va_copy(ap2, ap); +#endif + vsnprintf(s+s_len, len+1, fmt, ap2); return s; } -- cgit From eed5094264945ca8ccf47030375cc56808ae8ea3 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 17 May 2002 12:42:39 +0000 Subject: This removes --with-ssl from Samba. This option was badly maintained, useless and confused our users and distirbutors. (its SSL, therfore it must be good...) No windows client uses this protocol without help from an SSL tunnel. I can't see any reason why setting up a unix-side SSL wrapper would be any more difficult than the > 10 config options this mess added to samba in any case. On the Samba client end, I think the LIBSMB_PROG hack should be sufficient to start stunnel on the unix side. We might extend this to take %i and %p (IP and port) if there is demand. Andrew Bartlett (This used to be commit b04561d3fd3ee732877790fb4193b20ad72a75f8) --- source3/lib/util.c | 7 ----- source3/lib/util_sock.c | 71 ------------------------------------------------- 2 files changed, 78 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util.c b/source3/lib/util.c index 5f80fa6757..bb9b96b361 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -52,13 +52,6 @@ #endif /* WITH_NISPLUS_HOME */ #endif /* HAVE_NETGROUP && WITH_AUTOMOUNT */ -#ifdef WITH_SSL -#include -#undef Realloc /* SSLeay defines this and samba has a function of this name */ -extern SSL *ssl; -extern int sslFd; -#endif /* WITH_SSL */ - int Protocol = PROTOCOL_COREPLUS; /* a default finfo structure to ensure all fields are sensible */ diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index 5bdfb24be4..da75228870 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -21,13 +21,6 @@ #include "includes.h" -#ifdef WITH_SSL -#include -#undef Realloc /* SSLeay defines this and samba has a function of this name */ -extern SSL *ssl; -extern int sslFd; -#endif /* WITH_SSL */ - /* the last IP received from */ struct in_addr lastip; @@ -243,15 +236,7 @@ static ssize_t read_socket_with_timeout(int fd,char *buf,size_t mincnt,size_t ma if (mincnt == 0) mincnt = maxcnt; while (nread < mincnt) { -#ifdef WITH_SSL - if (fd == sslFd) { - readret = SSL_read(ssl, buf + nread, maxcnt - nread); - } else { - readret = sys_read(fd, buf + nread, maxcnt - nread); - } -#else /* WITH_SSL */ readret = sys_read(fd, buf + nread, maxcnt - nread); -#endif /* WITH_SSL */ if (readret == 0) { DEBUG(5,("read_socket_with_timeout: blocking read. EOF from client.\n")); @@ -300,15 +285,7 @@ static ssize_t read_socket_with_timeout(int fd,char *buf,size_t mincnt,size_t ma return -1; } -#ifdef WITH_SSL - if (fd == sslFd) { - readret = SSL_read(ssl, buf + nread, maxcnt - nread); - }else{ - readret = sys_read(fd, buf + nread, maxcnt - nread); - } -#else /* WITH_SSL */ readret = sys_read(fd, buf+nread, maxcnt-nread); -#endif /* WITH_SSL */ if (readret == 0) { /* we got EOF on the file descriptor */ @@ -353,15 +330,7 @@ ssize_t read_with_timeout(int fd, char *buf, size_t mincnt, size_t maxcnt, if (mincnt == 0) mincnt = maxcnt; while (nread < mincnt) { -#ifdef WITH_SSL - if(fd == sslFd){ - readret = SSL_read(ssl, buf + nread, maxcnt - nread); - }else{ - readret = sys_read(fd, buf + nread, maxcnt - nread); - } -#else /* WITH_SSL */ readret = sys_read(fd, buf + nread, maxcnt - nread); -#endif /* WITH_SSL */ if (readret <= 0) return readret; @@ -383,15 +352,7 @@ ssize_t read_with_timeout(int fd, char *buf, size_t mincnt, size_t maxcnt, if(selrtn <= 0) return selrtn; -#ifdef WITH_SSL - if(fd == sslFd){ - readret = SSL_read(ssl, buf + nread, maxcnt - nread); - }else{ - readret = sys_read(fd, buf + nread, maxcnt - nread); - } -#else /* WITH_SSL */ readret = sys_read(fd, buf+nread, maxcnt-nread); -#endif /* WITH_SSL */ if (readret <= 0) return readret; @@ -429,15 +390,7 @@ ssize_t read_data(int fd,char *buffer,size_t N) smb_read_error = 0; while (total < N) { -#ifdef WITH_SSL - if(fd == sslFd){ - ret = SSL_read(ssl, buffer + total, N - total); - }else{ - ret = sys_read(fd,buffer + total,N - total); - } -#else /* WITH_SSL */ ret = sys_read(fd,buffer + total,N - total); -#endif /* WITH_SSL */ if (ret == 0) { DEBUG(10,("read_data: read of %d returned 0. Error = %s\n", (int)(N - total), strerror(errno) )); @@ -467,15 +420,7 @@ static ssize_t read_socket_data(int fd,char *buffer,size_t N) smb_read_error = 0; while (total < N) { -#ifdef WITH_SSL - if(fd == sslFd){ - ret = SSL_read(ssl, buffer + total, N - total); - }else{ - ret = sys_read(fd,buffer + total,N - total); - } -#else /* WITH_SSL */ ret = sys_read(fd,buffer + total,N - total); -#endif /* WITH_SSL */ if (ret == 0) { DEBUG(10,("read_socket_data: recv of %d returned 0. Error = %s\n", (int)(N - total), strerror(errno) )); @@ -503,15 +448,7 @@ ssize_t write_data(int fd,char *buffer,size_t N) ssize_t ret; while (total < N) { -#ifdef WITH_SSL - if(fd == sslFd){ - ret = SSL_write(ssl,buffer + total,N - total); - }else{ - ret = sys_write(fd,buffer + total,N - total); - } -#else /* WITH_SSL */ ret = sys_write(fd,buffer + total,N - total); -#endif /* WITH_SSL */ if (ret == -1) { DEBUG(0,("write_data: write failure. Error = %s\n", strerror(errno) )); @@ -535,15 +472,7 @@ ssize_t write_socket_data(int fd,char *buffer,size_t N) ssize_t ret; while (total < N) { -#ifdef WITH_SSL - if(fd == sslFd){ - ret = SSL_write(ssl,buffer + total,N - total); - }else{ - ret = sys_send(fd,buffer + total,N - total, 0); - } -#else /* WITH_SSL */ ret = sys_send(fd,buffer + total,N - total,0); -#endif /* WITH_SSL */ if (ret == -1) { DEBUG(0,("write_socket_data: write failure. Error = %s\n", strerror(errno) )); -- cgit From e4672862fd5aea4aebd92fa286c542a311dfa17b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 17 May 2002 14:19:36 +0000 Subject: Make Get_Pwnam use getpwnam_alloc() in an attempt to make it segfault rather than allow silent reuse of stale static buffer. Next step is to make this fn return that allocated buffer. (This used to be commit e1daf816f3d809d288313fe2db98b5a731c93a79) --- source3/lib/username.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/username.c b/source3/lib/username.c index da603949bc..f6ce765b41 100644 --- a/source3/lib/username.c +++ b/source3/lib/username.c @@ -55,9 +55,10 @@ BOOL split_domain_and_name(const char *name, char *domain, char* username) } else if (lp_winbind_use_default_domain()) { fstrcpy(username, name); fstrcpy(domain, lp_workgroup()); - } else + } else { return False; - + } + DEBUG(10,("split_domain_and_name: all is fine, domain is |%s| and name is |%s|\n", domain, username)); return True; } @@ -238,6 +239,8 @@ BOOL map_username(char *user) * - using lp_usernamelevel() for permutations. ****************************************************************************/ +static struct passwd *Get_Pwnam_ret = NULL; + static struct passwd *Get_Pwnam_internals(const char *user, char *user2) { struct passwd *ret = NULL; @@ -252,14 +255,14 @@ static struct passwd *Get_Pwnam_internals(const char *user, char *user2) common case on UNIX systems */ strlower(user2); DEBUG(5,("Trying _Get_Pwnam(), username as lowercase is %s\n",user2)); - ret = sys_getpwnam(user2); + ret = getpwnam_alloc(user2); if(ret) goto done; /* Try as given, if username wasn't originally lowercase */ if(strcmp(user, user2) != 0) { DEBUG(5,("Trying _Get_Pwnam(), username as given is %s\n", user)); - ret = sys_getpwnam(user); + ret = getpwnam_alloc(user); if(ret) goto done; } @@ -268,7 +271,7 @@ static struct passwd *Get_Pwnam_internals(const char *user, char *user2) strupper(user2); if(strcmp(user, user2) != 0) { DEBUG(5,("Trying _Get_Pwnam(), username as uppercase is %s\n", user2)); - ret = sys_getpwnam(user2); + ret = getpwnam_alloc(user2); if(ret) goto done; } @@ -276,10 +279,31 @@ static struct passwd *Get_Pwnam_internals(const char *user, char *user2) /* Try all combinations up to usernamelevel */ strlower(user2); DEBUG(5,("Checking combinations of %d uppercase letters in %s\n", lp_usernamelevel(), user2)); - ret = uname_string_combinations(user2, sys_getpwnam, lp_usernamelevel()); + ret = uname_string_combinations(user2, getpwnam_alloc, lp_usernamelevel()); done: DEBUG(5,("Get_Pwnam_internals %s find user [%s]!\n",ret ? "did":"didn't", user)); + + /* This call used to just return the 'passwd' static buffer. + This could then have accidental reuse implications, so + we now malloc a copy, and free it in the next use. + + This should cause the (ab)user to segfault if it + uses an old struct. + + This is better than useing the wrong data in security + critical operations. + + The real fix is to make the callers free the returned + malloc'ed data. + */ + + if (Get_Pwnam_ret) { + passwd_free(&Get_Pwnam_ret); + } + + Get_Pwnam_ret = ret; + return ret; } @@ -288,7 +312,7 @@ done: NOTE: This can potentially modify 'user'! ****************************************************************************/ -struct passwd *Get_Pwnam_Modify(char *user) +struct passwd *Get_Pwnam_Modify(fstring user) { fstring user2; struct passwd *ret; @@ -320,8 +344,6 @@ struct passwd *Get_Pwnam(const char *user) ret = Get_Pwnam_internals(user, user2); - DEBUG(5,("Get_Pwnam %s find user [%s]!\n",ret ? "did":"didn't", user)); - return ret; } -- cgit From c7523c57512258007f0ac5271697fc6a9f4618d6 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 17 May 2002 14:51:22 +0000 Subject: Fix usage of va_list passed as an arg. Use __va_copy before using it when it exists. (This used to be commit 85ab07bdc1b2ce7b2c1b8197fad45124b1460dca) --- source3/lib/dprintf.c | 8 +++++++- source3/lib/snprintf.c | 25 +++++++++++++++++++++---- source3/lib/util.c | 8 +++++++- source3/lib/xfile.c | 8 +++++++- 4 files changed, 42 insertions(+), 7 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/dprintf.c b/source3/lib/dprintf.c index dadebdb3b4..4dcc283047 100644 --- a/source3/lib/dprintf.c +++ b/source3/lib/dprintf.c @@ -36,12 +36,18 @@ int d_vfprintf(FILE *f, const char *format, va_list ap) char *p, *p2; int ret, maxlen, clen; const char *msgstr; + va_list ap2; /* do any message translations */ msgstr = lang_msg(format); if (!msgstr) return -1; - ret = vasprintf(&p, msgstr, ap); +#if defined(HAVE_VA_COPY) + __va_copy(ap2, ap) +#else + ap2 = ap; +#endif + ret = vasprintf(&p, msgstr, ap2); lang_msg_free(msgstr); diff --git a/source3/lib/snprintf.c b/source3/lib/snprintf.c index ee0d302b0f..561e775c8f 100644 --- a/source3/lib/snprintf.c +++ b/source3/lib/snprintf.c @@ -106,7 +106,7 @@ #endif static size_t dopr(char *buffer, size_t maxlen, const char *format, - va_list args); + va_list args_in); static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, char *value, int flags, int min, int max); static void fmtint(char *buffer, size_t *currlen, size_t maxlen, @@ -149,7 +149,7 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c); #define MAX(p,q) (((p) >= (q)) ? (p) : (q)) #endif -static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args) +static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) { char ch; LLONG value; @@ -161,6 +161,13 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args int flags; int cflags; size_t currlen; + va_list args; + +#if defined(HAVE_VA_COPY) + __va_copy(args, args_in); +#else + args = args_in; +#endif state = DP_S_DEFAULT; currlen = flags = cflags = min = 0; @@ -793,13 +800,23 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) int vasprintf(char **ptr, const char *format, va_list ap) { int ret; + va_list ap2; + +#if defined(HAVE_VA_COPY) + __va_copy(ap2, ap); +#else + ap2 = ap; +#endif - ret = vsnprintf(NULL, 0, format, ap); + ret = vsnprintf(NULL, 0, format, ap2); if (ret <= 0) return ret; (*ptr) = (char *)malloc(ret+1); if (!*ptr) return -1; - ret = vsnprintf(*ptr, ret+1, format, ap); +#if defined(HAVE_VA_COPY) + __va_copy(ap2, ap); +#endif + ret = vsnprintf(*ptr, ret+1, format, ap2); return ret; } diff --git a/source3/lib/util.c b/source3/lib/util.c index bb9b96b361..d9be67599f 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1815,7 +1815,13 @@ char *smb_xstrdup(const char *s) int smb_xvasprintf(char **ptr, const char *format, va_list ap) { int n; - n = vasprintf(ptr, format, ap); + va_list ap2; +#if defined(HAVE_VA_COPY) + __va_copy(ap2, ap); +#else + ap2 = ap; +#endif + n = vasprintf(ptr, format, ap2); if (n == -1 || ! *ptr) { smb_panic("smb_xvasprintf: out of memory"); } diff --git a/source3/lib/xfile.c b/source3/lib/xfile.c index 00ea6e5cac..7b97d329ae 100644 --- a/source3/lib/xfile.c +++ b/source3/lib/xfile.c @@ -187,7 +187,13 @@ int x_vfprintf(XFILE *f, const char *format, va_list ap) { char *p; int len, ret; - len = vasprintf(&p, format, ap); + va_list ap2; +#if defined(HAVE_VA_COPY) + __va_copy(ap2, ap); +#else + ap2 = ap; +#endif + len = vasprintf(&p, format, ap2); if (len <= 0) return len; ret = x_fwrite(p, 1, len, f); SAFE_FREE(p); -- cgit From 27ecfceae15ae80224f4dedd07381598b945359e Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 17 May 2002 14:55:50 +0000 Subject: Don't forget the semicolon, you fool! (This used to be commit 1c9387330f776b9b96714f9c9c62087bbd32f7b6) --- source3/lib/dprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/dprintf.c b/source3/lib/dprintf.c index 4dcc283047..e3aa2c7669 100644 --- a/source3/lib/dprintf.c +++ b/source3/lib/dprintf.c @@ -43,7 +43,7 @@ int d_vfprintf(FILE *f, const char *format, va_list ap) if (!msgstr) return -1; #if defined(HAVE_VA_COPY) - __va_copy(ap2, ap) + __va_copy(ap2, ap); #else ap2 = ap; #endif -- cgit From 58e1fe62cc955c6b8449332447a6879c6fab64e7 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 18 May 2002 05:52:52 +0000 Subject: A few things in this commit: cleanup some of the code in net_rpc_join re const warnings and fstrings. Passdb: Make the %u and %U substituions in passdb work. This is done by declaring these paramters to be 'const' and doing the substitution manually. I'm told this is us going full circle, but I can't really see a better way. Finally these things actually seem to work properly... Make the lanman code use the pdb's recorded values for homedir etc rather than the values from lp_*() Add code to set the plaintext password in the passdb, where it can decide how to store/set it. For use with a future 'ldap password change' option, or somthing like that... Add pdb_unix, so as to remove the 'not in passdb' special cases from the local_lookup_*() code. Quite small, as it uses the new 'struct passwd -> SAM_ACCOUNT' code that is now in just one place. (also used by pdb_smbpasswd) Other: Fix up the adding of [homes] at session setup time to actually pass the right string, that is the unix homedir, not the UNC path. Fix up [homes] so that for winbind users is picks the correct name. (bad interactions with the default domain code previously) Change the rpc_server/srv_lsa_nt.c code to match NT when for the SATUS_NONE_MAPPED reply: This was only being triggered on no queries, now it is on the 'no mappings' (ie all mappings failed). Checked against Win2k. Policy Question: Should SID -> unix_user.234/unix_group.364 be considered a mapping or not? Currently it isn't. Andrew Bartlett (This used to be commit c28668068b5a3b3cf3c4317e5fb32ec9957f3e34) --- source3/lib/substitute.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ source3/lib/util_getent.c | 30 +++++++++++++++------------ 2 files changed, 69 insertions(+), 13 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c index e878ee8cbf..09921c145d 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -279,6 +279,58 @@ void standard_sub_advanced(int snum, const char *user, const char *connectpath, standard_sub_basic(smb_name, str); } +const char *standard_sub_specified(TALLOC_CTX *mem_ctx, const char *input_string, + const char *username, + const char *domain, + uid_t uid, + gid_t gid) +{ + pstring input_pstring; + char *p, *s; + + pstrcpy(input_pstring, input_string); + + for (s=input_pstring; (p=strchr_m(s, '%')); s=p) { + + int l = sizeof(pstring) - (int)(p-input_pstring); + + switch (*(p+1)) { + case 'U' : + string_sub(p,"%U",username,l); + break; + case 'u' : + string_sub(p,"%u",username,l); + break; + case 'G' : + case 'g' : + if (gid != -1) { + string_sub(p,"%G",gidtoname(gid),l); + string_sub(p,"%g",gidtoname(gid),l); + } else { + string_sub(p,"%G","NO_GROUP",l); + string_sub(p,"%g","NO_GROUP",l); + } + break; + case 'D' : + string_sub(p,"%D", domain,l); + break; + case 'N' : + string_sub(p,"%N", automount_server(username),l); + break; + case '\0': + p++; + break; /* don't run off the end of the string */ + + default: p+=2; + break; + } + } + + standard_sub_basic(username, input_pstring); + + return talloc_strdup(mem_ctx, input_pstring); +} + /**************************************************************************** Do some standard substitutions in a string. ****************************************************************************/ diff --git a/source3/lib/util_getent.c b/source3/lib/util_getent.c index 02e4b932de..2e76121aae 100644 --- a/source3/lib/util_getent.c +++ b/source3/lib/util_getent.c @@ -277,20 +277,24 @@ struct sys_userlist *get_users_in_group(const char *gname) DOM_SID sid; enum SID_NAME_USE name_type; - (void) split_domain_and_name(gname, domain, groupname); - - /* - * If we're doing this via winbindd, don't do the - * entire group list enumeration as we know this is - * pointless (and slow). - */ - - if (winbind_lookup_name(domain, groupname, &sid, &name_type) && name_type == SID_NAME_DOM_GRP) { - if ((gptr = (struct group *)getgrnam(gname)) == NULL) - return NULL; - return add_members_to_userlist(list_head, gptr); + /* No point using winbind if we can't split it in the + first place */ + if (split_domain_and_name(gname, domain, groupname)) { + + /* + * If we're doing this via winbindd, don't do the + * entire group list enumeration as we know this is + * pointless (and slow). + */ + + if (winbind_lookup_name(domain, groupname, &sid, &name_type) + && name_type == SID_NAME_DOM_GRP) { + if ((gptr = (struct group *)getgrnam(gname)) == NULL) + return NULL; + return add_members_to_userlist(list_head, gptr); + } } - + setgrent(); while((gptr = getgrent()) != NULL) { if (strequal(gname, gptr->gr_name)) { -- cgit From ac03889168cc5b97651ee5e4300ce50210de8800 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 18 May 2002 13:19:38 +0000 Subject: Move client_receive_smb to clientgen.c as a static, as proposed by Elrond. (only function that used it was unused, and this helps bring TNG and HEAD closer) Its also cleaner. Andrew Bartlett (This used to be commit 78f47c83332a6408a718a3dee45645935638b364) --- source3/lib/util_sock.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index da75228870..f5d56eb0d4 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -631,40 +631,6 @@ BOOL receive_smb(int fd,char *buffer, unsigned int timeout) return(True); } -/**************************************************************************** - read an smb from a fd ignoring all keepalive packets. Note that the buffer - *MUST* be of size BUFFER_SIZE+SAFETY_MARGIN. - The timeout is in milliseconds - - This is exactly the same as receive_smb except that it never returns - a session keepalive packet (just as receive_smb used to do). - receive_smb was changed to return keepalives as the oplock processing means this call - should never go into a blocking read. -****************************************************************************/ - -BOOL client_receive_smb(int fd,char *buffer, unsigned int timeout) -{ - BOOL ret; - - for(;;) - { - ret = receive_smb(fd, buffer, timeout); - - if (!ret) - { - DEBUG(10,("client_receive_smb failed\n")); - show_msg(buffer); - return ret; - } - - /* Ignore session keepalive packets. */ - if(CVAL(buffer,0) != SMBkeepalive) - break; - } - show_msg(buffer); - return ret; -} - /**************************************************************************** send an smb to a fd ****************************************************************************/ -- cgit From 2a02a76913a91c9882868b73c72ba2e8d2be764d Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 18 May 2002 15:09:21 +0000 Subject: so here it is the code to introduce seriously debugggging classes. this is a first step only passdb stuff has beein "classized". - so what can you do? set debug level to: 1 poasdb:10 that will make all the code run at debug level 1 except the code in passdb/* files that will run at level 10 TODO: fix the man page - also smbcontrol has this nice feature so smbcontrol smbd debug 3 passdb:5 will set every smbd to have a default log level of 3 while passdb stuff will be at level 5 and so no.. minor cosmetic fix to pdbedit is there too (This used to be commit be5c3b3f5781ddc002ffcc98df04ab024dcef4ca) --- source3/lib/debug.c | 332 +++++++++++++++++++++++++++++++++++++++---------- source3/lib/messages.c | 10 +- 2 files changed, 272 insertions(+), 70 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 7960c32b58..0a4cee89ae 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -2,6 +2,8 @@ Unix SMB/CIFS implementation. Samba utility functions Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Elrond 2002 + Copyright (C) Simo Sorce 2002 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -81,11 +83,23 @@ XFILE *dbf = NULL; pstring debugf = ""; BOOL append_log = False; +BOOL debug_warn_unknown_class = True; +BOOL debug_auto_add_unknown_class = True; +BOOL AllowDebugChange = True; -int DEBUGLEVEL_CLASS[DBGC_LAST]; -BOOL DEBUGLEVEL_CLASS_ISSET[DBGC_LAST]; -int DEBUGLEVEL = DEBUGLEVEL_CLASS; -BOOL AllowDebugChange = True; +/* + * This is to allow assignment to DEBUGLEVEL before the debug + * system has been initialised. + */ +static int debug_all_class_hack = 1; +static BOOL debug_all_class_isset_hack = True; + +static int debug_num_classes = 0; +int *DEBUGLEVEL_CLASS = &debug_all_class_hack; +BOOL *DEBUGLEVEL_CLASS_ISSET = &debug_all_class_isset_hack; + +/* DEBUGLEVEL is #defined to *debug_level */ +int DEBUGLEVEL = &debug_all_class_hack; /* -------------------------------------------------------------------------- ** @@ -129,7 +143,7 @@ static BOOL log_overflow = False; * white space. There must be one name for each DBGC_, and they * must be in the table in the order of DBGC_.. */ -char *classname_table[] = { +static const char *default_classname_table[] = { "all", /* DBGC_ALL; index refs traditional DEBUGLEVEL */ "tdb", /* DBGC_TDB */ "printdrivers", /* DBGC_PRINTDRIVERS */ @@ -137,38 +151,221 @@ char *classname_table[] = { "smb", /* DBGC_SMB */ "rpc", /* DBGC_RPC */ "rpc_hdr", /* DBGC_RPC_HDR */ + "passdb", /* DBGC_PASSDB */ + "auth", /* DBGC_AUTH */ "bdc", /* DBGC_BDC */ + NULL }; +static char **classname_table = NULL; + /* -------------------------------------------------------------------------- ** * Functions... */ + +/**************************************************************************** +utility lists registered debug class names's +****************************************************************************/ + +#define MAX_CLASS_NAME_SIZE 1024 + +char *debug_list_class_names_and_levels() +{ + int i, dim; + char **list; + char *buf = NULL; + char *b; + BOOL err = False; + + if (DEBUGLEVEL_CLASS == &debug_all_class_hack) + return NULL; + + list = calloc(debug_num_classes + 1, sizeof(char *)); + if (!list) + return NULL; + + /* prepare strings */ + for (i = 0, dim = 0; i < debug_num_classes; i++) { + int l = asprintf(&list[i], + "%s:%d ", + classname_table[i], + DEBUGLEVEL_CLASS_ISSET[i]?DEBUGLEVEL_CLASS[i]:DEBUGLEVEL); + if (l < 0 || l > MAX_CLASS_NAME_SIZE) { + err = True; + goto done; + } + dim += l; + } + + /* create single string list */ + b = buf = malloc(dim); + if (!buf) { + err = True; + goto done; + } + for (i = 0; i < debug_num_classes; i++) { + int l = strlen(list[i]); + strncpy(b, list[i], l); + b = b + l; + } + b[-1] = '\0'; + +done: + /* free strings list */ + for (i = 0; i < debug_num_classes; i++) + if (list[i]) free(list[i]); + free(list); + + if (err) { + if (buf) + free(buf); + return NULL; + } else { + return buf; + } +} + /**************************************************************************** utility access to debug class names's ****************************************************************************/ -char* debug_classname_from_index(int ndx) +const char *debug_classname_from_index(int ndx) { - return classname_table[ndx]; + if (ndx < 0 || ndx >= debug_num_classes) + return NULL; + else + return classname_table[ndx]; } /**************************************************************************** -utility to translate names to debug class index's +utility to translate names to debug class index's (internal version) ****************************************************************************/ -int debug_lookup_classname(char* classname) +static int debug_lookup_classname_int(const char* classname) { int i; if (!classname) return -1; - for (i=0; i= 0) + return ndx; + ndx = debug_num_classes; + + new_ptr = DEBUGLEVEL_CLASS; + if (DEBUGLEVEL_CLASS == &debug_all_class_hack) + { + /* Initial loading... */ + new_ptr = NULL; + } + new_ptr = Realloc(new_ptr, + sizeof(int) * (debug_num_classes + 1)); + if (!new_ptr) + return -1; + DEBUGLEVEL_CLASS = new_ptr; + DEBUGLEVEL_CLASS[ndx] = 0; + + /* debug_level is the pointer used for the DEBUGLEVEL-thingy */ + if (ndx==0) + { + /* Transfer the initial level from debug_all_class_hack */ + DEBUGLEVEL_CLASS[ndx] = DEBUGLEVEL; + } + debug_level = DEBUGLEVEL_CLASS; + + new_ptr = DEBUGLEVEL_CLASS_ISSET; + if (new_ptr == &debug_all_class_isset_hack) + { + new_ptr = NULL; + } + new_ptr = Realloc(new_ptr, + sizeof(BOOL) * (debug_num_classes + 1)); + if (!new_ptr) + return -1; + DEBUGLEVEL_CLASS_ISSET = new_ptr; + DEBUGLEVEL_CLASS_ISSET[ndx] = False; + + new_ptr = Realloc(classname_table, + sizeof(char *) * (debug_num_classes + 1)); + if (!new_ptr) + return -1; + classname_table = new_ptr; + + classname_table[ndx] = strdup(classname); + if (! classname_table[ndx]) + return -1; + + debug_num_classes++; + + return ndx; +} + +/**************************************************************************** +utility to translate names to debug class index's (public version) +****************************************************************************/ +int debug_lookup_classname(const char *classname) +{ + int ndx; + + if (!classname || !*classname) return -1; + + ndx = debug_lookup_classname_int(classname); + + if (ndx != -1) + return ndx; + + if (debug_warn_unknown_class) + { + DEBUG(0, ("debug_lookup_classname(%s): Unknown class\n", + classname)); + } + if (debug_auto_add_unknown_class) + { + return debug_add_class(classname); + } + return -1; +} + + +/**************************************************************************** +dump the current registered denug levels +****************************************************************************/ +static void debug_dump_status(int level) +{ + int q; + + DEBUG(level, ("INFO: Current debug levels:\n")); + for (q = 0; q < debug_num_classes; q++) + { + DEBUGADD(level, (" %s: %s/%d\n", + classname_table[q], + (DEBUGLEVEL_CLASS_ISSET[q] + ? "True" : "False"), + DEBUGLEVEL_CLASS[q])); + } +} + /**************************************************************************** parse the debug levels from smbcontrol. Example debug level parameter: printdrivers:7 @@ -179,9 +376,9 @@ BOOL debug_parse_params(char **params, int *debuglevel_class, int i, ndx; char *class_name; char *class_level; - - /* Set the new debug level array to the current DEBUGLEVEL array */ - memcpy(debuglevel_class, DEBUGLEVEL_CLASS, sizeof(DEBUGLEVEL_CLASS)); + + if (!params) + return False; /* Allow DBGC_ALL to be specified w/o requiring its class name e.g."10" * v.s. "all:10", this is the traditional way to set DEBUGLEVEL @@ -195,7 +392,7 @@ BOOL debug_parse_params(char **params, int *debuglevel_class, i = 0; /* DBGC_ALL not specified OR class name was included */ /* Fill in new debug class levels */ - for (; i < DBGC_LAST && params[i]; i++) { + for (; i < debug_num_classes && params[i]; i++) { if ((class_name=strtok(params[i],":")) && (class_level=strtok(NULL, "\0")) && ((ndx = debug_lookup_classname(class_name)) != -1)) { @@ -215,83 +412,80 @@ parse the debug levels from smb.conf. Example debug level string: 3 tdb:5 printdrivers:7 Note: the 1st param has no "name:" preceeding it. ****************************************************************************/ -BOOL debug_parse_levels(char *params_str) +BOOL debug_parse_levels(const char *params_str) { - int i; - char *params[DBGC_LAST]; - int debuglevel_class[DBGC_LAST]; - BOOL debuglevel_class_isset[DBGC_LAST]; + char **params; if (AllowDebugChange == False) - return True; - ZERO_ARRAY(params); - ZERO_ARRAY(debuglevel_class); - ZERO_ARRAY(debuglevel_class_isset); - - if ((params[0]=strtok(params_str," ,"))) { - for (i=1; idebuglevel_class, sizeof(dm->debuglevel_class)); - memcpy(DEBUGLEVEL_CLASS_ISSET, dm->debuglevel_class_isset, sizeof(dm->debuglevel_class_isset)); + /* Check, it's a proper string! */ + if (params_str[len-1] != '\0') + { + DEBUG(1, ("Invalid debug message from pid %u to pid %u\n", + (unsigned int)src, (unsigned int)getpid())); + return; + } - DEBUG(3,("INFO: Debug class %s level = %d (pid %u from pid %u)\n", - classname_table[DBGC_ALL], - DEBUGLEVEL_CLASS[DBGC_ALL], (unsigned int)sys_getpid(), (unsigned int)src)); + DEBUG(3, ("INFO: Remote set of debug to `%s' (pid %u from pid %u)\n", + params_str, (unsigned int)getpid(), (unsigned int)src)); - for (i=1; i Date: Sun, 19 May 2002 02:28:14 +0000 Subject: Keep the compiler happy (This used to be commit 84ea2a434b510ed49838a04a4b30bd2fc9ec5673) --- source3/lib/messages.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 6cb7507c0f..38d5e4af92 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -95,7 +95,7 @@ void debuglevel_message(int msg_type, pid_t src, void *buf, size_t len) char *debug_level_classes; DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %u\n",(unsigned int)src)); - if (debug_level_classes = debug_list_class_names_and_levels()) { + if ((debug_level_classes = debug_list_class_names_and_levels())) { /*{ debug_level_classes = "test:1000";*/ message_send_pid(src, MSG_DEBUGLEVEL, debug_level_classes, strlen(debug_level_classes) + 1, True); SAFE_FREE(debug_level_classes); -- cgit From c523cce510fb346c670c09243b5c0fb2edeaa46b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 19 May 2002 11:21:28 +0000 Subject: Fixed compiler warning. (This used to be commit 793d9306e29ddd23e3f52736b5cd558b5d058611) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 0a4cee89ae..dc1a55fb58 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -171,7 +171,7 @@ utility lists registered debug class names's #define MAX_CLASS_NAME_SIZE 1024 -char *debug_list_class_names_and_levels() +char *debug_list_class_names_and_levels(void) { int i, dim; char **list; -- cgit From 34278af77abe570f4046dba16a2cb8aec8ed00d4 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 20 May 2002 16:55:00 +0000 Subject: merge from SAMBA_2_2 (This used to be commit 2424578c298ea11f67415bcfe2928353cd95819b) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/time.c b/source3/lib/time.c index 5fc43612dd..9df4763b4c 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -413,7 +413,7 @@ void unix_to_nt_time(NTTIME *nt, time_t t) } /* this converts GMT to kludge-GMT */ - t -= LocTimeDiff(t) - get_serverzone(); + t -= TimeDiff(t) - get_serverzone(); d = (double)(t); d += TIME_FIXUP_CONSTANT; -- cgit From c2b867038a9e4ddad987bbc6472bd9b8d42fed9d Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 22 May 2002 11:25:43 +0000 Subject: Fix a silly memory (getpnam_alloc()) leak spotted by Elrond, and move the DATA_BLOB code into its own file. It would be nice to go over some of the other util.c functions, and check that we still use them all, and that we use them in more than one place. Andrew Bartlett (This used to be commit d0ea70fce55df9a5b5878f50fce7bc115ffb37c2) --- source3/lib/data_blob.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++ source3/lib/util.c | 103 ++++----------------------------------------- 2 files changed, 118 insertions(+), 94 deletions(-) create mode 100644 source3/lib/data_blob.c (limited to 'source3/lib') diff --git a/source3/lib/data_blob.c b/source3/lib/data_blob.c new file mode 100644 index 0000000000..6b9f5cbb04 --- /dev/null +++ b/source3/lib/data_blob.c @@ -0,0 +1,109 @@ +/* + Unix SMB/CIFS implementation. + Easy management of byte-length data + Copyright (C) Andrew Tridgell 2001 + Copyright (C) Andrew Bartlett 2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/******************************************************************* + free() a data blob +*******************************************************************/ +static void free_data_blob(DATA_BLOB *d) +{ + if ((d) && (d->free)) { + SAFE_FREE(d->data); + } +} + +/******************************************************************* + construct a data blob, must be freed with data_blob_free() + you can pass NULL for p and get a blank data blob +*******************************************************************/ +DATA_BLOB data_blob(const void *p, size_t length) +{ + DATA_BLOB ret; + + if (!length) { + ZERO_STRUCT(ret); + return ret; + } + + if (p) { + ret.data = smb_xmemdup(p, length); + } else { + ret.data = smb_xmalloc(length); + } + ret.length = length; + ret.free = free_data_blob; + return ret; +} + +/******************************************************************* + construct a data blob, using supplied TALLOC_CTX +*******************************************************************/ +DATA_BLOB data_blob_talloc(TALLOC_CTX *mem_ctx, const void *p, size_t length) +{ + DATA_BLOB ret; + + if (!p || !length) { + ZERO_STRUCT(ret); + return ret; + } + + ret.data = talloc_memdup(mem_ctx, p, length); + if (ret.data == NULL) + smb_panic("data_blob_talloc: talloc_memdup failed.\n"); + + ret.length = length; + ret.free = NULL; + return ret; +} + +/******************************************************************* +free a data blob +*******************************************************************/ +void data_blob_free(DATA_BLOB *d) +{ + if (d) { + if (d->free) { + (d->free)(d); + } + ZERO_STRUCTP(d); + } +} + +/******************************************************************* +clear a DATA_BLOB's contents +*******************************************************************/ +void data_blob_clear(DATA_BLOB *d) +{ + if (d->data) { + memset(d->data, 0, d->length); + } +} + +/******************************************************************* +free a data blob and clear its contents +*******************************************************************/ +void data_blob_clear_free(DATA_BLOB *d) +{ + data_blob_clear(d); + data_blob_free(d); +} + diff --git a/source3/lib/util.c b/source3/lib/util.c index d9be67599f..e143364db5 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1082,7 +1082,7 @@ char *gidtoname(gid_t gid) } /******************************************************************* - Convert a user name into a uid. If winbindd is present uses this. + Convert a user name into a uid. ********************************************************************/ uid_t nametouid(char *name) @@ -1091,21 +1091,22 @@ uid_t nametouid(char *name) char *p; uid_t u; - u = (uid_t)strtol(name, &p, 0); - if ((p != name) && (*p == '\0')) - return u; - pass = getpwnam_alloc(name); if (pass) { - return(pass->pw_uid); + u = pass->pw_uid; passwd_free(&pass); + return u; } + + u = (uid_t)strtol(name, &p, 0); + if ((p != name) && (*p == '\0')) + return u; + return (uid_t)-1; } /******************************************************************* - Convert a name to a gid_t if possible. Return -1 if not a group. If winbindd - is present does a shortcut lookup... + Convert a name to a gid_t if possible. Return -1 if not a group. ********************************************************************/ gid_t nametogid(const char *name) @@ -2122,92 +2123,6 @@ BOOL unix_wild_match(char *pattern, char *string) return unix_do_match(p2, s2) == 0; } -/******************************************************************* - free() a data blob -*******************************************************************/ -static void free_data_blob(DATA_BLOB *d) -{ - if ((d) && (d->free)) { - SAFE_FREE(d->data); - } -} - -/******************************************************************* - construct a data blob, must be freed with data_blob_free() - you can pass NULL for p and get a blank data blob -*******************************************************************/ -DATA_BLOB data_blob(const void *p, size_t length) -{ - DATA_BLOB ret; - - if (!length) { - ZERO_STRUCT(ret); - return ret; - } - - if (p) { - ret.data = smb_xmemdup(p, length); - } else { - ret.data = smb_xmalloc(length); - } - ret.length = length; - ret.free = free_data_blob; - return ret; -} - -/******************************************************************* - construct a data blob, using supplied TALLOC_CTX -*******************************************************************/ -DATA_BLOB data_blob_talloc(TALLOC_CTX *mem_ctx, const void *p, size_t length) -{ - DATA_BLOB ret; - - if (!p || !length) { - ZERO_STRUCT(ret); - return ret; - } - - ret.data = talloc_memdup(mem_ctx, p, length); - if (ret.data == NULL) - smb_panic("data_blob_talloc: talloc_memdup failed.\n"); - - ret.length = length; - ret.free = NULL; - return ret; -} - -/******************************************************************* -free a data blob -*******************************************************************/ -void data_blob_free(DATA_BLOB *d) -{ - if (d) { - if (d->free) { - (d->free)(d); - } - ZERO_STRUCTP(d); - } -} - -/******************************************************************* -clear a DATA_BLOB's contents -*******************************************************************/ -void data_blob_clear(DATA_BLOB *d) -{ - if (d->data) { - memset(d->data, 0, d->length); - } -} - -/******************************************************************* -free a data blob and clear its contents -*******************************************************************/ -void data_blob_clear_free(DATA_BLOB *d) -{ - data_blob_clear(d); - data_blob_free(d); -} - #ifdef __INSURE__ /******************************************************************* -- cgit From daec6cbbeee8401ef1aa0a3424ee05a3148d7ec8 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 22 May 2002 12:14:28 +0000 Subject: Cleanups! Make some code static, add some const to the PAM code, and make the plaintext password code actually function - particulary without the requirement to modify the 'struct passwd' (which it assumed was made up of fstrings) This kills some particularly ugly code in lib/util_pw.c Andrew Bartlett (This used to be commit 302dad4990ba5194f072e435465d9adaa089ae06) --- source3/lib/util.c | 2 +- source3/lib/util_pw.c | 44 -------------------------------------------- 2 files changed, 1 insertion(+), 45 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util.c b/source3/lib/util.c index e143364db5..a23ef91a31 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -118,7 +118,7 @@ BOOL in_group(gid_t group, gid_t current_gid, int ngroups, gid_t *groups) Like atoi but gets the value up to the separator character. ****************************************************************************/ -char *Atoic(char *p, int *n, char *c) +static char *Atoic(char *p, int *n, char *c) { if (!isdigit((int)*p)) { DEBUG(5, ("Atoic: malformed number\n")); diff --git a/source3/lib/util_pw.c b/source3/lib/util_pw.c index 259649a064..47711788c7 100644 --- a/source3/lib/util_pw.c +++ b/source3/lib/util_pw.c @@ -22,50 +22,6 @@ #include "includes.h" -struct passwd *make_modifyable_passwd(const struct passwd *from) -{ - struct passwd *ret = smb_xmalloc(sizeof(*ret)); -/* This is the assumed shape of the members by certain parts of the code... - fstring pw_name; - fstring pw_passwd; - fstring pw_gecos; - pstring pw_dir; - pstring pw_shell; -*/ - char *pw_name = smb_xmalloc(sizeof(fstring)); - char *pw_passwd = smb_xmalloc(sizeof(fstring)); - char *pw_gecos = smb_xmalloc(sizeof(fstring)); - char *pw_dir = smb_xmalloc(sizeof(pstring)); - char *pw_shell = smb_xmalloc(sizeof(pstring)); - - ZERO_STRUCTP(ret); - - /* - * Now point the struct's members as the - * newly allocated buffers: - */ - - ret->pw_name = pw_name; - fstrcpy(ret->pw_name, from->pw_name); - - ret->pw_passwd = pw_passwd; - fstrcpy(ret->pw_passwd, from->pw_passwd); - - ret->pw_uid = from->pw_uid; - ret->pw_gid = from->pw_gid; - - ret->pw_gecos = pw_gecos; - fstrcpy(ret->pw_gecos, from->pw_gecos); - - ret->pw_dir = pw_dir; - pstrcpy(ret->pw_dir, from->pw_dir); - - ret->pw_shell = pw_shell; - pstrcpy(ret->pw_shell, from->pw_shell); - - return ret; -} - static struct passwd *alloc_copy_passwd(const struct passwd *from) { struct passwd *ret = smb_xmalloc(sizeof(struct passwd)); -- cgit From b87eee983612c0d21b0c6f1346ba15ace797fe9e Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 22 May 2002 12:44:45 +0000 Subject: Add a bit more const, and kill of (finally!) sys_getpwnam and sys_getpwuid. These might be reimplmented as simple pass-through functions, but all users really should be doing 'getpwnam_alloc' or 'getpwuid_alloc' to ensure that there are not shared static buffers. I don't beleive we actually need a getpw*() cache inside samba - if we do then I think we should look at our code design first. (some of these changes are for platforms I don't have access to, but they look sane) Andrew Bartlett (This used to be commit 9d8431b04f41dceffe4c45cc969472ee59f7282f) --- source3/lib/sysacls.c | 16 +------- source3/lib/system.c | 110 +------------------------------------------------- source3/lib/util.c | 15 ++++--- 3 files changed, 12 insertions(+), 129 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/sysacls.c b/source3/lib/sysacls.c index 22245992f5..00d06e4a5a 100644 --- a/source3/lib/sysacls.c +++ b/source3/lib/sysacls.c @@ -644,13 +644,7 @@ char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) break; case SMB_ACL_USER: - if ((pw = sys_getpwuid(ap->a_id)) == NULL) { - slprintf(idbuf, sizeof(idbuf)-1, "%ld", - (long)ap->a_id); - id = idbuf; - } else { - id = pw->pw_name; - } + id = uidtoname(ap->a_id); case SMB_ACL_USER_OBJ: tag = "user"; break; @@ -1281,13 +1275,7 @@ char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) break; case SMB_ACL_USER: - if ((pw = sys_getpwuid(ap->a_id)) == NULL) { - slprintf(idbuf, sizeof(idbuf)-1, "%ld", - (long)ap->a_id); - id = idbuf; - } else { - id = pw->pw_name; - } + id = uidtoname(ap->a_id); case SMB_ACL_USER_OBJ: tag = "user"; break; diff --git a/source3/lib/system.c b/source3/lib/system.c index 9953df7058..3bf0994621 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -744,133 +744,25 @@ int sys_setgroups(int setlen, gid_t *gidset) #endif /* HAVE_SETGROUPS */ -/* - * We only wrap pw_name and pw_passwd for now as these - * are the only potentially modified fields. - */ - -/************************************************************************** - Helper function for getpwnam/getpwuid wrappers. -****************************************************************************/ - -struct saved_pw { - fstring pw_name; - fstring pw_passwd; - fstring pw_gecos; - pstring pw_dir; - pstring pw_shell; - struct passwd pass; -}; - -static struct saved_pw pw_mod; /* This is the structure returned - can be modified. */ -static struct saved_pw pw_cache; /* This is the structure saved - used to check cache. */ - -static int num_lookups; /* Counter so we don't always use cache. */ -#ifndef PW_RET_CACHE_MAX_LOOKUPS -#define PW_RET_CACHE_MAX_LOOKUPS 100 -#endif - -static void copy_pwent(struct saved_pw *dst, struct passwd *pass) -{ - memcpy((char *)&dst->pass, pass, sizeof(struct passwd)); - - fstrcpy(dst->pw_name, pass->pw_name); - dst->pass.pw_name = dst->pw_name; - - fstrcpy(dst->pw_passwd, pass->pw_passwd); - dst->pass.pw_passwd = dst->pw_passwd; - - fstrcpy(dst->pw_gecos, pass->pw_gecos); - dst->pass.pw_gecos = dst->pw_gecos; - - pstrcpy(dst->pw_dir, pass->pw_dir); - dst->pass.pw_dir = dst->pw_dir; - - pstrcpy(dst->pw_shell, pass->pw_shell); - dst->pass.pw_shell = dst->pw_shell; -} - -static struct passwd *setup_pwret(struct passwd *pass) -{ - if (pass == NULL) { - /* Clear the caches. */ - memset(&pw_cache, '\0', sizeof(struct saved_pw)); - memset(&pw_mod, '\0', sizeof(struct saved_pw)); - num_lookups = 0; - return NULL; - } - - copy_pwent( &pw_mod, pass); - - if (pass != &pw_cache.pass) { - - /* If it's a cache miss we must also refill the cache. */ - - copy_pwent( &pw_cache, pass); - num_lookups = 1; - - } else { - - /* Cache hit. */ - - num_lookups++; - num_lookups = (num_lookups % PW_RET_CACHE_MAX_LOOKUPS); - } - - return &pw_mod.pass; -} - /************************************************************************** Wrappers for setpwent(), getpwent() and endpwent() ****************************************************************************/ void sys_setpwent(void) { - setup_pwret(NULL); /* Clear cache. */ setpwent(); } struct passwd *sys_getpwent(void) { - return setup_pwret(getpwent()); + return getpwent(); } void sys_endpwent(void) { - setup_pwret(NULL); /* Clear cache. */ endpwent(); } -/************************************************************************** - Wrapper for getpwnam(). Always returns a static that can be modified. -****************************************************************************/ - -struct passwd *sys_getpwnam(const char *name) -{ - if (!name || !name[0]) - return NULL; - - /* check for a cache hit first */ - if (num_lookups && pw_cache.pass.pw_name && !strcmp(name, pw_cache.pass.pw_name)) { - return setup_pwret(&pw_cache.pass); - } - - return setup_pwret(getpwnam(name)); -} - -/************************************************************************** - Wrapper for getpwuid(). Always returns a static that can be modified. -****************************************************************************/ - -struct passwd *sys_getpwuid(uid_t uid) -{ - if (num_lookups && pw_cache.pass.pw_name && (uid == pw_cache.pass.pw_uid)) { - return setup_pwret(&pw_cache.pass); - } - - return setup_pwret(getpwuid(uid)); -} - #if 0 /* NOT CURRENTLY USED - JRA */ /************************************************************************** The following are the UNICODE versions of *all* system interface functions diff --git a/source3/lib/util.c b/source3/lib/util.c index a23ef91a31..2fe9ec331b 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1052,16 +1052,19 @@ BOOL process_exists(pid_t pid) Convert a uid into a user name. ********************************************************************/ -char *uidtoname(uid_t uid) +const char *uidtoname(uid_t uid) { static fstring name; struct passwd *pass; - pass = sys_getpwuid(uid); - if (pass) - return(pass->pw_name); - slprintf(name, sizeof(name) - 1, "%d",(int)uid); - return(name); + pass = getpwuid_alloc(uid); + if (pass) { + fstrcpy(name, pass->pw_name); + passwd_free(&pass); + } else { + slprintf(name, sizeof(name) - 1, "%ld",(long int)uid); + } + return name; } -- cgit From a3c98a841bcedf72ce513917707b5799c37abb95 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 22 May 2002 23:34:47 +0000 Subject: Merge of bugfixes from 2.2. Jeremy. (This used to be commit 5c8351228c55f2403214351f6fd16fe231aee917) --- source3/lib/select.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/select.c b/source3/lib/select.c index 550941ba77..efcf63becc 100644 --- a/source3/lib/select.c +++ b/source3/lib/select.c @@ -1,5 +1,6 @@ /* - Unix SMB/CIFS implementation. + Unix SMB/Netbios implementation. + Version 3.0 Samba select/poll implementation Copyright (C) Andrew Tridgell 1992-1998 @@ -133,10 +134,12 @@ int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorf { int ret; fd_set *readfds2, readfds_buf, *writefds2, writefds_buf, *errorfds2, errorfds_buf; + struct timeval tval2, *ptval; readfds2 = (readfds ? &readfds_buf : NULL); writefds2 = (writefds ? &writefds_buf : NULL); errorfds2 = (errorfds ? &errorfds_buf : NULL); + ptval = (tval ? &tval2 : NULL); do { if (readfds) @@ -145,7 +148,10 @@ int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorf writefds_buf = *writefds; if (errorfds) errorfds_buf = *errorfds; - ret = sys_select(maxfd, readfds2, writefds2, errorfds2, tval); + if (tval) + tval2 = *tval; + + ret = sys_select(maxfd, readfds2, writefds2, errorfds2, ptval); } while (ret == -1 && errno == EINTR); if (readfds) -- cgit From fb70dbdffa865b453330911841ce920ab19ad60c Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 23 May 2002 14:24:59 +0000 Subject: Nobody uses this, and its really just a layer of internal implementation. Make it static (till sombody needs its...) (This used to be commit 89dc15732062b46276d1d7a155954ee565070491) --- source3/lib/data_blob.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/data_blob.c b/source3/lib/data_blob.c index 6b9f5cbb04..d690cd05a0 100644 --- a/source3/lib/data_blob.c +++ b/source3/lib/data_blob.c @@ -91,7 +91,7 @@ void data_blob_free(DATA_BLOB *d) /******************************************************************* clear a DATA_BLOB's contents *******************************************************************/ -void data_blob_clear(DATA_BLOB *d) +static void data_blob_clear(DATA_BLOB *d) { if (d->data) { memset(d->data, 0, d->length); -- cgit From 20efe2fe6cbc4b5cf861a3296e29f5495637f79c Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 25 May 2002 07:37:44 +0000 Subject: Clean up a few unused functions, add a bit of static etc. Importantly: The removal of the silly 'delete user script' behaviour when secuity=domain. I have left the name the same - as it still does the (previously documented, but not in smb.conf(5)) sane behaviour of deleting users on request. When we decide what to do with the 'add user' functionality, we might rename it. Andrew Bartlett (This used to be commit cdcfe3671eb7570e15649b77f708e6579055e7bc) --- source3/lib/substitute.c | 19 +------------------ source3/lib/username.c | 2 +- 2 files changed, 2 insertions(+), 19 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c index 09921c145d..6c56cdd480 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -226,7 +226,7 @@ void standard_sub_basic(const char *smb_name, char *str) Do some standard substitutions in a string. ****************************************************************************/ -void standard_sub_advanced(int snum, const char *user, const char *connectpath, gid_t gid, const char *smb_name, char *str) +static void standard_sub_advanced(int snum, const char *user, const char *connectpath, gid_t gid, const char *smb_name, char *str) { char *p, *s, *home; @@ -391,20 +391,3 @@ void standard_sub_snum(int snum, char *str) standard_sub_advanced(snum, cached_user, "", -1, current_user_info.smb_name, str); } -/******************************************************************* - Substitute strings with useful parameters. -********************************************************************/ - -void standard_sub_vuser(char *str, user_struct *vuser) -{ - standard_sub_advanced(-1, vuser->user.unix_name, "", -1, current_user_info.smb_name, str); -} - -/******************************************************************* - Substitute strings with useful parameters. -********************************************************************/ - -void standard_sub_vsnum(char *str, user_struct *vuser, int snum) -{ - standard_sub_advanced(snum, vuser->user.unix_name, "", -1, current_user_info.smb_name, str); -} diff --git a/source3/lib/username.c b/source3/lib/username.c index f6ce765b41..be8acfb4d6 100644 --- a/source3/lib/username.c +++ b/source3/lib/username.c @@ -30,7 +30,7 @@ static struct passwd *uname_string_combinations2(char *s, int offset, struct pas *local* people, there's nothing for you here...). *****************************************************************/ -BOOL name_is_local(const char *name) +static BOOL name_is_local(const char *name) { return !(strchr_m(name, *lp_winbind_separator())); } -- cgit From 34728ec659751f2e14cfb8502300f3fdb96d405a Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 26 May 2002 11:28:38 +0000 Subject: move debug stuff from messages.c to debug.c (Elrond) (This used to be commit 44df5a13bc83dc331caa6788cf0805333ed79f8d) --- source3/lib/debug.c | 19 +++++++++++++++++++ source3/lib/messages.c | 21 +-------------------- 2 files changed, 20 insertions(+), 20 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index dc1a55fb58..1b2f9ac350 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -467,6 +467,24 @@ void debug_message_send(pid_t pid, const char *params_str) } +/**************************************************************************** + Return current debug level. +****************************************************************************/ + +static void debuglevel_message(int msg_type, pid_t src, void *buf, size_t len) +{ + char *debug_level_classes; + DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %u\n",(unsigned int)src)); + + if ((debug_level_classes = debug_list_class_names_and_levels())) { + /*{ debug_level_classes = "test:1000";*/ + message_send_pid(src, MSG_DEBUGLEVEL, debug_level_classes, strlen(debug_level_classes) + 1, True); + SAFE_FREE(debug_level_classes); + } else { + DEBUG(0, ("debuglevel_message: error retrieving class levels!\n")); + } +} + /**************************************************************************** Init debugging (one time stuff) ****************************************************************************/ @@ -481,6 +499,7 @@ void debug_init(void) initialised = True; message_register(MSG_DEBUG, debug_message); + message_register(MSG_REQ_DEBUGLEVEL, debuglevel_message); for(p = default_classname_table; *p; p++) { diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 38d5e4af92..c06644bc86 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -79,31 +79,13 @@ static void sig_usr1(void) A useful function for testing the message system. ****************************************************************************/ -void ping_message(int msg_type, pid_t src, void *buf, size_t len) +static void ping_message(int msg_type, pid_t src, void *buf, size_t len) { char *msg = buf ? buf : "none"; DEBUG(1,("INFO: Received PING message from PID %u [%s]\n",(unsigned int)src, msg)); message_send_pid(src, MSG_PONG, buf, len, True); } -/**************************************************************************** - Return current debug level. -****************************************************************************/ - -void debuglevel_message(int msg_type, pid_t src, void *buf, size_t len) -{ - char *debug_level_classes; - DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %u\n",(unsigned int)src)); - - if ((debug_level_classes = debug_list_class_names_and_levels())) { - /*{ debug_level_classes = "test:1000";*/ - message_send_pid(src, MSG_DEBUGLEVEL, debug_level_classes, strlen(debug_level_classes) + 1, True); - SAFE_FREE(debug_level_classes); - } else { - DEBUG(0, ("debuglevel_message: error retrieving class levels!\n")); - } -} - /**************************************************************************** Initialise the messaging functions. ****************************************************************************/ @@ -124,7 +106,6 @@ BOOL message_init(void) CatchSignal(SIGUSR1, SIGNAL_CAST sig_usr1); message_register(MSG_PING, ping_message); - message_register(MSG_REQ_DEBUGLEVEL, debuglevel_message); return True; } -- cgit From e066e5e614f4072384b704c628b35b91fb52ffe3 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 28 May 2002 14:35:11 +0000 Subject: Updates to better report some NTSTATUS errors into PAM, and update to PAM to correctly allow password changes on expired passwords. (No security implications, as its just a 'will I let you talk to the server' check). pam_winbind checks the password prior to changing it, so that users don't have to make up and type their new password when they havn't even got the old one right. This also helps with stacking etc. Andrew Bartlett (This used to be commit 2b78d493002a3ba13533429c6a14f5c0a92f43d1) --- source3/lib/pam_errors.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib') diff --git a/source3/lib/pam_errors.c b/source3/lib/pam_errors.c index f74e4bf176..e1d02151a6 100644 --- a/source3/lib/pam_errors.c +++ b/source3/lib/pam_errors.c @@ -67,6 +67,7 @@ const static struct { {NT_STATUS_WRONG_PASSWORD, PAM_AUTH_ERR}, {NT_STATUS_LOGON_FAILURE, PAM_AUTH_ERR}, {NT_STATUS_ACCOUNT_EXPIRED, PAM_ACCT_EXPIRED}, + {NT_STATUS_PASSWORD_EXPIRED, PAM_AUTHTOK_EXPIRED}, {NT_STATUS_PASSWORD_MUST_CHANGE, PAM_NEW_AUTHTOK_REQD}, {NT_STATUS_OK, PAM_SUCCESS} }; -- cgit From 0bb6053946a1572a3496958e543d5c9ddf74120b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 3 Jun 2002 03:07:24 +0000 Subject: put the ifdef for HAVE_VA_COPY in one place rather than in lots of functions (This used to be commit 1cf3228fdc20f0314d1f8e71ad710a5e548b3f72) --- source3/lib/dprintf.c | 7 ++----- source3/lib/snprintf.c | 18 +++++------------- source3/lib/talloc.c | 23 +++++++---------------- source3/lib/util.c | 8 +++----- source3/lib/xfile.c | 8 +++----- 5 files changed, 20 insertions(+), 44 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/dprintf.c b/source3/lib/dprintf.c index e3aa2c7669..f0f09e199d 100644 --- a/source3/lib/dprintf.c +++ b/source3/lib/dprintf.c @@ -42,11 +42,8 @@ int d_vfprintf(FILE *f, const char *format, va_list ap) msgstr = lang_msg(format); if (!msgstr) return -1; -#if defined(HAVE_VA_COPY) - __va_copy(ap2, ap); -#else - ap2 = ap; -#endif + VA_COPY(ap2, ap); + ret = vasprintf(&p, msgstr, ap2); lang_msg_free(msgstr); diff --git a/source3/lib/snprintf.c b/source3/lib/snprintf.c index 561e775c8f..aaad55f22a 100644 --- a/source3/lib/snprintf.c +++ b/source3/lib/snprintf.c @@ -163,11 +163,7 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args size_t currlen; va_list args; -#if defined(HAVE_VA_COPY) - __va_copy(args, args_in); -#else - args = args_in; -#endif + VA_COPY(args, args_in); state = DP_S_DEFAULT; currlen = flags = cflags = min = 0; @@ -802,20 +798,16 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) int ret; va_list ap2; -#if defined(HAVE_VA_COPY) - __va_copy(ap2, ap); -#else - ap2 = ap; -#endif + VA_COPY(ap2, ap); ret = vsnprintf(NULL, 0, format, ap2); if (ret <= 0) return ret; (*ptr) = (char *)malloc(ret+1); if (!*ptr) return -1; -#if defined(HAVE_VA_COPY) - __va_copy(ap2, ap); -#endif + + VA_COPY(ap2, ap); + ret = vsnprintf(*ptr, ret+1, format, ap2); return ret; diff --git a/source3/lib/talloc.c b/source3/lib/talloc.c index b66d674dd5..d81528588c 100644 --- a/source3/lib/talloc.c +++ b/source3/lib/talloc.c @@ -318,18 +318,13 @@ smb_ucs2_t *talloc_strdup_w(TALLOC_CTX *t, const smb_ucs2_t *p) char *ret; va_list ap2; -#ifdef HAVE_VA_COPY - __va_copy(ap2, ap); /* for systems were va_list is a struct */ -#else - ap2 = ap; -#endif + VA_COPY(ap2, ap); + len = vsnprintf(NULL, 0, fmt, ap2); ret = talloc(t, len+1); if (ret) { -#ifdef HAVE_VA_COPY - __va_copy(ap2, ap); -#endif + VA_COPY(ap2, ap); vsnprintf(ret, len+1, fmt, ap2); } @@ -366,20 +361,16 @@ smb_ucs2_t *talloc_strdup_w(TALLOC_CTX *t, const smb_ucs2_t *p) int len, s_len; va_list ap2; -#ifdef HAVE_VA_COPY - __va_copy(ap2, ap); -#else - ap2 = ap; -#endif + VA_COPY(ap2, ap); + s_len = strlen(s); len = vsnprintf(NULL, 0, fmt, ap2); s = talloc_realloc(t, s, s_len + len+1); if (!s) return NULL; -#ifdef HAVE_VA_COPY - __va_copy(ap2, ap); -#endif + VA_COPY(ap2, ap); + vsnprintf(s+s_len, len+1, fmt, ap2); return s; diff --git a/source3/lib/util.c b/source3/lib/util.c index 2fe9ec331b..fe1011668d 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1820,11 +1820,9 @@ int smb_xvasprintf(char **ptr, const char *format, va_list ap) { int n; va_list ap2; -#if defined(HAVE_VA_COPY) - __va_copy(ap2, ap); -#else - ap2 = ap; -#endif + + VA_COPY(ap2, ap); + n = vasprintf(ptr, format, ap2); if (n == -1 || ! *ptr) { smb_panic("smb_xvasprintf: out of memory"); diff --git a/source3/lib/xfile.c b/source3/lib/xfile.c index 7b97d329ae..59f9fd48ad 100644 --- a/source3/lib/xfile.c +++ b/source3/lib/xfile.c @@ -188,11 +188,9 @@ int x_vfprintf(XFILE *f, const char *format, va_list ap) char *p; int len, ret; va_list ap2; -#if defined(HAVE_VA_COPY) - __va_copy(ap2, ap); -#else - ap2 = ap; -#endif + + VA_COPY(ap2, ap); + len = vasprintf(&p, format, ap2); if (len <= 0) return len; ret = x_fwrite(p, 1, len, f); -- cgit From 9a2261a92a7880a93ab5c1ef8622b85c6e98d983 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Mon, 3 Jun 2002 13:37:52 +0000 Subject: Since includes.h isn't included here, VA_COPY has to be defined here. I don't see any include file that is guaranteed to be here, so I'm defining it locally. Fixes AIX and Solaris builds. (This used to be commit ca6bb47c22385a2c32be6ac3f8d9ffbfda45359b) --- source3/lib/snprintf.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/snprintf.c b/source3/lib/snprintf.c index aaad55f22a..cd1e63ce59 100644 --- a/source3/lib/snprintf.c +++ b/source3/lib/snprintf.c @@ -105,6 +105,14 @@ #define SAFE_FREE(x) do { if ((x) != NULL) {free((x)); (x)=NULL;} } while(0) #endif +#ifndef VA_COPY +#ifdef HAVE_VA_COPY +#define VA_COPY(dest, src) __va_copy(dest, src) +#else +#define VA_COPY(dest, src) (dest) = (src) +#endif +#endif + static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args_in); static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, -- cgit From 78418649404712acb73d78a94eb1050d6f529359 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 5 Jun 2002 07:11:22 +0000 Subject: Spelling fix. (This used to be commit 39ec94bffe536de5950611d6e4b28621b6aff844) --- source3/lib/messages.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/messages.c b/source3/lib/messages.c index c06644bc86..3929f526dc 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -329,7 +329,7 @@ void message_dispatch(void) } } if (!n_handled) { - DEBUG(5,("message_dispatch: warning: no handlers registed for " + DEBUG(5,("message_dispatch: warning: no handlers registered for " "msg_type %d in pid%d\n", msg_type, sys_getpid())); } -- cgit From aed3d69bc5f13d011d91b6abcc164b592bebbbaa Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 5 Jun 2002 18:30:07 +0000 Subject: merge from 2.2 (This used to be commit ce2ddb70411b30a0d6b2d6dded13c3b94895c1dd) --- source3/lib/interfaces.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/interfaces.c b/source3/lib/interfaces.c index 7b8ef0d0c1..96f4b4cd94 100644 --- a/source3/lib/interfaces.c +++ b/source3/lib/interfaces.c @@ -41,10 +41,6 @@ #include #include -#ifndef SIOCGIFCONF -#include -#endif - #ifdef AUTOCONF_TEST struct iface_struct { char name[16]; @@ -56,6 +52,16 @@ struct iface_struct { #include "interfaces.h" #endif +#ifdef HAVE_SYS_TIME_H +#include +#endif + +#ifndef SIOCGIFCONF +#ifdef HAVE_SYS_SOCKIO_H +#include +#endif +#endif + #ifdef HAVE_STDLIB_H #include #endif -- cgit From 39d0a1b832793b18c3790482a2240171e31017c7 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 7 Jun 2002 12:45:51 +0000 Subject: Move the code from lib/util_sid.c that deals with the global_sam_sid into a file that is linked with the passdb. This is to avoid linking insanity when this global becomes a self-initing function. (This used to be commit 743afd96cb54b4966e3afad11ea987f968b98651) --- source3/lib/util_sid.c | 242 +------------------------------------------------ 1 file changed, 1 insertion(+), 241 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c index 100324a047..70c85f4096 100644 --- a/source3/lib/util_sid.c +++ b/source3/lib/util_sid.c @@ -25,7 +25,7 @@ /* NOTE! the global_sam_sid is the SID of our local SAM. This is only equal to the domain SID when we are a DC, otherwise its our workstation SID */ -DOM_SID global_sam_sid; +extern DOM_SID global_sam_sid; extern pstring global_myname; extern fstring global_myworkgroup; @@ -48,56 +48,6 @@ DOM_SID global_sid_Anonymous; /* Anonymous login */ const DOM_SID *global_sid_everyone = &global_sid_World; -typedef struct _known_sid_users { - uint32 rid; - enum SID_NAME_USE sid_name_use; - char *known_user_name; -} known_sid_users; - -/* static known_sid_users no_users[] = {{0, 0, NULL}}; */ - -static known_sid_users everyone_users[] = { - { 0, SID_NAME_WKN_GRP, "Everyone" }, - {0, (enum SID_NAME_USE)0, NULL}}; - -static known_sid_users creator_owner_users[] = { - { 0, SID_NAME_ALIAS, "Creator Owner" }, - {0, (enum SID_NAME_USE)0, NULL}}; - -static known_sid_users nt_authority_users[] = { - { 1, SID_NAME_ALIAS, "Dialup" }, - { 2, SID_NAME_ALIAS, "Network"}, - { 3, SID_NAME_ALIAS, "Batch"}, - { 4, SID_NAME_ALIAS, "Interactive"}, - { 6, SID_NAME_ALIAS, "Service"}, - { 7, SID_NAME_ALIAS, "AnonymousLogon"}, - { 8, SID_NAME_ALIAS, "Proxy"}, - { 9, SID_NAME_ALIAS, "ServerLogon"}, - { 11, SID_NAME_ALIAS, "Authenticated Users"}, - { 18, SID_NAME_ALIAS, "SYSTEM"}, - { 0, (enum SID_NAME_USE)0, NULL}}; - -static known_sid_users builtin_groups[] = { - { BUILTIN_ALIAS_RID_ADMINS, SID_NAME_ALIAS, "Administrators" }, - { BUILTIN_ALIAS_RID_USERS, SID_NAME_ALIAS, "Users" }, - { BUILTIN_ALIAS_RID_GUESTS, SID_NAME_ALIAS, "Guests" }, - { BUILTIN_ALIAS_RID_ACCOUNT_OPS, SID_NAME_ALIAS, "Account Operators" }, - { BUILTIN_ALIAS_RID_SYSTEM_OPS, SID_NAME_ALIAS, "Server Operators" }, - { BUILTIN_ALIAS_RID_PRINT_OPS, SID_NAME_ALIAS, "Print Operators" }, - { BUILTIN_ALIAS_RID_BACKUP_OPS, SID_NAME_ALIAS, "Backup Operators" }, - { 0, (enum SID_NAME_USE)0, NULL}}; - -#define MAX_SID_NAMES 7 - -static struct sid_name_map_info -{ - DOM_SID *sid; - char *name; - known_sid_users *known_users; -} sid_name_map[MAX_SID_NAMES]; - -static BOOL sid_name_map_initialized = False; - /* * An NT compatible anonymous token. */ @@ -109,65 +59,6 @@ NT_USER_TOKEN anonymous_token = { anon_sid_array }; -/************************************************************************** - quick init function - *************************************************************************/ -static void init_sid_name_map (void) -{ - int i = 0; - - if (sid_name_map_initialized) return; - - - if ((lp_security() == SEC_USER) && lp_domain_logons()) { - sid_name_map[i].sid = &global_sam_sid; - sid_name_map[i].name = global_myworkgroup; - sid_name_map[i].known_users = NULL; - i++; - sid_name_map[i].sid = &global_sam_sid; - sid_name_map[i].name = global_myname; - sid_name_map[i].known_users = NULL; - i++; - } - else { - sid_name_map[i].sid = &global_sam_sid; - sid_name_map[i].name = global_myname; - sid_name_map[i].known_users = NULL; - i++; - } - - sid_name_map[i].sid = &global_sid_Builtin; - sid_name_map[i].name = "BUILTIN"; - sid_name_map[i].known_users = &builtin_groups[0]; - i++; - - sid_name_map[i].sid = &global_sid_World_Domain; - sid_name_map[i].name = ""; - sid_name_map[i].known_users = &everyone_users[0]; - i++; - - sid_name_map[i].sid = &global_sid_Creator_Owner_Domain; - sid_name_map[i].name = ""; - sid_name_map[i].known_users = &creator_owner_users[0]; - i++; - - sid_name_map[i].sid = &global_sid_NT_Authority; - sid_name_map[i].name = "NT Authority"; - sid_name_map[i].known_users = &nt_authority_users[0]; - i++; - - - /* end of array */ - sid_name_map[i].sid = NULL; - sid_name_map[i].name = NULL; - sid_name_map[i].known_users = NULL; - - sid_name_map_initialized = True; - - return; - -} - /**************************************************************************** Creates some useful well known sids ****************************************************************************/ @@ -193,115 +84,6 @@ void generate_wellknown_sids(void) sid_copy( &anonymous_token.user_sids[2], &global_sid_Anonymous); } -/************************************************************************** - Turns a domain SID into a name, returned in the nt_domain argument. -***************************************************************************/ - -BOOL map_domain_sid_to_name(DOM_SID *sid, fstring nt_domain) -{ - fstring sid_str; - int i = 0; - - sid_to_string(sid_str, sid); - - if (!sid_name_map_initialized) - init_sid_name_map(); - - DEBUG(5,("map_domain_sid_to_name: %s\n", sid_str)); - - if (nt_domain == NULL) - return False; - - while (sid_name_map[i].sid != NULL) { - sid_to_string(sid_str, sid_name_map[i].sid); - DEBUG(5,("map_domain_sid_to_name: compare: %s\n", sid_str)); - if (sid_equal(sid_name_map[i].sid, sid)) { - fstrcpy(nt_domain, sid_name_map[i].name); - DEBUG(5,("map_domain_sid_to_name: found '%s'\n", nt_domain)); - return True; - } - i++; - } - - DEBUG(5,("map_domain_sid_to_name: mapping for %s not found\n", sid_str)); - - return False; -} - -/************************************************************************** - Looks up a known username from one of the known domains. -***************************************************************************/ - -BOOL lookup_known_rid(DOM_SID *sid, uint32 rid, char *name, enum SID_NAME_USE *psid_name_use) -{ - int i = 0; - struct sid_name_map_info *psnm; - - if (!sid_name_map_initialized) - init_sid_name_map(); - - for(i = 0; sid_name_map[i].sid != NULL; i++) { - psnm = &sid_name_map[i]; - if(sid_equal(psnm->sid, sid)) { - int j; - for(j = 0; psnm->known_users && psnm->known_users[j].known_user_name != NULL; j++) { - if(rid == psnm->known_users[j].rid) { - DEBUG(5,("lookup_builtin_rid: rid = %u, domain = '%s', user = '%s'\n", - (unsigned int)rid, psnm->name, psnm->known_users[j].known_user_name )); - fstrcpy( name, psnm->known_users[j].known_user_name); - *psid_name_use = psnm->known_users[j].sid_name_use; - return True; - } - } - } - } - - return False; -} - -/************************************************************************** - Turns a domain name into a SID. - *** side-effect: if the domain name is NULL, it is set to our domain *** -***************************************************************************/ - -BOOL map_domain_name_to_sid(DOM_SID *sid, char *nt_domain) -{ - int i = 0; - - if (nt_domain == NULL) { - DEBUG(5,("map_domain_name_to_sid: mapping NULL domain to our SID.\n")); - sid_copy(sid, &global_sam_sid); - return True; - } - - if (nt_domain[0] == 0) { - fstrcpy(nt_domain, global_myname); - DEBUG(5,("map_domain_name_to_sid: overriding blank name to %s\n", nt_domain)); - sid_copy(sid, &global_sam_sid); - return True; - } - - DEBUG(5,("map_domain_name_to_sid: %s\n", nt_domain)); - - if (!sid_name_map_initialized) - init_sid_name_map(); - - while (sid_name_map[i].name != NULL) { - DEBUG(5,("map_domain_name_to_sid: compare: %s\n", sid_name_map[i].name)); - if (strequal(sid_name_map[i].name, nt_domain)) { - fstring sid_str; - sid_copy(sid, sid_name_map[i].sid); - sid_to_string(sid_str, sid_name_map[i].sid); - DEBUG(5,("map_domain_name_to_sid: found %s\n", sid_str)); - return True; - } - i++; - } - - DEBUG(0,("map_domain_name_to_sid: mapping to %s not found.\n", nt_domain)); - return False; -} - /************************************************************************** Splits a name of format \DOMAIN\name or name into its two components. Sets the DOMAIN name to global_myname if it has not been specified. @@ -626,14 +408,6 @@ BOOL sid_equal(const DOM_SID *sid1, const DOM_SID *sid2) } -/***************************************************************** - Check if the SID is our domain SID (S-1-5-21-x-y-z). -*****************************************************************/ -BOOL sid_check_is_domain(const DOM_SID *sid) -{ - return sid_equal(sid, &global_sam_sid); -} - /***************************************************************** Check if the SID is the builtin SID (S-1-5-32). @@ -644,20 +418,6 @@ BOOL sid_check_is_builtin(const DOM_SID *sid) } -/***************************************************************** - Check if the SID is our domain SID (S-1-5-21-x-y-z). -*****************************************************************/ -BOOL sid_check_is_in_our_domain(const DOM_SID *sid) -{ - DOM_SID dom_sid; - uint32 rid; - - sid_copy(&dom_sid, sid); - sid_split_rid(&dom_sid, &rid); - - return sid_equal(&dom_sid, &global_sam_sid); -} - /***************************************************************** Check if the SID is our domain SID (S-1-5-21-x-y-z). *****************************************************************/ -- cgit From b0ffabdcca53507a99ce8f00fccf2d4cac78fd6d Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 7 Jun 2002 14:33:33 +0000 Subject: Globally replace 'global_sam_sid' with get_global_sam_sid(), a self initialising function. This patch thanks to the work of "Stefan (metze) Metzmacher" This is partly to enable the transition to SIDs in the the passdb. Andrew Bartlett (This used to be commit 96afea638e15d4cbadc57023a511094a770c6adc) --- source3/lib/util_sid.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c index 70c85f4096..21ef9e081b 100644 --- a/source3/lib/util_sid.c +++ b/source3/lib/util_sid.c @@ -22,10 +22,6 @@ #include "includes.h" -/* NOTE! the global_sam_sid is the SID of our local SAM. This is only - equal to the domain SID when we are a DC, otherwise its our - workstation SID */ -extern DOM_SID global_sam_sid; extern pstring global_myname; extern fstring global_myworkgroup; -- cgit From 959ff024daf61b86ec1d487582dd663ab95d24d1 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 10 Jun 2002 12:27:05 +0000 Subject: Remove "sids.h" as it really wasn't being used anywhere, and was exporting the (now static) global_sam_sid. The only place it was being used was to return global_sid_NULL to some uid->sid functions - and I'm not convinced this is correct in any case. Andrew Bartlett (This used to be commit e2a76a7fc94dd59c09bba3cda91446fad9f8c0e0) --- source3/lib/util_seaccess.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_seaccess.c b/source3/lib/util_seaccess.c index 8ed266aced..9fdf03adfc 100644 --- a/source3/lib/util_seaccess.c +++ b/source3/lib/util_seaccess.c @@ -20,8 +20,6 @@ */ #include "includes.h" -#include "nterr.h" -#include "sids.h" /********************************************************************************** Check if this ACE has a SID in common with the token. -- cgit From 2d64b9880744746d4317d9da45c575b3a8fbbed1 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 11 Jun 2002 22:54:06 +0000 Subject: few fixes from Elrond(elrond@samba-tng.org) and Billy O'Connor(billy@oconnoronline.net) (This used to be commit 88718883e031a3249152861300432dfc895ac587) --- source3/lib/debug.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 1b2f9ac350..834c1b38f7 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -150,10 +150,11 @@ static const char *default_classname_table[] = { "lanman", /* DBGC_LANMAN */ "smb", /* DBGC_SMB */ "rpc", /* DBGC_RPC */ - "rpc_hdr", /* DBGC_RPC_HDR */ + "rpc_srv", /* DBGC_RPC_SRV */ + "rpc_cli", /* DBGC_RPC_CLI */ "passdb", /* DBGC_PASSDB */ "auth", /* DBGC_AUTH */ - "bdc", /* DBGC_BDC */ + "winbind", /* DBGC_WINBIND */ NULL }; @@ -171,7 +172,7 @@ utility lists registered debug class names's #define MAX_CLASS_NAME_SIZE 1024 -char *debug_list_class_names_and_levels(void) +static char *debug_list_class_names_and_levels(void) { int i, dim; char **list; @@ -416,8 +417,11 @@ BOOL debug_parse_levels(const char *params_str) { char **params; + /* Just in case */ + debug_init(); + if (AllowDebugChange == False) - return True; + return True; params = lp_list_make(params_str); -- cgit From bad738e6536e983064eee7647229354bc9028183 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 13 Jun 2002 14:06:08 +0000 Subject: Latest patch from metze to move most of samba across to using SIDs instead of RIDs. The new funciton sid_peek_check_rid() takes an 'expected domain sid' argument. The idea here is to prevent mistakes where the SID is implict, but isn't the same one that we have in the struct. Andrew Bartlett (This used to be commit 04f9a8ff4c7982f6597c0f6748f85d66d4784901) --- source3/lib/util_sid.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c index 21ef9e081b..3ad9e909d8 100644 --- a/source3/lib/util_sid.c +++ b/source3/lib/util_sid.c @@ -1,10 +1,11 @@ /* Unix SMB/CIFS implementation. Samba utility functions - Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) Luke Kenneth Caseson Leighton 1998-1999 - Copyright (C) Jeremy Allison 1999 - + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Luke Kenneth Caseson Leighton 1998-1999 + Copyright (C) Jeremy Allison 1999 + Copyright (C) Stefan (metze) Metzmacher 2002 + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -253,6 +254,9 @@ BOOL sid_split_rid(DOM_SID *sid, uint32 *rid) BOOL sid_peek_rid(DOM_SID *sid, uint32 *rid) { + if (!sid || !rid) + return False; + if (sid->num_auths > 0) { *rid = sid->sub_auths[sid->num_auths - 1]; return True; @@ -260,6 +264,25 @@ BOOL sid_peek_rid(DOM_SID *sid, uint32 *rid) return False; } +/***************************************************************** + Return the last rid from the end of a sid + and check the sid against the exp_dom_sid +*****************************************************************/ + +BOOL sid_peek_check_rid(DOM_SID *exp_dom_sid,DOM_SID *sid, uint32 *rid) +{ + if (!exp_dom_sid || !sid || !rid) + return False; + + + if (sid_compare_domain(exp_dom_sid, sid)!=0){ + *rid=(-1); + return False; + } + + return sid_peek_rid(sid,rid); +} + /***************************************************************** Copies a sid *****************************************************************/ -- cgit From d179b191794c06626375692ea81c1931db57f550 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 13 Jun 2002 22:49:13 +0000 Subject: Ensure we save any older SIGALRM signal handler. Jeremy. (This used to be commit aa0a6f5532a2689409426eef9a4b66a28fb97635) --- source3/lib/messages.c | 5 +++-- source3/lib/signal.c | 8 +++++--- source3/lib/util_file.c | 5 +++-- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 3929f526dc..5d861b485c 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -475,6 +475,7 @@ BOOL message_named_mutex(char *name, unsigned int timeout) { TDB_DATA key; int ret; + void (*oldsig_handler)(int); if (!message_init()) return False; @@ -484,7 +485,7 @@ BOOL message_named_mutex(char *name, unsigned int timeout) if (timeout) { gotalarm = 0; - CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig); + oldsig_handler = CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig); alarm(timeout); } @@ -492,7 +493,7 @@ BOOL message_named_mutex(char *name, unsigned int timeout) if (timeout) { alarm(0); - CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN); + CatchSignal(SIGALRM, SIGNAL_CAST oldsig_handler); if (gotalarm) return False; } diff --git a/source3/lib/signal.c b/source3/lib/signal.c index 99f908235c..dceb3b53bc 100644 --- a/source3/lib/signal.c +++ b/source3/lib/signal.c @@ -96,10 +96,11 @@ void BlockSignals(BOOL block,int signum) 2) The signal should be blocked during handler execution. ********************************************************************/ -void CatchSignal(int signum,void (*handler)(int )) +void (*CatchSignal(int signum,void (*handler)(int )))(int) { #ifdef HAVE_SIGACTION struct sigaction act; + struct sigaction oldact; ZERO_STRUCT(act); @@ -113,10 +114,11 @@ void CatchSignal(int signum,void (*handler)(int )) #endif sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask,signum); - sigaction(signum,&act,NULL); + sigaction(signum,&act,&oldact); + return oldact.sa_handler; #else /* !HAVE_SIGACTION */ /* FIXME: need to handle sigvec and systems with broken signal() */ - signal(signum, handler); + return signal(signum, handler); #endif } diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c index fd3aeb99d9..883827a4f5 100644 --- a/source3/lib/util_file.c +++ b/source3/lib/util_file.c @@ -40,9 +40,10 @@ BOOL do_file_lock(int fd, int waitsecs, int type) { SMB_STRUCT_FLOCK lock; int ret; + void (*oldsig_handler)(int); gotalarm = 0; - CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig); + oldsig_handler = CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig); lock.l_type = type; lock.l_whence = SEEK_SET; @@ -54,7 +55,7 @@ BOOL do_file_lock(int fd, int waitsecs, int type) /* Note we must *NOT* use sys_fcntl here ! JRA */ ret = fcntl(fd, SMB_F_SETLKW, &lock); alarm(0); - CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN); + CatchSignal(SIGALRM, SIGNAL_CAST oldsig_handler); if (gotalarm) { DEBUG(0, ("do_file_lock: failed to %s file.\n", -- cgit From baef1358d2b5a98a592f0247911a31d79148dcba Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 14 Jun 2002 00:47:08 +0000 Subject: Add const, kill of useless casts and therefore eliminate warnings. Andrew Bartlett (This used to be commit 29490f214750acd44cee6c4ab1354722d82d853a) --- source3/lib/util_sid.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c index 3ad9e909d8..ca9ebb14d2 100644 --- a/source3/lib/util_sid.c +++ b/source3/lib/util_sid.c @@ -252,7 +252,7 @@ BOOL sid_split_rid(DOM_SID *sid, uint32 *rid) Return the last rid from the end of a sid *****************************************************************/ -BOOL sid_peek_rid(DOM_SID *sid, uint32 *rid) +BOOL sid_peek_rid(const DOM_SID *sid, uint32 *rid) { if (!sid || !rid) return False; @@ -269,7 +269,7 @@ BOOL sid_peek_rid(DOM_SID *sid, uint32 *rid) and check the sid against the exp_dom_sid *****************************************************************/ -BOOL sid_peek_check_rid(DOM_SID *exp_dom_sid,DOM_SID *sid, uint32 *rid) +BOOL sid_peek_check_rid(const DOM_SID *exp_dom_sid, const DOM_SID *sid, uint32 *rid) { if (!exp_dom_sid || !sid || !rid) return False; @@ -280,7 +280,7 @@ BOOL sid_peek_check_rid(DOM_SID *exp_dom_sid,DOM_SID *sid, uint32 *rid) return False; } - return sid_peek_rid(sid,rid); + return sid_peek_rid(sid, rid); } /***************************************************************** -- cgit From 0886638844b6ea5253cae217682c680cc7b6cec8 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 14 Jun 2002 02:06:58 +0000 Subject: Patch (from ctrlsoft ) to poptify testparm, and the modifications required to suppress the const warnings. Andrew Bartlett (This used to be commit ec4f1e9e2f6c162a475b424d63b9802387ad905e) --- source3/lib/access.c | 18 +++++++++++++++++- source3/lib/debug.c | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/access.c b/source3/lib/access.c index 62d47b82cf..4e524735e4 100644 --- a/source3/lib/access.c +++ b/source3/lib/access.c @@ -188,7 +188,7 @@ static int list_match(char **list,char *item, int (*match_fn)(char *, char *)) /* return true if access should be allowed */ -BOOL allow_access(char **deny_list,char **allow_list, +static BOOL allow_access_internal(char **deny_list,char **allow_list, char *cname,char *caddr) { char *client[2]; @@ -240,6 +240,22 @@ BOOL allow_access(char **deny_list,char **allow_list, return (True); } +/* return true if access should be allowed */ +BOOL allow_access(char **deny_list,char **allow_list, + const char *cname, const char *caddr) +{ + BOOL ret; + + char *nc_cname = smb_xstrdup(cname); + char *nc_caddr = smb_xstrdup(caddr); + + ret = allow_access_internal(deny_list, allow_list, nc_cname, nc_caddr); + + SAFE_FREE(nc_cname); + SAFE_FREE(nc_caddr); + return ret; +} + /* return true if the char* contains ip addrs only. Used to avoid gethostbyaddr() calls */ static BOOL only_ipaddrs_in_list(char** list) diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 834c1b38f7..255b0568f1 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -516,7 +516,7 @@ void debug_init(void) * get ready for syslog stuff * ************************************************************************** ** */ -void setup_logging(char *pname, BOOL interactive) +void setup_logging(const char *pname, BOOL interactive) { debug_init(); @@ -531,7 +531,7 @@ void setup_logging(char *pname, BOOL interactive) } #ifdef WITH_SYSLOG else { - char *p = strrchr_m( pname,'/' ); + const char *p = strrchr_m( pname,'/' ); if (p) pname = p + 1; #ifdef LOG_DAEMON -- cgit From 0d7ac4bc2ca8eea117a0f594880b5aac02f1056d Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 14 Jun 2002 02:58:03 +0000 Subject: Patch from ctrlsoft to make the pluggable passdb subsystem use an lp_list rather than a string when configuring mulitple backends. Also adjust some of the users of get_global_sam_sid() to cope with the fact that it just might not exist (uninitialised, can't access secrets.tdb). More places need conversion. Add some const and remove silly casts. Andrew Bartlett (This used to be commit c264bf2ec93037d2a9927c00295fa60c88b7219d) --- source3/lib/util_sid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c index ca9ebb14d2..b27040b658 100644 --- a/source3/lib/util_sid.c +++ b/source3/lib/util_sid.c @@ -119,7 +119,7 @@ void split_domain_name(const char *fullname, char *domain, char *name) Convert a SID to an ascii string. *****************************************************************/ -char *sid_to_string(fstring sidstr_out, DOM_SID *sid) +char *sid_to_string(fstring sidstr_out, const DOM_SID *sid) { char subauth[16]; int i; @@ -149,7 +149,7 @@ char *sid_to_string(fstring sidstr_out, DOM_SID *sid) /* useful function for debug lines */ -const char *sid_string_static(DOM_SID *sid) +const char *sid_string_static(const DOM_SID *sid) { static fstring sid_str; sid_to_string(sid_str, sid); -- cgit From e69fba09846f9bfd1564c4c684bb5d4fc059b02d Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 14 Jun 2002 16:02:59 +0000 Subject: moved lp_list_* functions away from param/loadparm.c, put int lib/util_str.c and renamed to str_list_* as it is a better name. Elrond should be satisfied now :) (This used to be commit 4ae260adb9505384fcccfb4c9929cb60a45f2e84) --- source3/lib/debug.c | 6 +- source3/lib/username.c | 6 +- source3/lib/util_str.c | 182 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+), 6 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 255b0568f1..487b4957fe 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -423,16 +423,16 @@ BOOL debug_parse_levels(const char *params_str) if (AllowDebugChange == False) return True; - params = lp_list_make(params_str); + params = str_list_make(params_str); if (debug_parse_params(params, DEBUGLEVEL_CLASS, DEBUGLEVEL_CLASS_ISSET)) { debug_dump_status(5); - lp_list_free(¶ms); + str_list_free(¶ms); return True; } else { - lp_list_free(¶ms); + str_list_free(¶ms); return False; } } diff --git a/source3/lib/username.c b/source3/lib/username.c index be8acfb4d6..c83b4eea28 100644 --- a/source3/lib/username.c +++ b/source3/lib/username.c @@ -197,7 +197,7 @@ BOOL map_username(char *user) } } - dosuserlist = lp_list_make(dosname); + dosuserlist = str_list_make(dosname); if (!dosuserlist) { DEBUG(0,("Unable to build user list\n")); return False; @@ -210,13 +210,13 @@ BOOL map_username(char *user) sscanf(unixname,"%s",user); fstrcpy(last_to,user); if(return_if_mapped) { - lp_list_free (&dosuserlist); + str_list_free (&dosuserlist); x_fclose(f); return True; } } - lp_list_free (&dosuserlist); + str_list_free (&dosuserlist); } x_fclose(f); diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index ff3559ce14..eac3ebe929 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -1013,3 +1013,185 @@ some platforms don't have strnlen return i; } #endif + + + +/*********************************************************** + List of Strings manipulation functions +***********************************************************/ + +#define S_LIST_ABS 16 /* List Allocation Block Size */ + +char **str_list_make(const char *string) +{ + char **list, **rlist; + char *str, *s; + int num, lsize; + pstring tok; + + if (!string || !*string) return NULL; + s = strdup(string); + if (!s) { + DEBUG(0,("str_list_make: Unable to allocate memory")); + return NULL; + } + + num = lsize = 0; + list = NULL; + + str = s; + while (next_token(&str, tok, LIST_SEP, sizeof(tok))) + { + if (num == lsize) { + lsize += S_LIST_ABS; + rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1))); + if (!rlist) { + DEBUG(0,("str_list_make: Unable to allocate memory")); + str_list_free(&list); + SAFE_FREE(s); + return NULL; + } + else list = rlist; + memset (&list[num], 0, ((sizeof(char**)) * (S_LIST_ABS +1))); + } + + list[num] = strdup(tok); + if (!list[num]) { + DEBUG(0,("str_list_make: Unable to allocate memory")); + str_list_free(&list); + SAFE_FREE(s); + return NULL; + } + + num++; + } + + SAFE_FREE(s); + return list; +} + +BOOL str_list_copy(char ***dest, char **src) +{ + char **list, **rlist; + int num, lsize; + + *dest = NULL; + if (!src) return False; + + num = lsize = 0; + list = NULL; + + while (src[num]) + { + if (num == lsize) { + lsize += S_LIST_ABS; + rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1))); + if (!rlist) { + DEBUG(0,("str_list_copy: Unable to allocate memory")); + str_list_free(&list); + return False; + } + else list = rlist; + memset (&list[num], 0, ((sizeof(char **)) * (S_LIST_ABS +1))); + } + + list[num] = strdup(src[num]); + if (!list[num]) { + DEBUG(0,("str_list_copy: Unable to allocate memory")); + str_list_free(&list); + return False; + } + + num++; + } + + *dest = list; + return True; +} + +/* return true if all the elemnts of the list matches exactly */ +BOOL str_list_compare(char **list1, char **list2) +{ + int num; + + if (!list1 || !list2) return (list1 == list2); + + for (num = 0; list1[num]; num++) { + if (!list2[num]) return False; + if (!strcsequal(list1[num], list2[num])) return False; + } + if (list2[num]) return False; /* if list2 has more elements than list1 fail */ + + return True; +} + +void str_list_free(char ***list) +{ + char **tlist; + + if (!list || !*list) return; + tlist = *list; + for(; *tlist; tlist++) SAFE_FREE(*tlist); + SAFE_FREE(*list); +} + +BOOL str_list_substitute(char **list, const char *pattern, const char *insert) +{ + char *p, *s, *t; + ssize_t ls, lp, li, ld, i, d; + + if (!list) return False; + if (!pattern) return False; + if (!insert) return False; + + lp = (ssize_t)strlen(pattern); + li = (ssize_t)strlen(insert); + ld = li -lp; + + while (*list) + { + s = *list; + ls = (ssize_t)strlen(s); + + while ((p = strstr(s, pattern))) + { + t = *list; + d = p -t; + if (ld) + { + t = (char *) malloc(ls +ld +1); + if (!t) { + DEBUG(0,("str_list_substitute: Unable to allocate memory")); + return False; + } + memcpy(t, *list, d); + memcpy(t +d +li, p +lp, ls -d -lp +1); + SAFE_FREE(*list); + *list = t; + ls += ld; + s = t +d +li; + } + + for (i = 0; i < li; i++) { + switch (insert[i]) { + case '`': + case '"': + case '\'': + case ';': + case '$': + case '%': + case '\r': + case '\n': + t[d +i] = '_'; + break; + default: + t[d +i] = insert[i]; + } + } + } + + list++; + } + + return True; +} -- cgit From 9026074f6068f68725241c3e14f7f38bfa698b16 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 15 Jun 2002 00:47:52 +0000 Subject: Add back sys_getpwnam() and freinds to the system.c interface, but don't use the silly cache any more. Also add group functions and fix a few callers. Andrew Bartlett (This used to be commit 41d4b94077c118ecde2bf8792b9bb7ab71c6403e) --- source3/lib/system.c | 24 ++++++++++++++++++++++++ source3/lib/util.c | 2 +- source3/lib/util_pw.c | 4 ++-- source3/lib/util_sock.c | 4 ++-- 4 files changed, 29 insertions(+), 5 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/system.c b/source3/lib/system.c index 3bf0994621..8b2ba800f5 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -763,6 +763,30 @@ void sys_endpwent(void) endpwent(); } +/************************************************************************** + Wrappers for getpwnam(), getpwuid(), getgrnam(), getgrgid() +****************************************************************************/ + +struct passwd *sys_getpwnam(const char *name) +{ + return getpwnam(name); +} + +struct passwd *sys_getpwuid(uid_t uid) +{ + return getpwuid(uid); +} + +struct group *sys_getgrnam(const char *name) +{ + return getgrnam(name); +} + +struct group *sys_getgrgid(gid_t gid) +{ + return getgrgid(gid); +} + #if 0 /* NOT CURRENTLY USED - JRA */ /************************************************************************** The following are the UNICODE versions of *all* system interface functions diff --git a/source3/lib/util.c b/source3/lib/util.c index fe1011668d..92c8850cef 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1122,7 +1122,7 @@ gid_t nametogid(const char *name) if ((p != name) && (*p == '\0')) return g; - grp = getgrnam(name); + grp = sys_getgrnam(name); if (grp) return(grp->gr_gid); return (gid_t)-1; diff --git a/source3/lib/util_pw.c b/source3/lib/util_pw.c index 47711788c7..9d075a05e8 100644 --- a/source3/lib/util_pw.c +++ b/source3/lib/util_pw.c @@ -56,7 +56,7 @@ struct passwd *getpwnam_alloc(const char *name) { struct passwd *temp; - temp = getpwnam(name); + temp = sys_getpwnam(name); if (!temp) { #if 0 @@ -74,7 +74,7 @@ struct passwd *getpwuid_alloc(uid_t uid) { struct passwd *temp; - temp = getpwuid(uid); + temp = sys_getpwuid(uid); if (!temp) { #if 0 diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index f5d56eb0d4..e9e2ab8291 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -1042,8 +1042,8 @@ int open_pipe_sock(char *path) permissions, instead. ******************************************************************/ int create_pipe_sock(const char *socket_dir, - const char *socket_name, - mode_t dir_perms) + const char *socket_name, + mode_t dir_perms) { struct sockaddr_un sunaddr; struct stat st; -- cgit From b075458ee7f7632dfa57c1ad8e35d5818f1bcc12 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 15 Jun 2002 11:15:31 +0000 Subject: This patch does 2 things: It extends the 'server mutex' to conver security=server, becouse the connection race condition exists here too, and while people *should* use security=domain, some sites don't.... (This probably should be done in 2.2 as well). Also, start to actually extract and use the information that the remote server returns in the info3 struct. The server mutex code is now in a new file. Andrew Bartlett (This used to be commit 9b0dabdf4ec3bb45879caae76e03b57ccdad8b4b) --- source3/lib/server_mutex.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 source3/lib/server_mutex.c (limited to 'source3/lib') diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c new file mode 100644 index 0000000000..416d77564d --- /dev/null +++ b/source3/lib/server_mutex.c @@ -0,0 +1,57 @@ +/* + Unix SMB/CIFS implementation. + Authenticate against a remote domain + Copyright (C) Andrew Tridgell 1992-2002 + Copyright (C) Andrew Bartlett 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/* For reasons known only to MS, many of their NT/Win2k versions + need serialised access only. Two connections at the same time + may (in certain situations) cause connections to be reset, + or access to be denied. + + This locking allows smbd's mutlithread architecture to look + like the single-connection that NT makes. */ + +static char *mutex_server_name; + +BOOL grab_server_mutex(const char *name) +{ + mutex_server_name = strdup(name); + if (!mutex_server_name) { + DEBUG(0,("grab_server_mutex: malloc failed for %s\n", name)); + return False; + } + if (!message_named_mutex(mutex_server_name, 20)) { + DEBUG(10,("grab_server_mutex: failed for %s\n", name)); + SAFE_FREE(mutex_server_name); + return False; + } + + return True; +} + +void release_server_mutex(void) +{ + if (mutex_server_name) { + message_named_mutex_release(mutex_server_name); + SAFE_FREE(mutex_server_name); + } +} + -- cgit From ac08646c374cd70e47301bce3e031b35cb220347 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 15 Jun 2002 12:38:13 +0000 Subject: Rework much of the service.c code: The aim of this execise is to give the 'security>=user' code a straight paper path. Security=share will sill call authorise_login(), but otherwise we avoid that mess. This allow *much* more accurate error code reporting, beocuse we don't start pretending that we can use the (nonexistant) password etc. Also in this patch is code to create the 'homes' share at session setup time (as we have done in the past - been broken recently) and to record this on the user's vuser struct for later reference. The changes here should also allow for much better use of %H (some more changes to come here). The service.c changes move a lot of code around, but are not as drastric as they look... (Also included is a fix to srv_srvsvc_nt.c where 'total_entries' not '*total_entries' was compared). This code is needs testing, but passes my basic tests. I expect we have lost some functionality, but the stuff I had expected to loose was already broken before I started. In particular, we don't 'fall back' to guest if the user cannot access a share (for security=user). If you want this kind of stuff then you really want security=share anyway. Andrew Bartlett (This used to be commit 4c0cbcaed95231f8cf11edb43f6adbec9a0d0b5c) --- source3/lib/substitute.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c index 6c56cdd480..eea720c014 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -226,7 +226,9 @@ void standard_sub_basic(const char *smb_name, char *str) Do some standard substitutions in a string. ****************************************************************************/ -static void standard_sub_advanced(int snum, const char *user, const char *connectpath, gid_t gid, const char *smb_name, char *str) +static void standard_sub_advanced(int snum, const char *user, + const char *connectpath, gid_t gid, + const char *smb_name, char *str) { char *p, *s, *home; @@ -345,7 +347,8 @@ void standard_sub_conn(connection_struct *conn, char *str) share. No user specific snum created yet so servicename should be the username. ****************************************************************************/ -void standard_sub_home(int snum, const char *user, char *str) +void standard_sub_home(int snum, const char *share, + const char *user, const char *homedir, pstring str) { char *p, *s; @@ -353,8 +356,12 @@ void standard_sub_home(int snum, const char *user, char *str) int l = sizeof(pstring) - (int)(p-str); switch (*(p+1)) { + case 'H': + string_sub(p,"%H", homedir, l); + break; + case 'S': - string_sub(p,"%S", user, l); + string_sub(p,"%S", share, l); break; case 'p': string_sub(p,"%p", automount_path(user), l); -- cgit From 3c3814da252cdf45e33446c553e0ea009ea9c9bd Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 15 Jun 2002 12:40:37 +0000 Subject: Unsused function since last commit (This used to be commit 957c865cee7f799145f9f1d30dfd0d0a25d826cf) --- source3/lib/username.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/username.c b/source3/lib/username.c index c83b4eea28..4813c8fd19 100644 --- a/source3/lib/username.c +++ b/source3/lib/username.c @@ -82,40 +82,6 @@ char *get_user_home_dir(const char *user) return(pass->pw_dir); } -/**************************************************************************** - Get a users service home directory. -****************************************************************************/ - -char *get_user_service_home_dir(const char *user) -{ - static struct passwd *pass; - int snum; - - /* Ensure the user exists. */ - - pass = Get_Pwnam(user); - - if (!pass) - return(NULL); - - /* If a path is specified in [homes] then use it instead of the - user's home directory from struct passwd. */ - - if ((snum = lp_servicenumber(HOMES_NAME)) != -1) { - static pstring home_dir; - - pstrcpy(home_dir, lp_pathname(snum)); - standard_sub_home(snum, user, home_dir); - - if (home_dir[0]) - return home_dir; - } - - /* Return home directory from struct passwd. */ - - return(pass->pw_dir); -} - /******************************************************************* Map a username from a dos name to a unix name by looking in the username map. Note that this modifies the name in place. -- cgit From 249368f937406e1c714fff3d44775c414b32ff21 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 15 Jun 2002 13:05:37 +0000 Subject: Simplify this code further. Just substitute %H, and let the normal code paths handle the rest later. Andrew Bartlett (This used to be commit 09754ec797c4232d2016c7eff2e74044f28ebb7c) --- source3/lib/substitute.c | 36 ------------------------------------ 1 file changed, 36 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c index eea720c014..439263dd23 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -342,42 +342,6 @@ void standard_sub_conn(connection_struct *conn, char *str) standard_sub_advanced(SNUM(conn), conn->user, conn->connectpath, conn->gid, current_user_info.smb_name, str); } -/**************************************************************************** - Like standard_sub but for a homes share where snum still points to the [homes] - share. No user specific snum created yet so servicename should be the username. -****************************************************************************/ - -void standard_sub_home(int snum, const char *share, - const char *user, const char *homedir, pstring str) -{ - char *p, *s; - - for (s=str; (p=strchr_m(s, '%'));s=p) { - int l = sizeof(pstring) - (int)(p-str); - - switch (*(p+1)) { - case 'H': - string_sub(p,"%H", homedir, l); - break; - - case 'S': - string_sub(p,"%S", share, l); - break; - case 'p': - string_sub(p,"%p", automount_path(user), l); - break; - case '\0': - p++; - break; /* don't run off the end of the string */ - - default: p+=2; - break; - } - } - - standard_sub_advanced(snum, user, "", -1, current_user_info.smb_name, str); -} - /**************************************************************************** Like standard_sub but by snum. ****************************************************************************/ -- cgit From aaf43bbc8fc113527cb4bb6da5fa9be06b2a1548 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 17 Jun 2002 07:39:43 +0000 Subject: Fixed typo in debug. (This used to be commit 41f036ab37274ce7cdd782ead764dd1a36ecba1d) --- source3/lib/messages.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 5d861b485c..480b6daf02 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -330,7 +330,7 @@ void message_dispatch(void) } if (!n_handled) { DEBUG(5,("message_dispatch: warning: no handlers registered for " - "msg_type %d in pid%d\n", + "msg_type %d in pid %d\n", msg_type, sys_getpid())); } SAFE_FREE(buf); -- cgit From 7b60e2304052c5603740ea11ce1345a32e1b9175 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 17 Jun 2002 15:33:13 +0000 Subject: compile warngin fixes merged from 2.2 (This used to be commit 29874f4b8fecdc7cbd84d656dafce54cca49e0b1) --- source3/lib/messages.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 480b6daf02..b5e89a6aaa 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -453,7 +453,7 @@ BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type, return True; } -static VOLATILE sig_atomic_t gotalarm; +static SIG_ATOMIC_T gotalarm; /*************************************************************** Signal function to tell us we timed out. -- cgit From a60e37096d6576dcf749237df99e7c2c96359834 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 18 Jun 2002 09:20:13 +0000 Subject: more debug classess activated (This used to be commit 897e64d2e0c1d04ab93441ccaffe369bf43be46e) --- source3/lib/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 487b4957fe..f41c3b6497 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -149,7 +149,7 @@ static const char *default_classname_table[] = { "printdrivers", /* DBGC_PRINTDRIVERS */ "lanman", /* DBGC_LANMAN */ "smb", /* DBGC_SMB */ - "rpc", /* DBGC_RPC */ + "rpc_parse", /* DBGC_RPC_PARSE */ "rpc_srv", /* DBGC_RPC_SRV */ "rpc_cli", /* DBGC_RPC_CLI */ "passdb", /* DBGC_PASSDB */ -- cgit From df1893d53238927fbcf73a687f921d21abca5ded Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 20 Jun 2002 00:45:34 +0000 Subject: Fixed compiler warning. (This used to be commit c29cef7f3408714d4e6e18906760d74016c6748f) --- source3/lib/messages.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/messages.c b/source3/lib/messages.c index b5e89a6aaa..e6d2de4a58 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -475,7 +475,7 @@ BOOL message_named_mutex(char *name, unsigned int timeout) { TDB_DATA key; int ret; - void (*oldsig_handler)(int); + void (*oldsig_handler)(int) = NULL; if (!message_init()) return False; -- cgit From fdaf087daa672d8d87895d33923f34114210ae47 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 21 Jun 2002 01:12:12 +0000 Subject: Changed level of "bind succeded on port %d" debug to 10. (This used to be commit de00428ef12b597e5c29896bf961cfd7a1e122dd) --- source3/lib/util_sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index e9e2ab8291..f72c4638dc 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -755,7 +755,7 @@ int open_socket_in( int type, int port, int dlevel, uint32 socket_addr, BOOL reb return( -1 ); } - DEBUG( 3, ( "bind succeeded on port %d\n", port ) ); + DEBUG( 10, ( "bind succeeded on port %d\n", port ) ); return( res ); } -- cgit From de532c83339bcf70c4f6222203fe7b1991bf6926 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 25 Jun 2002 00:59:14 +0000 Subject: fixed a bug in handling select in the main daemon - this stops the daemon spinning if a signal is received at an inconvenient moment (This used to be commit d8d7dd523d897ea25a572c8f21903e94e8485404) --- source3/lib/select.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/select.c b/source3/lib/select.c index efcf63becc..f88ad52de6 100644 --- a/source3/lib/select.c +++ b/source3/lib/select.c @@ -102,6 +102,12 @@ int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, s } if (FD_ISSET(select_pipe[0], readfds2)) { + char c; + saved_errno = errno; + if (read(select_pipe[0], &c, 1) == 1) { + pipe_read++; + } + errno = saved_errno; FD_CLR(select_pipe[0], readfds2); ret--; if (ret == 0) { @@ -110,18 +116,6 @@ int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, s } } - saved_errno = errno; - - while (pipe_written != pipe_read) { - char c; - /* Due to the linux kernel bug in 2.0.x, we - * always increment here even if the read failed... */ - read(select_pipe[0], &c, 1); - pipe_read++; - } - - errno = saved_errno; - return ret; } -- cgit From 07f35f68e00b48ad6ec4d18c628d0bb57bad85ef Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 26 Jun 2002 06:44:37 +0000 Subject: - completely rewrote the wins_srv.c code. It is now much simpler, and gives us a good grounding to properly support multiple wins servers for different interfaces (which will be coming soon ...) - fixed our wins registration failover code to actually do failover! We were not trying to register with a secondary wins server at all when the primary was down. We now fallback correctly. - fixed the multi-homed name registration packets so that they work even in a non-connected network (ie. when one of our interfaces is not routable from the wins server. Yes, this really happens in the real world). (This used to be commit a049360d5b0d95a935b06aad43efc17d34de46dc) --- source3/lib/wins_srv.c | 393 +++++++++++-------------------------------------- 1 file changed, 90 insertions(+), 303 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/wins_srv.c b/source3/lib/wins_srv.c index 0181ee0956..cad0d06e49 100644 --- a/source3/lib/wins_srv.c +++ b/source3/lib/wins_srv.c @@ -1,7 +1,7 @@ /* Unix SMB/CIFS implementation. Samba utility functions - Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Andrew Tridgell 1992-2002 Copyright (C) Christopher R. Hertel 2000 This program is free software; you can redistribute it and/or modify @@ -21,319 +21,106 @@ #include "includes.h" -/* -------------------------------------------------------------------------- ** - * Discussion... - * - * This module implements WINS failover. - * - * Microsoft's WINS servers provide a feature called WINS replication, - * which synchronises the WINS name databases between two or more servers. - * This means that the two servers can be used interchangably (more or - * less). WINS replication is particularly useful if you are trying to - * synchronise the WINS namespace between servers in remote locations, or - * if your WINS servers tend to crash a lot. - * - * WINS failover allows the client to 'switch' to a different WINS server - * if the current WINS server mysteriously disappears. On Windows - * systems, this is typically represented as 'primary' and 'secondary' - * WINS servers. - * - * Failover only works if the WINS servers are synced. If they are not, - * then - * a) if the primary WINS server never fails the client will never 'see' - * the secondary (or tertiary or...) WINS server name space. - * b) if the primary *does* fail, the client will be entering an - * unfamiliar namespace. The client itself will not be registered in - * that namespace and any names which match names in the previous - * space will likely resolve to different host IP addresses. - * - * One key thing to remember regarding WINS failover is that Samba does - * not (yet) implement WINS replication. For those interested, sniff port - * 42 (TCP? UDP? ...dunno off hand) and see what two MS WINS servers do. - * - * At this stage, only failover is implemented. The next thing is to add - * support for multi-WINS server registration and query (multi-membership). - * - * Multi-membership is a little wierd. The idea is that the client can - * register itself with multiple non-replicated WINS servers, and query - * all of those servers (in a prescribed sequence) to resolve a name. - * - * The implications of multi-membership are not quite clear. Worth - * trying, I suppose. Changes will be needed in the name query and - * registration code to accomodate this feature. Also, there will need to - * be some sort of syntax extension for the 'wins server' parameter in - * smb.conf. I'm thinking that a colon could be used as a separator. - * - * Of course, for each WINS namespace there might be multiple, synced WINS - * servers. The change to this module would likely be the addition of a - * linked list of linked lists. - * - * crh@samba.org - */ -/* -------------------------------------------------------------------------- ** - * Defines... - * - * NECROMANCYCLE - The dead server retry period, in seconds. When a WINS - * server is declared dead, wait this many seconds before - * attempting to communicate with it. - */ +/* how long a server is marked dead for */ +#define DEATH_TIME 600 -#define NECROMANCYCLE 600 /* 600 seconds == 10 minutes. */ +/* a list of wins server that are marked dead. */ +static struct wins_dead { + struct in_addr ip; + time_t revival; /* when it will be revived */ + struct wins_dead *next, *prev; +} *dead_servers; -/* -------------------------------------------------------------------------- ** - * Typedefs... - */ -typedef struct - { - ubi_slNode node; /* Linked list node structure. */ - time_t mourning; /* If > current time then server is dead, Jim. */ - char *server; /* DNS name or IP of NBNS server to query. */ - struct in_addr ip_addr; /* Cache translated IP. */ - } list_entry; - -/* -------------------------------------------------------------------------- ** - * Private, static variables. - */ - -static ubi_slNewList( wins_srv_list ); - -/* -------------------------------------------------------------------------- ** - * Functions... - */ - - -BOOL wins_srv_load_list( char *src ) - /* ------------------------------------------------------------------------ ** - * Create or recreate the linked list of failover WINS servers. - * - * Input: src - String of DNS names and/or IP addresses delimited by the - * characters listed in LIST_SEP (see include/local.h). - * - * Output: True if at least one name or IP could be parsed out of the - * list, else False. - * - * Notes: There is no syntax checking done on the names or IPs. We do - * check to see if the field is an IP, in which case we copy it - * to the ip_addr field of the entry. Don't bother to to a host - * name lookup on all names now. They're done as needed in - * wins_srv_ip(). - * ------------------------------------------------------------------------ ** - */ - { - list_entry *entry; - char *p = src; - pstring wins_id_bufr; - unsigned long count; - - /* Empty the list. */ - while( NULL != (entry =(list_entry *)ubi_slRemHead( wins_srv_list )) ) - { - SAFE_FREE( entry->server ); - SAFE_FREE( entry ); - } - (void)ubi_slInitList( wins_srv_list ); /* shouldn't be needed */ - - /* Parse out the DNS names or IP addresses of the WINS servers. */ - DEBUG( 4, ("wins_srv_load_list(): Building WINS server list:\n") ); - while( next_token( &p, wins_id_bufr, LIST_SEP, sizeof( wins_id_bufr ) ) ) - { - entry = (list_entry *)malloc( sizeof( list_entry ) ); - if( NULL == entry ) - { - DEBUG( 0, ("wins_srv_load_list(): malloc(list_entry) failed.\n") ); - } - else - { - entry->mourning = 0; - /* Create a copy of the server name and store it in the list. */ - if( NULL == (entry->server = strdup( wins_id_bufr )) ) - { - SAFE_FREE( entry ); - DEBUG( 0, - ("wins_srv_load_list(): strdup(\"%s\") failed.\n", wins_id_bufr) ); - } - else - { - /* Add server to list. - * If the server name was actually an IP address we will store that - * too. It it was a DNS name, we will wait until we need to use - * the WINS server before doing the DNS lookup. Since this may be - * a list, and since we will reload the list whenever smb.conf is - * reloaded, there's no point in trying to look up names until we - * need them. ...of course, once we do the lookup we will cache - * the result. See wins_srv_ip(). - */ - if( is_ipaddress( wins_id_bufr ) ) - entry->ip_addr = *interpret_addr2( wins_id_bufr ); - else - entry->ip_addr = *interpret_addr2( "0.0.0.0" ); - (void)ubi_slAddTail( wins_srv_list, entry ); - DEBUGADD( 4, ("%s,\n", wins_id_bufr) ); - } - } - } - - count = ubi_slCount( wins_srv_list ); - DEBUGADD( 4, - ( "%d WINS server%s listed.\n", (int)count, (1==count)?"":"s" ) ); - - return( (count > 0) ? True : False ); - } /* wins_srv_load_list */ - - -struct in_addr wins_srv_ip( void ) - /* ------------------------------------------------------------------------ ** - * Return the IP address of an NBNS (WINS) server thought to be active. - * - * Input: none. - * - * Output: An IP address in struct in_addr form. - * - * Notes: This function will return the IP address of the first available - * NBNS (WINS) server. The order of the list is determined in - * smb.conf. If all of the WINS servers have been marked 'dead' - * then the zero IP (0.0.0.0) is returned. The zero IP is not a - * valid Unicast address on any system. - * - * ------------------------------------------------------------------------ ** - */ - { - time_t now = time(NULL); - list_entry *entry = (list_entry *)ubi_slFirst( wins_srv_list ); - - while( NULL != entry ) - { - if( now >= entry->mourning ) /* Found a live one. */ - { - /* If we don't have the IP, look it up. */ - if( is_zero_ip( entry->ip_addr ) ) - entry->ip_addr = *interpret_addr2( entry->server ); - - /* If we still don't have the IP then kill it, else return it. */ - if( is_zero_ip( entry->ip_addr ) ) - entry->mourning = now + NECROMANCYCLE; - else - return( entry->ip_addr ); - } - entry = (list_entry *)ubi_slNext( entry ); - } - - /* If there are no live entries, return the zero IP. */ - return( *interpret_addr2( "0.0.0.0" ) ); - } /* wins_srv_ip */ - - -char *wins_srv_name( void ) - /* ------------------------------------------------------------------------ ** - * Return the name of first live WINS server in the list. - * - * Input: none. - * - * Output: A pointer to a string containing either the DNS name or IP - * address of the WINS server as given in the WINS SERVER - * parameter in smb.conf, or NULL if no (live) WINS servers are - * in the list. - * - * Notes: This function will return the name of the first available - * NBNS (WINS) server. The order of the list is determined in - * smb.conf. If all of the WINS servers have been marked 'dead' - * then NULL is returned. - * - * - This function does not verify that the name can be mapped to - * an IP address, or that the WINS server is running. - * - * ------------------------------------------------------------------------ ** - */ - { - time_t now = time(NULL); - list_entry *entry = (list_entry *)ubi_slFirst( wins_srv_list ); - - while( NULL != entry ) - { - if( now >= entry->mourning ) - return( entry->server ); /* Found a live one. */ - entry = (list_entry *)ubi_slNext( entry ); - } - - /* If there are no live entries, return NULL. */ - return( NULL ); - } /* wins_srv_name */ - - -void wins_srv_died( struct in_addr boothill_ip ) - /* ------------------------------------------------------------------------ ** - * Called to indicate that a specific WINS server has died. - * - * Input: boothill_ip - IP address of an NBNS (WINS) server that has - * failed. - * - * Notes: This function marks the record 'dead' for NECROMANCYCLE - * seconds. - * - * ------------------------------------------------------------------------ ** - */ - { - list_entry *entry; +/* + see if an ip is on the dead list +*/ +static int wins_is_dead(struct in_addr ip) +{ + struct wins_dead *d; + for (d=dead_servers; d; d=d->next) { + if (ip_equal(ip, d->ip)) { + /* it might be due for revival */ + if (d->revival <= time(NULL)) { + DEBUG(4,("Reviving wins server %s\n", inet_ntoa(ip))); + DLIST_REMOVE(dead_servers, d); + free(d); + return 0; + } + return 1; + } + } + return 0; +} - if( is_zero_ip( boothill_ip ) ) - { - DEBUG( 4, ("wins_srv_died(): Invalid request to mark zero IP down.\n") ); - return; - } +/* + mark a wins server as temporarily dead +*/ +void wins_srv_died(struct in_addr ip) +{ + struct wins_dead *d; - entry = (list_entry *)ubi_slFirst( wins_srv_list ); - while( NULL != entry ) - { - /* Match based on IP. */ - if( ip_equal( boothill_ip, entry->ip_addr ) ) - { - entry->mourning = time(NULL) + NECROMANCYCLE; - entry->ip_addr.s_addr = 0; /* Force a re-lookup at re-birth. */ - DEBUG( 2, ( "wins_srv_died(): WINS server %s appears to be down.\n", - entry->server ) ); - return; - } - entry = (list_entry *)ubi_slNext( entry ); - } + if (is_zero_ip(ip) || wins_is_dead(ip)) { + return; + } - if( DEBUGLVL( 1 ) ) - { - dbgtext( "wins_srv_died(): Could not mark WINS server %s down.\n", - inet_ntoa( boothill_ip ) ); - dbgtext( "Address not found in server list.\n" ); - } - } /* wins_srv_died */ + d = (struct wins_dead *)malloc(sizeof(*d)); + if (!d) return; + d->ip = ip; + d->revival = time(NULL) + DEATH_TIME; -unsigned long wins_srv_count( void ) - /* ------------------------------------------------------------------------ ** - * Return the total number of entries in the list, dead or alive. - * ------------------------------------------------------------------------ ** - */ - { - unsigned long count = ubi_slCount( wins_srv_list ); + DEBUG(4,("Marking wins server %s dead for %u seconds\n", inet_ntoa(ip), DEATH_TIME)); - if( DEBUGLVL( 8 ) ) - { - list_entry *entry = (list_entry *)ubi_slFirst( wins_srv_list ); - time_t now = time(NULL); + DLIST_ADD(dead_servers, d); +} - dbgtext( "wins_srv_count: WINS status: %ld servers.\n", count ); - while( NULL != entry ) - { - dbgtext( " %s <%s>: ", entry->server, inet_ntoa( entry->ip_addr ) ); - if( now >= entry->mourning ) - dbgtext( "alive\n" ); - else - dbgtext( "dead for %d more seconds\n", (int)(entry->mourning - now) ); +/* + return the total number of wins servers, dead or not +*/ +unsigned long wins_srv_count(void) +{ + char **list; + int count = 0; - entry = (list_entry *)ubi_slNext( entry ); - } - } + list = lp_wins_server_list(); + while (list && *list) { + count++; + list++; + } - return( count ); - } /* wins_srv_count */ + DEBUG(6,("Found %u wins servers in list\n", count)); + return count; +} -/* ========================================================================== */ +/* + return the IP of the currently active wins server, or the zero IP otherwise +*/ +struct in_addr wins_srv_ip(void) +{ + char **list; + struct in_addr ip; + + list = lp_wins_server_list(); + if (!list || !*list) { + zero_ip(&ip); + return ip; + } + + /* find the first live one */ + while (list && *list) { + ip = *interpret_addr2(*list); + if (!wins_is_dead(ip)) { + DEBUG(6,("Current wins server is %s\n", inet_ntoa(ip))); + return ip; + } + list++; + } + + /* damn, they are all dead. Keep trying the primary until they revive */ + list = lp_wins_server_list(); + ip = *interpret_addr2(list[0]); + + return ip; +} -- cgit From 0dd78fbd7d2ce45f9158f6732c87859406751324 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 26 Jun 2002 07:23:00 +0000 Subject: fixed we_are_multihomed() to cope with dynamic interfaces (ie. don't cache the result!) (This used to be commit fc8aa198b16da24b68e45982eb45dd7d5fd089e1) --- source3/lib/interface.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/interface.c b/source3/lib/interface.c index d43001342e..8a59c3389e 100644 --- a/source3/lib/interface.c +++ b/source3/lib/interface.c @@ -280,12 +280,7 @@ int iface_count(void) **************************************************************************/ BOOL we_are_multihomed(void) { - static int multi = -1; - - if(multi == -1) - multi = (iface_count() > 1 ? True : False); - - return multi; + multi = (iface_count() > 1 ? True : False); } /**************************************************************************** -- cgit From 5d61d02c15a8e9ba09dcbf215fadf074be1f5760 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 26 Jun 2002 07:23:35 +0000 Subject: mumble ... fix typo ... mumble (This used to be commit 68be27cfea938d7f91a8ce1da39eb86c577f7719) --- source3/lib/interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/interface.c b/source3/lib/interface.c index 8a59c3389e..672a7621e6 100644 --- a/source3/lib/interface.c +++ b/source3/lib/interface.c @@ -280,7 +280,7 @@ int iface_count(void) **************************************************************************/ BOOL we_are_multihomed(void) { - multi = (iface_count() > 1 ? True : False); + return (iface_count() > 1 ? True : False); } /**************************************************************************** -- cgit From 2842de9d7c9343dcb5d57215afb7316d505148b8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 26 Jun 2002 07:27:00 +0000 Subject: made the wins list handling a littler clearer (This used to be commit d03efabc4dca842cafcd0edfa1eaa5b4d3e821b6) --- source3/lib/wins_srv.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/wins_srv.c b/source3/lib/wins_srv.c index cad0d06e49..c31e7505f0 100644 --- a/source3/lib/wins_srv.c +++ b/source3/lib/wins_srv.c @@ -85,10 +85,7 @@ unsigned long wins_srv_count(void) int count = 0; list = lp_wins_server_list(); - while (list && *list) { - count++; - list++; - } + for (count=0; list && list[count]; count++) /* nop */ ; DEBUG(6,("Found %u wins servers in list\n", count)); return count; @@ -101,25 +98,24 @@ struct in_addr wins_srv_ip(void) { char **list; struct in_addr ip; + int i; list = lp_wins_server_list(); - if (!list || !*list) { + if (!list || !list[0]) { zero_ip(&ip); return ip; } /* find the first live one */ - while (list && *list) { - ip = *interpret_addr2(*list); + for (i=0; list[i]; i++) { + ip = *interpret_addr2(list[i]); if (!wins_is_dead(ip)) { DEBUG(6,("Current wins server is %s\n", inet_ntoa(ip))); return ip; } - list++; } /* damn, they are all dead. Keep trying the primary until they revive */ - list = lp_wins_server_list(); ip = *interpret_addr2(list[0]); return ip; -- cgit From caeaa0acb02f681be6025e3eafded223983960a0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 26 Jun 2002 12:17:11 +0000 Subject: This commit finally gives us multiple wins server groups. We now accept an extended syntax for 'wins server' like this: wins server = group1:192.168.2.10 group2:192.168.3.99 group1:192.168.0.1 The tags before the IPs don't mean anything, they are just a way of grouping IPs together. If you use the old syntax (ie. no ':') then an implicit group name of '*' is used. In general I'd recommend people use interface names for the group names, but it doesn't matter much. When we register in nmbd we try to register all our IPs with each group of WINS servers. We keep trying until all of them are registered with every group, falling back to the failover WINS servers for each group as we go. When we do a WINS lookup we try each of the WINS servers for each group. If a WINS server for a group gives a negative answer then we give up on that group and move to the next group. If it times out then we move to the next failover wins server in the group. In either case, if a WINS server doesn't respond then we mark it dead for 10 minutes, to prevent lengthy waits for dead servers. (This used to be commit e125f06058b6b51382cf046b1dbb30728b8aeda5) --- source3/lib/wins_srv.c | 261 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 245 insertions(+), 16 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/wins_srv.c b/source3/lib/wins_srv.c index c31e7505f0..95b25b96b2 100644 --- a/source3/lib/wins_srv.c +++ b/source3/lib/wins_srv.c @@ -1,6 +1,6 @@ /* Unix SMB/CIFS implementation. - Samba utility functions + Samba wins server helper functions Copyright (C) Andrew Tridgell 1992-2002 Copyright (C) Christopher R. Hertel 2000 @@ -21,6 +21,41 @@ #include "includes.h" +/* + this is pretty much a complete rewrite of the earlier code. The main + aim of the rewrite is to add support for having multiple wins server + lists, so Samba can register with multiple groups of wins servers + and each group has a failover list of wins servers. + + Central to the way it all works is the idea of a wins server + 'tag'. A wins tag is a label for a group of wins servers. For + example if you use + + wins server = fred:192.168.2.10 mary:192.168.3.199 fred:192.168.2.61 + + then you would have two groups of wins servers, one tagged with the + name 'fred' and the other with the name 'mary'. I would usually + recommend using interface names instead of 'fred' and 'mary' but + they can be any alpha string. + + Now, how does it all work. Well, nmbd needs to register each of its + IPs with each of its names once with each group of wins servers. So + it tries registering with the first one mentioned in the list, then + if that fails it marks that WINS server dead and moves onto the next + one. + + In the client code things are a bit different. As each of the groups + of wins servers is a separate name space we need to try each of the + groups until we either succeed or we run out of wins servers to + try. If we get a negative response from a wins server then that + means the name doesn't exist in that group, so we give up on that + group and move to the next group. If we don't get a response at all + then maybe the wins server is down, in which case we need to + failover to the next one for that group. + + confused yet? (tridge) +*/ + /* how long a server is marked dead for */ #define DEATH_TIME 600 @@ -33,10 +68,17 @@ static struct wins_dead { } *dead_servers; +/* an internal convenience structure for an IP with a short string tag + attached */ +struct tagged_ip { + fstring tag; + struct in_addr ip; +}; + /* see if an ip is on the dead list */ -static int wins_is_dead(struct in_addr ip) +BOOL wins_srv_is_dead(struct in_addr ip) { struct wins_dead *d; for (d=dead_servers; d; d=d->next) { @@ -46,12 +88,12 @@ static int wins_is_dead(struct in_addr ip) DEBUG(4,("Reviving wins server %s\n", inet_ntoa(ip))); DLIST_REMOVE(dead_servers, d); free(d); - return 0; + return False; } - return 1; + return True; } } - return 0; + return False; } /* @@ -61,7 +103,7 @@ void wins_srv_died(struct in_addr ip) { struct wins_dead *d; - if (is_zero_ip(ip) || wins_is_dead(ip)) { + if (is_zero_ip(ip) || wins_srv_is_dead(ip)) { return; } @@ -79,11 +121,16 @@ void wins_srv_died(struct in_addr ip) /* return the total number of wins servers, dead or not */ -unsigned long wins_srv_count(void) +unsigned wins_srv_count(void) { char **list; int count = 0; + if (lp_wins_support()) { + /* simple - just talk to ourselves */ + return 1; + } + list = lp_wins_server_list(); for (count=0; list && list[count]; count++) /* nop */ ; @@ -91,32 +138,214 @@ unsigned long wins_srv_count(void) return count; } +/* + parse an IP string that might be in tagged format + the result is a tagged_ip structure containing the tag + and the ip in in_addr format. If there is no tag then + use the tag '*' +*/ +static void parse_ip(struct tagged_ip *ip, const char *str) +{ + char *s = strchr(str, ':'); + if (!s) { + fstrcpy(ip->tag, "*"); + ip->ip = *interpret_addr2(str); + return; + } + + ip->ip = *interpret_addr2(s+1); + fstrcpy(ip->tag, str); + s = strchr(ip->tag, ':'); + if (s) *s = 0; +} + + /* return the IP of the currently active wins server, or the zero IP otherwise */ struct in_addr wins_srv_ip(void) { char **list; - struct in_addr ip; int i; + struct tagged_ip t_ip; + + /* if we are a wins server then we always just talk to ourselves */ + if (lp_wins_support()) { + extern struct in_addr loopback_ip; + return loopback_ip; + } list = lp_wins_server_list(); if (!list || !list[0]) { - zero_ip(&ip); - return ip; + zero_ip(&t_ip.ip); + return t_ip.ip; } /* find the first live one */ for (i=0; list[i]; i++) { - ip = *interpret_addr2(list[i]); - if (!wins_is_dead(ip)) { - DEBUG(6,("Current wins server is %s\n", inet_ntoa(ip))); - return ip; + parse_ip(&t_ip, list[i]); + if (!wins_srv_is_dead(t_ip.ip)) { + DEBUG(6,("Current wins server is %s\n", inet_ntoa(t_ip.ip))); + return t_ip.ip; } } /* damn, they are all dead. Keep trying the primary until they revive */ - ip = *interpret_addr2(list[0]); + parse_ip(&t_ip, list[0]); + + return t_ip.ip; +} + + +/* + return the list of wins server tags. A 'tag' is used to distinguish + wins server as either belonging to the same name space or a separate + name space. Usually you would setup your 'wins server' option to + list one or more wins server per interface and use the interface + name as your tag, but you are free to use any tag you like. +*/ +char **wins_srv_tags(void) +{ + char **ret = NULL; + int count=0, i, j; + char **list; + + if (lp_wins_support()) { + /* give the caller something to chew on. This makes + the rest of the logic simpler (ie. less special cases) */ + ret = (char **)malloc(sizeof(char *)*2); + if (!ret) return NULL; + ret[0] = strdup("*"); + ret[1] = NULL; + return ret; + } + + list = lp_wins_server_list(); + if (!list) return NULL; + + /* yes, this is O(n^2) but n is very small */ + for (i=0;list[i];i++) { + struct tagged_ip t_ip; + + parse_ip(&t_ip, list[i]); + + /* see if we already have it */ + for (j=0;j Date: Thu, 27 Jun 2002 14:37:17 +0000 Subject: The next phase in the WINS rewrite! We now cope wiith multiple WINS groups and multiple failover servers for release and refresh as well as registration. We also do the regitrations in the same fashion as W2K does, where we don't try to register the next IP in the list for a name until the WINS server has acked the previos IP. This prevents us flooding the WINS server and also seems to make for much more reliable multi-homed registration. I also changed the dead WINS server code to mark pairs of IPs dead, not individual IPs. The idea is that a WINS server might be dead from the point of view of one of our interfaces, but not another, so we need to keep talking to it on one while moving onto a failover WINS server on the other interface. This copes much better with partial LAN outages and weird routing tables. (This used to be commit 313f2c9ff7a513802e4f893324865e70912d419e) --- source3/lib/interface.c | 8 ---- source3/lib/wins_srv.c | 104 +++++++++++++++++++++++++----------------------- 2 files changed, 55 insertions(+), 57 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/interface.c b/source3/lib/interface.c index 672a7621e6..85c49789c4 100644 --- a/source3/lib/interface.c +++ b/source3/lib/interface.c @@ -275,14 +275,6 @@ int iface_count(void) return ret; } -/**************************************************************************** - True if we have two or more interfaces. - **************************************************************************/ -BOOL we_are_multihomed(void) -{ - return (iface_count() > 1 ? True : False); -} - /**************************************************************************** return the Nth interface **************************************************************************/ diff --git a/source3/lib/wins_srv.c b/source3/lib/wins_srv.c index 95b25b96b2..27b5adf6b5 100644 --- a/source3/lib/wins_srv.c +++ b/source3/lib/wins_srv.c @@ -60,13 +60,19 @@ /* how long a server is marked dead for */ #define DEATH_TIME 600 -/* a list of wins server that are marked dead. */ +/* a list of wins server that are marked dead from the point of view + of a given source address. We keep a separate dead list for each src address + to cope with multiple interfaces that are not routable to each other + */ static struct wins_dead { - struct in_addr ip; + struct in_addr dest_ip; + struct in_addr src_ip; time_t revival; /* when it will be revived */ struct wins_dead *next, *prev; } *dead_servers; +extern BOOL global_in_nmbd; + /* an internal convenience structure for an IP with a short string tag attached */ @@ -78,14 +84,17 @@ struct tagged_ip { /* see if an ip is on the dead list */ -BOOL wins_srv_is_dead(struct in_addr ip) +BOOL wins_srv_is_dead(struct in_addr wins_ip, struct in_addr src_ip) { struct wins_dead *d; for (d=dead_servers; d; d=d->next) { - if (ip_equal(ip, d->ip)) { + if (ip_equal(wins_ip, d->dest_ip) && ip_equal(src_ip, d->src_ip)) { /* it might be due for revival */ if (d->revival <= time(NULL)) { - DEBUG(4,("Reviving wins server %s\n", inet_ntoa(ip))); + fstring src_name; + fstrcpy(src_name, inet_ntoa(src_ip)); + DEBUG(4,("Reviving wins server %s for source %s\n", + inet_ntoa(wins_ip), src_name)); DLIST_REMOVE(dead_servers, d); free(d); return False; @@ -96,24 +105,49 @@ BOOL wins_srv_is_dead(struct in_addr ip) return False; } + +/* + mark a wins server as being alive (for the moment) +*/ +void wins_srv_alive(struct in_addr wins_ip, struct in_addr src_ip) +{ + struct wins_dead *d; + for (d=dead_servers; d; d=d->next) { + if (ip_equal(wins_ip, d->dest_ip) && ip_equal(src_ip, d->src_ip)) { + fstring src_name; + fstrcpy(src_name, inet_ntoa(src_ip)); + DEBUG(4,("Reviving wins server %s for source %s\n", + inet_ntoa(wins_ip), src_name)); + DLIST_REMOVE(dead_servers, d); + return; + } + } +} + + /* mark a wins server as temporarily dead */ -void wins_srv_died(struct in_addr ip) +void wins_srv_died(struct in_addr wins_ip, struct in_addr src_ip) { struct wins_dead *d; + fstring src_name; - if (is_zero_ip(ip) || wins_srv_is_dead(ip)) { + if (is_zero_ip(wins_ip) || wins_srv_is_dead(wins_ip, src_ip)) { return; } d = (struct wins_dead *)malloc(sizeof(*d)); if (!d) return; - d->ip = ip; + d->dest_ip = wins_ip; + d->src_ip = src_ip; d->revival = time(NULL) + DEATH_TIME; - DEBUG(4,("Marking wins server %s dead for %u seconds\n", inet_ntoa(ip), DEATH_TIME)); + fstrcpy(src_name, inet_ntoa(src_ip)); + + DEBUG(4,("Marking wins server %s dead for %u seconds from source %s\n", + inet_ntoa(wins_ip), DEATH_TIME, src_name)); DLIST_ADD(dead_servers, d); } @@ -127,6 +161,8 @@ unsigned wins_srv_count(void) int count = 0; if (lp_wins_support()) { + if (global_in_nmbd) return 0; + /* simple - just talk to ourselves */ return 1; } @@ -134,7 +170,6 @@ unsigned wins_srv_count(void) list = lp_wins_server_list(); for (count=0; list && list[count]; count++) /* nop */ ; - DEBUG(6,("Found %u wins servers in list\n", count)); return count; } @@ -160,42 +195,6 @@ static void parse_ip(struct tagged_ip *ip, const char *str) } -/* - return the IP of the currently active wins server, or the zero IP otherwise -*/ -struct in_addr wins_srv_ip(void) -{ - char **list; - int i; - struct tagged_ip t_ip; - - /* if we are a wins server then we always just talk to ourselves */ - if (lp_wins_support()) { - extern struct in_addr loopback_ip; - return loopback_ip; - } - - list = lp_wins_server_list(); - if (!list || !list[0]) { - zero_ip(&t_ip.ip); - return t_ip.ip; - } - - /* find the first live one */ - for (i=0; list[i]; i++) { - parse_ip(&t_ip, list[i]); - if (!wins_srv_is_dead(t_ip.ip)) { - DEBUG(6,("Current wins server is %s\n", inet_ntoa(t_ip.ip))); - return t_ip.ip; - } - } - - /* damn, they are all dead. Keep trying the primary until they revive */ - parse_ip(&t_ip, list[0]); - - return t_ip.ip; -} - /* return the list of wins server tags. A 'tag' is used to distinguish @@ -211,6 +210,7 @@ char **wins_srv_tags(void) char **list; if (lp_wins_support()) { + if (global_in_nmbd) return NULL; /* give the caller something to chew on. This makes the rest of the logic simpler (ie. less special cases) */ ret = (char **)malloc(sizeof(char *)*2); @@ -272,7 +272,7 @@ void wins_srv_tags_free(char **list) return the IP of the currently active wins server for the given tag, or the zero IP otherwise */ -struct in_addr wins_srv_ip_tag(const char *tag) +struct in_addr wins_srv_ip_tag(const char *tag, struct in_addr src_ip) { char **list; int i; @@ -298,8 +298,13 @@ struct in_addr wins_srv_ip_tag(const char *tag) /* not for the right tag. Move along */ continue; } - if (!wins_srv_is_dead(t_ip.ip)) { - DEBUG(6,("Current wins server for tag '%s' is %s\n", tag, inet_ntoa(t_ip.ip))); + if (!wins_srv_is_dead(t_ip.ip, src_ip)) { + fstring src_name; + fstrcpy(src_name, inet_ntoa(src_ip)); + DEBUG(6,("Current wins server for tag '%s' with source %s is %s\n", + tag, + src_name, + inet_ntoa(t_ip.ip))); return t_ip.ip; } } @@ -330,6 +335,7 @@ unsigned wins_srv_count_tag(const char *tag) /* if we are a wins server then we always just talk to ourselves */ if (lp_wins_support()) { + if (global_in_nmbd) return 0; return 1; } -- cgit From 551a4cd89596b7f12d23a878d65361197b20a58f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 27 Jun 2002 14:54:01 +0000 Subject: fixed a link problem with global_in_nmbd (This used to be commit 9a3e323ec261a1ee3a83f8c558583c3d4a53e06a) --- source3/lib/wins_srv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/wins_srv.c b/source3/lib/wins_srv.c index 27b5adf6b5..9fd2760612 100644 --- a/source3/lib/wins_srv.c +++ b/source3/lib/wins_srv.c @@ -71,8 +71,8 @@ static struct wins_dead { struct wins_dead *next, *prev; } *dead_servers; -extern BOOL global_in_nmbd; - +/* nmbd sets this */ +BOOL global_in_nmbd = False; /* an internal convenience structure for an IP with a short string tag attached */ -- cgit From 5bc613c36299123118f046136132a96f5b7f6e8b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 28 Jun 2002 02:54:40 +0000 Subject: don't warn on the loading of zero length files. This fixes the 'valid.dat' warning (This used to be commit 57101ef770e34ef9fd2ddcb5d9c9e9ad050e5e3d) --- source3/lib/util_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c index 883827a4f5..90cb022f58 100644 --- a/source3/lib/util_file.c +++ b/source3/lib/util_file.c @@ -450,7 +450,7 @@ void *map_file(char *fname, size_t size) #endif if (!p) { p = file_load(fname, &s2); - if (!p || s2 != size) { + if (!p || (s2 != 0 && s2 != size)) { DEBUG(1,("incorrect size for %s - got %d expected %d\n", fname, s2, size)); if (p) free(p); -- cgit From 060b73bd8e069633cb50381f4e3dd14f0fd99968 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 28 Jun 2002 03:19:20 +0000 Subject: don't warn on non-existant files in map_file(), let the caller handle any warning (This used to be commit 98a119ee58286b708a54dcba9ffcfbdcf8cb6bba) --- source3/lib/util_file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c index 90cb022f58..611e0e40be 100644 --- a/source3/lib/util_file.c +++ b/source3/lib/util_file.c @@ -450,7 +450,8 @@ void *map_file(char *fname, size_t size) #endif if (!p) { p = file_load(fname, &s2); - if (!p || (s2 != 0 && s2 != size)) { + if (!p) return NULL; + if (s2 != size) { DEBUG(1,("incorrect size for %s - got %d expected %d\n", fname, s2, size)); if (p) free(p); -- cgit From 3563257247c9444f1b1489fb9f4faba3dc50959e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Jul 2002 05:39:32 +0000 Subject: bias the lookup sorting towards directly reachable IPs (This used to be commit 514b91827a970a0041314af341b8c66a01668e4a) --- source3/lib/interface.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/interface.c b/source3/lib/interface.c index 85c49789c4..2704397fb2 100644 --- a/source3/lib/interface.c +++ b/source3/lib/interface.c @@ -355,3 +355,11 @@ struct in_addr *iface_ip(struct in_addr ip) struct interface *i = iface_find(ip, True); return(i ? &i->ip : &local_interfaces->ip); } + +/* + return True if a IP is directly reachable on one of our interfaces +*/ +BOOL iface_local(struct in_addr ip) +{ + return iface_find(ip, True) ? True : False; +} -- cgit From 9930b0b0650ae3e38c033c28672398425dd8228c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Jul 2002 09:12:41 +0000 Subject: used findstatic.pl to make some variables static and remove some dead code (This used to be commit 91ad9041e9507d36eb3f40c23c5d4df61f139ef0) --- source3/lib/genrand.c | 4 +- source3/lib/interface.c | 27 ------------- source3/lib/md5.c | 4 +- source3/lib/talloc.c | 2 +- source3/lib/time.c | 5 --- source3/lib/util_sid.c | 28 +++---------- source3/lib/util_sock.c | 105 +++++++++--------------------------------------- 7 files changed, 29 insertions(+), 146 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/genrand.c b/source3/lib/genrand.c index 6296ead726..ee8bc0b1d5 100644 --- a/source3/lib/genrand.c +++ b/source3/lib/genrand.c @@ -24,8 +24,8 @@ static unsigned char hash[258]; static uint32 counter; -unsigned char *reseed_data; -size_t reseed_data_size; +static unsigned char *reseed_data; +static size_t reseed_data_size; /**************************************************************** Copy any user given reseed data. diff --git a/source3/lib/interface.c b/source3/lib/interface.c index 2704397fb2..0d751a9c7c 100644 --- a/source3/lib/interface.c +++ b/source3/lib/interface.c @@ -318,38 +318,11 @@ struct in_addr *iface_n_bcast(int n) } -/**************************************************************************** -this function provides a simple hash of the configured interfaces. It is -used to detect a change in interfaces to tell us whether to discard -the current wins.dat file. -Note that the result is independent of the order of the interfaces - **************************************************************************/ -unsigned iface_hash(void) -{ - unsigned ret = 0; - struct interface *i; - - for (i=local_interfaces;i;i=i->next) { - unsigned x1 = (unsigned)str_checksum(inet_ntoa(i->ip)); - unsigned x2 = (unsigned)str_checksum(inet_ntoa(i->nmask)); - ret ^= (x1 ^ x2); - } - - return ret; -} - - /* these 3 functions return the ip/bcast/nmask for the interface most appropriate for the given ip address. If they can't find an appropriate interface they return the requested field of the first known interface. */ -struct in_addr *iface_bcast(struct in_addr ip) -{ - struct interface *i = iface_find(ip, True); - return(i ? &i->bcast : &local_interfaces->bcast); -} - struct in_addr *iface_ip(struct in_addr ip) { struct interface *i = iface_find(ip, True); diff --git a/source3/lib/md5.c b/source3/lib/md5.c index 627725bb25..0d8f8e74d9 100644 --- a/source3/lib/md5.c +++ b/source3/lib/md5.c @@ -22,6 +22,8 @@ #include "md5.h" +void MD5Transform(uint32 buf[4], uint32 const in[16]); + /* * Note: this code is harmless on little-endian machines. */ @@ -161,7 +163,7 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx) * reflect the addition of 16 longwords of new data. MD5Update blocks * the data and converts bytes into longwords for this routine. */ -void MD5Transform(uint32 buf[4], uint32 const in[16]) +static void MD5Transform(uint32 buf[4], uint32 const in[16]) { register uint32 a, b, c, d; diff --git a/source3/lib/talloc.c b/source3/lib/talloc.c index d81528588c..0f293e1725 100644 --- a/source3/lib/talloc.c +++ b/source3/lib/talloc.c @@ -82,7 +82,7 @@ struct talloc_ctx { * @todo We should turn the global list off when using Insure++, * otherwise all the memory will be seen as still reachable. **/ -TALLOC_CTX *list_head = NULL; +static TALLOC_CTX *list_head = NULL; /** diff --git a/source3/lib/time.c b/source3/lib/time.c index 9df4763b4c..9d87414aea 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -44,11 +44,6 @@ int extra_time_offset = 0; External access to time_t_min and time_t_max. ********************************************************************/ -time_t get_time_t_min(void) -{ - return TIME_T_MIN; -} - time_t get_time_t_max(void) { return TIME_T_MAX; diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c index b27040b658..7d3bd848ef 100644 --- a/source3/lib/util_sid.c +++ b/source3/lib/util_sid.c @@ -34,16 +34,16 @@ DOM_SID global_sid_Builtin; /* Local well-known domain */ DOM_SID global_sid_World_Domain; /* Everyone domain */ DOM_SID global_sid_World; /* Everyone */ DOM_SID global_sid_Creator_Owner_Domain; /* Creator Owner domain */ -DOM_SID global_sid_Creator_Owner; /* Creator Owner */ -DOM_SID global_sid_Creator_Group; /* Creator Group */ DOM_SID global_sid_NT_Authority; /* NT Authority */ DOM_SID global_sid_NULL; /* NULL sid */ DOM_SID global_sid_Builtin_Guests; /* Builtin guest users */ DOM_SID global_sid_Authenticated_Users; /* All authenticated rids */ DOM_SID global_sid_Network; /* Network rids */ -DOM_SID global_sid_Anonymous; /* Anonymous login */ -const DOM_SID *global_sid_everyone = &global_sid_World; +static DOM_SID global_sid_Creator_Owner; /* Creator Owner */ +static DOM_SID global_sid_Creator_Group; /* Creator Group */ +static DOM_SID global_sid_Anonymous; /* Anonymous login */ +static const DOM_SID *global_sid_everyone = &global_sid_World; /* * An NT compatible anonymous token. @@ -302,24 +302,6 @@ void sid_copy(DOM_SID *dst, const DOM_SID *src) dst->sub_auths[i] = src->sub_auths[i]; } -/***************************************************************** - Duplicates a sid - mallocs the target. -*****************************************************************/ - -DOM_SID *sid_dup(DOM_SID *src) -{ - DOM_SID *dst; - - if(!src) - return NULL; - - if((dst = malloc(sizeof(DOM_SID))) != NULL) { - memset(dst, '\0', sizeof(DOM_SID)); - sid_copy( dst, src); - } - - return dst; -} /***************************************************************** Write a sid out into on-the-wire format. @@ -361,7 +343,7 @@ BOOL sid_parse(char *inbuf, size_t len, DOM_SID *sid) /***************************************************************** Compare the auth portion of two sids. *****************************************************************/ -int sid_compare_auth(const DOM_SID *sid1, const DOM_SID *sid2) +static int sid_compare_auth(const DOM_SID *sid1, const DOM_SID *sid2) { int i; diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index f72c4638dc..b16d34e1f4 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -50,7 +50,7 @@ typedef struct smb_socket_option { int opttype; } smb_socket_option; -smb_socket_option socket_options[] = { +static const smb_socket_option socket_options[] = { {"SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE, 0, OPT_BOOL}, {"SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR, 0, OPT_BOOL}, {"SO_BROADCAST", SOL_SOCKET, SO_BROADCAST, 0, OPT_BOOL}, @@ -189,7 +189,7 @@ ssize_t read_udp_socket(int fd,char *buf,size_t len) /******************************************************************* checks if read data is outstanding. ********************************************************************/ -int read_data_outstanding(int fd, unsigned int time_out) +static int read_data_outstanding(int fd, unsigned int time_out) { int selrtn; fd_set fds; @@ -364,20 +364,6 @@ ssize_t read_with_timeout(int fd, char *buf, size_t mincnt, size_t maxcnt, return((ssize_t)nread); } -/**************************************************************************** -send a keepalive packet (rfc1002) -****************************************************************************/ - -BOOL send_keepalive(int client) -{ - unsigned char buf[4]; - - buf[0] = SMBkeepalive; - buf[1] = buf[2] = buf[3] = 0; - - return(write_socket_data(client,(char *)buf,4) == 4); -} - /**************************************************************************** read data from the client, reading exactly N bytes. ****************************************************************************/ @@ -466,7 +452,7 @@ ssize_t write_data(int fd,char *buffer,size_t N) Write data to a socket - use send rather than write. ****************************************************************************/ -ssize_t write_socket_data(int fd,char *buffer,size_t N) +static ssize_t write_socket_data(int fd,char *buffer,size_t N) { size_t total=0; ssize_t ret; @@ -505,6 +491,21 @@ ssize_t write_socket(int fd,char *buf,size_t len) return(ret); } +/**************************************************************************** +send a keepalive packet (rfc1002) +****************************************************************************/ + +BOOL send_keepalive(int client) +{ + unsigned char buf[4]; + + buf[0] = SMBkeepalive; + buf[1] = buf[2] = buf[3] = 0; + + return(write_socket_data(client,(char *)buf,4) == 4); +} + + /**************************************************************************** read 4 bytes of a smb packet and return the smb length of the packet store the result in the buffer @@ -655,45 +656,6 @@ BOOL send_smb(int fd,char *buffer) return True; } -/**************************************************************************** -send a single packet to a port on another machine -****************************************************************************/ - -BOOL send_one_packet(char *buf,int len,struct in_addr ip,int port,int type) -{ - BOOL ret; - int out_fd; - struct sockaddr_in sock_out; - - /* create a socket to write to */ - out_fd = socket(AF_INET, type, 0); - if (out_fd == -1) - { - DEBUG(0,("socket failed")); - return False; - } - - /* set the address and port */ - memset((char *)&sock_out,'\0',sizeof(sock_out)); - putip((char *)&sock_out.sin_addr,(char *)&ip); - sock_out.sin_port = htons( port ); - sock_out.sin_family = AF_INET; - - if (DEBUGLEVEL > 0) - DEBUG(3,("sending a packet of len %d to (%s) on port %d of type %s\n", - len,inet_ntoa(ip),port,type==SOCK_DGRAM?"DGRAM":"STREAM")); - - /* send it */ - ret = (sys_sendto(out_fd,buf,len,0,(struct sockaddr *)&sock_out,sizeof(sock_out)) >= 0); - - if (!ret) - DEBUG(0,("Packet send to %s(%d) failed ERRNO=%s\n", - inet_ntoa(ip),port,strerror(errno))); - - close(out_fd); - return(ret); -} - /**************************************************************************** Open a socket of the specified type, port, and address for incoming data. ****************************************************************************/ @@ -1002,37 +964,6 @@ char *get_socket_addr(int fd) return addr_buf; } -/******************************************************************* - opens and connects to a unix pipe socket - ******************************************************************/ -int open_pipe_sock(char *path) -{ - int sock; - struct sockaddr_un sa; - - sock = socket(AF_UNIX, SOCK_STREAM, 0); - - if (sock < 0) - { - DEBUG(0, ("unix socket open failed\n")); - return sock; - } - - ZERO_STRUCT(sa); - sa.sun_family = AF_UNIX; - safe_strcpy(sa.sun_path, path, sizeof(sa.sun_path)-1); - - DEBUG(10, ("socket open succeeded. file name: %s\n", sa.sun_path)); - - if (connect(sock, (struct sockaddr*) &sa, sizeof(sa)) < 0) - { - DEBUG(0,("socket connect to %s failed\n", sa.sun_path)); - close(sock); - return -1; - } - - return sock; -} /******************************************************************* Create protected unix domain socket. -- cgit From 82176f4d85225c2aae15f9ce3e03730f019934f5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 2 Jul 2002 06:34:27 +0000 Subject: Address the string_sub problem by changing len = 0 to mean "no expand". Went through and checked all string_subs I could to ensure they're being used correctly. Jeremy. (This used to be commit 17cae0d683be404be69554cd0e84117bdcc56c87) --- source3/lib/substitute.c | 86 +++++++++++++++++++++++++++++++----------------- source3/lib/util_str.c | 32 ++++++++++++------ 2 files changed, 77 insertions(+), 41 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c index 439263dd23..dbd382a942 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -160,9 +160,11 @@ static char *automount_server(const char *user_name) /**************************************************************************** Do some standard substitutions in a string. + len is the length in bytes of the space allowed in string str. If zero means + don't allow expansions. ****************************************************************************/ -void standard_sub_basic(const char *smb_name, char *str) +void standard_sub_basic(const char *smb_name, char *str,size_t len) { char *p, *s; fstring pidstr; @@ -171,7 +173,10 @@ void standard_sub_basic(const char *smb_name, char *str) for (s=str; (p=strchr_m(s, '%'));s=p) { fstring tmp_str; - int l = sizeof(pstring) - (int)(p-str); + int l = (int)len - (int)(p-str); + + if (l < 0) + l = 0; switch (*(p+1)) { case 'U' : @@ -192,26 +197,43 @@ void standard_sub_basic(const char *smb_name, char *str) strupper(tmp_str); string_sub(p,"%D", tmp_str,l); break; - case 'I' : string_sub(p,"%I", client_addr(),l); break; + case 'I' : + string_sub(p,"%I", client_addr(),l); + break; case 'L' : - if (*local_machine) { + if (*local_machine) string_sub(p,"%L", local_machine,l); - } else { + else string_sub(p,"%L", global_myname,l); - } break; - case 'M' : string_sub(p,"%M", client_name(),l); break; - case 'R' : string_sub(p,"%R", remote_proto,l); break; - case 'T' : string_sub(p,"%T", timestring(False),l); break; - case 'a' : string_sub(p,"%a", remote_arch,l); break; + case 'M' : + string_sub(p,"%M", client_name(),l); + break; + case 'R' : + string_sub(p,"%R", remote_proto,l); + break; + case 'T' : + string_sub(p,"%T", timestring(False),l); + break; + case 'a' : + string_sub(p,"%a", remote_arch,l); + break; case 'd' : slprintf(pidstr,sizeof(pidstr)-1, "%d",(int)sys_getpid()); string_sub(p,"%d", pidstr,l); break; - case 'h' : string_sub(p,"%h", myhostname(),l); break; - case 'm' : string_sub(p,"%m", remote_machine,l); break; - case 'v' : string_sub(p,"%v", VERSION,l); break; - case '$' : p += expand_env_var(p,l); break; /* Expand environment variables */ + case 'h' : + string_sub(p,"%h", myhostname(),l); + break; + case 'm' : + string_sub(p,"%m", remote_machine,l); + break; + case 'v' : + string_sub(p,"%v", VERSION,l); + break; + case '$' : + p += expand_env_var(p,l); + break; /* Expand environment variables */ case '\0': p++; break; /* don't run off the end of the string */ @@ -228,30 +250,32 @@ void standard_sub_basic(const char *smb_name, char *str) static void standard_sub_advanced(int snum, const char *user, const char *connectpath, gid_t gid, - const char *smb_name, char *str) + const char *smb_name, char *str, size_t len) { char *p, *s, *home; for (s=str; (p=strchr_m(s, '%'));s=p) { - int l = sizeof(pstring) - (int)(p-str); - + int l = (int)len - (int)(p-str); + + if (l < 0) + l = 0; + switch (*(p+1)) { - case 'N' : string_sub(p,"%N", automount_server(user),l); break; + case 'N' : + string_sub(p,"%N", automount_server(user),l); + break; case 'H': - if ((home = get_user_home_dir(user))) { + if ((home = get_user_home_dir(user))) string_sub(p,"%H",home, l); - } else { + else p += 2; - } break; case 'P': string_sub(p,"%P", connectpath, l); break; - case 'S': string_sub(p,"%S", lp_servicename(snum), l); break; - case 'g': string_sub(p,"%g", gidtoname(gid), l); break; @@ -278,7 +302,7 @@ static void standard_sub_advanced(int snum, const char *user, } } - standard_sub_basic(smb_name, str); + standard_sub_basic(smb_name, str, len); } const char *standard_sub_specified(TALLOC_CTX *mem_ctx, const char *input_string, @@ -328,8 +352,7 @@ const char *standard_sub_specified(TALLOC_CTX *mem_ctx, const char *input_string } } - standard_sub_basic(username, input_pstring); - + standard_sub_basic(username, input_pstring, sizeof(pstring)); return talloc_strdup(mem_ctx, input_pstring); } @@ -337,16 +360,17 @@ const char *standard_sub_specified(TALLOC_CTX *mem_ctx, const char *input_string Do some standard substitutions in a string. ****************************************************************************/ -void standard_sub_conn(connection_struct *conn, char *str) +void standard_sub_conn(connection_struct *conn, char *str, size_t len) { - standard_sub_advanced(SNUM(conn), conn->user, conn->connectpath, conn->gid, current_user_info.smb_name, str); + standard_sub_advanced(SNUM(conn), conn->user, conn->connectpath, + conn->gid, current_user_info.smb_name, str, len); } /**************************************************************************** Like standard_sub but by snum. ****************************************************************************/ -void standard_sub_snum(int snum, char *str) +void standard_sub_snum(int snum, char *str, size_t len) { extern struct current_user current_user; static uid_t cached_uid = -1; @@ -359,6 +383,6 @@ void standard_sub_snum(int snum, char *str) cached_uid = current_user.uid; } - standard_sub_advanced(snum, cached_user, "", -1, current_user_info.smb_name, str); + standard_sub_advanced(snum, cached_user, "", -1, + current_user_info.smb_name, str, len); } - diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index eac3ebe929..9b4282c6e0 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -650,23 +650,30 @@ This routine looks for pattern in s and replaces it with insert. It may do multiple replacements. any of " ; ' $ or ` in the insert string are replaced with _ -if len==0 then no length check is performed +if len==0 then the string cannot be extended. This is different from the old +use of len==0 which was for no length checks to be done. ****************************************************************************/ + void string_sub(char *s,const char *pattern,const char *insert, size_t len) { char *p; ssize_t ls,lp,li, i; - if (!insert || !pattern || !s) return; + if (!insert || !pattern || !s) + return; ls = (ssize_t)strlen(s); lp = (ssize_t)strlen(pattern); li = (ssize_t)strlen(insert); - if (!*pattern) return; + if (!*pattern) + return; + + if (len == 0) + len = ls; while (lp <= ls && (p = strstr(s,pattern))) { - if (len && (ls + (li-lp) >= len)) { + if (ls + (li-lp) >= len) { DEBUG(0,("ERROR: string overflow by %d in string_sub(%.50s, %d)\n", (int)(ls + (li-lp) - len), pattern, (int)len)); @@ -709,23 +716,30 @@ void pstring_sub(char *s,const char *pattern,const char *insert) /**************************************************************************** similar to string_sub() but allows for any character to be substituted. Use with caution! -if len==0 then no length check is performed +if len==0 then the string cannot be extended. This is different from the old +use of len==0 which was for no length checks to be done. ****************************************************************************/ + void all_string_sub(char *s,const char *pattern,const char *insert, size_t len) { char *p; ssize_t ls,lp,li; - if (!insert || !pattern || !s) return; + if (!insert || !pattern || !s) + return; ls = (ssize_t)strlen(s); lp = (ssize_t)strlen(pattern); li = (ssize_t)strlen(insert); - if (!*pattern) return; + if (!*pattern) + return; + + if (len == 0) + len = ls; while (lp <= ls && (p = strstr(s,pattern))) { - if (len && (ls + (li-lp) >= len)) { + if (ls + (li-lp) >= len) { DEBUG(0,("ERROR: string overflow by %d in all_string_sub(%.50s, %d)\n", (int)(ls + (li-lp) - len), pattern, (int)len)); @@ -743,10 +757,8 @@ void all_string_sub(char *s,const char *pattern,const char *insert, size_t len) /**************************************************************************** similar to all_string_sub but for unicode strings. return a new allocate unicode string. -len is the number of bytes, not chars similar to string_sub() but allows for any character to be substituted. Use with caution! - if len==0 then no length check is performed ****************************************************************************/ smb_ucs2_t *all_string_sub_w(const smb_ucs2_t *s, const smb_ucs2_t *pattern, -- cgit From dd118a176a5b31923dbb2f42fe8809c813b0b935 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 3 Jul 2002 06:48:52 +0000 Subject: Fix the forword prototype to be a static for this static function. (This used to be commit bb1aa5e1d2e4f71dfaab0ade24ed15d1b5fdfc33) --- source3/lib/md5.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/md5.c b/source3/lib/md5.c index 0d8f8e74d9..2121b17047 100644 --- a/source3/lib/md5.c +++ b/source3/lib/md5.c @@ -22,7 +22,7 @@ #include "md5.h" -void MD5Transform(uint32 buf[4], uint32 const in[16]); +static void MD5Transform(uint32 buf[4], uint32 const in[16]); /* * Note: this code is harmless on little-endian machines. -- cgit From 8dc39c1112487a7c98cd48ebe9742af07fd3e1c6 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 8 Jul 2002 00:40:57 +0000 Subject: (this should have been part of the previous commit) Add a function to display 'sid types' as strings - makes rpcclient outptut and DEBUG() logs much eaiser to understand. Move the enum for SID types to smb.h, becouse is really isn't LSA specific any more. Andrew Bartlett (This used to be commit fc9739861104df4ddc93efab3275275307e4fbb9) --- source3/lib/util_sid.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c index 7d3bd848ef..3293026c7d 100644 --- a/source3/lib/util_sid.c +++ b/source3/lib/util_sid.c @@ -43,7 +43,6 @@ DOM_SID global_sid_Network; /* Network rids */ static DOM_SID global_sid_Creator_Owner; /* Creator Owner */ static DOM_SID global_sid_Creator_Group; /* Creator Group */ static DOM_SID global_sid_Anonymous; /* Anonymous login */ -static const DOM_SID *global_sid_everyone = &global_sid_World; /* * An NT compatible anonymous token. @@ -56,6 +55,43 @@ NT_USER_TOKEN anonymous_token = { anon_sid_array }; +/**************************************************************************** + Lookup string names for SID types. +****************************************************************************/ + +const static struct { + enum SID_NAME_USE sid_type; + char *string; +} sid_name_type[] = { + {SID_NAME_USER, "user"}, + {SID_NAME_DOM_GRP, "domain group"}, + {SID_NAME_DOMAIN, "domain"}, + {SID_NAME_ALIAS, "local group"}, + {SID_NAME_WKN_GRP, "well-known group"}, + {SID_NAME_DELETED, "deleted account"}, + {SID_NAME_INVALID, "invalid account"}, + {SID_NAME_UNKNOWN, "UNKNOWN"}, + + {SID_NAME_USE_NONE, NULL} +}; + +const char *sid_type_lookup(uint32 sid_type) +{ + int i = 0; + + /* Look through list */ + while(sid_name_type[i].sid_type != 0) { + if (sid_name_type[i].sid_type == sid_type) + return sid_name_type[i].string; + i++; + } + + /* Default return */ + return "SID *TYPE* is INVALID"; + +} + + /**************************************************************************** Creates some useful well known sids ****************************************************************************/ -- cgit From 21b9280cf516045f3ffb7d5249087a127855a38d Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 8 Jul 2002 02:14:57 +0000 Subject: Kill off const warnings - add a pile of const to various places. (This used to be commit 1de04ec4735c19ec21cdef6e679cea17c734c5f6) --- source3/lib/util_sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index b16d34e1f4..4f1f2a1470 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -93,7 +93,7 @@ static const smb_socket_option socket_options[] = { static void print_socket_options(int s) { int value, vlen = 4; - smb_socket_option *p = &socket_options[0]; + const smb_socket_option *p = &socket_options[0]; for (; p->name != NULL; p++) { if (getsockopt(s, p->level, p->option, (void *)&value, &vlen) == -1) { -- cgit From 7f42c53971bbbae42d879b67dc02d0579434496d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 9 Jul 2002 14:17:26 +0000 Subject: the last WINS update broke self registration when we are a WINS server. The real problem is all the special cases we had for when we are a wins server as opposed to when we are using a 'real' wins server. This patch removes the special cases. We now accept non-broadcast packets from ourselves and we use ourselves as a wins server when we are one. This gets rid of the special cases and simplifies things quite a bit. It all seems to work, but there are bound to be problems found later. (This used to be commit 3e843d30158d05cdfba716bac7e5c0a75ae7a79c) --- source3/lib/wins_srv.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/wins_srv.c b/source3/lib/wins_srv.c index 9fd2760612..adf405ae7e 100644 --- a/source3/lib/wins_srv.c +++ b/source3/lib/wins_srv.c @@ -71,9 +71,6 @@ static struct wins_dead { struct wins_dead *next, *prev; } *dead_servers; -/* nmbd sets this */ -BOOL global_in_nmbd = False; - /* an internal convenience structure for an IP with a short string tag attached */ struct tagged_ip { @@ -161,8 +158,6 @@ unsigned wins_srv_count(void) int count = 0; if (lp_wins_support()) { - if (global_in_nmbd) return 0; - /* simple - just talk to ourselves */ return 1; } @@ -210,7 +205,6 @@ char **wins_srv_tags(void) char **list; if (lp_wins_support()) { - if (global_in_nmbd) return NULL; /* give the caller something to chew on. This makes the rest of the logic simpler (ie. less special cases) */ ret = (char **)malloc(sizeof(char *)*2); @@ -335,7 +329,6 @@ unsigned wins_srv_count_tag(const char *tag) /* if we are a wins server then we always just talk to ourselves */ if (lp_wins_support()) { - if (global_in_nmbd) return 0; return 1; } -- cgit From fe23e902c643a4f12ac73cfc1e95b32dbac83248 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 9 Jul 2002 23:59:46 +0000 Subject: some support functions to ease the next commit. (This used to be commit 4be1c882be56ae0fe18bb134a1513e0e6f6965b0) --- source3/lib/util_str.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 96 insertions(+), 6 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 9b4282c6e0..4c8d5d8bf7 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -654,24 +654,21 @@ if len==0 then the string cannot be extended. This is different from the old use of len==0 which was for no length checks to be done. ****************************************************************************/ -void string_sub(char *s,const char *pattern,const char *insert, size_t len) +void string_sub(char *s,const char *pattern, const char *insert, size_t len) { char *p; ssize_t ls,lp,li, i; - if (!insert || !pattern || !s) + if (!insert || !pattern || !*pattern || !s) return; ls = (ssize_t)strlen(s); lp = (ssize_t)strlen(pattern); li = (ssize_t)strlen(insert); - if (!*pattern) - return; - if (len == 0) len = ls; - + while (lp <= ls && (p = strstr(s,pattern))) { if (ls + (li-lp) >= len) { DEBUG(0,("ERROR: string overflow by %d in string_sub(%.50s, %d)\n", @@ -713,6 +710,71 @@ void pstring_sub(char *s,const char *pattern,const char *insert) string_sub(s, pattern, insert, sizeof(pstring)); } +/* similar to string_sub, but it will accept only allocated strings + * and may realloc them so pay attention at what you pass on no + * pointers inside strings, no pstrings or const must be passed + * as string. + */ + +char *realloc_string_sub(char *string, const char *pattern, const char *insert) +{ + char *p, *in; + char *s; + ssize_t ls,lp,li,ld, i; + + if (!insert || !pattern || !*pattern || !string || !*string) + return NULL; + + s = string; + + in = strdup(insert); + if (!in) { + DEBUG(0, ("realloc_string_sub: out of memory!\n")); + return NULL; + } + ls = (ssize_t)strlen(s); + lp = (ssize_t)strlen(pattern); + li = (ssize_t)strlen(insert); + ld = li - lp; + for (i=0;i 0) { + char *t = Realloc(string, ls + ld + 1); + if (!t) { + DEBUG(0, ("realloc_string_sub: out of memory!\n")); + SAFE_FREE(in); + return NULL; + } + string = t; + s = t + (p - s); + } + if (li != lp) { + memmove(p+li,p+lp,strlen(p+lp)+1); + } + memcpy(p, in, li); + s = p + li; + ls += ld; + } + SAFE_FREE(in); + return string; +} + /**************************************************************************** similar to string_sub() but allows for any character to be substituted. Use with caution! @@ -927,6 +989,20 @@ void strlower_m(char *s) unix_strlower(s,strlen(s)+1,s,strlen(s)+1); } +/******************************************************************* + duplicate convert a string to lower case +********************************************************************/ +char *strdup_lower(char *s) +{ + char *t = strdup(s); + if (t == NULL) { + DEBUG(0, ("strdup_lower: Out of memory!\n")); + return NULL; + } + strlower_m(t); + return t; +} + /******************************************************************* convert a string to upper case ********************************************************************/ @@ -947,6 +1023,20 @@ void strupper_m(char *s) unix_strupper(s,strlen(s)+1,s,strlen(s)+1); } +/******************************************************************* + convert a string to upper case +********************************************************************/ +char *strdup_upper(char *s) +{ + char *t = strdup(s); + if (t == NULL) { + DEBUG(0, ("strdup_upper: Out of memory!\n")); + return NULL; + } + strupper_m(t); + return t; +} + /* return a RFC2254 binary string representation of a buffer used in LDAP filters -- cgit From 25148a148c1bec680924909722d59d0d47c795ae Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 11 Jul 2002 00:06:29 +0000 Subject: *Experimental* new large-scaling printer code. Splits printing.tdb into a separate tdb per printer, but only keeps (currently one) tdb open at a time (although this is easily changed by changing a #define). Needs scalability testing with large numbers of printers now.... Jeremy. (This used to be commit b0909cfa14fc7ef29d2b98b56d52723570da782a) --- source3/lib/util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util.c b/source3/lib/util.c index 92c8850cef..be108aa405 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1859,7 +1859,7 @@ char *myhostname(void) /***************************************************************** a useful function for returning a path in the Samba lock directory *****************************************************************/ -char *lock_path(char *name) +char *lock_path(const char *name) { static pstring fname; @@ -1879,7 +1879,7 @@ char *lock_path(char *name) /***************************************************************** a useful function for returning a path in the Samba pid directory *****************************************************************/ -char *pid_path(char *name) +char *pid_path(const char *name) { static pstring fname; @@ -1904,7 +1904,7 @@ char *pid_path(char *name) * * @retval Pointer to a static #pstring containing the full path. **/ -char *lib_path(char *name) +char *lib_path(const char *name) { static pstring fname; snprintf(fname, sizeof(fname), "%s/%s", dyn_LIBDIR, name); -- cgit From e40abc248f6456a7dba3a4c4c4274c0e7b77020f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 12 Jul 2002 21:09:24 +0000 Subject: The changes in make_sec_desc to make us match W2K broke the marshalling/unmarshalling of security descriptors. We need to calculate the maximum offset and set the offset back after reading/writing every field in the SEC_DESC. This was *nasty* to find.... Jeremy. (This used to be commit 175d43980e57c25582d8ab859f5730283e82f3b2) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index a6db286134..d42dc994b0 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -143,7 +143,7 @@ size_t convert_string(charset_t from, charset_t to, switch(errno) { case EINVAL: reason="Incomplete multibyte sequence"; break; case E2BIG: reason="No more room"; - DEBUG(0, ("Required %d, available %d\n", + DEBUG(0, ("convert_string: Required %d, available %d\n", srclen, destlen)); /* we are not sure we need srclen bytes, may be more, may be less. -- cgit From a0489b36c1c4e0de05acec022e59f17bf5e5760e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 13 Jul 2002 04:28:01 +0000 Subject: fixed a stdin bug in XFILE that prevented 'print -' from working (This used to be commit e66e354421b8be64a1b6774bde4d187532ee7690) --- source3/lib/xfile.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/xfile.c b/source3/lib/xfile.c index 59f9fd48ad..903dfb1ae0 100644 --- a/source3/lib/xfile.c +++ b/source3/lib/xfile.c @@ -31,16 +31,16 @@ #include "includes.h" -static XFILE _x_stdin = { 0, NULL, NULL, 0, 0, O_RDONLY, X_IOFBF, 0 }; -static XFILE _x_stdout = { 1, NULL, NULL, 0, 0, O_WRONLY, X_IOLBF, 0 }; +#define XBUFSIZE BUFSIZ + +static XFILE _x_stdin = { 0, NULL, NULL, XBUFSIZE, 0, O_RDONLY, X_IOFBF, 0 }; +static XFILE _x_stdout = { 1, NULL, NULL, XBUFSIZE, 0, O_WRONLY, X_IOLBF, 0 }; static XFILE _x_stderr = { 2, NULL, NULL, 0, 0, O_WRONLY, X_IONBF, 0 }; XFILE *x_stdin = &_x_stdin; XFILE *x_stdout = &_x_stdout; XFILE *x_stderr = &_x_stderr; -#define XBUFSIZE BUFSIZ - #define X_FLAG_EOF 1 #define X_FLAG_ERROR 2 -- cgit From d7bdcee189dabc1301284655751b8022dde03ebb Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 13 Jul 2002 09:18:55 +0000 Subject: make this a ZERO_STRUCTP for consitancy with the rest of Samba. (This used to be commit 587a3d91b7226f4e96c4320322f62c6490a3c6ac) --- source3/lib/util_sid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c index 3293026c7d..5dd1d75c70 100644 --- a/source3/lib/util_sid.c +++ b/source3/lib/util_sid.c @@ -327,7 +327,7 @@ void sid_copy(DOM_SID *dst, const DOM_SID *src) { int i; - memset((char *)dst, '\0', sizeof(DOM_SID)); + ZERO_STRUCTP(dst); dst->sid_rev_num = src->sid_rev_num; dst->num_auths = src->num_auths; -- cgit