summaryrefslogtreecommitdiffstats
path: root/source/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source/lib')
-rw-r--r--source/lib/access.c4
-rw-r--r--source/lib/charcnv.c38
-rw-r--r--source/lib/charset.c245
-rw-r--r--source/lib/getsmbpass.c4
-rw-r--r--source/lib/interface.c8
-rw-r--r--source/lib/kanji.c104
-rw-r--r--source/lib/md4.c448
-rw-r--r--source/lib/system.c16
-rw-r--r--source/lib/time.c21
-rw-r--r--source/lib/username.c71
-rw-r--r--source/lib/util.c834
11 files changed, 773 insertions, 1020 deletions
diff --git a/source/lib/access.c b/source/lib/access.c
index c338517ed67..599cb5ca7e3 100644
--- a/source/lib/access.c
+++ b/source/lib/access.c
@@ -70,8 +70,8 @@ BOOL check_access(int snum)
}
else
if (snum >= 0)
- DEBUG(0,("%s Denied connection from %s (%s) to %s\n",
- timestring(), client_name(),client_addr(),
+ DEBUG(0,("Denied connection from %s (%s) to %s\n",
+ client_name(),client_addr(),
lp_servicename(snum)));
}
diff --git a/source/lib/charcnv.c b/source/lib/charcnv.c
index a7dff4224be..6be455c47b2 100644
--- a/source/lib/charcnv.c
+++ b/source/lib/charcnv.c
@@ -107,18 +107,13 @@ char *unix2dos_format(char *str,BOOL overwrite)
char *dp;
if (!mapsinited) initmaps();
-
- if(lp_client_code_page() == KANJI_CODEPAGE)
- return (*_unix_to_dos)(str, overwrite);
- else {
- if (overwrite) {
- for (p = str; *p; p++) *p = unix2dos[(unsigned char)*p];
- return str;
- } else {
- for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = unix2dos[(unsigned char)*p];
- *dp = 0;
- return cvtbuf;
- }
+ if (overwrite) {
+ for (p = str; *p; p++) *p = unix2dos[(unsigned char)*p];
+ return str;
+ } else {
+ for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = unix2dos[(unsigned char)*p];
+ *dp = 0;
+ return cvtbuf;
}
}
@@ -131,18 +126,13 @@ char *dos2unix_format(char *str, BOOL overwrite)
char *dp;
if (!mapsinited) initmaps();
-
- if(lp_client_code_page() == KANJI_CODEPAGE)
- return (*_dos_to_unix)(str, overwrite);
- else {
- if (overwrite) {
- for (p = str; *p; p++) *p = dos2unix[(unsigned char)*p];
- return str;
- } else {
- for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = dos2unix[(unsigned char)*p];
- *dp = 0;
- return cvtbuf;
- }
+ if (overwrite) {
+ for (p = str; *p; p++) *p = dos2unix[(unsigned char)*p];
+ return str;
+ } else {
+ for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = dos2unix[(unsigned char)*p];
+ *dp = 0;
+ return cvtbuf;
}
}
diff --git a/source/lib/charset.c b/source/lib/charset.c
index 4869e09fecf..c4f67e75fb1 100644
--- a/source/lib/charset.c
+++ b/source/lib/charset.c
@@ -28,7 +28,6 @@ extern int DEBUGLEVEL;
* Codepage definitions.
*/
-#if !defined(KANJI)
/* lower->upper mapping for IBM Code Page 850 - MS-DOS Latin 1 */
unsigned char cp_850[][4] = {
/* dec col/row oct hex description */
@@ -96,13 +95,74 @@ unsigned char cp_850[][4] = {
{0x9C,0,0,0}, /* Pound */
{0,0,0,0}
};
-#else /* KANJI */
+
+/* lower->upper mapping for IBM Code Page 437 - MS-DOS Latin US */
+unsigned char cp_437[][4] = {
+/* 135 08/07 207 87 c cedilla */
+/* 128 08/00 200 80 C cedilla */ {0x87,0x80,1,1},
+/* 129 08/01 201 81 u diaeresis */
+/* 154 09/10 232 9A U diaeresis */ {0x81,0x9A,1,1},
+/* 130 08/02 202 82 e acute */
+/* 144 09/00 220 90 E acute */ {0x82,0x90,1,1},
+/* 131 08/03 203 83 a circumflex */ {0x83,0x41,1,0},
+/* 132 08/04 204 84 a diaeresis */
+/* 142 08/14 216 8E A diaeresis */ {0x84,0x8E,1,1},
+/* 133 08/05 205 85 a grave */ {0x85,0x41,1,0},
+/* 134 08/06 206 86 a ring */ {0x86,0x8F,1,1},
+/* 136 08/08 210 88 e circumflex */ {0x88,0x45,1,0},
+/* 137 08/09 211 89 e diaeresis */ {0x89,0x45,1,0},
+/* 138 08/10 212 8A e grave */ {0x8A,0x45,1,0},
+/* 139 08/11 213 8B i diaeresis */ {0x8B,0x49,1,0},
+/* 140 08/12 214 8C i circumflex */ {0x8C,0x49,1,0},
+/* 141 08/13 215 8D i grave */ {0x8D,0x49,1,0},
+/* 145 09/01 221 91 ae diphthong */
+/* 146 09/02 222 92 AE diphthong */ {0x91,0x92,1,1},
+/* 147 09/03 223 93 o circumflex */ {0x93,0x4F,1,0},
+/* 148 09/04 224 94 o diaeresis */
+/* 153 09/09 231 99 O diaeresis */ {0x94,0x99,1,1},
+/* 149 09/05 225 95 o grave */ {0x95,0x4F,1,0},
+/* 150 09/06 226 96 u circumflex */ {0x96,0x55,1,0},
+/* 151 09/07 227 97 u grave */ {0x97,0x55,1,0},
+/* 152 ??/?? 201 98 u diaeresis */
+ {0x9B,0,0,0}, /* Cent */
+ {0x9C,0,0,0}, /* Pound */
+ {0x9D,0,0,0}, /* Yen */
+/* 160 10/00 240 A0 a acute */ {0xA0,0x41,1,0},
+/* 161 10/01 241 A1 i acute */ {0xA1,0x49,1,0},
+/* 162 10/02 242 A2 o acute */ {0xA2,0x4F,1,0},
+/* 163 10/03 243 A3 u acute */ {0xA3,0x55,1,0},
+/* 164 10/04 244 A4 n tilde */
+/* 165 10/05 245 A5 N tilde */ {0xA4,0xA5,1,1},
+/* Punctuation... */
+ {0xA8,0,0,0},
+ {0xAD,0,0,0},
+ {0xAE,0,0,0},
+ {0xAF,0,0,0},
+/* Greek character set */
+ {0xE0,0,0,0},
+ {0xE1,0,0,0},
+ {0xE2,0,0,0},
+ {0xE3,0,0,0},
+ {0xE4,0,0,0},
+ {0xE5,0,0,0},
+ {0xE6,0,0,0},
+ {0xE7,0,0,0},
+ {0xE8,0,0,0},
+ {0xE9,0,0,0},
+ {0xEA,0,0,0},
+ {0xEB,0,0,0},
+ {0xEC,0,0,0},
+ {0xED,0,0,0},
+ {0xEE,0,0,0},
+ {0xEF,0,0,0},
+ {0,0,0,0}
+};
+
/* lower->upper mapping for IBM Code Page 932 - MS-DOS Japanese SJIS */
unsigned char cp_932[][4] = {
{0,0,0,0}
};
-#endif /* KANJI */
-
+
char xx_dos_char_map[256];
char xx_upper_char_map[256];
char xx_lower_char_map[256];
@@ -134,9 +194,9 @@ static void add_dos_char(int lower, BOOL map_lower_to_upper,
if (upper) dos_char_map[upper] = 1;
if (lower && upper) {
if(map_upper_to_lower)
- lower_char_map[upper] = (char)lower;
+ lower_char_map[upper] = (char)lower;
if(map_lower_to_upper)
- upper_char_map[lower] = (char)upper;
+ upper_char_map[lower] = (char)upper;
}
}
@@ -171,152 +231,12 @@ void charset_initialise()
}
/****************************************************************************
-load the client codepage.
-****************************************************************************/
-
-typedef unsigned char (*codepage_p)[4];
-
-static codepage_p load_client_codepage( int client_codepage )
-{
- pstring codepage_file_name;
- unsigned char buf[8];
- FILE *fp = NULL;
- unsigned int size;
- codepage_p cp_p = NULL;
- struct stat st;
-
- DEBUG(5, ("load_client_codepage: loading codepage %d.\n", client_codepage));
-
- if(strlen(CODEPAGEDIR) + 14 > sizeof(codepage_file_name))
- {
- DEBUG(0,("load_client_codepage: filename too long to load\n"));
- return NULL;
- }
-
- strcpy(codepage_file_name, CODEPAGEDIR);
- strcat(codepage_file_name, "/");
- strcat(codepage_file_name, "codepage.");
- sprintf( &codepage_file_name[strlen(codepage_file_name)], "%03d",
- client_codepage);
-
- if(!file_exist(codepage_file_name,&st))
- {
- DEBUG(0,("load_client_codepage: filename %s does not exist.\n",
- codepage_file_name));
- return NULL;
- }
-
- /* Check if it is at least big enough to hold the required
- data. Should be 2 byte version, 2 byte codepage, 4 byte length,
- plus zero or more bytes of data. Note that the data cannot be more
- than 512 bytes - giving a max size of 520.
- */
- size = (unsigned int)st.st_size;
-
- if( size < CODEPAGE_HEADER_SIZE || size > (CODEPAGE_HEADER_SIZE + 256))
- {
- DEBUG(0,("load_client_codepage: file %s is an incorrect size for a \
-code page file.\n", codepage_file_name));
- return NULL;
- }
-
- /* Read the first 8 bytes of the codepage file - check
- the version number and code page number. All the data
- is held in little endian format.
- */
-
- if((fp = fopen( codepage_file_name, "r")) == NULL)
- {
- DEBUG(0,("load_client_codepage: cannot open file %s. Error was %s\n",
- codepage_file_name, strerror(errno)));
- return NULL;
- }
-
- if(fread( buf, 1, CODEPAGE_HEADER_SIZE, fp)!=CODEPAGE_HEADER_SIZE)
- {
- DEBUG(0,("load_client_codepage: cannot read header from file %s. Error was %s\n",
- codepage_file_name, strerror(errno)));
- goto clean_and_exit;
- }
-
- /* Check the version value */
- if(SVAL(buf,CODEPAGE_VERSION_OFFSET) != CODEPAGE_FILE_VERSION_ID)
- {
- DEBUG(0,("load_client_codepage: filename %s has incorrect version id. \
-Needed %hu, got %hu.\n",
- codepage_file_name, (uint16)CODEPAGE_FILE_VERSION_ID,
- SVAL(buf,CODEPAGE_VERSION_OFFSET)));
- goto clean_and_exit;
- }
-
- /* Check the codepage matches */
- if(SVAL(buf,CODEPAGE_CLIENT_CODEPAGE_OFFSET) != (uint16)client_codepage)
- {
- DEBUG(0,("load_client_codepage: filename %s has incorrect codepage. \
-Needed %hu, got %hu.\n",
- codepage_file_name, (uint16)client_codepage,
- SVAL(buf,CODEPAGE_CLIENT_CODEPAGE_OFFSET)));
- goto clean_and_exit;
- }
-
- /* Check the length is correct. */
- if(IVAL(buf,CODEPAGE_LENGTH_OFFSET) !=
- (unsigned int)(size - CODEPAGE_HEADER_SIZE))
- {
- DEBUG(0,("load_client_codepage: filename %s has incorrect size headers. \
-Needed %u, got %u.\n", codepage_file_name, size - CODEPAGE_HEADER_SIZE,
- IVAL(buf,CODEPAGE_LENGTH_OFFSET)));
- goto clean_and_exit;
- }
-
- size -= CODEPAGE_HEADER_SIZE; /* Remove header */
-
- /* Make sure the size is a multiple of 4. */
- if((size % 4 ) != 0)
- {
- DEBUG(0,("load_client_codepage: filename %s has a codepage size not a \
-multiple of 4.\n", codepage_file_name));
- goto clean_and_exit;
- }
-
- /* Allocate space for the code page file and read it all in. */
- if((cp_p = (codepage_p)malloc( size + 4 )) == NULL)
- {
- DEBUG(0,("load_client_codepage: malloc fail.\n"));
- goto clean_and_exit;
- }
-
- if(fread( (char *)cp_p, 1, size, fp)!=size)
- {
- DEBUG(0,("load_client_codepage: read fail on file %s. Error was %s.\n",
- codepage_file_name, strerror(errno)));
- goto clean_and_exit;
- }
-
- /* Ensure array is correctly terminated. */
- memset(((char *)cp_p) + size, '\0', 4);
-
- fclose(fp);
- return cp_p;
-
-clean_and_exit:
-
- /* pseudo destructor :-) */
-
- if(fp != NULL)
- fclose(fp);
- if(cp_p)
- free((char *)cp_p);
- return NULL;
-}
-
-/****************************************************************************
initialise the client codepage.
****************************************************************************/
void codepage_initialise(int client_codepage)
{
int i;
- codepage_p cp = NULL;
+ unsigned char (*cp)[4] = NULL;
static BOOL done = False;
if(done == True)
@@ -332,21 +252,30 @@ void codepage_initialise(int client_codepage)
/*
* Known client codepages - these can be added to.
*/
- cp = load_client_codepage( client_codepage );
-
- if(cp == NULL)
+ switch(client_codepage)
{
+ case 850:
+ cp = cp_850;
+ break;
+ case 437:
+ cp = cp_437;
+ break;
+ case 932:
+ cp = cp_932;
+ break;
+ default:
#ifdef KANJI
- DEBUG(6,("codepage_initialise: loading dynamic codepage file %s/codepage.%d \
-for code page %d failed. Using default client codepage 932\n",
- CODEPAGEDIR, client_codepage, client_codepage));
- cp = cp_932;
+ /* Use default codepage - currently 932 */
+ DEBUG(6,("codepage_initialise: Using default client codepage %d\n",
+ 932));
+ cp = cp_932;
#else /* KANJI */
- DEBUG(6,("codepage_initialise: loading dynamic codepage file %s/codepage.%d \
-for code page %d failed. Using default client codepage 850\n",
- CODEPAGEDIR, client_codepage, client_codepage));
- cp = cp_850;
+ /* Use default codepage - currently 850 */
+ DEBUG(6,("codepage_initialise: Using default client codepage %d\n",
+ 850));
+ cp = cp_850;
#endif /* KANJI */
+ break;
}
if(cp)
diff --git a/source/lib/getsmbpass.c b/source/lib/getsmbpass.c
index e8cb683d0b1..9008d40f910 100644
--- a/source/lib/getsmbpass.c
+++ b/source/lib/getsmbpass.c
@@ -45,7 +45,7 @@ static struct termio t;
return ioctl(fd, TCGETA, t);
}
- int tcsetattr(int fd, int flags, struct termio *t)
+ int tcsetattr(int fd, int flags, const struct termio *t)
{
if(flags & TCSAFLUSH)
ioctl(fd, TCFLSH, TCIOFLUSH);
@@ -76,7 +76,7 @@ static struct sgttyb t;
return ioctl(fd, TIOCGETP, (char *)t);
}
- int tcsetattr(int fd, int flags, struct sgttyb *t)
+ int tcsetattr(int fd, int flags, const struct sgttyb *t)
{
return ioctl(fd, TIOCSETP, (char *)t);
}
diff --git a/source/lib/interface.c b/source/lib/interface.c
index 940af1eccf4..1dc605ff2fd 100644
--- a/source/lib/interface.c
+++ b/source/lib/interface.c
@@ -25,6 +25,7 @@ extern int DEBUGLEVEL;
struct in_addr ipzero;
struct in_addr wins_ip;
+struct in_addr loopback_ip;
static struct in_addr default_ip;
static struct in_addr default_bcast;
static struct in_addr default_nmask;
@@ -262,6 +263,7 @@ static void interpret_interfaces(char *s, struct interface **interfaces,
ipzero = *interpret_addr2("0.0.0.0");
wins_ip = *interpret_addr2("255.255.255.255");
+ loopback_ip = *interpret_addr2("127.0.0.1");
while (next_token(&ptr,token,NULL)) {
/* parse it into an IP address/netmasklength pair */
@@ -337,9 +339,9 @@ static void interpret_interfaces(char *s, struct interface **interfaces,
iface->next = NULL;
(*interfaces) = last_iface = iface;
- DEBUG(1,("Added interface ip=%s ",inet_ntoa(iface->ip)));
- DEBUG(1,("bcast=%s ",inet_ntoa(iface->bcast)));
- DEBUG(1,("nmask=%s\n",inet_ntoa(iface->nmask)));
+ DEBUG(2,("Added interface ip=%s ",inet_ntoa(iface->ip)));
+ DEBUG(2,("bcast=%s ",inet_ntoa(iface->bcast)));
+ DEBUG(2,("nmask=%s\n",inet_ntoa(iface->nmask)));
}
diff --git a/source/lib/kanji.c b/source/lib/kanji.c
index 5d7de87248d..479763fd406 100644
--- a/source/lib/kanji.c
+++ b/source/lib/kanji.c
@@ -23,6 +23,7 @@
and add all jis codes sequence type at 1995.8.16
Notes: Hexadecimal code by <ohki@gssm.otuka.tsukuba.ac.jp>
*/
+#ifdef KANJI
#define _KANJI_C_
#include "includes.h"
@@ -42,7 +43,8 @@ char hex_tag = HEXTAG;
search token from S1 separated any char of S2
S1 contain SHIFT JIS chars.
********************************************************************/
-char *sj_strtok(char *s1, char *s2)
+char *
+sj_strtok (char *s1, const char *s2)
{
static char *s = NULL;
char *q;
@@ -81,9 +83,10 @@ char *sj_strtok(char *s1, char *s2)
search string S2 from S1
S1 contain SHIFT JIS chars.
********************************************************************/
-char *sj_strstr(char *s1, char *s2)
+char *
+sj_strstr (const char *s1, const char *s2)
{
- int len = strlen ((char *) s2);
+ register int len = strlen ((char *) s2);
if (!*s2)
return (char *) s1;
for (;*s1;) {
@@ -104,7 +107,8 @@ char *sj_strstr(char *s1, char *s2)
Search char C from beginning of S.
S contain SHIFT JIS chars.
********************************************************************/
-char *sj_strchr (char *s, int c)
+char *
+sj_strchr (const char *s, int c)
{
for (; *s; ) {
if (*s == c)
@@ -122,9 +126,10 @@ char *sj_strchr (char *s, int c)
Search char C end of S.
S contain SHIFT JIS chars.
********************************************************************/
-char *sj_strrchr(char *s, int c)
+char *
+sj_strrchr (const char *s, int c)
{
- char *q;
+ register char *q;
for (q = 0; *s; ) {
if (*s == c) {
@@ -148,7 +153,8 @@ static char cvtbuf[1024];
/*******************************************************************
EUC <-> SJIS
********************************************************************/
-static int euc2sjis (int hi, int lo)
+static int
+euc2sjis (register int hi, register int lo)
{
if (hi & 1)
return ((hi / 2 + (hi < 0xdf ? 0x31 : 0x71)) << 8) |
@@ -157,7 +163,8 @@ static int euc2sjis (int hi, int lo)
return ((hi / 2 + (hi < 0xdf ? 0x30 : 0x70)) << 8) | (lo - 2);
}
-static int sjis2euc (int hi, int lo)
+static int
+sjis2euc (register int hi, register int lo)
{
if (lo >= 0x9f)
return ((hi * 2 - (hi >= 0xe0 ? 0xe0 : 0x60)) << 8) | (lo + 2);
@@ -170,9 +177,10 @@ static int sjis2euc (int hi, int lo)
Convert FROM contain SHIFT JIS codes to EUC codes
return converted buffer
********************************************************************/
-static char *sj_to_euc(char *from, BOOL overwrite)
+static char *
+sj_to_euc (const char *from, BOOL overwrite)
{
- char *out;
+ register char *out;
char *save;
save = (char *) from;
@@ -202,9 +210,10 @@ static char *sj_to_euc(char *from, BOOL overwrite)
Convert FROM contain EUC codes to SHIFT JIS codes
return converted buffer
********************************************************************/
-static char *euc_to_sj(char *from, BOOL overwrite)
+static char *
+euc_to_sj (const char *from, BOOL overwrite)
{
- char *out;
+ register char *out;
char *save;
save = (char *) from;
@@ -233,7 +242,8 @@ static char *euc_to_sj(char *from, BOOL overwrite)
/*******************************************************************
JIS7,JIS8,JUNET <-> SJIS
********************************************************************/
-static int sjis2jis(int hi, int lo)
+static int
+sjis2jis (register int hi, register int lo)
{
if (lo >= 0x9f)
return ((hi * 2 - (hi >= 0xe0 ? 0x160 : 0xe0)) << 8) | (lo - 0x7e);
@@ -242,7 +252,8 @@ static int sjis2jis(int hi, int lo)
(lo - (lo >= 0x7f ? 0x20 : 0x1f));
}
-static int jis2sjis(int hi, int lo)
+static int
+jis2sjis (register int hi, register int lo)
{
if (hi & 1)
return ((hi / 2 + (hi < 0x5f ? 0x71 : 0xb1)) << 8) |
@@ -255,10 +266,11 @@ static int jis2sjis(int hi, int lo)
Convert FROM contain JIS codes to SHIFT JIS codes
return converted buffer
********************************************************************/
-static char *jis8_to_sj(char *from, BOOL overwrite)
+static char *
+jis8_to_sj (const char *from, BOOL overwrite)
{
- char *out;
- int shifted;
+ register char *out;
+ register int shifted;
char *save;
shifted = _KJ_ROMAN;
@@ -305,10 +317,11 @@ static char *jis8_to_sj(char *from, BOOL overwrite)
Convert FROM contain SHIFT JIS codes to JIS codes
return converted buffer
********************************************************************/
-static char *sj_to_jis8(char *from, BOOL overwrite)
+static char *
+sj_to_jis8 (const char *from, BOOL overwrite)
{
- char *out;
- int shifted;
+ register char *out;
+ register int shifted;
char *save;
shifted = _KJ_ROMAN;
@@ -361,10 +374,11 @@ static char *sj_to_jis8(char *from, BOOL overwrite)
Convert FROM contain 7 bits JIS codes to SHIFT JIS codes
return converted buffer
********************************************************************/
-static char *jis7_to_sj(char *from, BOOL overwrite)
+static char *
+jis7_to_sj (const char *from, BOOL overwrite)
{
- char *out;
- int shifted;
+ register char *out;
+ register int shifted;
char *save;
shifted = _KJ_ROMAN;
@@ -420,10 +434,11 @@ static char *jis7_to_sj(char *from, BOOL overwrite)
Convert FROM contain SHIFT JIS codes to 7 bits JIS codes
return converted buffer
********************************************************************/
-static char *sj_to_jis7(char *from, BOOL overwrite)
+static char *
+sj_to_jis7 (const char *from, BOOL overwrite)
{
- char *out;
- int shifted;
+ register char *out;
+ register int shifted;
char *save;
shifted = _KJ_ROMAN;
@@ -496,10 +511,11 @@ static char *sj_to_jis7(char *from, BOOL overwrite)
Convert FROM contain 7 bits JIS(junet) codes to SHIFT JIS codes
return converted buffer
********************************************************************/
-static char *junet_to_sj(char *from, BOOL overwrite)
+static char *
+junet_to_sj (const char *from, BOOL overwrite)
{
- char *out;
- int shifted;
+ register char *out;
+ register int shifted;
char *save;
shifted = _KJ_ROMAN;
@@ -552,10 +568,11 @@ static char *junet_to_sj(char *from, BOOL overwrite)
Convert FROM contain SHIFT JIS codes to 7 bits JIS(junet) codes
return converted buffer
********************************************************************/
-static char *sj_to_junet(char *from, BOOL overwrite)
+static char *
+sj_to_junet (const char *from, BOOL overwrite)
{
- char *out;
- int shifted;
+ register char *out;
+ register int shifted;
char *save;
shifted = _KJ_ROMAN;
@@ -621,7 +638,8 @@ static char *sj_to_junet(char *from, BOOL overwrite)
HEX <-> SJIS
********************************************************************/
/* ":xx" -> a byte */
-static char *hex_to_sj(char *from, BOOL overwrite)
+static char *
+hex_to_sj (const char *from, BOOL overwrite)
{
char *sp, *dp;
@@ -646,7 +664,8 @@ static char *hex_to_sj(char *from, BOOL overwrite)
/*******************************************************************
kanji/kana -> ":xx"
********************************************************************/
-static char *sj_to_hex(char *from, BOOL overwrite)
+static char *
+sj_to_hex (const char *from, BOOL overwrite)
{
unsigned char *sp, *dp;
@@ -682,7 +701,8 @@ static char *sj_to_hex(char *from, BOOL overwrite)
/*******************************************************************
kanji/kana -> ":xx"
********************************************************************/
-static char *sj_to_cap(char *from, BOOL overwrite)
+static char *
+sj_to_cap (const char *from, BOOL overwrite)
{
unsigned char *sp, *dp;
@@ -710,7 +730,8 @@ static char *sj_to_cap(char *from, BOOL overwrite)
/*******************************************************************
sj to sj
********************************************************************/
-static char *sj_to_sj(char *from, BOOL overwrite)
+static char *
+sj_to_sj (const char *from, BOOL overwrite)
{
if (!overwrite) {
strcpy (cvtbuf, (char *) from);
@@ -725,10 +746,11 @@ static char *sj_to_sj(char *from, BOOL overwrite)
_dos_to_unix _unix_to_dos
************************************************************************/
-char *(*_dos_to_unix)(char *str, BOOL overwrite) = sj_to_sj;
-char *(*_unix_to_dos)(char *str, BOOL overwrite) = sj_to_sj;
+char* (*_dos_to_unix) (const char *str, BOOL overwrite) = sj_to_sj;
+char* (*_unix_to_dos) (const char *str, BOOL overwrite) = sj_to_sj;
-static int setup_string_function(int codes)
+static int
+setup_string_function (int codes)
{
switch (codes) {
default:
@@ -866,3 +888,7 @@ int interpret_coding_system(char *str, int def)
}
return setup_string_function (codes);
}
+#else
+ int kanji_dummy_procedure(void)
+{return 0;}
+#endif /* KANJI */
diff --git a/source/lib/md4.c b/source/lib/md4.c
index 1c9c2e6ecd5..bdff075c7e7 100644
--- a/source/lib/md4.c
+++ b/source/lib/md4.c
@@ -1,171 +1,299 @@
-/*
- Unix SMB/Netbios implementation.
- Version 1.9.
- a implementation of MD4 designed for use in the SMB authentication protocol
- Copyright (C) Andrew Tridgell 1997
-
- 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.
+#ifdef SMB_PASSWD
+/*
+ This code is from rfc1186.
*/
+ /*
+ ** ********************************************************************
+ ** md4.c -- Implementation of MD4 Message Digest Algorithm **
+ ** Updated: 2/16/90 by Ronald L. Rivest **
+ ** (C) 1990 RSA Data Security, Inc. **
+ ** ********************************************************************
+ */
-/* NOTE: This code makes no attempt to be fast!
+ /*
+ ** To use MD4:
+ ** -- Include md4.h in your program
+ ** -- Declare an MDstruct MD to hold the state of the digest
+ ** computation.
+ ** -- Initialize MD using MDbegin(&MD)
+ ** -- For each full block (64 bytes) X you wish to process, call
+ ** MDupdate(&MD,X,512)
+ ** (512 is the number of bits in a full block.)
+ ** -- For the last block (less than 64 bytes) you wish to process,
+ ** MDupdate(&MD,X,n)
+ ** where n is the number of bits in the partial block. A partial
+ ** block terminates the computation, so every MD computation
+ ** should terminate by processing a partial block, even if it
+ ** has n = 0.
+ ** -- The message digest is available in MD.buffer[0] ...
+ ** MD.buffer[3]. (Least-significant byte of each word
+ ** should be output first.)
+ ** -- You can print out the digest using MDprint(&MD)
+ */
- It assumes that a int is at least 32 bits long
-*/
+ /* Implementation notes:
+ ** This implementation assumes that ints are 32-bit quantities.
+ ** If the machine stores the least-significant byte of an int in the
+ ** least-addressed byte (e.g., VAX and 8086), then LOWBYTEFIRST
+ ** should be set to TRUE. Otherwise (e.g., SUNS), LOWBYTEFIRST
+ ** should be set to FALSE. Note that on machines with LOWBYTEFIRST
+ ** FALSE the routine MDupdate modifies has a side-effect on its input
+ ** array (the order of bytes in each word are reversed). If this is
+ ** undesired a call to MDreverse(X) can reverse the bytes of X back
+ ** into order after each call to MDupdate.
+ */
-typedef unsigned int uint32;
-
-static uint32 A, B, C, D;
-
-static uint32 F(uint32 X, uint32 Y, uint32 Z)
-{
- return (X&Y) | ((~X)&Z);
-}
-
-static uint32 G(uint32 X, uint32 Y, uint32 Z)
-{
- return (X&Y) | (X&Z) | (Y&Z);
-}
-
-static uint32 H(uint32 X, uint32 Y, uint32 Z)
-{
- return X^Y^Z;
-}
-
-static uint32 lshift(uint32 x, int s)
-{
- x &= 0xFFFFFFFF;
- return ((x<<s)&0xFFFFFFFF) | (x>>(32-s));
-}
-
-#define ROUND1(a,b,c,d,k,s) a = lshift(a + F(b,c,d) + X[k], s)
-#define ROUND2(a,b,c,d,k,s) a = lshift(a + G(b,c,d) + X[k] + (uint32)0x5A827999,s)
-#define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + (uint32)0x6ED9EBA1,s)
-
-/* this applies md4 to 64 byte chunks */
-static void mdfour64(uint32 *M)
-{
- int j;
- uint32 AA, BB, CC, DD;
- uint32 X[16];
-
- for (j=0;j<16;j++)
- X[j] = M[j];
-
- AA = A; BB = B; CC = C; DD = D;
-
- ROUND1(A,B,C,D, 0, 3); ROUND1(D,A,B,C, 1, 7);
- ROUND1(C,D,A,B, 2, 11); ROUND1(B,C,D,A, 3, 19);
- ROUND1(A,B,C,D, 4, 3); ROUND1(D,A,B,C, 5, 7);
- ROUND1(C,D,A,B, 6, 11); ROUND1(B,C,D,A, 7, 19);
- ROUND1(A,B,C,D, 8, 3); ROUND1(D,A,B,C, 9, 7);
- ROUND1(C,D,A,B, 10, 11); ROUND1(B,C,D,A, 11, 19);
- ROUND1(A,B,C,D, 12, 3); ROUND1(D,A,B,C, 13, 7);
- ROUND1(C,D,A,B, 14, 11); ROUND1(B,C,D,A, 15, 19);
-
- ROUND2(A,B,C,D, 0, 3); ROUND2(D,A,B,C, 4, 5);
- ROUND2(C,D,A,B, 8, 9); ROUND2(B,C,D,A, 12, 13);
- ROUND2(A,B,C,D, 1, 3); ROUND2(D,A,B,C, 5, 5);
- ROUND2(C,D,A,B, 9, 9); ROUND2(B,C,D,A, 13, 13);
- ROUND2(A,B,C,D, 2, 3); ROUND2(D,A,B,C, 6, 5);
- ROUND2(C,D,A,B, 10, 9); ROUND2(B,C,D,A, 14, 13);
- ROUND2(A,B,C,D, 3, 3); ROUND2(D,A,B,C, 7, 5);
- ROUND2(C,D,A,B, 11, 9); ROUND2(B,C,D,A, 15, 13);
-
- ROUND3(A,B,C,D, 0, 3); ROUND3(D,A,B,C, 8, 9);
- ROUND3(C,D,A,B, 4, 11); ROUND3(B,C,D,A, 12, 15);
- ROUND3(A,B,C,D, 2, 3); ROUND3(D,A,B,C, 10, 9);
- ROUND3(C,D,A,B, 6, 11); ROUND3(B,C,D,A, 14, 15);
- ROUND3(A,B,C,D, 1, 3); ROUND3(D,A,B,C, 9, 9);
- ROUND3(C,D,A,B, 5, 11); ROUND3(B,C,D,A, 13, 15);
- ROUND3(A,B,C,D, 3, 3); ROUND3(D,A,B,C, 11, 9);
- ROUND3(C,D,A,B, 7, 11); ROUND3(B,C,D,A, 15, 15);
-
- A += AA; B += BB; C += CC; D += DD;
-
- A &= 0xFFFFFFFF; B &= 0xFFFFFFFF;
- C &= 0xFFFFFFFF; D &= 0xFFFFFFFF;
-
- for (j=0;j<16;j++)
- X[j] = 0;
-}
-
-static void copy64(uint32 *M, unsigned char *in)
-{
- int i;
-
- for (i=0;i<16;i++)
- M[i] = (in[i*4+3]<<24) | (in[i*4+2]<<16) |
- (in[i*4+1]<<8) | (in[i*4+0]<<0);
-}
-
-static void copy4(unsigned char *out,uint32 x)
-{
- out[0] = x&0xFF;
- out[1] = (x>>8)&0xFF;
- out[2] = (x>>16)&0xFF;
- out[3] = (x>>24)&0xFF;
-}
-
-/* produce a md4 message digest from data of length n bytes */
-void mdfour(unsigned char *out, unsigned char *in, int n)
-{
- unsigned char buf[128];
- uint32 M[16];
- uint32 b = n * 8;
- int i;
-
- A = 0x67452301;
- B = 0xefcdab89;
- C = 0x98badcfe;
- D = 0x10325476;
-
- while (n > 64) {
- copy64(M, in);
- mdfour64(M);
- in += 64;
- n -= 64;
- }
+#define TRUE 1
+#define FALSE 0
- for (i=0;i<128;i++)
- buf[i] = 0;
- memcpy(buf, in, n);
- buf[n] = 0x80;
-
- if (n <= 55) {
- copy4(buf+56, b);
- copy64(M, buf);
- mdfour64(M);
- } else {
- copy4(buf+120, b);
- copy64(M, buf);
- mdfour64(M);
- copy64(M, buf+64);
- mdfour64(M);
- }
+ /* Compile-time includes
+ */
+
+#include <stdio.h>
+#include "md4.h"
+
+#define uchar unsigned char
+#define int16 unsigned short
+#define uint32 unsigned int
+
+#include "byteorder.h"
+
+ /* Compile-time declarations of MD4 "magic constants".
+ */
+#define I0 0x67452301 /* Initial values for MD buffer */
+#define I1 0xefcdab89
+#define I2 0x98badcfe
+#define I3 0x10325476
+#define C2 013240474631 /* round 2 constant = sqrt(2) in octal */
+#define C3 015666365641 /* round 3 constant = sqrt(3) in octal */
+ /* C2 and C3 are from Knuth, The Art of Programming, Volume 2
+ ** (Seminumerical Algorithms), Second Edition (1981), Addison-Wesley.
+ ** Table 2, page 660.
+ */
- for (i=0;i<128;i++)
- buf[i] = 0;
- copy64(M, buf);
+#define fs1 3 /* round 1 shift amounts */
+#define fs2 7
+#define fs3 11
+#define fs4 19
+#define gs1 3 /* round 2 shift amounts */
+#define gs2 5
+#define gs3 9
+#define gs4 13
+#define hs1 3 /* round 3 shift amounts */
+#define hs2 9
+#define hs3 11
+#define hs4 15
- copy4(out, A);
- copy4(out+4, B);
- copy4(out+8, C);
- copy4(out+12, D);
+ /* Compile-time macro declarations for MD4.
+ ** Note: The "rot" operator uses the variable "tmp".
+ ** It assumes tmp is declared as unsigned int, so that the >>
+ ** operator will shift in zeros rather than extending the sign bit.
+ */
+#define f(X,Y,Z) ((X&Y) | ((~X)&Z))
+#define g(X,Y,Z) ((X&Y) | (X&Z) | (Y&Z))
+#define h(X,Y,Z) (X^Y^Z)
+#define rot(X,S) (tmp=X,(tmp<<S) | (tmp>>(32-S)))
+#define ff(A,B,C,D,i,s) A = rot((A + f(B,C,D) + X[i]),s)
+#define gg(A,B,C,D,i,s) A = rot((A + g(B,C,D) + X[i] + C2),s)
+#define hh(A,B,C,D,i,s) A = rot((A + h(B,C,D) + X[i] + C3),s)
+
+ /* MDprint(MDp)
+ ** Print message digest buffer MDp as 32 hexadecimal digits.
+ ** Order is from low-order byte of buffer[0] to high-order byte of
+ ** buffer[3].
+ ** Each byte is printed with high-order hexadecimal digit first.
+ ** This is a user-callable routine.
+ */
+ void
+ MDprint(MDp)
+ MDptr MDp;
+ { int i,j;
+ for (i=0;i<4;i++)
+ for (j=0;j<32;j=j+8)
+ printf("%02x",(MDp->buffer[i]>>j) & 0xFF);
+ }
+
+ /* MDbegin(MDp)
+ ** Initialize message digest buffer MDp.
+ ** This is a user-callable routine.
+ */
+ void
+ MDbegin(MDp)
+ MDptr MDp;
+ { int i;
+ MDp->buffer[0] = I0;
+ MDp->buffer[1] = I1;
+ MDp->buffer[2] = I2;
+ MDp->buffer[3] = I3;
+ for (i=0;i<8;i++) MDp->count[i] = 0;
+ MDp->done = 0;
+ }
+
+ /* MDreverse(X)
+ ** Reverse the byte-ordering of every int in X.
+ ** Assumes X is an array of 16 ints.
+ ** The macro revx reverses the byte-ordering of the next word of X.
+ */
+ void MDreverse(X)
+ unsigned int *X;
+ { register unsigned int t;
+ register unsigned int i;
+
+ for(i = 0; i < 16; i++) {
+ t = X[i];
+ SIVAL(X,i*4,t);
+ }
+ }
- A = B = C = D = 0;
-}
+ /* MDblock(MDp,X)
+ ** Update message digest buffer MDp->buffer using 16-word data block X.
+ ** Assumes all 16 words of X are full of data.
+ ** Does not update MDp->count.
+ ** This routine is not user-callable.
+ */
+ static void
+ MDblock(MDp,X)
+ MDptr MDp;
+ unsigned int *X;
+ {
+ register unsigned int tmp, A, B, C, D;
+ MDreverse(X);
+ A = MDp->buffer[0];
+ B = MDp->buffer[1];
+ C = MDp->buffer[2];
+ D = MDp->buffer[3];
+ /* Update the message digest buffer */
+ ff(A , B , C , D , 0 , fs1); /* Round 1 */
+ ff(D , A , B , C , 1 , fs2);
+ ff(C , D , A , B , 2 , fs3);
+ ff(B , C , D , A , 3 , fs4);
+ ff(A , B , C , D , 4 , fs1);
+ ff(D , A , B , C , 5 , fs2);
+ ff(C , D , A , B , 6 , fs3);
+ ff(B , C , D , A , 7 , fs4);
+ ff(A , B , C , D , 8 , fs1);
+ ff(D , A , B , C , 9 , fs2);
+ ff(C , D , A , B , 10 , fs3);
+ ff(B , C , D , A , 11 , fs4);
+ ff(A , B , C , D , 12 , fs1);
+ ff(D , A , B , C , 13 , fs2);
+ ff(C , D , A , B , 14 , fs3);
+ ff(B , C , D , A , 15 , fs4);
+ gg(A , B , C , D , 0 , gs1); /* Round 2 */
+ gg(D , A , B , C , 4 , gs2);
+ gg(C , D , A , B , 8 , gs3);
+ gg(B , C , D , A , 12 , gs4);
+ gg(A , B , C , D , 1 , gs1);
+ gg(D , A , B , C , 5 , gs2);
+ gg(C , D , A , B , 9 , gs3);
+ gg(B , C , D , A , 13 , gs4);
+ gg(A , B , C , D , 2 , gs1);
+ gg(D , A , B , C , 6 , gs2);
+ gg(C , D , A , B , 10 , gs3);
+ gg(B , C , D , A , 14 , gs4);
+ gg(A , B , C , D , 3 , gs1);
+ gg(D , A , B , C , 7 , gs2);
+ gg(C , D , A , B , 11 , gs3);
+ gg(B , C , D , A , 15 , gs4);
+ hh(A , B , C , D , 0 , hs1); /* Round 3 */
+ hh(D , A , B , C , 8 , hs2);
+ hh(C , D , A , B , 4 , hs3);
+ hh(B , C , D , A , 12 , hs4);
+ hh(A , B , C , D , 2 , hs1);
+ hh(D , A , B , C , 10 , hs2);
+ hh(C , D , A , B , 6 , hs3);
+ hh(B , C , D , A , 14 , hs4);
+ hh(A , B , C , D , 1 , hs1);
+ hh(D , A , B , C , 9 , hs2);
+ hh(C , D , A , B , 5 , hs3);
+ hh(B , C , D , A , 13 , hs4);
+ hh(A , B , C , D , 3 , hs1);
+ hh(D , A , B , C , 11 , hs2);
+ hh(C , D , A , B , 7 , hs3);
+ hh(B , C , D , A , 15 , hs4);
+ MDp->buffer[0] += A;
+ MDp->buffer[1] += B;
+ MDp->buffer[2] += C;
+ MDp->buffer[3] += D;
+ }
+ /* MDupdate(MDp,X,count)
+ ** Input: MDp -- an MDptr
+ ** X -- a pointer to an array of unsigned characters.
+ ** count -- the number of bits of X to use.
+ ** (if not a multiple of 8, uses high bits of last byte.)
+ ** Update MDp using the number of bits of X given by count.
+ ** This is the basic input routine for an MD4 user.
+ ** The routine completes the MD computation when count < 512, so
+ ** every MD computation should end with one call to MDupdate with a
+ ** count less than 512. A call with count 0 will be ignored if the
+ ** MD has already been terminated (done != 0), so an extra call with
+ ** count 0 can be given as a "courtesy close" to force termination
+ ** if desired.
+ */
+ void
+ MDupdate(MDp,X,count)
+ MDptr MDp;
+ unsigned char *X;
+ unsigned int count;
+ { unsigned int i, tmp, bit, byte, mask;
+ unsigned char XX[64];
+ unsigned char *p;
+ /* return with no error if this is a courtesy close with count
+ ** zero and MDp->done is true.
+ */
+ if (count == 0 && MDp->done) return;
+ /* check to see if MD is already done and report error */
+ if (MDp->done)
+ { printf("\nError: MDupdate MD already done."); return; }
+ /* Add count to MDp->count */
+ tmp = count;
+ p = MDp->count;
+ while (tmp)
+ { tmp += *p;
+ *p++ = tmp;
+ tmp = tmp >> 8;
+ }
+ /* Process data */
+ if (count == 512)
+ { /* Full block of data to handle */
+ MDblock(MDp,(unsigned int *)X);
+ }
+ else if (count > 512) /* Check for count too large */
+ { printf("\nError: MDupdate called with illegal count value %d."
+ ,count);
+ return;
+ }
+ else /* partial block -- must be last block so finish up */
+ { /* Find out how many bytes and residual bits there are */
+ byte = count >> 3;
+ bit = count & 7;
+ /* Copy X into XX since we need to modify it */
+ for (i=0;i<=byte;i++) XX[i] = X[i];
+ for (i=byte+1;i<64;i++) XX[i] = 0;
+ /* Add padding '1' bit and low-order zeros in last byte */
+ mask = 1 << (7 - bit);
+ XX[byte] = (XX[byte] | mask) & ~( mask - 1);
+ /* If room for bit count, finish up with this block */
+ if (byte <= 55)
+ { for (i=0;i<8;i++) XX[56+i] = MDp->count[i];
+ MDblock(MDp,(unsigned int *)XX);
+ }
+ else /* need to do two blocks to finish up */
+ { MDblock(MDp,(unsigned int *)XX);
+ for (i=0;i<56;i++) XX[i] = 0;
+ for (i=0;i<8;i++) XX[56+i] = MDp->count[i];
+ MDblock(MDp,(unsigned int *)XX);
+ }
+ /* Set flag saying we're done with MD computation */
+ MDp->done = 1;
+ }
+ }
+ /*
+ ** End of md4.c
+ */
+#else
+ void md4_dummy() {;}
+#endif
diff --git a/source/lib/system.c b/source/lib/system.c
index fe8e8004d04..b149ccb4b98 100644
--- a/source/lib/system.c
+++ b/source/lib/system.c
@@ -194,15 +194,25 @@ now for utime()
********************************************************************/
int sys_utime(char *fname,struct utimbuf *times)
{
- return(utime(dos_to_unix(fname,False),times));
+ /* if the modtime is 0 or -1 then ignore the call and
+ return success */
+ if (times->modtime == (time_t)0 || times->modtime == (time_t)-1)
+ return 0;
+
+ /* if the access time is 0 or -1 then set it to the modtime */
+ if (times->actime == (time_t)0 || times->actime == (time_t)-1)
+ times->actime = times->modtime;
+
+ return(utime(dos_to_unix(fname,False),times));
}
+
/*********************************************************
for rename across filesystems Patch from Warren Birnbaum
<warrenb@hpcvscdp.cv.hp.com>
**********************************************************/
-
-static int copy_reg(char *source, const char *dest)
+static int
+copy_reg (const char *source, const char *dest)
{
struct stat source_stats;
int ifd;
diff --git a/source/lib/time.c b/source/lib/time.c
index 4f688d2214a..ad6b04484c5 100644
--- a/source/lib/time.c
+++ b/source/lib/time.c
@@ -298,7 +298,7 @@ void put_long_date(char *p,time_t t)
/****************************************************************************
check if it's a null mtime
****************************************************************************/
-static BOOL null_mtime(time_t mtime)
+BOOL null_mtime(time_t mtime)
{
if (mtime == 0 || mtime == 0xFFFFFFFF || mtime == (time_t)-1)
return(True);
@@ -446,25 +446,6 @@ time_t make_unix_date3(void *date_ptr)
}
/****************************************************************************
-set the time on a file
-****************************************************************************/
-BOOL set_filetime(char *fname,time_t mtime)
-{
- struct utimbuf times;
-
- if (null_mtime(mtime)) return(True);
-
- times.modtime = times.actime = mtime;
-
- if (sys_utime(fname,&times)) {
- DEBUG(4,("set_filetime(%s) failed: %s\n",fname,strerror(errno)));
- }
-
- return(True);
-}
-
-
-/****************************************************************************
return the date and time as a string
****************************************************************************/
char *timestring(void )
diff --git a/source/lib/username.c b/source/lib/username.c
index a9f64259916..46b8f4cb332 100644
--- a/source/lib/username.c
+++ b/source/lib/username.c
@@ -22,9 +22,6 @@
#include "includes.h"
extern int DEBUGLEVEL;
-/* internal functions - modified versions of the ones in password.c */
-static struct passwd *uname_string_combinations(char *s, struct passwd * (*fn) (), int N);
-static struct passwd *uname_string_combinations2(char *s, int offset, struct passwd * (*fn) (), int N);
/****************************************************************************
get a users home directory. tries as-is then lower case
@@ -144,8 +141,6 @@ Note that this changes user!
struct passwd *Get_Pwnam(char *user,BOOL allow_change)
{
fstring user2;
- int last_char;
- int usernamelevel = lp_usernamelevel();
struct passwd *ret;
@@ -177,19 +172,6 @@ struct passwd *Get_Pwnam(char *user,BOOL allow_change)
ret = _Get_Pwnam(user);
if (ret) return(ret);
- /* try with last letter capitalised */
- strlower(user);
- last_char = strlen(user)-1;
- user[last_char] = toupper(user[last_char]);
- DEBUG(3, ("Trying username %s\n", user));
- ret = _Get_Pwnam(user);
- if (ret) return(ret);
-
- /* try all combinations up to usernamelevel */
- strlower(user);
- ret = uname_string_combinations(user, _Get_Pwnam, usernamelevel);
- if (ret) return(ret);
-
if (allow_change)
fstrcpy(user,user2);
@@ -268,57 +250,4 @@ BOOL user_in_list(char *user,char *list)
return(False);
}
-/* The functions below have been taken from password.c and slightly modified */
-/****************************************************************************
-apply a function to upper/lower case combinations
-of a string and return true if one of them returns true.
-try all combinations with N uppercase letters.
-offset is the first char to try and change (start with 0)
-it assumes the string starts lowercased
-****************************************************************************/
-static struct passwd *uname_string_combinations2(char *s,int offset,struct passwd *(*fn)(),int N)
-{
- int len = strlen(s);
- int i;
- struct passwd *ret;
-
-#ifdef PASSWORD_LENGTH
- len = MIN(len,PASSWORD_LENGTH);
-#endif
-
- if (N <= 0 || offset >= len)
- return(fn(s));
-
- for (i=offset;i<(len-(N-1));i++)
-
- {
- char c = s[i];
- if (!islower(c)) continue;
- s[i] = toupper(c);
- ret = uname_string_combinations2(s,i+1,fn,N-1);
- if(ret) return(ret);
- s[i] = c;
- }
- return(NULL);
-}
-
-/****************************************************************************
-apply a function to upper/lower case combinations
-of a string and return true if one of them returns true.
-try all combinations with up to N uppercase letters.
-offset is the first char to try and change (start with 0)
-it assumes the string starts lowercased
-****************************************************************************/
-static struct passwd * uname_string_combinations(char *s,struct passwd * (*fn)(),int N)
-{
- int n;
- struct passwd *ret;
-
- for (n=1;n<=N;n++)
- {
- ret = uname_string_combinations2(s,0,fn,n);
- if(ret) return(ret);
- }
- return(NULL);
-}
diff --git a/source/lib/util.c b/source/lib/util.c
index 01e2dae154c..54b2dc08ac8 100644
--- a/source/lib/util.c
+++ b/source/lib/util.c
@@ -156,7 +156,7 @@ static void check_log_size(void)
int maxlog;
struct stat st;
- if (debug_count++ < 100) return;
+ if (debug_count++ < 100 || getuid() != 0) return;
maxlog = lp_max_log_size() * 1024;
if (!dbf || maxlog <= 0) return;
@@ -175,7 +175,6 @@ static void check_log_size(void)
debug_count=0;
}
-
/*******************************************************************
write an debug message on the debugfile. This is called by the DEBUG
macro
@@ -190,7 +189,8 @@ va_dcl
char *format_str;
#endif
va_list ap;
-
+ int old_errno = errno;
+
if (stdout_logging) {
#ifdef __STDC__
va_start(ap, format_str);
@@ -200,6 +200,7 @@ va_dcl
#endif
vfprintf(dbf,format_str,ap);
va_end(ap);
+ errno = old_errno;
return(0);
}
@@ -207,16 +208,17 @@ va_dcl
if (!lp_syslog_only())
#endif
{
- if (!dbf)
- {
- int oldumask = umask(022);
- dbf = fopen(debugf,"w");
- umask(oldumask);
- if (dbf)
- setbuf(dbf,NULL);
- else
- return(0);
- }
+ if (!dbf) {
+ int oldumask = umask(022);
+ dbf = fopen(debugf,"w");
+ umask(oldumask);
+ if (dbf) {
+ setbuf(dbf,NULL);
+ } else {
+ errno = old_errno;
+ return(0);
+ }
+ }
}
#ifdef SYSLOG
@@ -273,6 +275,8 @@ va_dcl
check_log_size();
+ errno = old_errno;
+
return(0);
}
@@ -807,145 +811,131 @@ char *attrib_string(int mode)
/*******************************************************************
case insensitive string compararison
********************************************************************/
-int StrCaseCmp(char *s, char *t)
+int StrCaseCmp(const char *s, const char *t)
{
/* compare until we run out of string, either t or s, or find a difference */
/* We *must* use toupper rather than tolower here due to the
asynchronous upper to lower mapping.
*/
-#if !defined(KANJI_WIN95_COMPATIBILITY)
- if(lp_client_code_page() == KANJI_CODEPAGE)
+#if defined(KANJI) && !defined(KANJI_WIN95_COMPATIBILITY)
+ /* Win95 treats full width ascii characters as case sensitive. */
+ int diff;
+ for (;;)
{
- /* Win95 treats full width ascii characters as case sensitive. */
- int diff;
- for (;;)
- {
- if (!*s || !*t)
- return toupper (*s) - toupper (*t);
- else if (is_sj_alph (*s) && is_sj_alph (*t))
- {
- diff = sj_toupper2 (*(s+1)) - sj_toupper2 (*(t+1));
- if (diff)
- return diff;
- s += 2;
- t += 2;
- }
- else if (is_shift_jis (*s) && is_shift_jis (*t))
- {
- diff = ((int) (unsigned char) *s) - ((int) (unsigned char) *t);
- if (diff)
- return diff;
- diff = ((int) (unsigned char) *(s+1)) - ((int) (unsigned char) *(t+1));
- if (diff)
- return diff;
- s += 2;
- t += 2;
- }
- else if (is_shift_jis (*s))
- return 1;
- else if (is_shift_jis (*t))
- return -1;
- else
- {
- diff = toupper (*s) - toupper (*t);
- if (diff)
- return diff;
- s++;
- t++;
- }
- }
+ if (!*s || !*t)
+ return toupper (*s) - toupper (*t);
+ else if (is_sj_alph (*s) && is_sj_alph (*t))
+ {
+ diff = sj_toupper2 (*(s+1)) - sj_toupper2 (*(t+1));
+ if (diff)
+ return diff;
+ s += 2;
+ t += 2;
+ }
+ else if (is_shift_jis (*s) && is_shift_jis (*t))
+ {
+ diff = ((int) (unsigned char) *s) - ((int) (unsigned char) *t);
+ if (diff)
+ return diff;
+ diff = ((int) (unsigned char) *(s+1)) - ((int) (unsigned char) *(t+1));
+ if (diff)
+ return diff;
+ s += 2;
+ t += 2;
+ }
+ else if (is_shift_jis (*s))
+ return 1;
+ else if (is_shift_jis (*t))
+ return -1;
+ else
+ {
+ diff = toupper (*s) - toupper (*t);
+ if (diff)
+ return diff;
+ s++;
+ t++;
+ }
}
- else
-#endif /* KANJI_WIN95_COMPATIBILITY */
+#else /* KANJI */
+ while (*s && *t && toupper(*s) == toupper(*t))
{
- while (*s && *t && toupper(*s) == toupper(*t))
- {
- s++;
- t++;
- }
-
- return(toupper(*s) - toupper(*t));
+ s++; t++;
}
+
+ return(toupper(*s) - toupper(*t));
+#endif /* KANJI */
}
/*******************************************************************
case insensitive string compararison, length limited
********************************************************************/
-int StrnCaseCmp(char *s, char *t, int n)
+int StrnCaseCmp(const char *s, const char *t, int n)
{
/* compare until we run out of string, either t or s, or chars */
/* We *must* use toupper rather than tolower here due to the
asynchronous upper to lower mapping.
*/
-#if !defined(KANJI_WIN95_COMPATIBILITY)
- if(lp_client_code_page() == KANJI_CODEPAGE)
+#if defined(KANJI) && !defined(KANJI_WIN95_COMPATIBILITY)
+ /* Win95 treats full width ascii characters as case sensitive. */
+ int diff;
+ for (;n > 0;)
{
- /* Win95 treats full width ascii characters as case sensitive. */
- int diff;
- for (;n > 0;)
- {
- if (!*s || !*t)
- return toupper (*s) - toupper (*t);
- else if (is_sj_alph (*s) && is_sj_alph (*t))
- {
- diff = sj_toupper2 (*(s+1)) - sj_toupper2 (*(t+1));
- if (diff)
- return diff;
- s += 2;
- t += 2;
- n -= 2;
- }
- else if (is_shift_jis (*s) && is_shift_jis (*t))
- {
- diff = ((int) (unsigned char) *s) - ((int) (unsigned char) *t);
- if (diff)
- return diff;
- diff = ((int) (unsigned char) *(s+1)) - ((int) (unsigned char) *(t+1));
- if (diff)
- return diff;
- s += 2;
- t += 2;
- n -= 2;
- }
- else if (is_shift_jis (*s))
- return 1;
- else if (is_shift_jis (*t))
- return -1;
- else
- {
- diff = toupper (*s) - toupper (*t);
- if (diff)
- return diff;
- s++;
- t++;
- n--;
- }
- }
- return 0;
+ if (!*s || !*t)
+ return toupper (*s) - toupper (*t);
+ else if (is_sj_alph (*s) && is_sj_alph (*t))
+ {
+ diff = sj_toupper2 (*(s+1)) - sj_toupper2 (*(t+1));
+ if (diff)
+ return diff;
+ s += 2;
+ t += 2;
+ n -= 2;
+ }
+ else if (is_shift_jis (*s) && is_shift_jis (*t))
+ {
+ diff = ((int) (unsigned char) *s) - ((int) (unsigned char) *t);
+ if (diff)
+ return diff;
+ diff = ((int) (unsigned char) *(s+1)) - ((int) (unsigned char) *(t+1));
+ if (diff)
+ return diff;
+ s += 2;
+ t += 2;
+ n -= 2;
+ }
+ else if (is_shift_jis (*s))
+ return 1;
+ else if (is_shift_jis (*t))
+ return -1;
+ else
+ {
+ diff = toupper (*s) - toupper (*t);
+ if (diff)
+ return diff;
+ s++;
+ t++;
+ n--;
+ }
}
- else
-#endif /* KANJI_WIN95_COMPATIBILITY */
+ return 0;
+#else /* KANJI */
+ while (n-- && *s && *t && toupper(*s) == toupper(*t))
{
- while (n-- && *s && *t && toupper(*s) == toupper(*t))
- {
- s++;
- t++;
- }
+ s++; t++;
+ }
- /* not run out of chars - strings are different lengths */
- if (n)
- return(toupper(*s) - toupper(*t));
+ /* not run out of chars - strings are different lengths */
+ if (n) return(toupper(*s) - toupper(*t));
- /* identical up to where we run out of chars,
- and strings are same length */
- return(0);
- }
+ /* identical up to where we run out of chars, and strings are same length */
+ return(0);
+#endif /* KANJI */
}
/*******************************************************************
compare 2 strings
********************************************************************/
-BOOL strequal(char *s1, char *s2)
+BOOL strequal(const char *s1, const char *s2)
{
if (s1 == s2) return(True);
if (!s1 || !s2) return(False);
@@ -956,7 +946,7 @@ BOOL strequal(char *s1, char *s2)
/*******************************************************************
compare 2 strings up to and including the nth char.
******************************************************************/
-BOOL strnequal(char *s1,char *s2,int n)
+BOOL strnequal(const char *s1,const char *s2,int n)
{
if (s1 == s2) return(True);
if (!s1 || !s2 || !n) return(False);
@@ -982,36 +972,27 @@ BOOL strcsequal(char *s1,char *s2)
void strlower(char *s)
{
while (*s)
- {
-#if !defined(KANJI_WIN95_COMPATIBILITY)
- if(lp_client_code_page() == KANJI_CODEPAGE)
- {
- /* Win95 treats full width ascii characters as case sensitive. */
- if (is_shift_jis (*s))
- {
- if (is_sj_upper (s[0], s[1]))
- s[1] = sj_tolower2 (s[1]);
- s += 2;
- }
- else if (is_kana (*s))
- {
- s++;
- }
- else
- {
- if (isupper(*s))
- *s = tolower(*s);
- s++;
- }
- }
- else
-#endif /* KANJI_WIN95_COMPATIBILITY */
{
+#if defined(KANJI) && !defined(KANJI_WIN95_COMPATIBILITY)
+ /* Win95 treats full width ascii characters as case sensitive. */
+ if (is_shift_jis (*s)) {
+ if (is_sj_upper (s[0], s[1])) {
+ s[1] = sj_tolower2 (s[1]);
+ }
+ s += 2;
+ } else if (is_kana (*s)) {
+ s++;
+ } else {
+ if (isupper(*s))
+ *s = tolower(*s);
+ s++;
+ }
+#else /* KANJI */
if (isupper(*s))
- *s = tolower(*s);
+ *s = tolower(*s);
s++;
+#endif /* KANJI */
}
- }
}
/*******************************************************************
@@ -1020,36 +1001,27 @@ void strlower(char *s)
void strupper(char *s)
{
while (*s)
- {
-#if !defined(KANJI_WIN95_COMPATIBILITY)
- if(lp_client_code_page() == KANJI_CODEPAGE)
- {
- /* Win95 treats full width ascii characters as case sensitive. */
- if (is_shift_jis (*s))
- {
- if (is_sj_lower (s[0], s[1]))
- s[1] = sj_toupper2 (s[1]);
- s += 2;
- }
- else if (is_kana (*s))
- {
- s++;
- }
- else
- {
- if (islower(*s))
- *s = toupper(*s);
- s++;
- }
- }
- else
-#endif /* KANJI_WIN95_COMPATIBILITY */
{
+#if defined(KANJI) && !defined(KANJI_WIN95_COMPATIBILITY)
+ /* Win95 treats full width ascii characters as case sensitive. */
+ if (is_shift_jis (*s)) {
+ if (is_sj_lower (s[0], s[1])) {
+ s[1] = sj_toupper2 (s[1]);
+ }
+ s += 2;
+ } else if (is_kana (*s)) {
+ s++;
+ } else {
+ if (islower(*s))
+ *s = toupper(*s);
+ s++;
+ }
+#else /* KANJI */
if (islower(*s))
- *s = toupper(*s);
+ *s = toupper(*s);
s++;
+#endif /* KANJI */
}
- }
}
/*******************************************************************
@@ -1081,30 +1053,24 @@ BOOL strisnormal(char *s)
void string_replace(char *s,char oldc,char newc)
{
while (*s)
- {
-#if !defined(KANJI_WIN95_COMPATIBILITY)
- if(lp_client_code_page() == KANJI_CODEPAGE)
- {
- /* Win95 treats full width ascii characters as case sensitive. */
- if (is_shift_jis (*s))
- s += 2;
- else if (is_kana (*s))
- s++;
- else
- {
- if (oldc == *s)
- *s = newc;
- s++;
- }
- }
- else
-#endif /* KANJI_WIN95_COMPATIBILITY */
{
+#if defined(KANJI) && !defined(KANJI_WIN95_COMPATIBILITY)
+ /* Win95 treats full width ascii characters as case sensitive. */
+ if (is_shift_jis (*s)) {
+ s += 2;
+ } else if (is_kana (*s)) {
+ s++;
+ } else {
+ if (oldc == *s)
+ *s = newc;
+ s++;
+ }
+#else /* KANJI */
if (oldc == *s)
- *s = newc;
+ *s = newc;
s++;
+#endif /* KANJI */
}
- }
}
/****************************************************************************
@@ -1488,7 +1454,7 @@ char *GetWd(char *str)
if (!sys_getwd(s))
{
- DEBUG(0,("Getwd failed, errno %s\n",strerror(errno)));
+ DEBUG(0,("Getwd failed, errno %d\n",errno));
return (NULL);
}
@@ -1726,30 +1692,22 @@ does a string have any uppercase chars in it?
BOOL strhasupper(char *s)
{
while (*s)
- {
-#if !defined(KANJI_WIN95_COMPATIBILITY)
- if(lp_client_code_page() == KANJI_CODEPAGE)
{
- /* Win95 treats full width ascii characters as case sensitive. */
- if (is_shift_jis (*s))
- s += 2;
- else if (is_kana (*s))
- s++;
- else
- {
- if (isupper(*s))
- return(True);
- s++;
- }
- }
- else
-#endif /* KANJI_WIN95_COMPATIBILITY */
- {
- if (isupper(*s))
- return(True);
+#if defined(KANJI) && !defined(KANJI_WIN95_COMPATIBILITY)
+ /* Win95 treats full width ascii characters as case sensitive. */
+ if (is_shift_jis (*s)) {
+ s += 2;
+ } else if (is_kana (*s)) {
+ s++;
+ } else {
+ if (isupper(*s)) return(True);
+ s++;
+ }
+#else /* KANJI */
+ if (isupper(*s)) return(True);
s++;
+#endif /* KANJI */
}
- }
return(False);
}
@@ -1759,38 +1717,24 @@ does a string have any lowercase chars in it?
BOOL strhaslower(char *s)
{
while (*s)
- {
-#if !defined(KANJI_WIN95_COMPATIBILITY)
- if(lp_client_code_page() == KANJI_CODEPAGE)
{
- /* Win95 treats full width ascii characters as case sensitive. */
- if (is_shift_jis (*s))
- {
- if (is_sj_upper (s[0], s[1]))
- return(True);
- if (is_sj_lower (s[0], s[1]))
- return (True);
- s += 2;
- }
- else if (is_kana (*s))
- {
- s++;
- }
- else
- {
- if (islower(*s))
- return(True);
- s++;
- }
- }
- else
-#endif /* KANJI_WIN95_COMPATIBILITY */
- {
- if (islower(*s))
- return(True);
+#if defined(KANJI) && !defined(KANJI_WIN95_COMPATIBILITY)
+ /* Win95 treats full width ascii characters as case sensitive. */
+ if (is_shift_jis (*s)) {
+ if (is_sj_upper (s[0], s[1])) return(True);
+ if (is_sj_lower (s[0], s[1])) return (True);
+ s += 2;
+ } else if (is_kana (*s)) {
+ s++;
+ } else {
+ if (islower(*s)) return(True);
+ s++;
+ }
+#else /* KANJI */
+ if (islower(*s)) return(True);
s++;
+#endif /* KANJI */
}
- }
return(False);
}
@@ -1800,33 +1744,27 @@ find the number of chars in a string
int count_chars(char *s,char c)
{
int count=0;
-
-#if !defined(KANJI_WIN95_COMPATIBILITY)
- if(lp_client_code_page() == KANJI_CODEPAGE)
- {
- /* Win95 treats full width ascii characters as case sensitive. */
- while (*s)
+#if defined(KANJI) && !defined(KANJI_WIN95_COMPATIBILITY)
+ /* Win95 treats full width ascii characters as case sensitive. */
+ while (*s)
{
- if (is_shift_jis (*s))
- s += 2;
- else
- {
- if (*s == c)
- count++;
- s++;
- }
+ if (is_shift_jis (*s))
+ s += 2;
+ else
+ {
+ if (*s == c)
+ count++;
+ s++;
}
}
- else
-#endif /* KANJI_WIN95_COMPATIBILITY */
- {
- while (*s)
+#else /* KANJI */
+ while (*s)
{
if (*s == c)
- count++;
+ count++;
s++;
}
- }
+#endif /* KANJI */
return(count);
}
@@ -1951,7 +1889,7 @@ int read_udp_socket(int fd,char *buf,int len)
bzero((char *)&lastip,sizeof(lastip));
ret = recvfrom(fd,buf,len,0,&sock,&socklen);
if (ret <= 0) {
- DEBUG(2,("read socket failed. ERRNO=%s\n",strerror(errno)));
+ DEBUG(2,("read socket failed. ERRNO=%d\n",errno));
return(0);
}
@@ -2270,11 +2208,10 @@ int read_smb_length(int fd,char *inbuf,int timeout)
/****************************************************************************
- read an smb from a fd. Note that the buffer *MUST* be of size
- BUFFER_SIZE+SAFETY_MARGIN.
+ read an smb from a fd and return it's length
The timeout is in milli seconds
****************************************************************************/
-BOOL receive_smb(int fd,char *buffer, int timeout)
+BOOL receive_smb(int fd,char *buffer,int timeout)
{
int len,ret;
@@ -2301,204 +2238,6 @@ BOOL receive_smb(int fd,char *buffer, int timeout)
return(True);
}
-#ifdef USE_OPLOCKS
-/****************************************************************************
- read a message from a udp fd.
-The timeout is in milli seconds
-****************************************************************************/
-BOOL receive_local_message(int fd, char *buffer, int buffer_len, int timeout)
-{
- struct sockaddr_in from;
- int fromlen = sizeof(from);
- int32 msg_len = 0;
-
- if(timeout != 0)
- {
- struct timeval to;
- fd_set fds;
- int selrtn;
-
- FD_ZERO(&fds);
- FD_SET(fd,&fds);
-
- to.tv_sec = timeout / 1000;
- to.tv_usec = (timeout % 1000) * 1000;
-
- selrtn = sys_select(&fds,&to);
-
- /* Check if error */
- if(selrtn == -1)
- {
- /* something is wrong. Maybe the socket is dead? */
- smb_read_error = READ_ERROR;
- return False;
- }
-
- /* Did we timeout ? */
- if (selrtn == 0)
- {
- smb_read_error = READ_TIMEOUT;
- return False;
- }
- }
-
- /*
- * Read a loopback udp message.
- */
- msg_len = recvfrom(fd, &buffer[UDP_CMD_HEADER_LEN],
- buffer_len - UDP_CMD_HEADER_LEN, 0,
- (struct sockaddr *)&from, &fromlen);
-
- if(msg_len < 0)
- {
- DEBUG(0,("receive_local_message. Error in recvfrom. (%s).\n",strerror(errno)));
- return False;
- }
-
- /* Validate message length. */
- if(msg_len > (buffer_len - UDP_CMD_HEADER_LEN))
- {
- DEBUG(0,("receive_local_message: invalid msg_len (%d) max can be %d\n",
- msg_len,
- buffer_len - UDP_CMD_HEADER_LEN));
- return False;
- }
-
- /* Validate message from address (must be localhost). */
- if(from.sin_addr.s_addr != htonl(INADDR_LOOPBACK))
- {
- DEBUG(0,("receive_local_message: invalid 'from' address \
-(was %x should be 127.0.0.1\n", from.sin_addr.s_addr));
- return False;
- }
-
- /* Setup the message header */
- SIVAL(buffer,UDP_CMD_LEN_OFFSET,msg_len);
- SSVAL(buffer,UDP_CMD_PORT_OFFSET,ntohs(from.sin_port));
-
- return True;
-}
-
-/****************************************************************************
- structure to hold a linked list of local udp messages.
- for processing.
-****************************************************************************/
-
-typedef struct _udp_message_list {
- struct _udp_message_list *msg_next;
- char *msg_buf;
- int msg_len;
-} udp_message_list;
-
-static udp_message_list *udp_msg_head = NULL;
-
-/****************************************************************************
- Function to push a linked list of local udp messages ready
- for processing.
-****************************************************************************/
-BOOL push_local_message(char *buf, int msg_len)
-{
- udp_message_list *msg = (udp_message_list *)malloc(sizeof(udp_message_list));
-
- if(msg == NULL)
- {
- DEBUG(0,("push_local_message: malloc fail (1)\n"));
- return False;
- }
-
- msg->msg_buf = (char *)malloc(msg_len);
- if(msg->msg_buf == NULL)
- {
- DEBUG(0,("push_local_message: malloc fail (2)\n"));
- free((char *)msg);
- return False;
- }
-
- memcpy(msg->msg_buf, buf, msg_len);
- msg->msg_len = msg_len;
-
- msg->msg_next = udp_msg_head;
- udp_msg_head = msg;
-
- return True;
-}
-
-/****************************************************************************
- Do a select on an two fd's - with timeout.
-
- If a local udp message has been pushed onto the
- queue (this can only happen during oplock break
- processing) return this first.
-
- If the first smbfd is ready then read an smb from it.
- if the second (loopback UDP) fd is ready then read a message
- from it and setup the buffer header to identify the length
- and from address.
- Returns False on timeout or error.
- Else returns True.
-
-The timeout is in milli seconds
-****************************************************************************/
-BOOL receive_message_or_smb(int smbfd, int oplock_fd,
- char *buffer, int buffer_len,
- int timeout, BOOL *got_smb)
-{
- fd_set fds;
- int selrtn;
- struct timeval to;
-
- *got_smb = False;
-
- /*
- * Check to see if we already have a message on the udp queue.
- * If so - copy and return it.
- */
-
- if(udp_msg_head)
- {
- udp_message_list *msg = udp_msg_head;
- memcpy(buffer, msg->msg_buf, MIN(buffer_len, msg->msg_len));
- udp_msg_head = msg->msg_next;
-
- /* Free the message we just copied. */
- free((char *)msg->msg_buf);
- free((char *)msg);
- return True;
- }
-
- FD_ZERO(&fds);
- FD_SET(smbfd,&fds);
- FD_SET(oplock_fd,&fds);
-
- to.tv_sec = timeout / 1000;
- to.tv_usec = (timeout % 1000) * 1000;
-
- selrtn = sys_select(&fds,timeout>0?&to:NULL);
-
- /* Check if error */
- if(selrtn == -1) {
- /* something is wrong. Maybe the socket is dead? */
- smb_read_error = READ_ERROR;
- return False;
- }
-
- /* Did we timeout ? */
- if (selrtn == 0) {
- smb_read_error = READ_TIMEOUT;
- return False;
- }
-
- if (FD_ISSET(smbfd,&fds))
- {
- *got_smb = True;
- return receive_smb(smbfd, buffer, 0);
- }
- else
- {
- return receive_local_message(oplock_fd, buffer, buffer_len, 0);
- }
-}
-#endif /* USE_OPLOCKS */
/****************************************************************************
send an smb to a fd
@@ -2607,8 +2346,8 @@ BOOL send_one_packet(char *buf,int len,struct in_addr ip,int port,int type)
ret = (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)));
+ DEBUG(0,("Packet send to %s(%d) failed ERRNO=%d\n",
+ inet_ntoa(ip),port,errno));
close(out_fd);
return(ret);
@@ -2860,7 +2599,7 @@ BOOL mask_match(char *str, char *regexp, int case_sig,BOOL trans2)
if (strequal(p1,"*")) return(True);
- DEBUG(8,("mask_match str=<%s> regexp=<%s>, case_sig = %d\n", p2, p1, case_sig));
+ DEBUG(5,("mask_match str=<%s> regexp=<%s>, case_sig = %d\n", p2, p1, case_sig));
if (trans2) {
fstrcpy(ebase,p1);
@@ -2888,7 +2627,7 @@ BOOL mask_match(char *str, char *regexp, int case_sig,BOOL trans2)
matched = do_match(sbase,ebase,case_sig) &&
(trans2 || do_match(sext,eext,case_sig));
- DEBUG(8,("mask_match returning %d\n", matched));
+ DEBUG(5,("mask_match returning %d\n", matched));
return matched;
}
@@ -3296,8 +3035,26 @@ int open_socket_out(int type, struct in_addr *addr, int port ,int timeout)
if (res == -1)
{ DEBUG(0,("socket error\n")); return -1; }
- if (type != SOCK_STREAM) return(res);
+#ifdef BIND_LOCAL_OUTPUT_SOCKET
+ {
+ struct sockaddr_in sock_in;
+ /* Bind the local part of this socket to the address
+ given in the socket address parameter. */
+
+ bzero((char *)&sock_in,sizeof(sock_in));
+ putip((char *)&sock_in.sin_addr,(char *)interpret_addr2(lp_socket_address()));
+ sock_in.sin_port = 0;
+ sock_in.sin_family = PF_INET;
+
+ if (bind(res, (struct sockaddr * ) &sock_in,sizeof(sock_in)) < 0)
+ DEBUG(0,("Failed to bind local socket address for output socket. Error was %s\n",
+ strerror(errno)));
+ }
+#endif /* BIND_LOCAL_OUTPUT_SOCKET */
+
+ if (type != SOCK_STREAM) return(res);
+
bzero((char *)&sock_out,sizeof(sock_out));
putip((char *)&sock_out.sin_addr,(char *)addr);
@@ -3834,24 +3591,24 @@ char *readdirname(void *p)
return(dname);
}
-/*******************************************************************
- Utility function used to decide if the last component
- of a path matches a (possibly wildcarded) entry in a namelist.
-********************************************************************/
+/*
+ * Utility function used to decide if the last component
+ * of a path matches a (possibly wildcarded) entry in a namelist.
+ */
BOOL is_in_path(char *name, name_compare_entry *namelist)
{
pstring last_component;
char *p;
- DEBUG(8, ("is_in_path: %s\n", name));
+ DEBUG(5, ("is_in_path: %s\n", name));
/* if we have no list it's obviously not in the path */
if((namelist == NULL ) || ((namelist != NULL) && (namelist[0].name == NULL)))
- {
- DEBUG(8,("is_in_path: no name list.\n"));
+ {
+ DEBUG(5,("is_in_path: no name list.\n"));
return False;
- }
+}
/* Get the last component of the unix name. */
p = strrchr(name, '/');
@@ -3865,7 +3622,7 @@ BOOL is_in_path(char *name, name_compare_entry *namelist)
/* look for a wildcard match. */
if (mask_match(last_component, namelist->name, case_sensitive, False))
{
- DEBUG(8,("is_in_path: mask match succeeded\n"));
+ DEBUG(5,("is_in_path: mask match succeeded\n"));
return True;
}
}
@@ -3874,29 +3631,29 @@ BOOL is_in_path(char *name, name_compare_entry *namelist)
if((case_sensitive && (strcmp(last_component, namelist->name) == 0))||
(!case_sensitive && (StrCaseCmp(last_component, namelist->name) == 0)))
{
- DEBUG(8,("is_in_path: match succeeded\n"));
+ DEBUG(5,("is_in_path: match succeeded\n"));
return True;
}
}
}
- DEBUG(8,("is_in_path: match not found\n"));
+ DEBUG(5,("is_in_path: match not found\n"));
return False;
}
-/*******************************************************************
- Strip a '/' separated list into an array of
- name_compare_enties structures suitable for
- passing to is_in_path(). We do this for
- speed so we can pre-parse all the names in the list
- and don't do it for each call to is_in_path().
- namelist is modified here and is assumed to be
- a copy owned by the caller.
- We also check if the entry contains a wildcard to
- remove a potentially expensive call to mask_match
- if possible.
-********************************************************************/
-
+/*
+ * Strip a '/' separated list into an array of
+ * name_compare_enties structures suitable for
+ * passing to is_in_path(). We do this for
+ * speed so we can pre-parse all the names in the list
+ * and don't do it for each call to is_in_path().
+ * namelist is modified here and is assumed to be
+ * a copy owned by the caller.
+ * We also check if the entry contains a wildcard to
+ * remove a potentially expensive call to mask_match
+ * if possible.
+ */
+
void set_namearray(name_compare_entry **ppname_array, char *namelist)
{
char *name_end;
@@ -4037,7 +3794,7 @@ BOOL fcntl_lock(int fd,int op,uint32 offset,uint32 count,int type)
#endif
- DEBUG(8,("fcntl_lock %d %d %d %d %d\n",fd,op,(int)offset,(int)count,type));
+ DEBUG(5,("fcntl_lock %d %d %d %d %d\n",fd,op,(int)offset,(int)count,type));
lock.l_type = type;
lock.l_whence = SEEK_SET;
@@ -4085,7 +3842,7 @@ BOOL fcntl_lock(int fd,int op,uint32 offset,uint32 count,int type)
}
/* everything went OK */
- DEBUG(8,("Lock call successful\n"));
+ DEBUG(5,("Lock call successful\n"));
return(True);
#else
@@ -4131,7 +3888,7 @@ void file_unlock(int fd)
is the name specified one of my netbios names
returns true is it is equal, false otherwise
********************************************************************/
-BOOL is_myname(char *s)
+BOOL is_myname(const char *s)
{
int n;
BOOL ret = False;
@@ -4182,52 +3939,53 @@ enum remote_arch_types get_remote_arch()
return ra_type;
}
+
/*******************************************************************
safe string copy into a fstring
********************************************************************/
void fstrcpy(char *dest, char *src)
{
- int maxlength = sizeof(fstring) - 1;
- if (!dest) {
- DEBUG(0,("ERROR: NULL dest in fstrcpy\n"));
- return;
- }
+ int maxlength = sizeof(fstring) - 1;
+ if (!dest) {
+ DEBUG(0,("ERROR: NULL dest in fstrcpy\n"));
+ return;
+ }
- if (!src) {
- *dest = 0;
- return;
- }
-
- while (maxlength-- && *src)
- *dest++ = *src++;
- *dest = 0;
- if (*src) {
- DEBUG(0,("ERROR: string overflow by %d in fstrcpy\n",
- strlen(src)));
- }
-}
+ if (!src) {
+ *dest = 0;
+ return;
+ }
+
+ while (maxlength-- && *src)
+ *dest++ = *src++;
+ *dest = 0;
+ if (*src) {
+ DEBUG(0,("ERROR: string overflow by %d in fstrcpy\n",
+ strlen(src)));
+ }
+}
/*******************************************************************
safe string copy into a pstring
********************************************************************/
void pstrcpy(char *dest, char *src)
{
- int maxlength = sizeof(pstring) - 1;
- if (!dest) {
- DEBUG(0,("ERROR: NULL dest in pstrcpy\n"));
- return;
- }
-
- if (!src) {
- *dest = 0;
- return;
- }
-
- while (maxlength-- && *src)
- *dest++ = *src++;
- *dest = 0;
- if (*src) {
- DEBUG(0,("ERROR: string overflow by %d in pstrcpy\n",
- strlen(src)));
- }
-}
+ int maxlength = sizeof(pstring) - 1;
+ if (!dest) {
+ DEBUG(0,("ERROR: NULL dest in pstrcpy\n"));
+ return;
+ }
+
+ if (!src) {
+ *dest = 0;
+ return;
+ }
+
+ while (maxlength-- && *src)
+ *dest++ = *src++;
+ *dest = 0;
+ if (*src) {
+ DEBUG(0,("ERROR: string overflow by %d in pstrcpy\n",
+ strlen(src)));
+ }
+}