diff options
Diffstat (limited to 'source/utils')
-rw-r--r-- | source/utils/make_unicodemap.c | 308 | ||||
-rw-r--r-- | source/utils/nbio.c | 236 |
2 files changed, 0 insertions, 544 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/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); -} |