summaryrefslogtreecommitdiffstats
path: root/source/utils
diff options
context:
space:
mode:
Diffstat (limited to 'source/utils')
-rw-r--r--source/utils/make_unicodemap.c308
-rw-r--r--source/utils/masktest.c485
-rw-r--r--source/utils/nbio.c236
3 files changed, 0 insertions, 1029 deletions
diff --git a/source/utils/make_unicodemap.c b/source/utils/make_unicodemap.c
deleted file mode 100644
index 76c49361bec..00000000000
--- a/source/utils/make_unicodemap.c
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- Unix SMB/Netbios implementation.
- Version 2.0.x.
- Create unicode map files from unicode_def.XXX files.
-
- Copyright (C) Jeremy Allison 1997-1999.
-
- 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"
-
-static char *prog_name = NULL;
-
-/*
- * Print program usage and die.
- */
-
-static void unicode_map_usage(char *progname)
-{
- fprintf(stderr, "Usage is : %s <codepage> <inputfile> <outputfile>\n",
- progname);
- exit(1);
-}
-
-/*
- * Read a line from a buffer into a line buffer. Ensure null
- * terminated.
- */
-
-static void read_line( char **buf, char *line_buf, size_t size)
-{
- char *p = *buf;
- size_t num = 0;
-
- for(; *p && (*p != '\n') && (*p != '\032'); p++) {
- if(num < (size - 1))
- line_buf[num++] = *p;
- }
- if(*p)
- p++; /* Go past the '\n' */
- line_buf[num] = '\0';
- *buf = p;
-}
-
-/*
- * Strip comment lines and blank lines from the data.
- * Copies into a new buffer and frees the old.
- * Returns the number of lines copied.
- */
-
-static size_t clean_data( char **buf, size_t *size)
-{
- pstring linebuf;
- char *p = *buf;
- size_t num_lines = 0;
- char *newbuf = (char *)malloc( *size + 1);
- char *newbuf_p = NULL;
-
- if(newbuf == NULL) {
- fprintf(stderr, "%s: malloc fail for size %u.\n", prog_name, (unsigned int)(*size + 1));
- exit(1);
- }
-
- newbuf_p = newbuf;
- *newbuf_p = '\0';
-
- while( *p ) {
- char *cp;
-
- read_line( &p, linebuf, sizeof(linebuf));
- /* Null terminate after comment. */
- if((cp = strchr( linebuf, '#'))!= NULL)
- *cp = '\0';
-
- for(cp = linebuf;*cp && isspace(*cp); cp++)
- ;
-
- if(*cp == '\0')
- continue;
-
- safe_strcpy(newbuf_p, cp, *size - (newbuf_p - newbuf));
- num_lines++;
- newbuf_p += (strlen(newbuf_p) + 1);
- }
-
- free(*buf);
- *buf = newbuf;
- return num_lines;
-}
-
-/*
- * Parse a uint16 from a codepage file.
- */
-
-static BOOL parse_uint16(char *buf, uint16 *uip)
-{
- unsigned int ui;
- char *endptr = NULL;
-
- ui = (unsigned int)strtol(buf, &endptr, 0);
- if(endptr == buf || ui > 65535)
- return False;
-
- *uip = (uint16)ui;
- return True;
-}
-
-/*
- * Print a parse error and exit.
- */
-
-static void parse_error(const char *buf, const char *input_file, const char *msg)
-{
- fprintf(stderr, "%s: In file %s : %s whilst parsing line \n%s\n", prog_name,
- input_file, msg, buf);
- exit(1);
-}
-
-/*
- * Create a compiled unicode map file from a unicode map definition file.
- */
-
-static int do_compile(const char *codepage, const char *input_file, const char *output_file)
-{
- FILE *fp = NULL;
- size_t size = 0;
- size_t offset = 0;
- char *buf = NULL;
- char *output_buf = NULL;
- uint16 cp_to_ucs2[65536];
- uint16 ucs2_to_cp[65536];
- BOOL multibyte_code_page = False;
- int num_lines = 0;
- int i = 0;
- SMB_STRUCT_STAT st;
-
- /* Get the size of the input file. Read the entire thing into memory. */
- if(sys_stat((char *)input_file, &st)!= 0) {
- fprintf(stderr, "%s: failed to get the file size for file %s. Error was %s\n",
- prog_name, input_file, strerror(errno));
- exit(1);
- }
-
- size = (size_t)st.st_size;
-
- if((fp = sys_fopen(input_file, "r")) == NULL) {
- fprintf(stderr, "%s: cannot open file %s for input.\n", prog_name, input_file);
- exit(1);
- }
-
- /* As we will be reading text, allocate one more byte for a '\0' */
- if((buf = (char *)malloc( size + 1 )) == NULL) {
- fprintf(stderr, "%s: malloc fail for size %d.\n", prog_name, size + 1);
- fclose(fp);
- exit(1);
- }
-
- if(fread( buf, 1, size, fp) != size) {
- fprintf(stderr, "%s: read failed for file %s. Error was %s.\n", prog_name,
- input_file, strerror(errno));
- free((char *)buf);
- fclose(fp);
- exit(1);
- }
-
- /* Null terminate the text read. */
- buf[size] = '\0';
-
- /* Go through the data line by line, strip out comments (anything
- after a '#' to end-of-line) and blank lines. The rest should be
- the codepage data.
- */
-
- num_lines = clean_data( &buf, &size);
-
- /*
- * Initialize the output data.
- */
-
- memset(cp_to_ucs2, '\0', sizeof(cp_to_ucs2));
- ucs2_to_cp[0] = 0;
- for (i = 1; i < 65536; i++)
- ucs2_to_cp[i] = (uint16)'_';
-
- /* Now convert the lines into the compiled form. */
-
- for(i = 0; i < num_lines; i++) {
- char token_buf[512];
- char *p = buf;
- uint16 cp = 0;
- uint16 ucs2 = 0;
-
- /* Get the codepage value. */
- if(!next_token(&p, token_buf, NULL, sizeof(token_buf)))
- parse_error(buf, input_file, "cannot parse first value");
-
- if(!parse_uint16( token_buf, &cp))
- parse_error(buf, input_file, "first value doesn't resolve to an unsigned 16 bit integer");
-
- if(cp > 255)
- multibyte_code_page = True;
-
- /* Get the ucs2 value. */
-
- if(!next_token(&p, token_buf, NULL, sizeof(token_buf))) {
-
- /*
- * Some of the multibyte codepage to unicode map files
- * list a single byte as a leading multibyte and have no
- * second value.
- */
-
- buf += (strlen(buf) + 1);
- continue;
- }
-
- if(!parse_uint16( token_buf, &ucs2))
- parse_error(buf, input_file, "second value doesn't resolve to an unsigned 16 bit integer");
-
- /*
- * Set up the cross reference in little-endian format.
- */
-
- SSVAL(((char *)&cp_to_ucs2[cp]),0,ucs2);
- SSVAL(((char *)&ucs2_to_cp[ucs2]),0,cp);
-
- /*
- * Next line.
- */
- buf += (strlen(buf) + 1);
- }
-
- size = UNICODE_MAP_HEADER_SIZE + (multibyte_code_page ? (4*65536) : (2*256 + 2*65536));
-
- if((output_buf = (char *)malloc( size )) == NULL) {
- fprintf(stderr, "%s: output buffer malloc fail for size %d.\n", prog_name, size);
- fclose(fp);
- exit(1);
- }
-
- /* Setup the output file header. */
- SSVAL(output_buf,UNICODE_MAP_VERSION_OFFSET,UNICODE_MAP_FILE_VERSION_ID);
- memset(&output_buf[UNICODE_MAP_CLIENT_CODEPAGE_OFFSET],'\0',UNICODE_MAP_CODEPAGE_ID_SIZE);
- safe_strcpy(&output_buf[UNICODE_MAP_CLIENT_CODEPAGE_OFFSET], codepage, UNICODE_MAP_CODEPAGE_ID_SIZE - 1);
- output_buf[UNICODE_MAP_CLIENT_CODEPAGE_OFFSET+UNICODE_MAP_CODEPAGE_ID_SIZE-1] = '\0';
-
- offset = UNICODE_MAP_HEADER_SIZE;
-
- if (multibyte_code_page) {
- SIVAL(output_buf,UNICODE_MAP_CP_TO_UNICODE_LENGTH_OFFSET,2*65536);
- memcpy(output_buf+offset, (char *)cp_to_ucs2, 2*65536);
- offset += 2*65536;
- } else {
- SIVAL(output_buf,UNICODE_MAP_CP_TO_UNICODE_LENGTH_OFFSET,2*256);
- memcpy(output_buf+offset, (char *)cp_to_ucs2, 2*256);
- offset += 2*256;
- }
- SIVAL(output_buf,UNICODE_MAP_UNICODE_TO_CP_LENGTH_OFFSET,65536*2);
- memcpy(output_buf+offset, (char *)ucs2_to_cp, 2*65536);
-
- /* Now write out the output_buf. */
- if((fp = sys_fopen(output_file, "w"))==NULL) {
- fprintf(stderr, "%s: Cannot open output file %s. Error was %s.\n",
- prog_name, output_file, strerror(errno));
- exit(1);
- }
-
- if(fwrite(output_buf, 1, size, fp) != size) {
- fprintf(stderr, "%s: Cannot write output file %s. Error was %s.\n",
- prog_name, output_file, strerror(errno));
- exit(1);
- }
-
- fclose(fp);
-
- return 0;
-}
-
-int main(int argc, char **argv)
-{
- const char *codepage = NULL;
- char *input_file = NULL;
- char *output_file = NULL;
-
- prog_name = argv[0];
-
- if(argc != 4)
- unicode_map_usage(prog_name);
-
- codepage = argv[1];
- input_file = argv[2];
- output_file = argv[3];
-
- return do_compile( codepage, input_file, output_file);
-}
diff --git a/source/utils/masktest.c b/source/utils/masktest.c
deleted file mode 100644
index f7b6ad1b1b8..00000000000
--- a/source/utils/masktest.c
+++ /dev/null
@@ -1,485 +0,0 @@
-/*
- Unix SMB/Netbios implementation.
- Version 2.0
- mask_match tester
- Copyright (C) Andrew Tridgell 1999
-
- 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.
-*/
-
-#define NO_SYSLOG
-
-#include "includes.h"
-
-extern int DEBUGLEVEL;
-static fstring password;
-static fstring username;
-static fstring workgroup;
-static int got_pass;
-
-static BOOL showall = False;
-
-static char *maskchars = "<>\"?*abc.";
-static char *filechars = "abcdefghijklm.";
-
-char *standard_masks[] = {"*", "*.", "*.*",
- ".*", "d2.??", "d2\">>", "??",
- NULL};
-char *standard_files[] = {"abc", "abc.", ".abc",
- "abc.def", "abc.de.f",
- "d2.x",
- NULL};
-
-
-#include <regex.h>
-
-static BOOL reg_match_one(char *pattern, char *file)
-{
- pstring rpattern;
- pstring rfile;
-
- pstrcpy(rpattern, pattern);
-
- if (strcmp(file,"..") == 0) file = ".";
- if (strcmp(rpattern,".") == 0) return False;
-
- all_string_sub(rpattern,"\"", ".", 0);
- all_string_sub(rpattern,"<", "*", 0);
-
- all_string_sub(rpattern,"*>", "*", 0);
- all_string_sub(rpattern,">*", "*", 0);
- all_string_sub(rpattern,">", "?", 0);
-
- if (is_8_3(file, False)) {
- return fnmatch(rpattern, file, 0)==0;
- }
-
- pstrcpy(rfile, file);
- mangle_name_83(rfile);
- strlower(rfile);
-
- return (fnmatch(rpattern, file, 0)==0 ||
- fnmatch(rpattern, rfile, 0)==0);
-}
-
-static BOOL regex_reg_match_one(char *pattern, char *file)
-{
- pstring rpattern;
- regex_t preg;
- BOOL ret = False;
-
- return fnmatch(pattern, file, 0)==0;
-
- if (strcmp(file,"..") == 0) file = ".";
- if (strcmp(pattern,".") == 0) return False;
-
- if (strcmp(pattern,"") == 0) {
- if (strcmp(file,".") == 0) return False;
- return True;
- }
-
- pstrcpy(rpattern,"^");
- pstrcat(rpattern, pattern);
-
- all_string_sub(rpattern,".", "[.]", 0);
- all_string_sub(rpattern,"?", ".{1}", 0);
- all_string_sub(rpattern,"*", ".*", 0);
- all_string_sub(rpattern+strlen(rpattern)-1,">", "([^.]?|[.]?$)", 0);
- all_string_sub(rpattern,">", "[^.]?", 0);
-
- all_string_sub(rpattern,"<[.]", ".*[.]", 0);
- all_string_sub(rpattern,"<\"", "(.*[.]|.*$)", 0);
- all_string_sub(rpattern,"<", "([^.]*|[^.]*[.]|[.][^.]*|[.].*[.])", 0);
- if (strlen(pattern)>1) {
- all_string_sub(rpattern+strlen(rpattern)-1,"\"", "[.]?", 0);
- }
- all_string_sub(rpattern,"\"", "([.]|$)", 0);
- pstrcat(rpattern,"$");
-
- /* printf("pattern=[%s] rpattern=[%s]\n", pattern, rpattern); */
-
- regcomp(&preg, rpattern, REG_ICASE|REG_NOSUB|REG_EXTENDED);
- ret = (regexec(&preg, file, 0, NULL, 0) == 0);
-
- regfree(&preg);
-
- return ret;
-}
-
-static char *reg_test(char *pattern, char *file)
-{
- static fstring ret;
- fstrcpy(ret, "---");
-
- pattern = 1+strrchr(pattern,'\\');
- file = 1+strrchr(file,'\\');
-
- if (reg_match_one(pattern, ".")) ret[0] = '+';
- if (reg_match_one(pattern, "..")) ret[1] = '+';
- if (reg_match_one(pattern, file)) ret[2] = '+';
- return ret;
-}
-
-
-/*****************************************************
-return a connection to a server
-*******************************************************/
-struct cli_state *connect_one(char *share)
-{
- struct cli_state *c;
- struct nmb_name called, calling;
- char *server_n;
- char *server;
- struct in_addr ip;
- extern struct in_addr ipzero;
-
- server = share+2;
- share = strchr(server,'\\');
- if (!share) return NULL;
- *share = 0;
- share++;
-
- server_n = server;
-
- ip = ipzero;
-
- make_nmb_name(&calling, "masktest", 0x0);
- make_nmb_name(&called , server, 0x20);
-
- again:
- ip = ipzero;
-
- /* have to open a new connection */
- if (!(c=cli_initialise(NULL)) || (cli_set_port(c, 139) == 0) ||
- !cli_connect(c, server_n, &ip)) {
- DEBUG(0,("Connection to %s failed\n", server_n));
- return NULL;
- }
-
- if (!cli_session_request(c, &calling, &called)) {
- DEBUG(0,("session request to %s failed\n", called.name));
- cli_shutdown(c);
- if (strcmp(called.name, "*SMBSERVER")) {
- make_nmb_name(&called , "*SMBSERVER", 0x20);
- goto again;
- }
- return NULL;
- }
-
- DEBUG(4,(" session request ok\n"));
-
- if (!cli_negprot(c)) {
- DEBUG(0,("protocol negotiation failed\n"));
- cli_shutdown(c);
- return NULL;
- }
-
- if (!got_pass) {
- char *pass = getpass("Password: ");
- if (pass) {
- pstrcpy(password, pass);
- }
- }
-
- if (!cli_session_setup(c, username,
- password, strlen(password),
- password, strlen(password),
- workgroup)) {
- DEBUG(0,("session setup failed: %s\n", cli_errstr(c)));
- return NULL;
- }
-
- /*
- * These next two lines are needed to emulate
- * old client behaviour for people who have
- * scripts based on client output.
- * QUESTION ? Do we want to have a 'client compatibility
- * mode to turn these on/off ? JRA.
- */
-
- if (*c->server_domain || *c->server_os || *c->server_type)
- DEBUG(1,("Domain=[%s] OS=[%s] Server=[%s]\n",
- c->server_domain,c->server_os,c->server_type));
-
- DEBUG(4,(" session setup ok\n"));
-
- if (!cli_send_tconX(c, share, "?????",
- password, strlen(password)+1)) {
- DEBUG(0,("tree connect failed: %s\n", cli_errstr(c)));
- cli_shutdown(c);
- return NULL;
- }
-
- DEBUG(4,(" tconx ok\n"));
-
- return c;
-}
-
-static char *resultp;
-
-void listfn(file_info *f, const char *s)
-{
- if (strcmp(f->name,".") == 0) {
- resultp[0] = '+';
- } else if (strcmp(f->name,"..") == 0) {
- resultp[1] = '+';
- } else {
- resultp[2] = '+';
- }
-}
-
-
-static void testpair(struct cli_state *cli1, struct cli_state *cli2,
- char *mask, char *file)
-{
- int fnum;
- fstring res1, res2;
- char *res3;
- static int count;
-
- count++;
-
- fstrcpy(res1, "---");
- fstrcpy(res2, "---");
-
- fnum = cli_open(cli1, file, O_CREAT|O_TRUNC|O_RDWR, 0);
- if (fnum == -1) {
- DEBUG(0,("Can't create %s on cli1\n", file));
- return;
- }
- cli_close(cli1, fnum);
-
- fnum = cli_open(cli2, file, O_CREAT|O_TRUNC|O_RDWR, 0);
- if (fnum == -1) {
- DEBUG(0,("Can't create %s on cli2\n", file));
- return;
- }
- cli_close(cli2, fnum);
-
- resultp = res1;
- cli_list(cli1, mask, aHIDDEN | aDIR, listfn);
-
- res3 = reg_test(mask, file);
-
- resultp = res2;
- cli_list(cli2, mask, aHIDDEN | aDIR, listfn);
-
- if (showall || strcmp(res1, res3)) {
- char *p;
- pstring rfile;
- p = strrchr(file,'\\');
- pstrcpy(rfile, p+1);
- mangle_name_83(rfile);
- strlower(rfile);
- DEBUG(0,("%s %s %s %d mask=[%s] file=[%s] mfile=[%s]\n",
- res1, res2, res3, count, mask, file, rfile));
- }
-
- cli_unlink(cli1, file);
- cli_unlink(cli2, file);
-
-
- if (count % 500 == 0) DEBUG(0,("%d\n", count));
-}
-
-static void test_mask(int argc, char *argv[],
- struct cli_state *cli1, struct cli_state *cli2)
-{
- pstring mask, file;
- int l1, l2, i, j, l;
- int mc_len = strlen(maskchars);
- int fc_len = strlen(filechars);
-
- cli_mkdir(cli1, "masktest");
- cli_mkdir(cli2, "masktest");
-
- cli_unlink(cli1, "\\masktest\\*");
- cli_unlink(cli2, "\\masktest\\*");
-
- if (argc >= 2) {
- while (argc >= 2) {
- pstrcpy(mask,"\\masktest\\");
- pstrcpy(file,"\\masktest\\");
- pstrcat(mask, argv[0]);
- pstrcat(file, argv[1]);
- testpair(cli1, cli2, mask, file);
- argv += 2;
- argc -= 2;
- }
- goto finished;
- }
-
-#if 1
- for (i=0; standard_masks[i]; i++) {
- for (j=0; standard_files[j]; j++) {
- pstrcpy(mask,"\\masktest\\");
- pstrcpy(file,"\\masktest\\");
- pstrcat(mask, standard_masks[i]);
- pstrcat(file, standard_files[j]);
- testpair(cli1, cli2, mask, file);
- }
- }
-#endif
-
- while (1) {
- l1 = 1 + random() % 20;
- l2 = 1 + random() % 20;
- pstrcpy(mask,"\\masktest\\");
- pstrcpy(file,"\\masktest\\");
- l = strlen(mask);
- for (i=0;i<l1;i++) {
- mask[i+l] = maskchars[random() % mc_len];
- }
- mask[l+l1] = 0;
-
- for (i=0;i<l2;i++) {
- file[i+l] = filechars[random() % fc_len];
- }
- file[l+l2] = 0;
-
- if (strcmp(file+l,".") == 0 ||
- strcmp(file+l,"..") == 0 ||
- strcmp(mask+l,"..") == 0) continue;
-
- testpair(cli1, cli2, mask, file);
- }
-
- finished:
- cli_rmdir(cli1, "\\masktest");
- cli_rmdir(cli2, "\\masktest");
-}
-
-
-static void usage(void)
-{
- printf(
-"Usage:\n\
- masktest //server1/share1 //server2/share2 [options..]\n\
- options:\n\
- -U user%%pass\n\
- -s seed\n\
- -f filechars (default %s)\n\
- -m maskchars (default %s)\n\
- -a show all tests\n\
-\n\
- This program tests wildcard matching between two servers. It generates\n\
- random pairs of filenames/masks and tests that they match in the same\n\
- way on two servers\n\
-",
- filechars, maskchars);
-}
-
-/****************************************************************************
- main program
-****************************************************************************/
- int main(int argc,char *argv[])
-{
- char *share1, *share2;
- struct cli_state *cli1, *cli2;
- extern char *optarg;
- extern int optind;
- extern FILE *dbf;
- int opt;
- char *p;
- int seed;
- static pstring servicesf = CONFIGFILE;
-
- setlinebuf(stdout);
-
- dbf = stderr;
-
- if (argv[1][0] == '-' || argc < 3) {
- usage();
- exit(1);
- }
-
- share1 = argv[1];
- share2 = argv[2];
-
- all_string_sub(share1,"/","\\",0);
- all_string_sub(share2,"/","\\",0);
-
- setup_logging(argv[0],True);
-
- argc -= 2;
- argv += 2;
-
- TimeInit();
- charset_initialise();
-
- lp_load(servicesf,True,False,False);
- load_interfaces();
-
- if (getenv("USER")) {
- pstrcpy(username,getenv("USER"));
- }
-
- seed = time(NULL);
-
- while ((opt = getopt(argc, argv, "U:s:hm:f:a")) != EOF) {
- switch (opt) {
- case 'U':
- pstrcpy(username,optarg);
- p = strchr(username,'%');
- if (p) {
- *p = 0;
- pstrcpy(password, p+1);
- got_pass = 1;
- }
- break;
- case 's':
- seed = atoi(optarg);
- break;
- case 'h':
- usage();
- exit(1);
- case 'm':
- maskchars = optarg;
- break;
- case 'f':
- filechars = optarg;
- break;
- case 'a':
- showall = 1;
- break;
- default:
- printf("Unknown option %c (%d)\n", (char)opt, opt);
- exit(1);
- }
- }
-
- argc -= optind;
- argv += optind;
-
- DEBUG(0,("seed=%d\n", seed));
- srandom(seed);
-
- cli1 = connect_one(share1);
- if (!cli1) {
- DEBUG(0,("Failed to connect to %s\n", share1));
- exit(1);
- }
-
- cli2 = connect_one(share2);
- if (!cli2) {
- DEBUG(0,("Failed to connect to %s\n", share2));
- exit(1);
- }
-
-
- test_mask(argc, argv, cli1, cli2);
-
- return(0);
-}
diff --git a/source/utils/nbio.c b/source/utils/nbio.c
deleted file mode 100644
index f72be36842f..00000000000
--- a/source/utils/nbio.c
+++ /dev/null
@@ -1,236 +0,0 @@
-#define NBDEBUG 0
-
-/*
- Unix SMB/Netbios implementation.
- Version 1.9.
- SMB torture tester
- Copyright (C) Andrew Tridgell 1997-1998
-
- 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.
-*/
-
-#define NO_SYSLOG
-
-#include "includes.h"
-
-#define MAX_FILES 1000
-
-static char buf[70000];
-extern int line_count;
-
-static struct {
- int fd;
- int handle;
-} ftable[MAX_FILES];
-
-static struct cli_state *c;
-
-static void sigsegv(int sig)
-{
- char line[200];
- printf("segv at line %d\n", line_count);
- slprintf(line, sizeof(line), "/usr/X11R6/bin/xterm -e gdb /proc/%d/exe %d",
- (int)getpid(), (int)getpid());
- system(line);
- exit(1);
-}
-
-void nb_setup(struct cli_state *cli)
-{
- signal(SIGSEGV, sigsegv);
- /* to be like a true Windows client we need to negotiate oplocks */
- cli->use_oplocks = True;
- c = cli;
-}
-
-
-void nb_unlink(char *fname)
-{
- strupper(fname);
-
- if (!cli_unlink(c, fname)) {
-#if NBDEBUG
- printf("(%d) unlink %s failed (%s)\n",
- line_count, fname, cli_errstr(c));
-#endif
- }
-}
-
-void nb_open(char *fname, int handle, int size)
-{
- int fd, i;
- int flags = O_RDWR|O_CREAT;
- size_t st_size;
- static int count;
-
- strupper(fname);
-
- if (size == 0) flags |= O_TRUNC;
-
- fd = cli_open(c, fname, flags, DENY_NONE);
- if (fd == -1) {
-#if NBDEBUG
- printf("(%d) open %s failed for handle %d (%s)\n",
- line_count, fname, handle, cli_errstr(c));
-#endif
- return;
- }
- cli_getattrE(c, fd, NULL, &st_size, NULL, NULL, NULL);
- if (size > st_size) {
-#if NBDEBUG
- printf("(%d) needs expanding %s to %d from %d\n",
- line_count, fname, size, (int)st_size);
-#endif
- } else if (size < st_size) {
-#if NBDEBUG
- printf("(%d) needs truncating %s to %d from %d\n",
- line_count, fname, size, (int)st_size);
-#endif
- }
- for (i=0;i<MAX_FILES;i++) {
- if (ftable[i].handle == 0) break;
- }
- if (i == MAX_FILES) {
- printf("file table full for %s\n", fname);
- exit(1);
- }
- ftable[i].handle = handle;
- ftable[i].fd = fd;
- if (count++ % 100 == 0) {
- printf(".");
- }
-}
-
-void nb_write(int handle, int size, int offset)
-{
- int i;
-
- if (buf[0] == 0) memset(buf, 1, sizeof(buf));
-
- for (i=0;i<MAX_FILES;i++) {
- if (ftable[i].handle == handle) break;
- }
- if (i == MAX_FILES) {
-#if NBDEBUG
- printf("(%d) nb_write: handle %d was not open size=%d ofs=%d\n",
- line_count, handle, size, offset);
-#endif
- return;
- }
- if (cli_smbwrite(c, ftable[i].fd, buf, offset, size) != size) {
- printf("(%d) write failed on handle %d\n",
- line_count, handle);
- }
-}
-
-void nb_read(int handle, int size, int offset)
-{
- int i, ret;
-
- for (i=0;i<MAX_FILES;i++) {
- if (ftable[i].handle == handle) break;
- }
- if (i == MAX_FILES) {
- printf("(%d) nb_read: handle %d was not open size=%d ofs=%d\n",
- line_count, handle, size, offset);
- return;
- }
- if ((ret=cli_read(c, ftable[i].fd, buf, offset, size)) != size) {
-#if NBDEBUG
- printf("(%d) read failed on handle %d ofs=%d size=%d res=%d\n",
- line_count, handle, offset, size, ret);
-#endif
- }
-}
-
-void nb_close(int handle)
-{
- int i;
- for (i=0;i<MAX_FILES;i++) {
- if (ftable[i].handle == handle) break;
- }
- if (i == MAX_FILES) {
- printf("(%d) nb_close: handle %d was not open\n",
- line_count, handle);
- return;
- }
- cli_close(c, ftable[i].fd);
- ftable[i].handle = 0;
-}
-
-void nb_mkdir(char *fname)
-{
- strupper(fname);
-
- if (!cli_mkdir(c, fname)) {
-#if NBDEBUG
- printf("mkdir %s failed (%s)\n",
- fname, cli_errstr(c));
-#endif
- }
-}
-
-void nb_rmdir(char *fname)
-{
- strupper(fname);
-
- if (!cli_rmdir(c, fname)) {
-#if NBDEBUG
- printf("rmdir %s failed (%s)\n",
- fname, cli_errstr(c));
-#endif
- }
-}
-
-void nb_rename(char *old, char *new)
-{
- strupper(old);
- strupper(new);
-
- if (!cli_rename(c, old, new)) {
-#if NBDEBUG
- printf("rename %s %s failed (%s)\n",
- old, new, cli_errstr(c));
-#endif
- }
-}
-
-
-void nb_stat(char *fname, int size)
-{
- size_t st_size;
-
- strupper(fname);
-
- if (!cli_getatr(c, fname, NULL, &st_size, NULL)) {
-#if NBDEBUG
- printf("(%d) nb_stat: %s size=%d %s\n",
- line_count, fname, size, cli_errstr(c));
-#endif
- return;
- }
- if (st_size != size) {
-#if NBDEBUG
- printf("(%d) nb_stat: %s wrong size %d %d\n",
- line_count, fname, (int)st_size, size);
-#endif
- }
-}
-
-void nb_create(char *fname, int size)
-{
- nb_open(fname, 5000, size);
- nb_close(5000);
-}