From 0e8fd3398771da2f016d72830179507f3edda51b Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Sat, 4 May 1996 07:50:46 +0000 Subject: Initial version imported to CVS (This used to be commit 291551d80711daab7b7581720bcd9a08d6096517) --- source3/utils/nmblookup.c | 217 ++++++++++++++++++++++ source3/utils/smbpasswd.c | 456 ++++++++++++++++++++++++++++++++++++++++++++++ source3/utils/status.c | 258 ++++++++++++++++++++++++++ source3/utils/testparm.c | 113 ++++++++++++ source3/utils/testprns.c | 72 ++++++++ 5 files changed, 1116 insertions(+) create mode 100644 source3/utils/nmblookup.c create mode 100644 source3/utils/smbpasswd.c create mode 100644 source3/utils/status.c create mode 100644 source3/utils/testparm.c create mode 100644 source3/utils/testprns.c (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c new file mode 100644 index 0000000000..aa43173332 --- /dev/null +++ b/source3/utils/nmblookup.c @@ -0,0 +1,217 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT client - used to lookup netbios names + Copyright (C) Andrew Tridgell 1994-1995 + + 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 SYSLOG +#undef SYSLOG +#endif + +#include "includes.h" +#include "nameserv.h" + +extern int DEBUGLEVEL; + +extern pstring scope; + +extern struct in_addr bcast_ip; +extern pstring myhostname; + +static BOOL got_bcast = False; + +int ServerFD= -1; + +/**************************************************************************** + open the socket communication + **************************************************************************/ +static BOOL open_sockets(void) +{ + struct hostent *hp; + + /* get host info */ + if ((hp = Get_Hostbyname(myhostname)) == 0) + { + DEBUG(0,( "Get_Hostbyname: Unknown host. %s\n",myhostname)); + return False; + } + + ServerFD = open_socket_in(SOCK_DGRAM, 0,3); + + if (ServerFD == -1) + return(False); + + set_socket_options(ServerFD,"SO_BROADCAST"); + + DEBUG(3, ("Socket opened.\n")); + return True; +} + + +/**************************************************************************** + initialise connect, service and file structs +****************************************************************************/ +static BOOL init_structs(void ) +{ + struct in_addr myip; + + if (!get_myname(myhostname,&myip)) + return(False); + + /* Read the broadcast address from the interface */ + { + struct in_addr ip0,ip2; + + ip0 = myip; + + if (!got_bcast) { + get_broadcast(&ip0,&bcast_ip,&ip2); + + DEBUG(2,("Using broadcast %s\n",inet_ntoa(bcast_ip))); + } + } + + return True; +} + +/**************************************************************************** +usage on the program +****************************************************************************/ +static void usage(void) +{ + printf("Usage: nmblookup [-M] [-B bcast address] [-d debuglevel] name\n"); + printf("Version %s\n",VERSION); + printf("\t-d debuglevel set the debuglevel\n"); + printf("\t-B broadcast address the address to use for broadcasts\n"); + printf("\t-M searches for a master browser\n"); + printf("\t-S lookup node status as well\n"); + printf("\n"); +} + + +/**************************************************************************** + main program +****************************************************************************/ +int main(int argc,char *argv[]) +{ + int opt; + unsigned int lookup_type = 0x20; + pstring lookup; + extern int optind; + extern char *optarg; + BOOL find_master=False; + BOOL find_status=False; + int i; + + DEBUGLEVEL = 1; + *lookup = 0; + + TimeInit(); + + setup_logging(argv[0],True); + + charset_initialise(); + + while ((opt = getopt(argc, argv, "p:d:B:i:SMh")) != EOF) + switch (opt) + { + case 'B': + { + unsigned long a = interpret_addr(optarg); + putip((char *)&bcast_ip,(char *)&a); + got_bcast = True; + } + break; + case 'i': + strcpy(scope,optarg); + strupper(scope); + break; + case 'M': + find_master = True; + break; + case 'S': + find_status = True; + break; + case 'd': + DEBUGLEVEL = atoi(optarg); + break; + case 'h': + usage(); + exit(0); + break; + default: + usage(); + exit(1); + } + + if (argc < 2) { + usage(); + exit(1); + } + + init_structs(); + if (!open_sockets()) return(1); + + DEBUG(1,("Sending queries to %s\n",inet_ntoa(bcast_ip))); + + + for (i=optind;i= (PTR_DIFF(p, linebuf) + 33)) && (p[32] == ':')) { + /* NT Entry was valid - even if 'X' or '*', can be overwritten */ + *got_valid_nt_entry = True; + if (*p != '*' && *p != 'X') { + if(gethexpwd(p,smbntpwd)) + pw_buf.smb_nt_passwd = smbntpwd; + } + } + pw_buf.smb_name = user_name; + pw_buf.smb_userid = uidval; + pw_buf.smb_passwd = NULL; /* No password */ + return (&pw_buf); + } + if (linebuf_len < (PTR_DIFF(p, linebuf) + 33)) + return (False); + + if (p[32] != ':') + return (False); + + if (!strncasecmp(p, "NO PASSWORD", 11)) { + pw_buf.smb_passwd = NULL; /* No password */ + } else { + if(!gethexpwd(p,smbpwd)) + return False; + pw_buf.smb_passwd = smbpwd; + } + + pw_buf.smb_name = user_name; + pw_buf.smb_userid = uidval; + pw_buf.smb_nt_passwd = NULL; + *got_valid_nt_entry = False; + *valid_old_pwd = True; + + /* Now check if the NT compatible password is + available. */ + p += 33; /* Move to the first character of the line after + the lanman password. */ + if ((linebuf_len >= (PTR_DIFF(p, linebuf) + 33)) && (p[32] == ':')) { + /* NT Entry was valid - even if 'X' or '*', can be overwritten */ + *got_valid_nt_entry = True; + if (*p != '*' && *p != 'X') { + if(gethexpwd(p,smbntpwd)) + pw_buf.smb_nt_passwd = smbntpwd; + } + } + return &pw_buf; + } + return NULL; +} + +/* + * Print command usage on stderr and die. + */ +void +usage(char *name) +{ + fprintf(stderr, "Usage is : %s [username]\n", name); + exit(1); +} + +int main(int argc, char **argv) +{ + int real_uid; + struct passwd *pwd; + fstring old_passwd; + uchar old_p16[16]; + uchar old_nt_p16[16]; + fstring new_passwd; + uchar new_p16[16]; + uchar new_nt_p16[16]; + char *p; + struct smb_passwd *smb_pwent; + FILE *fp; + BOOL valid_old_pwd = False; + BOOL got_valid_nt_entry = False; + long seekpos; + int pwfd; + char ascii_p16[66]; + char c; + int ret, i, err, writelen; + int lockfd = -1; + char *pfile = SMB_PASSWD_FILE; + char readbuf[16 * 1024]; + + setup_logging(argv[0],True); + + charset_initialise(); + +#ifndef DEBUG_PASSWORD + /* Check the effective uid */ + if (geteuid() != 0) { + fprintf(stderr, "%s: Must be setuid root.\n", argv[0]); + exit(1); + } +#endif + + /* Get the real uid */ + real_uid = getuid(); + + /* Deal with usage problems */ + if (real_uid == 0) { + /* As root we can change anothers password. */ + if (argc != 1 && argc != 2) + usage(argv[0]); + } else if (argc != 1) + usage(argv[0]); + + + if (real_uid == 0 && argc == 2) { + /* If we are root we can change anothers password. */ + strncpy(user_name, argv[1], sizeof(user_name) - 1); + user_name[sizeof(user_name) - 1] = '\0'; + pwd = getpwnam(user_name); + } else { + pwd = getpwuid(real_uid); + } + + if (pwd == 0) { + fprintf(stderr, "%s: Unable to get UNIX password entry for user.\n", argv[0]); + exit(1); + } + /* If we are root we don't ask for the old password. */ + old_passwd[0] = '\0'; + if (real_uid != 0) { + p = getpass("Old SMB password:"); + strncpy(old_passwd, p, sizeof(fstring)); + old_passwd[sizeof(fstring)-1] = '\0'; + } + new_passwd[0] = '\0'; + p = getpass("New SMB password:"); + strncpy(new_passwd, p, sizeof(fstring)); + new_passwd[sizeof(fstring)-1] = '\0'; + p = getpass("Retype new SMB password:"); + if (strcmp(p, new_passwd)) { + fprintf(stderr, "%s: Mismatch - password unchanged.\n", argv[0]); + exit(1); + } + + if (new_passwd[0] == '\0') { + printf("Password not set\n"); + exit(0); + } + + /* Calculate the MD4 hash (NT compatible) of the old and new passwords */ + memset(old_nt_p16, '\0', 16); + E_md4hash((uchar *)old_passwd, old_nt_p16); + + memset(new_nt_p16, '\0', 16); + E_md4hash((uchar *) new_passwd, new_nt_p16); + + /* Mangle the passwords into Lanman format */ + old_passwd[14] = '\0'; + strupper(old_passwd); + new_passwd[14] = '\0'; + strupper(new_passwd); + + /* + * Calculate the SMB (lanman) hash functions of both old and new passwords. + */ + + memset(old_p16, '\0', 16); + E_P16((uchar *) old_passwd, old_p16); + + memset(new_p16, '\0', 16); + E_P16((uchar *) new_passwd, new_p16); + + /* + * Open the smbpaswd file XXXX - we need to parse smb.conf to get the + * filename + */ + if ((fp = fopen(pfile, "r+")) == NULL) { + err = errno; + fprintf(stderr, "%s: Failed to open password file %s.\n", + argv[0], pfile); + errno = err; + perror(argv[0]); + exit(err); + } + /* Set read buffer to 16k for effiecient reads */ + setvbuf(fp, readbuf, _IOFBF, sizeof(readbuf)); + + /* make sure it is only rw by the owner */ + chmod(pfile, 0600); + + /* Lock the smbpasswd file for write. */ + if ((lockfd = pw_file_lock(pfile, F_WRLCK, 5)) < 0) { + err = errno; + fprintf(stderr, "%s: Failed to lock password file %s.\n", + argv[0], pfile); + fclose(fp); + errno = err; + perror(argv[0]); + exit(err); + } + /* Get the smb passwd entry for this user */ + smb_pwent = _my_get_smbpwnam(fp, pwd->pw_name, &valid_old_pwd, + &got_valid_nt_entry, &seekpos); + if (smb_pwent == NULL) { + fprintf(stderr, "%s: Failed to find entry for user %s in file %s.\n", + argv[0], pwd->pw_name, pfile); + fclose(fp); + pw_file_unlock(lockfd); + exit(1); + } + /* If we are root we don't need to check the old password. */ + if (real_uid != 0) { + if ((valid_old_pwd == False) || (smb_pwent->smb_passwd == NULL)) { + fprintf(stderr, "%s: User %s is disabled, plase contact your administrator to enable it.\n", argv[0], pwd->pw_name); + fclose(fp); + pw_file_unlock(lockfd); + exit(1); + } + /* Check the old Lanman password */ + if (memcmp(old_p16, smb_pwent->smb_passwd, 16)) { + fprintf(stderr, "%s: Couldn't change password.\n", argv[0]); + fclose(fp); + pw_file_unlock(lockfd); + exit(1); + } + /* Check the NT password if it exists */ + if (smb_pwent->smb_nt_passwd != NULL) { + if (memcmp(old_nt_p16, smb_pwent->smb_nt_passwd, 16)) { + fprintf(stderr, "%s: Couldn't change password.\n", argv[0]); + fclose(fp); + pw_file_unlock(lockfd); + exit(1); + } + } + } + /* + * If we get here either we were root or the old password checked out + * ok. + */ + /* Create the 32 byte representation of the new p16 */ + for (i = 0; i < 16; i++) { + sprintf(&ascii_p16[i * 2], "%02X", (uchar) new_p16[i]); + } + if(got_valid_nt_entry) { + /* Add on the NT md4 hash */ + ascii_p16[32] = ':'; + for (i = 0; i < 16; i++) { + sprintf(&ascii_p16[(i * 2)+33], "%02X", (uchar) new_nt_p16[i]); + } + } + /* + * Do an atomic write into the file at the position defined by + * seekpos. + */ + pwfd = fileno(fp); + ret = lseek(pwfd, seekpos - 1, SEEK_SET); + if (ret != seekpos - 1) { + err = errno; + fprintf(stderr, "%s: seek fail on file %s.\n", + argv[0], pfile); + fclose(fp); + errno = err; + perror(argv[0]); + pw_file_unlock(lockfd); + exit(1); + } + /* Sanity check - ensure the character is a ':' */ + if (read(pwfd, &c, 1) != 1) { + err = errno; + fprintf(stderr, "%s: read fail on file %s.\n", + argv[0], pfile); + fclose(fp); + errno = err; + perror(argv[0]); + pw_file_unlock(lockfd); + exit(1); + } + if (c != ':') { + fprintf(stderr, "%s: sanity check on passwd file %s failed.\n", + argv[0], pfile); + fclose(fp); + pw_file_unlock(lockfd); + exit(1); + } + writelen = (got_valid_nt_entry) ? 65 : 32; + if (write(pwfd, ascii_p16, writelen) != writelen) { + err = errno; + fprintf(stderr, "%s: write fail in file %s.\n", + argv[0], pfile); + fclose(fp); + errno = err; + perror(argv[0]); + pw_file_unlock(lockfd); + exit(err); + } + fclose(fp); + pw_file_unlock(lockfd); + printf("Password changed\n"); + return 0; +} + +#else + +#include "includes.h" + +int +main(int argc, char **argv) +{ + printf("smb password encryption not selected in Makefile\n"); + return 0; +} +#endif diff --git a/source3/utils/status.c b/source3/utils/status.c new file mode 100644 index 0000000000..ed0ae53211 --- /dev/null +++ b/source3/utils/status.c @@ -0,0 +1,258 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + status reporting + Copyright (C) Andrew Tridgell 1994-1995 + + 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. +*/ + +/* + * This program reports current SMB connections + */ + +#ifdef SYSLOG +#undef SYSLOG +#endif + +#include "includes.h" +#include "loadparm.h" + +struct connect_record crec; +extern int DEBUGLEVEL; +extern FILE *dbf; + +static pstring Ucrit_username = ""; /* added by OH */ +int Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ +int Ucrit_MaxPid=0; /* added by OH */ +unsigned int Ucrit_IsActive = 0; /* added by OH */ +void Ucrit_addUsername(pstring username); /* added by OH */ +unsigned int Ucrit_checkUsername(pstring username); /* added by OH */ +void Ucrit_addPid(int pid); /* added by OH */ +unsigned int Ucrit_checkPid(int pid); /* added by OH */ + +int main(int argc, char *argv[]) +{ + FILE *f; + pstring fname; + int uid, c, n; + static pstring servicesf = CONFIGFILE; + extern char *optarg; + int verbose = 0; + void *dir; + char *s; + BOOL firstopen=True; + BOOL processes_only=False; + int last_pid=0; + + setup_logging(argv[0],True); + + charset_initialise(); + + DEBUGLEVEL = 0; + dbf = fopen("/dev/null","w"); + + if (getuid() != geteuid()) { + printf("smbstatus should not be run setuid\n"); + return(1); + } + + while ((c = getopt(argc, argv, "pdsu:")) != EOF) { + switch (c) { + case 'd': + verbose = 1; + break; + case 'p': + processes_only = 1; + break; + case 's': + strcpy(servicesf, optarg); + break; + case 'u': /* added by OH */ + Ucrit_addUsername(optarg); /* added by OH */ + break; + default: + fprintf(stderr, "Usage: %s [-d] [-p] [-s configfile] [-u username]\n", *argv); /* changed by OH */ + return (-1); + } + } + + + + if (!lp_load(servicesf,False)) { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); + return (-1); + } + + if (verbose) { + printf("using configfile = %s\n", servicesf); + printf("lockdir = %s\n", *lp_lockdir() ? lp_lockdir() : "NULL"); + } + + strcpy(fname,lp_lockdir()); + standard_sub_basic(fname); + trim_string(fname,"","/"); + strcat(fname,"/STATUS..LCK"); + + f = fopen(fname,"r"); + if (!f) { + printf("Couldn't open status file %s\n",fname); + if (!lp_status(-1)) + printf("You need to have status=yes in your smb config file\n"); + return(0); + } + + uid = getuid(); + + if (!processes_only) { + printf("\nSamba version %s\n",VERSION); + + printf("Service uid gid pid machine\n"); + printf("----------------------------------------------\n"); + } + + while (!feof(f)) + { + if (fread(&crec,sizeof(crec),1,f) != 1) + break; + if ( crec.magic == 0x280267 && process_exists(crec.pid) + && Ucrit_checkUsername(uidtoname(crec.uid)) /* added by OH */ + ) + { + Ucrit_addPid(crec.pid); /* added by OH */ + if (processes_only) { + if (last_pid != crec.pid) + printf("%d\n",crec.pid); + last_pid = crec.pid; /* XXXX we can still get repeats, have to + add a sort at some time */ + } + else + printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", + crec.name,uidtoname(crec.uid),gidtoname(crec.gid),crec.pid, + crec.machine,crec.addr, + asctime(LocalTime(&crec.start,GMT_TO_LOCAL))); + } + } + fclose(f); + + if (processes_only) exit(0); + + printf("\n"); + + dir = opendir(lp_lockdir()); + if (!dir) return(0); + while ((s=readdirname(dir))) { + char buf[16]; + int pid,mode; + time_t t; + int fd; + pstring lname; + int dev,inode; + + if (sscanf(s,"share.%d.%d",&dev,&inode)!=2) continue; + + strcpy(lname,lp_lockdir()); + trim_string(lname,NULL,"/"); + strcat(lname,"/"); + strcat(lname,s); + + fd = open(lname,O_RDONLY,0); + if (fd < 0) continue; + if (read(fd,buf,16) != 16) continue; + n = read(fd,fname,sizeof(fname)); + fname[MAX(n,0)]=0; + close(fd); + + t = IVAL(buf,0); + mode = IVAL(buf,4); + pid = IVAL(buf,8); + + if ( !Ucrit_checkPid(pid) ) /* added by OH */ + continue; + + if (IVAL(buf,12) != LOCKING_VERSION || !process_exists(pid)) { + if (unlink(lname)==0) + printf("Deleted stale share file %s\n",s); + continue; + } + + fname[sizeof(fname)-1] = 0; + + if (firstopen) { + firstopen=False; + printf("Locked files:\n"); + printf("Pid DenyMode R/W Name\n"); + printf("------------------------------\n"); + } + + + printf("%-5d ",pid); + switch ((mode>>4)&0xF) + { + case DENY_NONE: printf("DENY_NONE "); break; + case DENY_ALL: printf("DENY_ALL "); break; + case DENY_DOS: printf("DENY_DOS "); break; + case DENY_READ: printf("DENY_READ "); break; + case DENY_WRITE:printf("DENY_WRITE "); break; + } + switch (mode&0xF) + { + case 0: printf("RDONLY "); break; + case 1: printf("WRONLY "); break; + case 2: printf("RDWR "); break; + } + printf(" %s %s",fname,asctime(LocalTime(&t,GMT_TO_LOCAL))); + } + closedir(dir); + + if (firstopen) + printf("No locked files\n"); + + return (0); +} + +/* added by OH */ +void Ucrit_addUsername(pstring username) +{ + strcpy(Ucrit_username, username); + if(strlen(Ucrit_username) > 0) + Ucrit_IsActive = 1; +} + +unsigned int Ucrit_checkUsername(pstring username) +{ + if ( !Ucrit_IsActive) return 1; + if (strcmp(Ucrit_username,username) ==0) return 1; + return 0; +} + +void Ucrit_addPid(int pid) +{ + int i; + if ( !Ucrit_IsActive) return; + for (i=0;i 8) { + printf("WARNING: You have some share names that are longer than 8 chars\n"); + printf("These may give errors while browsing or may not be accessible\nto some older clients\n"); + break; + } + + if (argc < 4) + { + printf("Press enter to see a dump of your service definitions\n"); + fflush(stdout); + getc(stdin); + lp_dump(); + } + + if (argc == 4) + { + struct from_host f; + f.name = argv[2]; + f.addr = argv[3]; + + /* this is totally ugly, a real `quick' hack */ + for (s=0;s<1000;s++) + if (VALID_SNUM(s)) + { + if (allow_access(lp_hostsdeny(s),lp_hostsallow(s),&f)) + { + printf("Allow connection from %s (%s) to %s\n", + f.name,f.addr,lp_servicename(s)); + } + else + { + printf("Deny connection from %s (%s) to %s\n", + f.name,f.addr,lp_servicename(s)); + } + } + } + return(0); +} + + diff --git a/source3/utils/testprns.c b/source3/utils/testprns.c new file mode 100644 index 0000000000..89c615898d --- /dev/null +++ b/source3/utils/testprns.c @@ -0,0 +1,72 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + test printer setup + Copyright (C) Karl Auer 1993, 1994 + + 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. +*/ + +/* + * Testbed for pcap.c + * + * This module simply checks a given printer name against the compiled-in + * printcap file. + * + * The operation is performed with DEBUGLEVEL at 3. + * + * Useful for a quick check of a printcap file. + * + */ + +#include "includes.h" +#include "smb.h" +#include "pcap.h" + +/* these live in util.c */ +extern FILE *dbf; +extern int DEBUGLEVEL; + +int main(int argc, char *argv[]) +{ + char *pszTemp; + + setup_logging(argv[0],True); + + charset_initialise(); + + if (argc < 2 || argc > 3) + printf("Usage: testprns printername [printcapfile]\n"); + else + { + dbf = fopen("test.log", "w"); + if (dbf == NULL) + printf("Unable to open logfile.\n"); + else + { + DEBUGLEVEL = 3; + pszTemp = (argc < 3) ? PRINTCAP_NAME : argv[2]; + printf("Looking for printer %s in printcap file %s\n", + argv[1], pszTemp); + if (!pcap_printername_ok(argv[1], pszTemp)) + printf("Printer name %s is not valid.\n", argv[1]); + else + printf("Printer name %s is valid.\n", argv[1]); + fclose(dbf); + } + } + return (0); +} + -- cgit From efdeaf4cf626348fd90dffebaec6169af5634e53 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 5 May 1996 11:34:03 +0000 Subject: - added hostname support to smbstatus - fix a bug where -s would not be recognised (This used to be commit 03744dc0cd49a54b4dd30645a2b77007c9d19bdc) --- source3/utils/status.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index ed0ae53211..1ae38528d0 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -33,6 +33,7 @@ struct connect_record crec; extern int DEBUGLEVEL; extern FILE *dbf; +extern pstring myhostname; static pstring Ucrit_username = ""; /* added by OH */ int Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ @@ -69,7 +70,7 @@ int main(int argc, char *argv[]) return(1); } - while ((c = getopt(argc, argv, "pdsu:")) != EOF) { + while ((c = getopt(argc, argv, "pds:u:")) != EOF) { switch (c) { case 'd': verbose = 1; @@ -89,13 +90,13 @@ int main(int argc, char *argv[]) } } - - if (!lp_load(servicesf,False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); return (-1); } + get_myname(myhostname, NULL); + if (verbose) { printf("using configfile = %s\n", servicesf); printf("lockdir = %s\n", *lp_lockdir() ? lp_lockdir() : "NULL"); @@ -113,6 +114,9 @@ int main(int argc, char *argv[]) printf("You need to have status=yes in your smb config file\n"); return(0); } + else if (verbose) { + printf("Opened status file %s\n", fname); + } uid = getuid(); -- cgit From 1956d1349441d8d5694df6dda67528bec4b1c10e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 29 May 1996 07:47:47 +0000 Subject: cleanups to make thinsg compile cleanly (This used to be commit 39fbeb04ae938594c380d97ebe67c012fa0dd51a) --- source3/utils/smbpasswd.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 167eb2ed5f..2b3a48a75b 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -152,8 +152,8 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, /* NT Entry was valid - even if 'X' or '*', can be overwritten */ *got_valid_nt_entry = True; if (*p != '*' && *p != 'X') { - if(gethexpwd(p,smbntpwd)) - pw_buf.smb_nt_passwd = smbntpwd; + if (gethexpwd((char *)p,(char *)smbntpwd)) + pw_buf.smb_nt_passwd = smbntpwd; } } pw_buf.smb_name = user_name; @@ -167,12 +167,12 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, if (p[32] != ':') return (False); - if (!strncasecmp(p, "NO PASSWORD", 11)) { - pw_buf.smb_passwd = NULL; /* No password */ + if (!strncasecmp((char *)p, "NO PASSWORD", 11)) { + pw_buf.smb_passwd = NULL; /* No password */ } else { - if(!gethexpwd(p,smbpwd)) - return False; - pw_buf.smb_passwd = smbpwd; + if(!gethexpwd((char *)p,(char *)smbpwd)) + return False; + pw_buf.smb_passwd = smbpwd; } pw_buf.smb_name = user_name; @@ -189,8 +189,8 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, /* NT Entry was valid - even if 'X' or '*', can be overwritten */ *got_valid_nt_entry = True; if (*p != '*' && *p != 'X') { - if(gethexpwd(p,smbntpwd)) - pw_buf.smb_nt_passwd = smbntpwd; + if (gethexpwd((char *)p,(char *)smbntpwd)) + pw_buf.smb_nt_passwd = smbntpwd; } } return &pw_buf; -- cgit From 58734631b4233ec08b7a262587e400792f31f185 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 31 May 1996 15:13:29 +0000 Subject: Lots of changes! - add faq info on NT printer handling - add "delete readonly" option to help rcs users - add stuff to man pages on new printer options - add "proxy name resolution" option - add "command string" -c option to smbclient (thanks Ken) - split time functions into time.c - rearrange the quotas stuff a bit and fix some bugs - complete rehash of the time handling code thanks to Paul Eggert - fix nmblookup output a bit - add plp print queue parsing from Bertrand Wallrich (This used to be commit 635b56f19c817527c52e9bbde31faa6a8a47777b) --- source3/utils/smbpasswd.c | 2 ++ source3/utils/status.c | 5 +++-- source3/utils/testparm.c | 2 ++ source3/utils/testprns.c | 2 ++ 4 files changed, 9 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 2b3a48a75b..1569a3cd88 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -232,6 +232,8 @@ int main(int argc, char **argv) char *pfile = SMB_PASSWD_FILE; char readbuf[16 * 1024]; + TimeInit(); + setup_logging(argv[0],True); charset_initialise(); diff --git a/source3/utils/status.c b/source3/utils/status.c index 1ae38528d0..2a2a5ca4c1 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -58,6 +58,7 @@ int main(int argc, char *argv[]) BOOL processes_only=False; int last_pid=0; + TimeInit(); setup_logging(argv[0],True); charset_initialise(); @@ -146,7 +147,7 @@ int main(int argc, char *argv[]) printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", crec.name,uidtoname(crec.uid),gidtoname(crec.gid),crec.pid, crec.machine,crec.addr, - asctime(LocalTime(&crec.start,GMT_TO_LOCAL))); + asctime(LocalTime(&crec.start))); } } fclose(f); @@ -217,7 +218,7 @@ int main(int argc, char *argv[]) case 1: printf("WRONLY "); break; case 2: printf("RDWR "); break; } - printf(" %s %s",fname,asctime(LocalTime(&t,GMT_TO_LOCAL))); + printf(" %s %s",fname,asctime(LocalTime(&t))); } closedir(dir); diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index e1f070a4b8..1eaaa10b3b 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -46,6 +46,8 @@ int main(int argc, char *argv[]) pstring configfile; int s; + TimeInit(); + setup_logging(argv[0],True); charset_initialise(); diff --git a/source3/utils/testprns.c b/source3/utils/testprns.c index 89c615898d..1474f0ecc6 100644 --- a/source3/utils/testprns.c +++ b/source3/utils/testprns.c @@ -43,6 +43,8 @@ int main(int argc, char *argv[]) { char *pszTemp; + TimeInit(); + setup_logging(argv[0],True); charset_initialise(); -- cgit From a2c1623827406667a4f2f058c24f1d971f6627f8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Jun 1996 06:42:03 +0000 Subject: a huge pile of changes :-) The biggest thing is the integration of Lukes new nmbd. Its still largely untested, so we will really need some feedback I've also added auto prototype generation and cleaned up a lot of minor things as a result (This used to be commit 0d8dcfa13c527ec2c8aca39ba49c09e4e694b26c) --- source3/utils/nmblookup.c | 4 +++- source3/utils/smbpasswd.c | 5 ++--- source3/utils/status.c | 2 +- source3/utils/testparm.c | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index aa43173332..6289ef74b1 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -25,7 +25,6 @@ #endif #include "includes.h" -#include "nameserv.h" extern int DEBUGLEVEL; @@ -35,6 +34,7 @@ extern struct in_addr bcast_ip; extern pstring myhostname; static BOOL got_bcast = False; +struct in_addr ipzero; int ServerFD= -1; @@ -124,6 +124,8 @@ int main(int argc,char *argv[]) TimeInit(); + ipzero = *interpret_addr2("0.0.0.0"); + setup_logging(argv[0],True); charset_initialise(); diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 1569a3cd88..c79aa15c80 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -201,14 +201,13 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, /* * Print command usage on stderr and die. */ -void -usage(char *name) +static void usage(char *name) { fprintf(stderr, "Usage is : %s [username]\n", name); exit(1); } -int main(int argc, char **argv) + int main(int argc, char **argv) { int real_uid; struct passwd *pwd; diff --git a/source3/utils/status.c b/source3/utils/status.c index 2a2a5ca4c1..65e9d975f1 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -44,7 +44,7 @@ unsigned int Ucrit_checkUsername(pstring username); /* added by OH */ void Ucrit_addPid(int pid); /* added by OH */ unsigned int Ucrit_checkPid(int pid); /* added by OH */ -int main(int argc, char *argv[]) + int main(int argc, char *argv[]) { FILE *f; pstring fname; diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 1eaaa10b3b..c6fa674b2d 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -41,7 +41,7 @@ extern FILE *dbf; extern int DEBUGLEVEL; -int main(int argc, char *argv[]) + int main(int argc, char *argv[]) { pstring configfile; int s; -- cgit From b9ae225b28f4707609e6436dad4be7ebdd7e181f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Jun 1996 11:43:09 +0000 Subject: - added interface.c and removed all the references to myip, bcast_ip and Netmask, instead replacing them with calls to routines in interface.c - got rid of old MAXINT define - added code to ensure we only return one entry for each name in the ipc enum routines - added new_only option to add_netbios_entry() to prevent overwriting of important names - minor time handling fixup (This used to be commit 7ed71b73ae745da099072eee36fc2700d1d91407) --- source3/utils/nmblookup.c | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 6289ef74b1..43c328a41e 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -30,11 +30,8 @@ extern int DEBUGLEVEL; extern pstring scope; -extern struct in_addr bcast_ip; extern pstring myhostname; - -static BOOL got_bcast = False; -struct in_addr ipzero; +extern struct in_addr ipzero; int ServerFD= -1; @@ -69,24 +66,9 @@ static BOOL open_sockets(void) ****************************************************************************/ static BOOL init_structs(void ) { - struct in_addr myip; - - if (!get_myname(myhostname,&myip)) + if (!get_myname(myhostname,NULL)) return(False); - /* Read the broadcast address from the interface */ - { - struct in_addr ip0,ip2; - - ip0 = myip; - - if (!got_bcast) { - get_broadcast(&ip0,&bcast_ip,&ip2); - - DEBUG(2,("Using broadcast %s\n",inet_ntoa(bcast_ip))); - } - } - return True; } @@ -124,8 +106,6 @@ int main(int argc,char *argv[]) TimeInit(); - ipzero = *interpret_addr2("0.0.0.0"); - setup_logging(argv[0],True); charset_initialise(); @@ -134,11 +114,7 @@ int main(int argc,char *argv[]) switch (opt) { case 'B': - { - unsigned long a = interpret_addr(optarg); - putip((char *)&bcast_ip,(char *)&a); - got_bcast = True; - } + iface_set_default(NULL,optarg,NULL); break; case 'i': strcpy(scope,optarg); @@ -167,10 +143,11 @@ int main(int argc,char *argv[]) exit(1); } + load_interfaces(); init_structs(); if (!open_sockets()) return(1); - DEBUG(1,("Sending queries to %s\n",inet_ntoa(bcast_ip))); + DEBUG(1,("Sending queries to %s\n",inet_ntoa(*iface_bcast(ipzero)))); for (i=optind;i Date: Sat, 8 Jun 1996 04:33:37 +0000 Subject: - added comments to byteorder.h explaining how it works. - fixed problem with installscripts if srcdir is not set - fixed ptr init bug in interface.c - changed default lookup type in nmblookup to match nbtstat under NT - new quotas fixes for sunos and solaris (This used to be commit e775576f026d282473256aeac6fef65a85acd98e) --- source3/utils/nmblookup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 43c328a41e..4d7c6e8534 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -93,7 +93,7 @@ static void usage(void) int main(int argc,char *argv[]) { int opt; - unsigned int lookup_type = 0x20; + unsigned int lookup_type = 0; pstring lookup; extern int optind; extern char *optarg; -- cgit From 7e3b4a1c0df1434eb3d02f93c736ce065f9898d8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Jun 1996 04:38:24 +0000 Subject: got rid of a lot of redundent header files as we now globally generate prototypes automatically using "make proto". This is much less prone to error than the old method of manually adding prototypes (This used to be commit b551dc98f7cc194a5fc2e67a4ebae7fd67a01bbc) --- source3/utils/status.c | 5 ----- source3/utils/testparm.c | 2 -- source3/utils/testprns.c | 1 - 3 files changed, 8 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 65e9d975f1..3d52056489 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -28,7 +28,6 @@ #endif #include "includes.h" -#include "loadparm.h" struct connect_record crec; extern int DEBUGLEVEL; @@ -39,10 +38,6 @@ static pstring Ucrit_username = ""; /* added by OH */ int Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ int Ucrit_MaxPid=0; /* added by OH */ unsigned int Ucrit_IsActive = 0; /* added by OH */ -void Ucrit_addUsername(pstring username); /* added by OH */ -unsigned int Ucrit_checkUsername(pstring username); /* added by OH */ -void Ucrit_addPid(int pid); /* added by OH */ -unsigned int Ucrit_checkPid(int pid); /* added by OH */ int main(int argc, char *argv[]) { diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index c6fa674b2d..1d6cc2b000 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -34,8 +34,6 @@ #include "includes.h" #include "smb.h" -#include "params.h" -#include "loadparm.h" /* these live in util.c */ extern FILE *dbf; diff --git a/source3/utils/testprns.c b/source3/utils/testprns.c index 1474f0ecc6..b41b4a4c42 100644 --- a/source3/utils/testprns.c +++ b/source3/utils/testprns.c @@ -33,7 +33,6 @@ #include "includes.h" #include "smb.h" -#include "pcap.h" /* these live in util.c */ extern FILE *dbf; -- cgit From ed2639ebe21dde49af816a96ec6ea1e40f76e768 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Sat, 29 Jun 1996 18:49:20 +0000 Subject: luke's first attempt at using cvs accidentally updated the Makefile updated the name database structure (again!). this time, there is one name database per local interface. there is also a pseudo-interface on ip 255.255.255.255. its purpose is to store WINS name entries. all the local interface name databases store SELF names only. the WINS name database stores non-special browser names. added wins.dat file: records WINS entries in ascii format. this is reloaded when nmbd restarts. added repeating code for response packets. timer is in seconds only at the moment. updated the response queue code to deal with samba registering with a WINS server a bit better (added more cases when a response isn't received). tidied up the response packet processing code and expire_response_queue() code. added cross references between response received and await-response expired code. added over-zealous code that checks all machines that register with samba as a WINS server (every 10 minutes i think): to see whether they are still alive or not (see rfc1001.txt) bug reported by terry@ren.pc.athabascau.ca: DNSFAILed names _stay_ as DNSFAIL, even though the machine may come back up and REGISTER. removed update_from_reg() function. it's not necessary, and it does too much. added code that announces on each local interface samba's ttl as zero and servertype as zero when nmbd is kill -TERMed first attempt at putting the first functionality of samba browsing back in (remote subnets should have samba appear in a workgroup specified through the lmhosts file) lots of other miscellaneous tidying up / chopping about. (This used to be commit 7e8c60cfe54060860e5ce20b1c3b8ec6aa5c54da) --- source3/utils/nmblookup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 4d7c6e8534..4fbd839036 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -93,7 +93,7 @@ static void usage(void) int main(int argc,char *argv[]) { int opt; - unsigned int lookup_type = 0; + unsigned int lookup_type = 0x0; pstring lookup; extern int optind; extern char *optarg; -- cgit From 25b30c08dce8c04b7b98c02ac1de61d7aa76798f Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Wed, 17 Jul 1996 18:33:36 +0000 Subject: lots of changes to nmbd lkcl (This used to be commit 45d3b2644733333c657c48a69719fec72881f7df) --- source3/utils/nmblookup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 4fbd839036..a543b90762 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -49,7 +49,7 @@ static BOOL open_sockets(void) return False; } - ServerFD = open_socket_in(SOCK_DGRAM, 0,3); + ServerFD = open_socket_in(SOCK_DGRAM, NMB_PORT,3); if (ServerFD == -1) return(False); @@ -164,7 +164,7 @@ int main(int argc,char *argv[]) strcpy(lookup,"\01\02__MSBROWSE__\02"); lookup_type = 1; } else { - lookup_type = 0x1d; + lookup_type = 0x1b; } } -- cgit From 3ffb30e8be5bcddca9d0489e1993085a4995c3af Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 1 Aug 1996 17:49:40 +0000 Subject: local_only NetServerEnum syncs can now be issued. bug spotted in nameservresp.c - arguments to test subnet the response is received on (same_net()) were the wrong way round (ccm@shentel.net) samba was adding WORKGROUP(1e) as a unique not a group name: fixed this bug in reply_name_status() and reply_name_query(): WINS entries weren't being looked up. name status reply adds local SELF entries to WINS SELF entries: some SELF entries are only added locally, while others are only added via WINS. name status needs to have both, combined. a sync will only occur when an ANN_LocalMasterAnnouncement is received, NOT an ANN_HostAnnouncement or an ANN_DomainAnnouncement. when samba is a member of a workgroup, it looks for (using a wins server) and announces to its domain master. NAME_QUERY_ANNOUNCE_HOST - yet another 'state' - has been created to do this: do the name query on the wins server and send the announce host to the answer to this query. jeremy @ vantive wrote the original code to do this, which used the name_query() function. i'm trying to avoid name_query: it times out and generally messes things up, but using queue_netbios_packet() and queue_netbios_pkt_wins() is... not intuitive? lkcl with help from jra (This used to be commit 6e932e4bae8b46e7ff4a55a75484bad78308336a) --- source3/utils/nmblookup.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index a543b90762..292b526df9 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -49,7 +49,7 @@ static BOOL open_sockets(void) return False; } - ServerFD = open_socket_in(SOCK_DGRAM, NMB_PORT,3); + ServerFD = open_socket_in(SOCK_DGRAM, 0,3); if (ServerFD == -1) return(False); @@ -151,7 +151,7 @@ int main(int argc,char *argv[]) for (i=optind;i Date: Thu, 15 Aug 1996 15:11:34 +0000 Subject: - added FAST_SHARE_MODES code - added some named pipe code from Jim (This used to be commit c94866e9e44ea1eb72da06bc65ef1c032ae8e0c9) --- source3/utils/status.c | 177 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 137 insertions(+), 40 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 3d52056489..c9fda5d359 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -17,6 +17,11 @@ 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. + + Revision History: + + 12 aug 96: Erik.Devriendt@te6.siemens.be + added support for shared memory implementation of share mode locking */ /* @@ -43,15 +48,24 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ { FILE *f; pstring fname; - int uid, c, n; + int uid, c; static pstring servicesf = CONFIGFILE; extern char *optarg; int verbose = 0; - void *dir; - char *s; BOOL firstopen=True; BOOL processes_only=False; int last_pid=0; +#ifdef FAST_SHARE_MODES + pstring shmem_file_name; + share_mode_record *scanner_p; + share_mode_record *prev_p; + int bytes_free, bytes_used, bytes_overhead, bytes_total; +#else + int n; + void *dir; + char *s; +#endif + TimeInit(); setup_logging(argv[0],True); @@ -151,42 +165,99 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ printf("\n"); - dir = opendir(lp_lockdir()); - if (!dir) return(0); - while ((s=readdirname(dir))) { - char buf[16]; - int pid,mode; - time_t t; - int fd; - pstring lname; - int dev,inode; - - if (sscanf(s,"share.%d.%d",&dev,&inode)!=2) continue; - - strcpy(lname,lp_lockdir()); - trim_string(lname,NULL,"/"); - strcat(lname,"/"); - strcat(lname,s); - - fd = open(lname,O_RDONLY,0); - if (fd < 0) continue; - if (read(fd,buf,16) != 16) continue; - n = read(fd,fname,sizeof(fname)); - fname[MAX(n,0)]=0; - close(fd); - - t = IVAL(buf,0); - mode = IVAL(buf,4); - pid = IVAL(buf,8); - - if ( !Ucrit_checkPid(pid) ) /* added by OH */ - continue; - - if (IVAL(buf,12) != LOCKING_VERSION || !process_exists(pid)) { - if (unlink(lname)==0) - printf("Deleted stale share file %s\n",s); - continue; - } +#ifdef FAST_SHARE_MODES + /******************************************************************* + initialize the shared memory for share_mode management + ******************************************************************/ + + + strcpy(shmem_file_name,lp_lockdir()); + trim_string(shmem_file_name,"","/"); + if (!*shmem_file_name) exit(-1); + strcat(shmem_file_name, "/SHARE_MEM_FILE"); + if(!shm_open(shmem_file_name, SHMEM_SIZE)) exit(-1); + + if(!shm_lock()) + { + shm_close(); + exit (-1); + } + + scanner_p = (share_mode_record *)shm_offset2addr(shm_get_userdef_off()); + prev_p = scanner_p; + while(scanner_p) + { + int pid,mode; + time_t t; + + pid = scanner_p->pid; + + if ( !Ucrit_checkPid(pid) ) + { + prev_p = scanner_p ; + scanner_p = (share_mode_record *)shm_offset2addr(scanner_p->next_offset); + continue; + } + + if( (scanner_p->locking_version != LOCKING_VERSION) || !process_exists(pid)) + { + DEBUG(2,("Deleting stale share mode record")); + if(prev_p == scanner_p) + { + shm_set_userdef_off(scanner_p->next_offset); + shm_free(shm_addr2offset(scanner_p)); + scanner_p = (share_mode_record *)shm_offset2addr(shm_get_userdef_off()); + prev_p = scanner_p; + } + else + { + prev_p->next_offset = scanner_p->next_offset; + shm_free(shm_addr2offset(scanner_p)); + scanner_p = (share_mode_record *)shm_offset2addr(prev_p->next_offset); + } + continue; + } + t = scanner_p->time; + mode = scanner_p->share_mode; + strcpy(fname, scanner_p->file_name); +#else + dir = opendir(lp_lockdir()); + if (!dir) return(0); + while ((s=readdirname(dir))) { + char buf[16]; + int pid,mode; + time_t t; + int fd; + pstring lname; + int dev,inode; + + if (sscanf(s,"share.%d.%d",&dev,&inode)!=2) continue; + + strcpy(lname,lp_lockdir()); + trim_string(lname,NULL,"/"); + strcat(lname,"/"); + strcat(lname,s); + + fd = open(lname,O_RDONLY,0); + if (fd < 0) continue; + if (read(fd,buf,16) != 16) continue; + n = read(fd,fname,sizeof(fname)); + fname[MAX(n,0)]=0; + close(fd); + + t = IVAL(buf,0); + mode = IVAL(buf,4); + pid = IVAL(buf,8); + + if ( !Ucrit_checkPid(pid) ) /* added by OH */ + continue; + + if (IVAL(buf,12) != LOCKING_VERSION || !process_exists(pid)) { + if (unlink(lname)==0) + printf("Deleted stale share file %s\n",s); + continue; + } +#endif fname[sizeof(fname)-1] = 0; @@ -214,11 +285,37 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ case 2: printf("RDWR "); break; } printf(" %s %s",fname,asctime(LocalTime(&t))); - } + +#ifdef FAST_SHARE_MODES + prev_p = scanner_p ; + scanner_p = (share_mode_record *)shm_offset2addr(scanner_p->next_offset); + } /* end while */ + + shm_get_usage(&bytes_free, &bytes_used, &bytes_overhead); + bytes_total = bytes_free + bytes_used + bytes_overhead; + shm_unlock(); + + /******************************************************************* + deinitialize the shared memory for share_mode management + ******************************************************************/ + shm_close(); + +#else + } /* end while */ closedir(dir); +#endif if (firstopen) printf("No locked files\n"); +#ifdef FAST_SHARE_MODES + printf("\nShare mode memory usage (bytes):\n"); + printf(" %d(%d%%) free + %d(%d%%) used + %d(%d%%) overhead = %d(100%%) total\n", + bytes_free, (bytes_free * 100)/bytes_total, + bytes_used, (bytes_used * 100)/bytes_total, + bytes_overhead, (bytes_overhead * 100)/bytes_total, + bytes_total); + +#endif return (0); } -- cgit From efb8113d00a4513c1115640004c0905465d3b673 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 17 Aug 1996 14:27:12 +0000 Subject: - made FAST_SHARE_MODES standard for Linux - you can now press enter after a password prompt with "smbclient -L hostname" and it will use a blank username and password, the same as if you used -U% - changed the wins.dat store code to not go via a string variable (just use fprintf instead) - removed a "unsigned long" that luke put back in, changing it to uint32 to keep 64 bit machines happy. Naughtly luke! - allow guest non-connnected print queue listings so ms client 3 can work (This used to be commit 917160dee69bbc198985b6f3232ca2dcda809d8a) --- source3/utils/status.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index c9fda5d359..ab61a4db89 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -55,7 +55,7 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ BOOL firstopen=True; BOOL processes_only=False; int last_pid=0; -#ifdef FAST_SHARE_MODES +#if FAST_SHARE_MODES pstring shmem_file_name; share_mode_record *scanner_p; share_mode_record *prev_p; @@ -165,7 +165,7 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ printf("\n"); -#ifdef FAST_SHARE_MODES +#if FAST_SHARE_MODES /******************************************************************* initialize the shared memory for share_mode management ******************************************************************/ @@ -286,7 +286,7 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ } printf(" %s %s",fname,asctime(LocalTime(&t))); -#ifdef FAST_SHARE_MODES +#if FAST_SHARE_MODES prev_p = scanner_p ; scanner_p = (share_mode_record *)shm_offset2addr(scanner_p->next_offset); } /* end while */ @@ -307,7 +307,7 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ #endif if (firstopen) printf("No locked files\n"); -#ifdef FAST_SHARE_MODES +#if FAST_SHARE_MODES printf("\nShare mode memory usage (bytes):\n"); printf(" %d(%d%%) free + %d(%d%%) used + %d(%d%%) overhead = %d(100%%) total\n", bytes_free, (bytes_free * 100)/bytes_total, -- cgit From 0c33046a0aa0461a5e932dd7b0b6e38ab9708867 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 19 Aug 1996 11:17:29 +0000 Subject: - added "netbios name" option in smb.conf to make controlling the name that samba uses possible - added "socket address" option to allow virtual SMB servers (on systems with IP aliasing line Linux) - disabled FAST_SHARE_MODES by default in Linux as older Linux boxes can't do shared writeable mappings. We really need autoconf ... - added new option types in loadparm so a string type can be specified ot be uppercase only, this is used for the workgroup and netbios name options - auto-create the lock directory if it doesn't exist in shared mem startup - get rid of announce_backup() - change a few comments in nmbd code - rewrote the chaining code completely. Hopefully it will handle any depth chains now. - added LPRng support (This used to be commit e9eac6cd49c352349580ddb13d720cb201aecc48) --- source3/utils/nmblookup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 292b526df9..d418814a69 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -49,7 +49,7 @@ static BOOL open_sockets(void) return False; } - ServerFD = open_socket_in(SOCK_DGRAM, 0,3); + ServerFD = open_socket_in(SOCK_DGRAM, 0,3,interpret_addr(lp_socket_address())); if (ServerFD == -1) return(False); -- cgit From 5a2f52b79e28530c454cb488a44588147640f061 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 2 Oct 1996 14:09:22 +0000 Subject: - a huge pile of changes from Luke which implement the browse.conf stuff and also fix a pile of nmbd bugs. Unfortunately I found it very hard to disentangle the new features from the bug fixes so I am putting in the new code. I hope this is the last big pile of changes to the 1.9.16 series! (This used to be commit 20b6203dac4bbb43e4e7bea0b214496d76d679d9) --- source3/utils/nmblookup.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index d418814a69..c137b4f93a 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -100,6 +100,7 @@ int main(int argc,char *argv[]) BOOL find_master=False; BOOL find_status=False; int i; + static pstring servicesf = CONFIGFILE; DEBUGLEVEL = 1; *lookup = 0; @@ -110,7 +111,7 @@ int main(int argc,char *argv[]) charset_initialise(); - while ((opt = getopt(argc, argv, "p:d:B:i:SMh")) != EOF) + while ((opt = getopt(argc, argv, "p:d:B:i:s:SMh")) != EOF) switch (opt) { case 'B': @@ -129,6 +130,9 @@ int main(int argc,char *argv[]) case 'd': DEBUGLEVEL = atoi(optarg); break; + case 's': + strcpy(servicesf, optarg); + break; case 'h': usage(); exit(0); @@ -143,6 +147,11 @@ int main(int argc,char *argv[]) exit(1); } + if (!lp_load(servicesf,True)) { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); + return (-1); + } + load_interfaces(); init_structs(); if (!open_sockets()) return(1); -- cgit From e23f2b9cef8428bda51b413642d9720ba5c590d5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 4 Oct 1996 09:31:07 +0000 Subject: - changed the umask handling. We now set the umask to 0 and explicitly set the mode on all created files. I think this is a better policy. - change the debug levels on some items - fix a charset handling bug which affected foreign and extended charset users - no longer switch back to the original directory when idle, instead switch to / as the original directory may not be readable by ordinary users. - fix some bugs where the create mode of files was not being explicitly set (it was relying on the umask and using fopen). Not a big bug as it only affected obscure commands like the messaging ops. - got rid of the lock code in the lpq cache as its no longer needed - rewrote smbrun to be faster and to remove the security hole. We now don't actually need a external smbrun binary, its all done by smbd. - add a more explicit warning about uids and gids of -1 or 65535 (This used to be commit 5aa735c940ccdb6acae5f28449d484181c912e49) --- source3/utils/testprns.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/testprns.c b/source3/utils/testprns.c index b41b4a4c42..4709eb0691 100644 --- a/source3/utils/testprns.c +++ b/source3/utils/testprns.c @@ -53,10 +53,9 @@ int main(int argc, char *argv[]) else { dbf = fopen("test.log", "w"); - if (dbf == NULL) + if (dbf == NULL) { printf("Unable to open logfile.\n"); - else - { + } else { DEBUGLEVEL = 3; pszTemp = (argc < 3) ? PRINTCAP_NAME : argv[2]; printf("Looking for printer %s in printcap file %s\n", -- cgit From e5893bdfbef0ac16772199d7ec6fac7d3e4f8431 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 5 Oct 1996 10:41:13 +0000 Subject: I have fixed quite a few important bugs in this commit. Luke, can you take special note of the bug fixes to nmbd so you can propogate them to your new code. - rewrote the code that used to use fromhost(). We now call gethostbyaddr() only if necessary and a maximum of once per connection. Calling gethostbyaddr() causes problems on some systems so avoiding it if possible is a good thing :-) - added the "fake oplocks" option. See the docs in smb.conf(5) and Speed.txt - fixed a serious bug in nmbd where it would try a DNS lookup on FIND_SELF queries. This caused a lot of unnecessary (and incorrect) DNS lookups to happen. FIND_SELF queries should only go to the internal name tables. - don't set FIND_SELF for name queries if we are a wins proxy, as we are supposed to be answering queries for other hosts. - fixed a bug in nmbd which had "if (search | FIND_LOCAL)" instead of "if (search & FIND_LOCAL)". Luke, this was in nameservreply.c - the above 3 bugs together meant that DNS queries were being cached, but the cache wasn't being used, so every query was going to DNS, no wonder nmbd has been chewing so much CPU time! Another side effect was that queries on names in lmhosts weren't being answered for bcast queries with "wins proxy" set. - ignore the maxxmit for seconday session setups (see CIFS spec) - close user opened files in a uLogoffX for user level security (see CIFS spec) - added uid into the files struct to support the above change (This used to be commit ea472b7217b7693627a13a7b1e428a0a6a3d8755) --- source3/utils/testparm.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 1d6cc2b000..7e05283625 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -87,23 +87,22 @@ extern int DEBUGLEVEL; if (argc == 4) { - struct from_host f; - f.name = argv[2]; - f.addr = argv[3]; + char *cname = argv[2]; + char *caddr = argv[3]; /* this is totally ugly, a real `quick' hack */ for (s=0;s<1000;s++) if (VALID_SNUM(s)) { - if (allow_access(lp_hostsdeny(s),lp_hostsallow(s),&f)) + if (allow_access(lp_hostsdeny(s),lp_hostsallow(s),cname,caddr)) { printf("Allow connection from %s (%s) to %s\n", - f.name,f.addr,lp_servicename(s)); + cname,caddr,lp_servicename(s)); } else { printf("Deny connection from %s (%s) to %s\n", - f.name,f.addr,lp_servicename(s)); + cname,caddr,lp_servicename(s)); } } } -- cgit From dfa2b456c743a643080d3a2eb0d9db62503141f5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 7 Oct 1996 11:06:34 +0000 Subject: - continue when failing to load config file in nmblookup and smbclient - fix important bug in nmbd where it set the return code for a negative name response to 0 (which means success!) (This used to be commit bfa816cc8f30d9a629b4fe9f71bf0707aa6c4502) --- source3/utils/nmblookup.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index c137b4f93a..ccdbec45e6 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -101,6 +101,8 @@ int main(int argc,char *argv[]) BOOL find_status=False; int i; static pstring servicesf = CONFIGFILE; + struct in_addr bcast_addr; + BOOL got_bcast = False; DEBUGLEVEL = 1; *lookup = 0; @@ -116,6 +118,8 @@ int main(int argc,char *argv[]) { case 'B': iface_set_default(NULL,optarg,NULL); + bcast_addr = *interpret_addr2(optarg); + got_bcast = True; break; case 'i': strcpy(scope,optarg); @@ -149,14 +153,16 @@ int main(int argc,char *argv[]) if (!lp_load(servicesf,True)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); - return (-1); } load_interfaces(); init_structs(); if (!open_sockets()) return(1); - DEBUG(1,("Sending queries to %s\n",inet_ntoa(*iface_bcast(ipzero)))); + if (!got_bcast) + bcast_addr = *iface_bcast(ipzero); + + DEBUG(1,("Sending queries to %s\n",inet_ntoa(bcast_addr))); for (i=optind;i Date: Wed, 6 Nov 1996 20:14:24 +0000 Subject: nmblookup was looking for 0x1b (domain master browser) not 0x1d (local master browser) names with the -M switch. lkcl (This used to be commit f27a9ccc972432a8a49dc0f0290751971d5699cd) --- source3/utils/nmblookup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index ccdbec45e6..c969276838 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -179,7 +179,7 @@ int main(int argc,char *argv[]) strcpy(lookup,"\01\02__MSBROWSE__\02"); lookup_type = 1; } else { - lookup_type = 0x1b; + lookup_type = 0x1d; } } -- cgit From 8bc7d6bebd4fcf8c95cb6d58da14404a5e46de91 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 9 Jan 1997 18:02:17 +0000 Subject: Makefile: Changes to split Solaris into Solaris2.3 and previous, and 2.4 and after from Paul Eggert. Makefile: Added AMIGA changes from Rask Ingemann Lambertsen . charset.c: Patch for Western European Languages from Josef Hinteregger charset.h: Patch for Western European Languages from Josef Hinteregger clitar.c: Patch to re-sync after read fail from (lost contributor name, sorry). includes.h: Patch for AMIGA from Rask Ingemann Lambertsen includes.h: Patch for SunOS atexit by Jeremy (jra@cygnus.com) interface.c: Patch for AMIGA from Rask Ingemann Lambertsen kanji.h: Patch for Western European Languages from Josef Hinteregger locking.c: Patch to fix file locking from Jeremy (jra@cygnus.com) locking.c: Patch to add granularity of lock files to usec by Jeremy (jra@cygnus.com) pipes.c: Patch to fix file locking from Jeremy (jra@cygnus.com) proto.h: Patch to fix file locking from Jeremy (jra@cygnus.com) reply.c: Patch to fix file locking from Jeremy (jra@cygnus.com) server.c: Patch to fix file locking from Jeremy (jra@cygnus.com) server.c: Patch for FAST_SHARE_MODE fix from (lost contributor name, sorry). smb.h: Patch to fix file locking from Jeremy (jra@cygnus.com) smb.h: Patch to add granularity of lock files to usec by Jeremy (jra@cygnus.com) status.c: Patch to fix file locking from Jeremy (jra@cygnus.com) statuc.c: Patch to add granularity of lock files to usec by Jeremy (jra@cygnus.com) system.c: Patch for Western European Languages from Josef Hinteregger trans2.c: Patch to fix file locking from Jeremy (jra@cygnus.com) trans2.c: Patch to fix volume name reported to Win95 from Jeremy (jra@cygnus.com) util.c: Patch for Western European Languages from Josef Hinteregger util.c: Patch to fix client_name from continuously returning UNKNOWN (from various contributors). version.h: Update to 1.9.16p10. (This used to be commit 03d28fa32eb094affa33133ebe2602fdb70f6361) --- source3/utils/status.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index ab61a4db89..69fbda5ea8 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -224,9 +224,9 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ dir = opendir(lp_lockdir()); if (!dir) return(0); while ((s=readdirname(dir))) { - char buf[16]; + char buf[20]; int pid,mode; - time_t t; + struct timeval t; int fd; pstring lname; int dev,inode; @@ -240,19 +240,20 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ fd = open(lname,O_RDONLY,0); if (fd < 0) continue; - if (read(fd,buf,16) != 16) continue; + if (read(fd,buf,20) != 20) continue; n = read(fd,fname,sizeof(fname)); fname[MAX(n,0)]=0; close(fd); - t = IVAL(buf,0); - mode = IVAL(buf,4); - pid = IVAL(buf,8); + t.tv_sec = IVAL(buf,4); + t.tv_usec = IVAL(buf,8); + mode = IVAL(buf,12); + pid = IVAL(buf,16); if ( !Ucrit_checkPid(pid) ) /* added by OH */ continue; - if (IVAL(buf,12) != LOCKING_VERSION || !process_exists(pid)) { + if (IVAL(buf,0) != LOCKING_VERSION || !process_exists(pid)) { if (unlink(lname)==0) printf("Deleted stale share file %s\n",s); continue; @@ -284,7 +285,7 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ case 1: printf("WRONLY "); break; case 2: printf("RDWR "); break; } - printf(" %s %s",fname,asctime(LocalTime(&t))); + printf(" %s %s",fname,asctime(LocalTime((time_t *)&t.tv_sec))); #if FAST_SHARE_MODES prev_p = scanner_p ; -- cgit From 869f24e0b1915ec8d3e14f8850417474200e687e Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Wed, 15 Jan 1997 01:53:25 +0000 Subject: locking.c proto.h shmem.c smb.h status.c : Changed shm_ prefixes to smb_shm_ prefixes as shm_ is a POSIX.4 prefix. Updated fd code in FAST_SHARE_MODE code to work with new fd indirection. quotas.c: Fixed #ifdef not on position zero. Jeremy. (jra@cygnus.com). (This used to be commit c9a9d56642cc34369a42f48a28116e466240d303) --- source3/utils/status.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 69fbda5ea8..459349f5eb 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -175,27 +175,27 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ trim_string(shmem_file_name,"","/"); if (!*shmem_file_name) exit(-1); strcat(shmem_file_name, "/SHARE_MEM_FILE"); - if(!shm_open(shmem_file_name, SHMEM_SIZE)) exit(-1); + if(!smb_shm_open(shmem_file_name, SHMEM_SIZE)) exit(-1); - if(!shm_lock()) + if(!smb_shm_lock()) { - shm_close(); + smb_shm_close(); exit (-1); } - scanner_p = (share_mode_record *)shm_offset2addr(shm_get_userdef_off()); + scanner_p = (share_mode_record *)smb_shm_offset2addr(smb_shm_get_userdef_off()); prev_p = scanner_p; while(scanner_p) { int pid,mode; - time_t t; + struct timeval t; pid = scanner_p->pid; if ( !Ucrit_checkPid(pid) ) { prev_p = scanner_p ; - scanner_p = (share_mode_record *)shm_offset2addr(scanner_p->next_offset); + scanner_p = (share_mode_record *)smb_shm_offset2addr(scanner_p->next_offset); continue; } @@ -204,20 +204,21 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ DEBUG(2,("Deleting stale share mode record")); if(prev_p == scanner_p) { - shm_set_userdef_off(scanner_p->next_offset); - shm_free(shm_addr2offset(scanner_p)); - scanner_p = (share_mode_record *)shm_offset2addr(shm_get_userdef_off()); + smb_shm_set_userdef_off(scanner_p->next_offset); + smb_shm_free(smb_shm_addr2offset(scanner_p)); + scanner_p = (share_mode_record *)smb_shm_offset2addr(smb_shm_get_userdef_off()); prev_p = scanner_p; } else { prev_p->next_offset = scanner_p->next_offset; - shm_free(shm_addr2offset(scanner_p)); - scanner_p = (share_mode_record *)shm_offset2addr(prev_p->next_offset); + smb_shm_free(smb_shm_addr2offset(scanner_p)); + scanner_p = (share_mode_record *)smb_shm_offset2addr(prev_p->next_offset); } continue; } - t = scanner_p->time; + t.tv_sec = scanner_p->time.tv_sec; + t.tv_usec = scanner_p->time.tv_usec; mode = scanner_p->share_mode; strcpy(fname, scanner_p->file_name); #else @@ -289,17 +290,17 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ #if FAST_SHARE_MODES prev_p = scanner_p ; - scanner_p = (share_mode_record *)shm_offset2addr(scanner_p->next_offset); + scanner_p = (share_mode_record *)smb_shm_offset2addr(scanner_p->next_offset); } /* end while */ - shm_get_usage(&bytes_free, &bytes_used, &bytes_overhead); + smb_shm_get_usage(&bytes_free, &bytes_used, &bytes_overhead); bytes_total = bytes_free + bytes_used + bytes_overhead; - shm_unlock(); + smb_shm_unlock(); /******************************************************************* deinitialize the shared memory for share_mode management ******************************************************************/ - shm_close(); + smb_shm_close(); #else } /* end while */ -- cgit From 0f1f0ceb9519368188f695e18e2341ccfd1b2d15 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 8 May 1997 01:14:17 +0000 Subject: 'The mother of all checkins' :-). Jeremy Allison (jallison@whistle.com) Wed May 7 1997: Update for 1.9.17alpha1 release - 'browsefix release' designed to make browsing across subnets work. byteorder.h: Updated copyright to 1997. charcnv.c: Updated copyright to 1997. charset.c Updated copyright to 1997. charset.h Updated copyright to 1997. client.c Updated copyright to 1997. clientutil.c Updated copyright to 1997. dir.c Updated copyright to 1997. fault.c Updated copyright to 1997. includes.h Updated copyright to 1997. interface.c Updated copyright to 1997. ipc.c Updated copyright to 1997. kanji.c Updated copyright to 1997. kanji.h Updated copyright to 1997. loadparm.c Updated copyright to 1997. locking.c Updated copyright to 1997. mangle.c Updated copyright to 1997. message.c Updated copyright to 1997. nameannounce.c Made use of WINS subnet explicit. Added reset_announce_timer() so announcement can be made immediately when we become a master. Expanded code to do sync with dmb. namebrowse.c Removed redundent checks for AM_MASTER in sync code. Made use of WINS subnet explicit. namedbname.c Made use of WINS subnet explicit. namedbresp.c Made use of WINS subnet explicit. namedbserver.c Made use of WINS subnet explicit. namedbsubnet.c Explicitly add workgroup to WINS subnet when we become a dmb. Made use of WINS subnet explicit. namedbwork.c Made use of WINS subnet explicit. Removed redundent check_work_servertype() function. nameelect.c Explicitly add workgroup to WINS subnet when we become a master browser. Made use of WINS subnet explicit. namelogon.c Updated copyright to 1997. namepacket.c Updated copyright to 1997. namequery.c Updated copyright to 1997. nameresp.c Made use of WINS subnet explicit. Made nmbd fail if configured as master browser and one exists already. nameserv.c Made use of WINS subnet explicit. Remove redundent logon server and domain master code. nameserv.h Add emumerate subnet macros. nameservreply.c Made use of WINS subnet explicit. nameservresp.c Updated copyright to 1997. namework.c Made use of WINS subnet explicit. Updated code to add sync browser entries to add subnet parameter. nmbd.c Added sanity check for misconfigured nmbd. nmblib.c Updated copyright to 1997. nmblookup.c Updated copyright to 1997. nmbsync.c Removed redundent AM_ANY_MASTER check. params.c Updated copyright to 1997. password.c Updated copyright to 1997. pipes.c Updated copyright to 1997. predict.c Updated copyright to 1997. printing.c Updated copyright to 1997. proto.h Changed protos for new nmbd code. quotas.c Updated copyright to 1997. replace.c Updated copyright to 1997. reply.c Updated copyright to 1997. server.c Updated copyright to 1997. shmem.c Updated copyright to 1997. smb.h Updated copyright to 1997. smbencrypt.c Updated copyright to 1997. smbpasswd.c Updated copyright to 1997. smbrun.c Updated copyright to 1997. status.c Updated copyright to 1997. system.c Updated copyright to 1997. testparm.c Updated copyright to 1997. testprns.c Updated copyright to 1997. time.c Updated copyright to 1997. trans2.c Updated copyright to 1997. trans2.h Updated copyright to 1997. uid.c Updated copyright to 1997. username.c Updated copyright to 1997. util.c Updated copyright to 1997. version.h Changed to 1.9.17alpha1. (This used to be commit cf23a155a1315f50d488794a2caf88402bf3e3e6) --- source3/utils/nmblookup.c | 2 +- source3/utils/smbpasswd.c | 2 +- source3/utils/status.c | 2 +- source3/utils/testparm.c | 2 +- source3/utils/testprns.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index c969276838..582f4eb6db 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. NBT client - used to lookup netbios names - Copyright (C) Andrew Tridgell 1994-1995 + Copyright (C) Andrew Tridgell 1994-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 diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index c79aa15c80..c820ad673a 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -2,7 +2,7 @@ /* * Unix SMB/Netbios implementation. Version 1.9. smbpasswd module. Copyright - * (C) Jeremy Allison 1995. + * (C) Jeremy Allison 1995-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 diff --git a/source3/utils/status.c b/source3/utils/status.c index 459349f5eb..ba7c5f3210 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. status reporting - Copyright (C) Andrew Tridgell 1994-1995 + Copyright (C) Andrew Tridgell 1994-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 diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 7e05283625..81e69cd76f 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. Test validity of smb.conf - Copyright (C) Karl Auer 1993, 1994 + Copyright (C) Karl Auer 1993, 1994-1997 Extensively modified by Andrew Tridgell, 1995 diff --git a/source3/utils/testprns.c b/source3/utils/testprns.c index 4709eb0691..4a2ddb7c63 100644 --- a/source3/utils/testprns.c +++ b/source3/utils/testprns.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. test printer setup - Copyright (C) Karl Auer 1993, 1994 + Copyright (C) Karl Auer 1993, 1994-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 -- cgit From 441855fe0e6b37201d2ef6a8375de4bcc76b9752 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 8 May 1997 21:17:59 +0000 Subject: status.c: Added brief option. Patch from ccctim@mailbox.ucdavis.edu client.c: Added translation of '/' characters to '\' characters. Suggested by friedl@mtndew.com (Stephen J. Friedl) charcn.c: Fix for iso8859-2 (Eastern European) conversions based on a patch from Miroslaw M. Maczka (This used to be commit 27708a73cef690ea8aea0f3d82619eaed1fe476d) --- source3/utils/status.c | 93 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 77 insertions(+), 16 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index ba7c5f3210..e8e57b3dd7 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -35,6 +35,15 @@ #include "includes.h" struct connect_record crec; + +struct session_record{ + int pid; + int uid; + char machine[31]; + time_t start; + struct session_record *next; +} *srecs; + extern int DEBUGLEVEL; extern FILE *dbf; extern pstring myhostname; @@ -51,7 +60,7 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ int uid, c; static pstring servicesf = CONFIGFILE; extern char *optarg; - int verbose = 0; + int verbose = 0, brief =0; BOOL firstopen=True; BOOL processes_only=False; int last_pid=0; @@ -65,6 +74,7 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ void *dir; char *s; #endif + struct session_record *ptr; TimeInit(); @@ -80,8 +90,11 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ return(1); } - while ((c = getopt(argc, argv, "pds:u:")) != EOF) { + while ((c = getopt(argc, argv, "pds:u:b")) != EOF) { switch (c) { + case 'b': + brief = 1; + break; case 'd': verbose = 1; break; @@ -133,8 +146,16 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ if (!processes_only) { printf("\nSamba version %s\n",VERSION); - printf("Service uid gid pid machine\n"); - printf("----------------------------------------------\n"); + if (brief) + { + printf("PID Username Machine Time logged in\n"); + printf("-------------------------------------------------------------------\n"); + } + else + { + printf("Service uid gid pid machine\n"); + printf("----------------------------------------------\n"); + } } while (!feof(f)) @@ -145,23 +166,63 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ && Ucrit_checkUsername(uidtoname(crec.uid)) /* added by OH */ ) { - Ucrit_addPid(crec.pid); /* added by OH */ - if (processes_only) { - if (last_pid != crec.pid) - printf("%d\n",crec.pid); - last_pid = crec.pid; /* XXXX we can still get repeats, have to - add a sort at some time */ - } - else - printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", - crec.name,uidtoname(crec.uid),gidtoname(crec.gid),crec.pid, - crec.machine,crec.addr, - asctime(LocalTime(&crec.start))); + if (brief) + { + ptr=srecs; + while (ptr!=NULL) + { + if ((ptr->pid==crec.pid)&&(strncmp(ptr->machine,crec.machine,30)==0)) + { + if (ptr->start > crec.start) + ptr->start=crec.start; + break; + } + ptr=ptr->next; + } + if (ptr==NULL) + { + ptr=(struct session_record *) malloc(sizeof(struct session_record)); + ptr->uid=crec.uid; + ptr->pid=crec.pid; + ptr->start=crec.start; + strncpy(ptr->machine,crec.machine,30); + ptr->machine[30]='\0'; + ptr->next=srecs; + srecs=ptr; + } + } + else + { + Ucrit_addPid(crec.pid); /* added by OH */ + if (processes_only) { + if (last_pid != crec.pid) + printf("%d\n",crec.pid); + last_pid = crec.pid; /* XXXX we can still get repeats, have to + add a sort at some time */ + } + else + printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", + crec.name,uidtoname(crec.uid),gidtoname(crec.gid),crec.pid, + crec.machine,crec.addr, + asctime(LocalTime(&crec.start))); + } } } fclose(f); if (processes_only) exit(0); + + if (brief) + { + ptr=srecs; + while (ptr!=NULL) + { + printf("%-8d%-10.10s%-30.30s%s",ptr->pid,uidtoname(ptr->uid),ptr->machine,asctime(LocalTime(&(ptr->start)))); + ptr=ptr->next; + } + printf("\n"); + exit(0); + } printf("\n"); -- cgit From aa864415c5183c948fe9ae221023d40265c38013 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Tue, 20 May 1997 00:32:51 +0000 Subject: dir.c: Fixed double slash issue. includes.h: Changed to ifdef FAST_SHARE_MODES. ipc.c: Changed lp_workgroup() to myworkgroup. loadparm.c: Added new shared mem parameters. Added Luke's fix. locking.c: Rewrite to do share modes better (both fast and slow modes). nameannounce.c: Changed lp_workgroup() to myworkgroup. Added Luke's fix. nameconf.c: Changed lp_workgroup() to myworkgroup. namedbname.c: Improved debug. namedbserver.c: Changed lp_workgroup() to myworkgroup. namedbsubnet.c: Added Luke's fix - rewritten somewhat. namedbwork.c: Changed lp_workgroup() to myworkgroup. nameelect.c: Added Luke's fix - rewritten somewhat. nameresp.c: Stoped shadowing global. nameserv.c: Added Luke's fix - Improved debug. nameservreply.c: Improved debug. namework.c: Changed lp_workgroup() to myworkgroup. nmbd.c: Added Luke's fix - Changed lp_workgroup() to myworkgroup. pipes.c: Changed lp_workgroup() to myworkgroup. proto.h: Added Luke's fix, added smb_shm_ proto's. reply.c: Changed lp_workgroup() to myworkgroup. server.c: Rewrite to do share modes better (both fast and slow modes). shmem.c: Rewrite to do share modes better (both fast and slow modes). smb.h: Rewrite to do share modes better (both fast and slow modes). status.c: Rewrite to do share modes better (both fast and slow modes). trans2.c: Fixed double slash issue. util.c: Tidied up, created myworkgroup. Jeremy Allison (jallison@whistle.com). (This used to be commit 2a1711eaaf08bb6776770cd3c96b3010f431a677) --- source3/utils/status.c | 260 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 177 insertions(+), 83 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index e8e57b3dd7..b439741e6c 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -53,6 +53,81 @@ int Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ int Ucrit_MaxPid=0; /* added by OH */ unsigned int Ucrit_IsActive = 0; /* added by OH */ +#ifndef FAST_SHARE_MODES +static char *read_share_file(int fd, char *fname, char *progname) +{ + struct stat sb; + char *buf; + int size; + + if(fstat(fd, &sb) != 0) + { + printf("%s: ERROR: read_share_file: Failed to do stat on share file %s (%s)\n", + progname, fname, strerror(errno)); + return 0; + } + + if(sb.st_size == 0) + { + return 0; + } + + /* Allocate space for the file */ + if((buf = (char *)malloc(sb.st_size)) == NULL) + { + printf("%s: read_share_file: malloc for file size %d fail !\n", + progname, (int)sb.st_size); + return 0; + } + + if(lseek(fd, 0, SEEK_SET) != 0) + { + printf("%s: ERROR: read_share_file: Failed to reset position to 0 \ +for share file %s (%s)\n", progname, fname, strerror(errno)); + if(buf) + free(buf); + return 0; + } + + if (read(fd,buf,sb.st_size) != sb.st_size) + { + printf("%s: ERROR: read_share_file: Failed to read share file %s (%s)\n", + progname, fname, strerror(errno)); + if(buf) + free(buf); + return 0; + } + + if (IVAL(buf,0) != LOCKING_VERSION) { + printf("%s: ERROR: read_share_file: share file %s has incorrect \ +locking version (was %d, should be %d).\n",fname, + progname, IVAL(buf,0), LOCKING_VERSION); + if(buf) + free(buf); + return 0; + } + + /* Sanity check for file contents */ + size = sb.st_size; + size -= 10; /* Remove the header */ + + /* Remove the filename component. */ + size -= SVAL(buf, 8); + + /* The remaining size must be a multiple of 16 - error if not. */ + if((size % 16) != 0) + { + printf("%s: ERROR: read_share_file: share file %s is an incorrect length.\n", + progname, fname); + if(buf) + free(buf); + return 0; + } + + return buf; +} +#endif /* FAST_SHARE_MODES */ + int main(int argc, char *argv[]) { FILE *f; @@ -64,16 +139,16 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ BOOL firstopen=True; BOOL processes_only=False; int last_pid=0; -#if FAST_SHARE_MODES +#ifdef FAST_SHARE_MODES pstring shmem_file_name; - share_mode_record *scanner_p; - share_mode_record *prev_p; + share_mode_record *file_scanner_p; + smb_shm_offset_t *mode_array; int bytes_free, bytes_used, bytes_overhead, bytes_total; -#else - int n; +#else /* FAST_SHARE_MODES */ void *dir; char *s; -#endif +#endif /* FAST_SHARE_MODES */ + int i; struct session_record *ptr; @@ -226,101 +301,110 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ printf("\n"); -#if FAST_SHARE_MODES +#ifdef FAST_SHARE_MODES /******************************************************************* initialize the shared memory for share_mode management ******************************************************************/ - strcpy(shmem_file_name,lp_lockdir()); trim_string(shmem_file_name,"","/"); if (!*shmem_file_name) exit(-1); strcat(shmem_file_name, "/SHARE_MEM_FILE"); - if(!smb_shm_open(shmem_file_name, SHMEM_SIZE)) exit(-1); + if(!smb_shm_open(shmem_file_name, lp_shmem_size())) exit(-1); - if(!smb_shm_lock()) + mode_array = (smb_shm_offset_t *)smb_shm_offset2addr(smb_shm_get_userdef_off()); + if(mode_array == NULL) { - smb_shm_close(); - exit (-1); + printf("%s: base of shared memory hash array == 0! Exiting.\n", argv[0]); + smb_shm_close(); + exit(-1); } - scanner_p = (share_mode_record *)smb_shm_offset2addr(smb_shm_get_userdef_off()); - prev_p = scanner_p; - while(scanner_p) + for( i = 0; i < lp_shmem_hash_size(); i++) { - int pid,mode; - struct timeval t; - - pid = scanner_p->pid; - - if ( !Ucrit_checkPid(pid) ) - { - prev_p = scanner_p ; - scanner_p = (share_mode_record *)smb_shm_offset2addr(scanner_p->next_offset); - continue; - } + smb_shm_lock_hash_entry(i); + if(mode_array[i] == NULL_OFFSET) + { + smb_shm_unlock_hash_entry(i); + continue; + } + file_scanner_p = (share_mode_record *)smb_shm_offset2addr(mode_array[i]); + while((file_scanner_p != 0) && (file_scanner_p->num_share_mode_entries != 0)) + { + share_mode_entry *entry_scanner_p = + (share_mode_entry *)smb_shm_offset2addr( + file_scanner_p->share_mode_entries); + + while(entry_scanner_p != 0) + { + struct timeval t; + int pid = entry_scanner_p->pid; + int mode = entry_scanner_p->share_mode; - if( (scanner_p->locking_version != LOCKING_VERSION) || !process_exists(pid)) + t.tv_sec = entry_scanner_p->time.tv_sec; + t.tv_usec = entry_scanner_p->time.tv_usec; + strcpy(fname, file_scanner_p->file_name); +#else /* FAST_SHARE_MODES */ + + /* For slow share modes go through all the files in + the share mode directory and read the entries in + each. + */ + + dir = opendir(lp_lockdir()); + if (!dir) { - DEBUG(2,("Deleting stale share mode record")); - if(prev_p == scanner_p) - { - smb_shm_set_userdef_off(scanner_p->next_offset); - smb_shm_free(smb_shm_addr2offset(scanner_p)); - scanner_p = (share_mode_record *)smb_shm_offset2addr(smb_shm_get_userdef_off()); - prev_p = scanner_p; - } - else - { - prev_p->next_offset = scanner_p->next_offset; - smb_shm_free(smb_shm_addr2offset(scanner_p)); - scanner_p = (share_mode_record *)smb_shm_offset2addr(prev_p->next_offset); - } - continue; + printf("%s: Unable to open lock directory %s.\n", argv[0], lp_lockdir()); + return(0); } - t.tv_sec = scanner_p->time.tv_sec; - t.tv_usec = scanner_p->time.tv_usec; - mode = scanner_p->share_mode; - strcpy(fname, scanner_p->file_name); -#else - dir = opendir(lp_lockdir()); - if (!dir) return(0); while ((s=readdirname(dir))) { - char buf[20]; - int pid,mode; - struct timeval t; + char *buf; + char *base; int fd; pstring lname; - int dev,inode; + uint32 dev,inode; - if (sscanf(s,"share.%d.%d",&dev,&inode)!=2) continue; + if (sscanf(s,"share.%u.%u",&dev,&inode)!=2) continue; strcpy(lname,lp_lockdir()); trim_string(lname,NULL,"/"); strcat(lname,"/"); strcat(lname,s); - fd = open(lname,O_RDONLY,0); - if (fd < 0) continue; - if (read(fd,buf,20) != 20) continue; - n = read(fd,fname,sizeof(fname)); - fname[MAX(n,0)]=0; - close(fd); - - t.tv_sec = IVAL(buf,4); - t.tv_usec = IVAL(buf,8); - mode = IVAL(buf,12); - pid = IVAL(buf,16); - - if ( !Ucrit_checkPid(pid) ) /* added by OH */ - continue; - - if (IVAL(buf,0) != LOCKING_VERSION || !process_exists(pid)) { - if (unlink(lname)==0) - printf("Deleted stale share file %s\n",s); - continue; + fd = open(lname,O_RDWR,0); + if (fd < 0) + { + printf("%s: Unable to open share file %s.\n", argv[0], lname); + continue; } -#endif + + /* Lock the share mode file while we read it. */ + if(fcntl_lock(fd, F_SETLKW, 0, 1, F_WRLCK) == False) + { + printf("%s: Unable to lock open share file %s.\n", argv[0], lname); + close(fd); + continue; + } + + if(( buf = read_share_file( fd, lname, argv[0] )) == NULL) + { + close(fd); + continue; + } + strcpy( fname, &buf[10]); + close(fd); + + base = buf + 10 + SVAL(buf,8); + for( i = 0; i < IVAL(buf, 4); i++) + { + char *p = base + (i*16); + struct timeval t; + int pid = IVAL(p,12); + int mode = IVAL(p,8); + + t.tv_sec = IVAL(p,0); + t.tv_usec = IVAL(p,4); +#endif /* FAST_SHARE_MODES */ fname[sizeof(fname)-1] = 0; @@ -349,28 +433,38 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ } printf(" %s %s",fname,asctime(LocalTime((time_t *)&t.tv_sec))); -#if FAST_SHARE_MODES - prev_p = scanner_p ; - scanner_p = (share_mode_record *)smb_shm_offset2addr(scanner_p->next_offset); - } /* end while */ +#ifdef FAST_SHARE_MODES + + entry_scanner_p = (share_mode_entry *)smb_shm_offset2addr( + entry_scanner_p->next_share_mode_entry); + } /* end while entry_scanner_p */ + file_scanner_p = (share_mode_record *)smb_shm_offset2addr( + file_scanner_p->next_offset); + } /* end while file_scanner_p */ + smb_shm_unlock_hash_entry(i); + } /* end for */ smb_shm_get_usage(&bytes_free, &bytes_used, &bytes_overhead); bytes_total = bytes_free + bytes_used + bytes_overhead; - smb_shm_unlock(); /******************************************************************* deinitialize the shared memory for share_mode management ******************************************************************/ smb_shm_close(); -#else +#else /* FAST_SHARE_MODES */ + } /* end for i */ + + if(buf) + free(buf); + base = 0; } /* end while */ closedir(dir); -#endif +#endif /* FAST_SHARE_MODES */ if (firstopen) printf("No locked files\n"); -#if FAST_SHARE_MODES +#ifdef FAST_SHARE_MODES printf("\nShare mode memory usage (bytes):\n"); printf(" %d(%d%%) free + %d(%d%%) used + %d(%d%%) overhead = %d(100%%) total\n", bytes_free, (bytes_free * 100)/bytes_total, @@ -378,7 +472,7 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ bytes_overhead, (bytes_overhead * 100)/bytes_total, bytes_total); -#endif +#endif /* FAST_SHARE_MODES */ return (0); } -- cgit From c6e63aa896a10656f6205828e744b722fc72f8ac Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Wed, 11 Jun 1997 01:03:06 +0000 Subject: Makefile: Added quoata changes for Linux from Thorvald Natvig Makefile.RPM: Added quoata changes for Linux from Thorvald Natvig charset.c: Large changes to add multiple client code pages. charset.h: Changed charset_initialise() proto. client.c: Fixed message sending bug. Changed charset_initialise(). ipc.c: Fixed #ifdef compile problems. loadparm.c: Added "client code page" option. nmbd.c: Changed charset_initialise(). Fixed lmhosts read. nmblookup.c: Changed charset_initialise(). proto.h: Added lp_client_code_page(void). quotas.c: Added quoata changes for Linux from Thorvald Natvig reply.c: Changed debug level. Made SMBecho ignore tid. server.c: Changed charset_initialise(). smb.h: Added DEFAULT_CLIENT_CODE_PAGE as 850. smbpasswd.c: Changed charset_initialise(). status.c: Changed charset_initialise(). testparm.c: Changed charset_initialise(). testprns.c: Changed charset_initialise(). Jeremy Allison (jallison@whistle.com) (This used to be commit 957025bace1bcff34d21a6caeca498e85abccb23) --- source3/utils/nmblookup.c | 2 +- source3/utils/smbpasswd.c | 2 +- source3/utils/status.c | 2 +- source3/utils/testparm.c | 2 +- source3/utils/testprns.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 582f4eb6db..68093c10ed 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -111,7 +111,7 @@ int main(int argc,char *argv[]) setup_logging(argv[0],True); - charset_initialise(); + charset_initialise(0); while ((opt = getopt(argc, argv, "p:d:B:i:s:SMh")) != EOF) switch (opt) diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index c820ad673a..495f8e585c 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -235,7 +235,7 @@ static void usage(char *name) setup_logging(argv[0],True); - charset_initialise(); + charset_initialise(0); #ifndef DEBUG_PASSWORD /* Check the effective uid */ diff --git a/source3/utils/status.c b/source3/utils/status.c index b439741e6c..77fbc7fae1 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -155,7 +155,7 @@ locking version (was %d, should be %d).\n",fname, TimeInit(); setup_logging(argv[0],True); - charset_initialise(); + charset_initialise(0); DEBUGLEVEL = 0; dbf = fopen("/dev/null","w"); diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 81e69cd76f..e9a848eb0b 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -48,7 +48,7 @@ extern int DEBUGLEVEL; setup_logging(argv[0],True); - charset_initialise(); + charset_initialise(0); if (argc < 2) strcpy(configfile,CONFIGFILE); diff --git a/source3/utils/testprns.c b/source3/utils/testprns.c index 4a2ddb7c63..c96ad476d2 100644 --- a/source3/utils/testprns.c +++ b/source3/utils/testprns.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) setup_logging(argv[0],True); - charset_initialise(); + charset_initialise(0); if (argc < 2 || argc > 3) printf("Usage: testprns printername [printcapfile]\n"); -- cgit From 0378cd5a8c42b99007ec54ac8a65bf21b9c9bfac Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 10 Jul 1997 20:15:48 +0000 Subject: Added -a option (for Andrew:-). Fixed bug where users with "NO PASSWORD" couldn't change their passwords. Jeremy (jallison@whistle.com) (This used to be commit 87d17af0087fb0eced7628239b73e2c6cae774a9) --- source3/utils/smbpasswd.c | 119 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 99 insertions(+), 20 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 495f8e585c..6867ff3b8a 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -203,7 +203,7 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, */ static void usage(char *name) { - fprintf(stderr, "Usage is : %s [username]\n", name); + fprintf(stderr, "Usage is : %s [-add] [username]\n", name); exit(1); } @@ -222,6 +222,7 @@ static void usage(char *name) FILE *fp; BOOL valid_old_pwd = False; BOOL got_valid_nt_entry = False; + BOOL add_user = False; long seekpos; int pwfd; char ascii_p16[66]; @@ -250,16 +251,23 @@ static void usage(char *name) /* Deal with usage problems */ if (real_uid == 0) { - /* As root we can change anothers password. */ - if (argc != 1 && argc != 2) + /* As root we can change anothers password and add a user. */ + if (argc > 3 ) usage(argv[0]); - } else if (argc != 1) + } else if (argc != 1) { + fprintf(stderr, "%s: Only root can set anothers password.\n", argv[0]); usage(argv[0]); + } - - if (real_uid == 0 && argc == 2) { + if (real_uid == 0 && (argc > 1)) { + /* We are root - check if we should add the user */ + if ((argv[1][0] == '-') && (argv[1][1] == 'a')) + add_user = True; + if(add_user && (argc != 3)) + usage(argv[0]); + /* If we are root we can change anothers password. */ - strncpy(user_name, argv[1], sizeof(user_name) - 1); + strncpy(user_name, add_user ? argv[2] : argv[1], sizeof(user_name) - 1); user_name[sizeof(user_name) - 1] = '\0'; pwd = getpwnam(user_name); } else { @@ -347,27 +355,98 @@ static void usage(char *name) smb_pwent = _my_get_smbpwnam(fp, pwd->pw_name, &valid_old_pwd, &got_valid_nt_entry, &seekpos); if (smb_pwent == NULL) { - fprintf(stderr, "%s: Failed to find entry for user %s in file %s.\n", - argv[0], pwd->pw_name, pfile); - fclose(fp); - pw_file_unlock(lockfd); - exit(1); - } - /* If we are root we don't need to check the old password. */ - if (real_uid != 0) { - if ((valid_old_pwd == False) || (smb_pwent->smb_passwd == NULL)) { - fprintf(stderr, "%s: User %s is disabled, plase contact your administrator to enable it.\n", argv[0], pwd->pw_name); + if(add_user == False) { + fprintf(stderr, "%s: Failed to find entry for user %s in file %s.\n", + argv[0], pwd->pw_name, pfile); fclose(fp); pw_file_unlock(lockfd); exit(1); } - /* Check the old Lanman password */ - if (memcmp(old_p16, smb_pwent->smb_passwd, 16)) { - fprintf(stderr, "%s: Couldn't change password.\n", argv[0]); + + /* Create a new smb passwd entry and set it to the given password. */ + { + int fd; + int i; + int new_entry_length; + char *new_entry; + char *p; + long offpos; + + /* The add user write needs to be atomic - so get the fd from + the fp and do a raw write() call. + */ + fd = fileno(fp); + + if((offpos = lseek(fd, 0, SEEK_END)) == -1) { + fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ +Error was %d\n", argv[0], pwd->pw_name, pfile, errno); + fclose(fp); + pw_file_unlock(lockfd); + exit(1); + } + + new_entry_length = strlen(pwd->pw_name) + 1 + 15 + 1 + + 32 + 1 + 32 + 1 + strlen(pwd->pw_gecos) + + 1 + strlen(pwd->pw_dir) + 1 + + strlen(pwd->pw_shell) + 1; + if((new_entry = (char *)malloc( new_entry_length )) == 0) { + fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ +Error was %d\n", argv[0], pwd->pw_name, pfile, errno); + fclose(fp); + pw_file_unlock(lockfd); + exit(1); + } + + sprintf(new_entry, "%s:%u:", pwd->pw_name, pwd->pw_uid); + p = &new_entry[strlen(new_entry)]; + for( i = 0; i < 16; i++) + sprintf(&p[i*2], "%02X", new_p16[i]); + p += 32; + *p++ = ':'; + for( i = 0; i < 16; i++) + sprintf(&p[i*2], "%02X", old_p16[i]); + p += 32; + *p++ = ':'; + sprintf(p, "%s:%s:%s\n", pwd->pw_gecos, + pwd->pw_dir, pwd->pw_shell); + if(write(fd, new_entry, strlen(new_entry)) != strlen(new_entry)) { + fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ +Error was %d\n", argv[0], pwd->pw_name, pfile, errno); + /* Remove the entry we just wrote. */ + if(ftruncate(fd, offpos) == -1) { + fprintf(stderr, "%s: ERROR failed to ftruncate file %s. \ +Error was %d. Password file may be corrupt ! Please examine by hand !\n", + argv[0], pwd->pw_name, errno); + } + fclose(fp); + pw_file_unlock(lockfd); + exit(1); + } + + fclose(fp); + pw_file_unlock(lockfd); + exit(0); + } + } + + /* If we are root or the password is 'NO PASSWORD' then + we don't need to check the old password. */ + if (real_uid != 0) { + if (valid_old_pwd == False) { + fprintf(stderr, "%s: User %s is disabled, plase contact your administrator to enable it.\n", argv[0], pwd->pw_name); fclose(fp); pw_file_unlock(lockfd); exit(1); } + /* Check the old Lanman password - NULL means 'NO PASSWORD' */ + if (smb_pwent->smb_passwd != NULL) { + if (memcmp(old_p16, smb_pwent->smb_passwd, 16)) { + fprintf(stderr, "%s: Couldn't change password.\n", argv[0]); + fclose(fp); + pw_file_unlock(lockfd); + exit(1); + } + } /* Check the NT password if it exists */ if (smb_pwent->smb_nt_passwd != NULL) { if (memcmp(old_nt_p16, smb_pwent->smb_nt_passwd, 16)) { -- cgit From 612111c7a1a048d19e24b5e2e4d426247d320d1e Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Fri, 18 Jul 1997 20:21:32 +0000 Subject: charset.c: Split charset_initialise() into 2 - a charset_initialise() and a codepage_initialise(). Fixes problem with initialising dos map twice. charset.h: Changes to support charset changes. client.c: Changes to support charset changes. loadparm.c: follow symlinks parameter from David Clerc nmbd.c: Changes to support charset changes. nmblookup.c:Changes to support charset changes. proto.h: Changes to support charset changes. reply.c: Don't call security=server with no user/no password guest. Fix from Stefaan A Eeckels server.c: follow symlinks code from David Clerc smbpasswd.c:Changes to support charset changes. status.c: Changes to support charset changes. testparm.c: Changes to support charset changes. testprns.c: Changes to support charset changes. uid.c: Fixed log message with no \n. Jeremy (jallison@whistle.com) (This used to be commit 2a28a6e5e461aca7fe6c19cd01d287010056cffb) --- source3/utils/nmblookup.c | 2 +- source3/utils/smbpasswd.c | 2 +- source3/utils/status.c | 2 +- source3/utils/testparm.c | 2 +- source3/utils/testprns.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 68093c10ed..582f4eb6db 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -111,7 +111,7 @@ int main(int argc,char *argv[]) setup_logging(argv[0],True); - charset_initialise(0); + charset_initialise(); while ((opt = getopt(argc, argv, "p:d:B:i:s:SMh")) != EOF) switch (opt) diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 6867ff3b8a..e03ebbaaef 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -236,7 +236,7 @@ static void usage(char *name) setup_logging(argv[0],True); - charset_initialise(0); + charset_initialise(); #ifndef DEBUG_PASSWORD /* Check the effective uid */ diff --git a/source3/utils/status.c b/source3/utils/status.c index 77fbc7fae1..b439741e6c 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -155,7 +155,7 @@ locking version (was %d, should be %d).\n",fname, TimeInit(); setup_logging(argv[0],True); - charset_initialise(0); + charset_initialise(); DEBUGLEVEL = 0; dbf = fopen("/dev/null","w"); diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index e9a848eb0b..81e69cd76f 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -48,7 +48,7 @@ extern int DEBUGLEVEL; setup_logging(argv[0],True); - charset_initialise(0); + charset_initialise(); if (argc < 2) strcpy(configfile,CONFIGFILE); diff --git a/source3/utils/testprns.c b/source3/utils/testprns.c index c96ad476d2..4a2ddb7c63 100644 --- a/source3/utils/testprns.c +++ b/source3/utils/testprns.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) setup_logging(argv[0],True); - charset_initialise(0); + charset_initialise(); if (argc < 2 || argc > 3) printf("Usage: testprns printername [printcapfile]\n"); -- cgit From b95057c1276f0350a5b7d6a4bc4847e21d7be86b Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Mon, 21 Jul 1997 16:58:10 +0000 Subject: Fixed bug with -add code that put wrong password in nt md4 field. Jeremy (jallison@whistle.com) (This used to be commit aabb18953b5d026af3548610aa1ffd6ea2fd72e5) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index e03ebbaaef..6088263bcc 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -404,7 +404,7 @@ Error was %d\n", argv[0], pwd->pw_name, pfile, errno); p += 32; *p++ = ':'; for( i = 0; i < 16; i++) - sprintf(&p[i*2], "%02X", old_p16[i]); + sprintf(&p[i*2], "%02X", new_nt_p16[i]); p += 32; *p++ = ':'; sprintf(p, "%s:%s:%s\n", pwd->pw_gecos, -- cgit From 049640c8b6f1b234c3fa449b9a928515b849f4d7 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Wed, 6 Aug 1997 14:35:23 +0000 Subject: updated smbpasswd to take the password on the command-line. two sets of operation: as root: specify username password. as user: specify old password new password this will allow shell scripts (like adduser) to include smbpasswd. lkcl (This used to be commit 7e5f1681bd538c3a1b576cff1d86fa8167704525) --- source3/utils/smbpasswd.c | 92 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 72 insertions(+), 20 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 6088263bcc..f43262ef83 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -203,7 +203,8 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, */ static void usage(char *name) { - fprintf(stderr, "Usage is : %s [-add] [username]\n", name); + fprintf(stderr, "Usage (as root) is : %s [-add] [username] [password]\n", name); + fprintf(stderr, "Usage (as user) is : %s [old password new password]\n", name); exit(1); } @@ -223,6 +224,7 @@ static void usage(char *name) BOOL valid_old_pwd = False; BOOL got_valid_nt_entry = False; BOOL add_user = False; + int add_pass = 0; long seekpos; int pwfd; char ascii_p16[66]; @@ -250,27 +252,51 @@ static void usage(char *name) real_uid = getuid(); /* Deal with usage problems */ - if (real_uid == 0) { + if (real_uid == 0) + { /* As root we can change anothers password and add a user. */ - if (argc > 3 ) + if (argc > 4 ) usage(argv[0]); - } else if (argc != 1) { + } + else if (argc == 2 || argc > 3) + { fprintf(stderr, "%s: Only root can set anothers password.\n", argv[0]); usage(argv[0]); } - if (real_uid == 0 && (argc > 1)) { + if (real_uid == 0 && (argc > 1)) + { /* We are root - check if we should add the user */ if ((argv[1][0] == '-') && (argv[1][1] == 'a')) add_user = True; - if(add_user && (argc != 3)) + + if(add_user && (argc != 4 || argc != 3)) usage(argv[0]); - /* If we are root we can change anothers password. */ + /* root can specify password on command-line */ + if (argc == (add_user ? 4 : 3)) + { + /* -a argument (add_user): new password is 3rd argument. */ + /* no -a argument (add_user): new password is 2nd argument */ + + add_pass = add_user ? 3 : 2; + } + + /* If we are root we can change another's password. */ strncpy(user_name, add_user ? argv[2] : argv[1], sizeof(user_name) - 1); user_name[sizeof(user_name) - 1] = '\0'; + pwd = getpwnam(user_name); - } else { + } + else + { + /* non-root can specify old pass / new pass on command-line */ + if (argc == 3) + { + /* non-root specifies new password as 2nd argument */ + add_pass = 2; + } + pwd = getpwuid(real_uid); } @@ -278,24 +304,50 @@ static void usage(char *name) fprintf(stderr, "%s: Unable to get UNIX password entry for user.\n", argv[0]); exit(1); } + /* If we are root we don't ask for the old password. */ old_passwd[0] = '\0'; - if (real_uid != 0) { - p = getpass("Old SMB password:"); - strncpy(old_passwd, p, sizeof(fstring)); + if (real_uid != 0) + { + if (add_pass) + { + /* old password, as non-root, is 1st argument */ + strncpy(old_passwd, argv[1], sizeof(fstring)); + } + else + { + p = getpass("Old SMB password:"); + strncpy(old_passwd, p, sizeof(fstring)); + } old_passwd[sizeof(fstring)-1] = '\0'; } - new_passwd[0] = '\0'; - p = getpass("New SMB password:"); - strncpy(new_passwd, p, sizeof(fstring)); - new_passwd[sizeof(fstring)-1] = '\0'; - p = getpass("Retype new SMB password:"); - if (strcmp(p, new_passwd)) { - fprintf(stderr, "%s: Mismatch - password unchanged.\n", argv[0]); - exit(1); + + if (add_pass) + { + /* new password is specified on the command line */ + strncpy(new_passwd, argv[add_user ? 3 : 2], sizeof(new_passwd) - 1); + new_passwd[sizeof(new_passwd) - 1] = '\0'; + } + else + { + new_passwd[0] = '\0'; + + p = getpass("New SMB password:"); + + strncpy(new_passwd, p, sizeof(fstring)); + new_passwd[sizeof(fstring)-1] = '\0'; + + p = getpass("Retype new SMB password:"); + + if (strcmp(p, new_passwd)) + { + fprintf(stderr, "%s: Mismatch - password unchanged.\n", argv[0]); + exit(1); + } } - if (new_passwd[0] == '\0') { + if (new_passwd[0] == '\0') + { printf("Password not set\n"); exit(0); } -- cgit From 1330324e7bb702b08e884e44da1cddab47cb9ee1 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Sat, 9 Aug 1997 13:29:02 +0000 Subject: bug in num. arguments detection that stopped the -add option working lkcl (This used to be commit e025ffa0aacb577619cc35f0b9e5c5a862f4429f) --- source3/utils/smbpasswd.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index f43262ef83..7a4a1e2cdb 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -203,8 +203,7 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, */ static void usage(char *name) { - fprintf(stderr, "Usage (as root) is : %s [-add] [username] [password]\n", name); - fprintf(stderr, "Usage (as user) is : %s [old password new password]\n", name); + fprintf(stderr, "Usage is : %s [-add] [username] [password]\n", name); exit(1); } @@ -270,7 +269,7 @@ static void usage(char *name) if ((argv[1][0] == '-') && (argv[1][1] == 'a')) add_user = True; - if(add_user && (argc != 4 || argc != 3)) + if(add_user && (argc < 2 || argc > 4)) usage(argv[0]); /* root can specify password on command-line */ @@ -485,10 +484,7 @@ Error was %d. Password file may be corrupt ! Please examine by hand !\n", we don't need to check the old password. */ if (real_uid != 0) { if (valid_old_pwd == False) { - fprintf(stderr, "%s: User %s is disabled, plase contact your administrator to enable it.\n", argv[0], pwd->pw_name); - fclose(fp); - pw_file_unlock(lockfd); - exit(1); + fprintf(stderr, "%s: User %s has no old SMB password.\n", argv[0], pwd->pw_name); } /* Check the old Lanman password - NULL means 'NO PASSWORD' */ if (smb_pwent->smb_passwd != NULL) { -- cgit From e9269c67a59ffa741123cb2ce3ab8dfb97136dec Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Tue, 19 Aug 1997 19:22:26 +0000 Subject: Makefile: Changed for HPUX10 tidyup. includes.h: Changed for HPUX10 tidyup. ipc.c: Fixed bug where getting local server list from NT browsers would fail. nmbsync.c: Fixed bug where getting local server list from NT browsers would fail. proto.h: Changed for crash bug on SCO with USE_MMAP. quotas.c: Added OSF quotas (patch from Bret Giddings ). Rolled back solaris uid change - I think it was wrong. reply.c: Changed for crash bug on SCO with USE_MMAP. server.c: Removed Lukes changes. Changed for crash bug on SCO with USE_MMAP. smb.h: Changed for crash bug on SCO with USE_MMAP. smbpasswd.c:Fixed crash bug with Lukes changes. uid.c: Removed Lukes changes. util.c: Fixed I18N bug with extended char filenames and widelinks = no. Jeremy (jallison@whistle.com) (This used to be commit bf1c79f7fd7f9beec4f9f4e58337cadceeb1cb38) --- source3/utils/smbpasswd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 7a4a1e2cdb..161555d52c 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -269,7 +269,7 @@ static void usage(char *name) if ((argv[1][0] == '-') && (argv[1][1] == 'a')) add_user = True; - if(add_user && (argc < 2 || argc > 4)) + if(add_user && (argc <= 2 || argc > 4)) usage(argv[0]); /* root can specify password on command-line */ @@ -338,7 +338,7 @@ static void usage(char *name) p = getpass("Retype new SMB password:"); - if (strcmp(p, new_passwd)) + if (strncmp(p, new_passwd, sizeof(fstring)-1)) { fprintf(stderr, "%s: Mismatch - password unchanged.\n", argv[0]); exit(1); -- cgit From 57408548f3cc717116b5eb3fe7381f0568ac473d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 30 Aug 1997 01:13:39 +0000 Subject: Adding codepage definition files and codepage file compiler/decompiler. Adding install/uninstall scripts for compiled codepage files. Preparing for dynamic codepage loading. Jeremy (jallison@whistle.com) (This used to be commit e3fc9533bd87d0d520e3dac98261e42370907b11) --- source3/utils/make_smbcodepage.c | 472 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 472 insertions(+) create mode 100644 source3/utils/make_smbcodepage.c (limited to 'source3/utils') diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c new file mode 100644 index 0000000000..c8b4fea8bc --- /dev/null +++ b/source3/utils/make_smbcodepage.c @@ -0,0 +1,472 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + Create codepage files from codepage_def.XXX files. + + Copyright (C) Jeremy Allison 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. +*/ + +#include "includes.h" + +static char *prog_name = NULL; + +/* + * Print program usage and die. + */ + +void codepage_usage(const char *progname) +{ + fprintf(stderr, "Usage is : %s [c|d] \n", + progname); + exit(1); +} + +/* + * Read a line from a buffer into a line buffer. Ensure null + * terminated. + */ + +void read_line( char **buf, char *line_buf, int size) +{ + char *p = *buf; + int num = 0; + + for(; *p && (*p != '\n'); 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. + */ + +int clean_data( char **buf, uint32 *size) +{ + char linebuf[512]; + char *p = *buf; + int num_lines = 0; + char *newbuf = (char *)malloc( *size + 1); + char *newbuf_p = NULL; + + if(newbuf == NULL) + { + fprintf(stderr, "%s: malloc fail for size %d.\n", prog_name, *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; + + strcpy(newbuf_p, cp); + num_lines++; + newbuf_p += (strlen(newbuf_p) + 1); + } + + free(*buf); + *buf = newbuf; + return num_lines; +} + +/* + * Parse a byte from a codepage file. + */ + +BOOL parse_byte(char *buf, unsigned char *bp) +{ + unsigned int b; + char *endptr = NULL; + + b = (unsigned int)strtol(buf, &endptr, 0); + if(endptr == buf || b > 255) + return False; + + *bp = (unsigned char)b; + return True; +} + +/* + * Parse a bool from a codepage file. + */ + +BOOL parse_bool(char *buf, unsigned char *bp) +{ + if(isdigit(*buf)) + { + char *endptr = NULL; + + *bp = (unsigned char)strtol(buf, &endptr, 0); + if(endptr == buf ) + return False; + if(*bp != 0) + *bp = 1; + } else { + if(strcasecmp(buf, "True") && strcasecmp(buf, "False")) + return False; + if(strcasecmp(buf, "True")==0) + *bp = 1; + else + *bp = 0; + } + return True; +} + +/* + * Print a parse error and exit. + */ + +void parse_error(char *buf, char *msg) +{ + fprintf(stderr, "%s: %s whilst parsing line \n%s\n", prog_name, + msg, buf); + exit(1); +} + +/* + * Create a compiled codepage file from a codepage definition file. + */ + +int do_compile(int codepage, const char *input_file, const char *output_file) +{ + FILE *fp = NULL; + uint32 size = 0; + char *buf = NULL; + char output_buf[CODEPAGE_HEADER_SIZE + 512]; + int num_lines = 0; + int i = 0; + struct stat st; + + /* Get the size of the input file. Read the entire thing into memory. */ + if(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 = (uint32)st.st_size; + + /* I don't believe these things should be bigger than 100k :-) */ + if(size > 100*1024) + { + fprintf(stderr, "%s: filesize %d is too large for a codepage definition file. \ +The maximum size I will believe is 100k.\n", prog_name, size); + exit(1); + } + + if((fp = 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); + + /* There can be a maximum of 128 lines. */ + if(num_lines > 128) + { + fprintf(stderr, "%s: There can be a maximum 128 lines of data in a codepage \ +definition file. File %s has %d.\n", prog_name, input_file, num_lines); + exit(1); + } + + /* Setup the output file header. */ + SSVAL(output_buf,CODEPAGE_VERSION_OFFSET,CODEPAGE_FILE_VERSION_ID); + SSVAL(output_buf,CODEPAGE_CLIENT_CODEPAGE_OFFSET,(uint16)codepage); + SIVAL(output_buf,CODEPAGE_LENGTH_OFFSET,(num_lines * 4)); + + /* Now convert the lines into the compiled form. */ + for(i = 0; i < num_lines; i++) + { + char token_buf[512]; + char *p = buf; + unsigned char b = 0; + + /* Get the 'lower' value. */ + if(!next_token(&p, token_buf, NULL)) + parse_error(buf, "cannot parse first value"); + if(!parse_byte( token_buf, &b)) + parse_error(buf, "first value doesn't resolve to a byte"); + + /* Add this to the output buffer. */ + SCVAL(output_buf,CODEPAGE_HEADER_SIZE+(i*4),b); + + /* Get the 'upper' value. */ + if(!next_token(&p, token_buf, NULL)) + parse_error(buf, "cannot parse second value"); + if(!parse_byte( token_buf, &b)) + parse_error(buf, "second value doesn't resolve to a byte"); + + /* Add this to the output buffer. */ + SCVAL(output_buf,CODEPAGE_HEADER_SIZE+(i*4) + 1,b); + + /* Get the 'upper to lower' value. */ + if(!next_token(&p, token_buf, NULL)) + parse_error(buf, "cannot parse third value"); + if(!parse_bool( token_buf, &b)) + parse_error(buf, "third value doesn't resolve to a boolean"); + + /* Add this to the output buffer. */ + SCVAL(output_buf,CODEPAGE_HEADER_SIZE+(i*4) + 2,b); + + /* Get the 'lower to upper' value. */ + if(!next_token(&p, token_buf, NULL)) + parse_error(buf, "cannot parse fourth value"); + if(!parse_bool( token_buf, &b)) + parse_error(buf, "fourth value doesn't resolve to a boolean"); + + /* Add this to the output buffer. */ + SCVAL(output_buf,CODEPAGE_HEADER_SIZE+(i*4) + 3,b); + + buf += (strlen(buf) + 1); + } + + /* Now write out the output_buf. */ + if((fp = 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, CODEPAGE_HEADER_SIZE + (num_lines*4), fp) != + CODEPAGE_HEADER_SIZE + (num_lines*4)) + { + fprintf(stderr, "%s: Cannot write output file %s. Error was %s.\n", + prog_name, output_file, strerror(errno)); + exit(1); + } + + fclose(fp); + + return 0; +} + +/* + * Placeholder for now. + */ + +int do_decompile( int codepage, const char *input_file, const char *output_file) +{ + uint32 size = 0; + struct stat st; + char header_buf[CODEPAGE_HEADER_SIZE]; + char *buf = NULL; + FILE *fp = NULL; + int num_lines = 0; + int i = 0; + + /* Get the size of the input file. Read the entire thing into memory. */ + if(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 = (uint32)st.st_size; + + if( size < CODEPAGE_HEADER_SIZE || size > (CODEPAGE_HEADER_SIZE + 256)) + { + fprintf(stderr, "%s: file %s is an incorrect size for a \ +code page file.\n", prog_name, input_file); + exit(1); + } + + /* 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( input_file, "r")) == NULL) + { + fprintf(stderr, "%s: cannot open file %s. Error was %s\n", + prog_name, input_file, strerror(errno)); + exit(1); + } + + if(fread( header_buf, 1, CODEPAGE_HEADER_SIZE, fp)!=CODEPAGE_HEADER_SIZE) + { + fprintf(stderr, "%s: cannot read header from file %s. Error was %s\n", + prog_name, input_file, strerror(errno)); + exit(1); + } + + /* Check the version value */ + if(SVAL(header_buf,CODEPAGE_VERSION_OFFSET) != CODEPAGE_FILE_VERSION_ID) + { + fprintf(stderr, "%s: filename %s has incorrect version id. \ +Needed %hu, got %hu.\n", + prog_name, input_file, (uint16)CODEPAGE_FILE_VERSION_ID, + SVAL(header_buf,CODEPAGE_VERSION_OFFSET)); + exit(1); + } + + /* Check the codepage matches */ + if(SVAL(header_buf,CODEPAGE_CLIENT_CODEPAGE_OFFSET) != (uint16)codepage) + { + fprintf(stderr, "%s: filename %s has incorrect codepage. \ +Needed %hu, got %hu.\n", + prog_name, input_file, (uint16)codepage, + SVAL(header_buf,CODEPAGE_CLIENT_CODEPAGE_OFFSET)); + exit(1); + } + + /* Check the length is correct. */ + if(IVAL(header_buf,CODEPAGE_LENGTH_OFFSET) != + (unsigned int)(size - CODEPAGE_HEADER_SIZE)) + { + fprintf(stderr, "%s: filename %s has incorrect size headers. \ +Needed %u, got %u.\n", prog_name, input_file, size - CODEPAGE_HEADER_SIZE, + IVAL(header_buf,CODEPAGE_LENGTH_OFFSET)); + exit(1); + } + + size -= CODEPAGE_HEADER_SIZE; /* Remove header */ + + /* Make sure the size is a multiple of 4. */ + if((size % 4 ) != 0) + { + fprintf(stderr, "%s: filename %s has a codepage size not a \ +multiple of 4.\n", prog_name, input_file); + exit(1); + } + + /* Allocate space for the code page file and read it all in. */ + if((buf = (char *)malloc( size )) == NULL) + { + fprintf (stderr, "%s: malloc fail for size %d.\n", + prog_name, size ); + exit(1); + } + + if(fread( buf, 1, size, fp)!=size) + { + fprintf(stderr, "%s: read fail on file %s. Error was %s.\n", + prog_name, input_file, strerror(errno)); + exit(1); + } + + fclose(fp); + + /* Now dump the codepage into an ascii file. */ + if((fp = fopen(output_file, "w")) == NULL) + { + fprintf(stderr, "%s: cannot open file %s. Error was %s\n", + prog_name, output_file, strerror(errno)); + exit(1); + } + + fprintf(fp, "#\n# Codepage definition file for IBM Code Page %d.\n#\n", + codepage); + fprintf(fp, "# This file was automatically generated.\n#\n"); + fprintf(fp, "# defines lower->upper mapping.\n"); + fprintf(fp, "#\n#The columns are :\n# lower\tupper\tu-t-l\tl-t-u\n#\n"); + + num_lines = size / 4; + for( i = 0; i < num_lines; i++) + { + fprintf(fp, "0x%02X\t0x%02X\t%s\t%s\n", CVAL(buf, (i*4)), CVAL(buf, (i*4)+1), + CVAL(buf, (i*4)+2) ? "True" : "False", + CVAL(buf, (i*4)+3) ? "True" : "False"); + } + fclose(fp); + return 0; +} + +int main(int argc, char **argv) +{ + int codepage = 0; + char *input_file = NULL; + char *output_file = NULL; + BOOL compile = False; + + prog_name = argv[0]; + + if(argc != 5) + codepage_usage(prog_name); + + if(argv[1][0] != 'c' && argv[1][0] != 'C' && argv[1][0] != 'd' && + argv[1][0] != 'D') + codepage_usage(prog_name); + + input_file = argv[3]; + output_file = argv[4]; + + /* Are we compiling or decompiling. */ + if(argv[1][0] == 'c' || argv[1][0] == 'C') + compile = True; + + /* Convert the second argument into a client codepage value. */ + if((codepage = atoi(argv[2])) == 0) + { + fprintf(stderr, "%s: %s is not a valid codepage.\n", prog_name, argv[2]); + exit(1); + } + + if(compile) + return do_compile( codepage, input_file, output_file); + else + return do_decompile( codepage, input_file, output_file); +} -- cgit From e7e49a6e6a1e7d5b1bc64563f29e7cebd5d8e01f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 5 Sep 1997 21:32:32 +0000 Subject: client.c: Made sure myhostname was initialised before substitutions. status.c: Made sure myhostname was initialised before substitutions. server.c trans2.c: Moved OS/2 WPS fix. Jeremy (jallison@whistle.com) (This used to be commit 8a12b6a4f0feec712f5c4e02e21198c455b060ae) --- source3/utils/status.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index b439741e6c..6fa85c0a63 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -188,13 +188,13 @@ locking version (was %d, should be %d).\n",fname, } } + get_myname(myhostname, NULL); + if (!lp_load(servicesf,False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); return (-1); } - get_myname(myhostname, NULL); - if (verbose) { printf("using configfile = %s\n", servicesf); printf("lockdir = %s\n", *lp_lockdir() ? lp_lockdir() : "NULL"); -- cgit From 646a7219609364939856ad2697ffd85af87b1cbe Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 11 Sep 1997 02:19:23 +0000 Subject: add the stdout parameter to lp_dump() (This used to be commit 77f5bc87058dfb5c1b14e7cd8c6097a6bcb2c0cc) --- source3/utils/testparm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 81e69cd76f..ca364cb8c9 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -82,7 +82,7 @@ extern int DEBUGLEVEL; printf("Press enter to see a dump of your service definitions\n"); fflush(stdout); getc(stdin); - lp_dump(); + lp_dump(stdout); } if (argc == 4) -- cgit From 77df5c87c69ea7f929df211c41da522248d73cfc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 11 Sep 1997 02:30:00 +0000 Subject: fix a couple of "declaration shadows previous local" warnings. (This used to be commit c30f6a74d0e6c256b1d46b28c1f31f1c1f3dd856) --- source3/utils/smbpasswd.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 161555d52c..92abce8d8f 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -417,10 +417,8 @@ static void usage(char *name) /* Create a new smb passwd entry and set it to the given password. */ { int fd; - int i; int new_entry_length; char *new_entry; - char *p; long offpos; /* The add user write needs to be atomic - so get the fd from -- cgit From 30416c0b8a0f54f6cc1179c2e00860eaf5f58401 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 11 Sep 1997 20:17:32 +0000 Subject: charcnv.c client.c clitar.c kanji.c kanji.h loadparm.c mangle.c smb.h util.c: Big merge to allow KANJI support to be in the main binary without explicitly compiling with it. locking.c: Fix for smbstatus not being able to read files. namepacket.c: Removed unneccesary debug statement. trans2.c: Added Luke's proposed fix (ifdefed out until further testing). nmblookup.c: Fixed bug where query fails and status is done on bogus IP. Jeremy (jallison@whistle.com) (This used to be commit 9196255022ae8c51b527412747b324819bea2c13) --- source3/utils/nmblookup.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 582f4eb6db..25c94dcd6a 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -192,17 +192,25 @@ int main(int argc,char *argv[]) retries = 1; } - if (name_query(ServerFD,lookup,lookup_type,bcast,True, + if (name_query(ServerFD,lookup,lookup_type,bcast,True, bcast_addr,&ip,NULL)) - { - printf("%s %s\n",inet_ntoa(ip),lookup); - } + { + printf("%s %s\n",inet_ntoa(ip),lookup); + + /* We can only do find_status if the ip address returned + was valid - ie. name_query returned true. + */ if (find_status) { printf("Looking up status of %s\n",inet_ntoa(ip)); name_status(ServerFD,lookup,lookup_type,True,ip,NULL,NULL,NULL); printf("\n"); } + } + else + { + printf("name_query failed to find name %s\n", lookup); + } } return(0); -- cgit From 33a003de4056532be0c9a199d4857b9da1b18034 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 14 Sep 1997 16:37:18 +0000 Subject: This commit does 3 main things: 1) put the encryption code in by default, with no #ifdef. It is still disabled by default so you need to add "encrypt passwords = yes" in smb.conf but at least all binaries will have it. 2) cleanup the kanji code so it compiles with no warnings 3) get rid of lots of uses of ugly non-portable C code. The main offender being things like "register" but also remove uses of the "const" keyword as there are compilers out there that don't support it and even those that do often complain about its usage. Users don't like warnings :-( There is still some work to do. We need to replace the md4 code with our own implementation. The current code (from rfc1186) is PD but is not very portable. The new RFC (rfc1320) is more portable but adds copyright restrictions. I'll do a from-scratch MD4 soon. We also need to test that what I've implemented is portable. It should be, but I'm too tired right now to test it on anything other than intel linux. (This used to be commit db917c62c14315afe6f0745a8097c1bca25cbf07) --- source3/utils/make_smbcodepage.c | 6 +++--- source3/utils/smbpasswd.c | 14 -------------- 2 files changed, 3 insertions(+), 17 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c index c8b4fea8bc..b4cb152334 100644 --- a/source3/utils/make_smbcodepage.c +++ b/source3/utils/make_smbcodepage.c @@ -28,7 +28,7 @@ static char *prog_name = NULL; * Print program usage and die. */ -void codepage_usage(const char *progname) +void codepage_usage(char *progname) { fprintf(stderr, "Usage is : %s [c|d] \n", progname); @@ -162,7 +162,7 @@ void parse_error(char *buf, char *msg) * Create a compiled codepage file from a codepage definition file. */ -int do_compile(int codepage, const char *input_file, const char *output_file) +int do_compile(int codepage, char *input_file, char *output_file) { FILE *fp = NULL; uint32 size = 0; @@ -307,7 +307,7 @@ definition file. File %s has %d.\n", prog_name, input_file, num_lines); * Placeholder for now. */ -int do_decompile( int codepage, const char *input_file, const char *output_file) +int do_decompile( int codepage, char *input_file, char *output_file) { uint32 size = 0; struct stat st; diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 92abce8d8f..bbcefa6b18 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -1,5 +1,3 @@ -#ifdef SMB_PASSWD - /* * Unix SMB/Netbios implementation. Version 1.9. smbpasswd module. Copyright * (C) Jeremy Allison 1995-1997. @@ -20,7 +18,6 @@ */ #include "includes.h" -#include "des.h" /* Static buffers we will return. */ static struct smb_passwd pw_buf; @@ -569,14 +566,3 @@ Error was %d. Password file may be corrupt ! Please examine by hand !\n", return 0; } -#else - -#include "includes.h" - -int -main(int argc, char **argv) -{ - printf("smb password encryption not selected in Makefile\n"); - return 0; -} -#endif -- cgit From 552818e60eff4a87ece94f98c33424c93354bf6c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Sep 1997 05:43:37 +0000 Subject: - change a lot of occurances of errno to use strerror(errno). We can't assume all our users are programmers :-) - automatically create the smbpasswd file if it doesn't exist when running smbpasswd. (This used to be commit 1d2361bd2dec35bce029699f54c6a61fa739fa4b) --- source3/utils/smbpasswd.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index bbcefa6b18..c781427474 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -375,7 +375,7 @@ static void usage(char *name) * Open the smbpaswd file XXXX - we need to parse smb.conf to get the * filename */ - if ((fp = fopen(pfile, "r+")) == NULL) { + if ((fp = fopen(pfile, "a+")) == NULL) { err = errno; fprintf(stderr, "%s: Failed to open password file %s.\n", argv[0], pfile); @@ -383,6 +383,10 @@ static void usage(char *name) perror(argv[0]); exit(err); } + + /* position at the start of the file */ + fseek(fp, 0, SEEK_SET); + /* Set read buffer to 16k for effiecient reads */ setvbuf(fp, readbuf, _IOFBF, sizeof(readbuf)); @@ -425,7 +429,7 @@ static void usage(char *name) if((offpos = lseek(fd, 0, SEEK_END)) == -1) { fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ -Error was %d\n", argv[0], pwd->pw_name, pfile, errno); +Error was %s\n", argv[0], pwd->pw_name, pfile, strerror(errno)); fclose(fp); pw_file_unlock(lockfd); exit(1); @@ -437,7 +441,7 @@ Error was %d\n", argv[0], pwd->pw_name, pfile, errno); strlen(pwd->pw_shell) + 1; if((new_entry = (char *)malloc( new_entry_length )) == 0) { fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ -Error was %d\n", argv[0], pwd->pw_name, pfile, errno); +Error was %s\n", argv[0], pwd->pw_name, pfile, strerror(errno)); fclose(fp); pw_file_unlock(lockfd); exit(1); @@ -457,12 +461,12 @@ Error was %d\n", argv[0], pwd->pw_name, pfile, errno); pwd->pw_dir, pwd->pw_shell); if(write(fd, new_entry, strlen(new_entry)) != strlen(new_entry)) { fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ -Error was %d\n", argv[0], pwd->pw_name, pfile, errno); +Error was %s\n", argv[0], pwd->pw_name, pfile, strerror(errno)); /* Remove the entry we just wrote. */ if(ftruncate(fd, offpos) == -1) { fprintf(stderr, "%s: ERROR failed to ftruncate file %s. \ -Error was %d. Password file may be corrupt ! Please examine by hand !\n", - argv[0], pwd->pw_name, errno); +Error was %s. Password file may be corrupt ! Please examine by hand !\n", + argv[0], pwd->pw_name, strerror(errno)); } fclose(fp); pw_file_unlock(lockfd); -- cgit From d55427c85fca8ac7b44e32bdfff344ab573af993 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Sep 1997 06:36:55 +0000 Subject: - if the user already exists then ignore the -add command - change the way the smbpasswd file is auto-created if it doesn't exist. It didn't work under IRIX for some unknown reason The smbpasswd.c code is really a bit of a mess. We should probably rewrite it sometime. (This used to be commit 6e3697ad1218264c85c6c1f4b1521960e21e2a67) --- source3/utils/smbpasswd.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index c781427474..d20ff42c0e 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -375,18 +375,24 @@ static void usage(char *name) * Open the smbpaswd file XXXX - we need to parse smb.conf to get the * filename */ - if ((fp = fopen(pfile, "a+")) == NULL) { - err = errno; - fprintf(stderr, "%s: Failed to open password file %s.\n", - argv[0], pfile); - errno = err; - perror(argv[0]); - exit(err); + fp = fopen(pfile, "r+"); + if (!fp && errno == ENOENT) { + fp = fopen(pfile, "w"); + if (fp) { + fprintf(fp, "# Samba SMB password file\n"); + fclose(fp); + fp = fopen(pfile, "r+"); + } + } + if (!fp) { + err = errno; + fprintf(stderr, "%s: Failed to open password file %s.\n", + argv[0], pfile); + errno = err; + perror(argv[0]); + exit(err); } - /* position at the start of the file */ - fseek(fp, 0, SEEK_SET); - /* Set read buffer to 16k for effiecient reads */ setvbuf(fp, readbuf, _IOFBF, sizeof(readbuf)); @@ -477,6 +483,9 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n", pw_file_unlock(lockfd); exit(0); } + } else { + /* the entry already existed */ + add_user = False; } /* If we are root or the password is 'NO PASSWORD' then -- cgit From cef59090bb2fd3f8a9efd1a453cb90264b891d58 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 26 Sep 1997 18:55:29 +0000 Subject: Adding Andrews buffer overflow fixes into the main branch. Jeremy (jallison@whistle.com) (This used to be commit e7eb1f044d3101679dc7a118820ea5efe0cd837c) --- source3/utils/nmblookup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 25c94dcd6a..aebbc4292c 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -122,7 +122,7 @@ int main(int argc,char *argv[]) got_bcast = True; break; case 'i': - strcpy(scope,optarg); + fstrcpy(scope,optarg); strupper(scope); break; case 'M': @@ -135,7 +135,7 @@ int main(int argc,char *argv[]) DEBUGLEVEL = atoi(optarg); break; case 's': - strcpy(servicesf, optarg); + pstrcpy(servicesf, optarg); break; case 'h': usage(); @@ -172,7 +172,7 @@ int main(int argc,char *argv[]) char *p; struct in_addr ip; - strcpy(lookup,argv[i]); + fstrcpy(lookup,argv[i]); if (find_master) { if (*lookup == '-') { -- cgit From 5864551aef50295addd1c8aa690a52870f70626d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 1 Oct 1997 23:32:22 +0000 Subject: OPLOCK CHECK-IN - oplocks are now *OPERATIONAL* !!!! Yipeee. At least as far as I can check in a short time :-). local.h: Changed OPLOCK_BREAK_TIMEOUT to 30 seconds. locking.c: Big changes to delete oplocks on a share mode entry. proto.h: updated. reply.c: Added oplock break code in lockingX reply & readbraw reply. server.c: Add batch oplock code. Force server shutdown if client fails to respond to oplock break. smb.h: Fix silly slow share mode oplock define bug. status.c: Add oplock status info. Jeremy (jallison@whistle.com) (This used to be commit 4c83d37239f15f855fc10f01d7b4bf4217fb9eda) --- source3/utils/status.c | 61 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 18 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 6fa85c0a63..703105012e 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -98,10 +98,10 @@ for share file %s (%s)\n", progname, fname, strerror(errno)); return 0; } - if (IVAL(buf,0) != LOCKING_VERSION) { + if (IVAL(buf,SMF_VERSION_OFFSET) != LOCKING_VERSION) { printf("%s: ERROR: read_share_file: share file %s has incorrect \ locking version (was %d, should be %d).\n",fname, - progname, IVAL(buf,0), LOCKING_VERSION); + progname, IVAL(buf,SMF_VERSION_OFFSET), LOCKING_VERSION); if(buf) free(buf); return 0; @@ -109,13 +109,13 @@ locking version (was %d, should be %d).\n",fname, /* Sanity check for file contents */ size = sb.st_size; - size -= 10; /* Remove the header */ + size -= SMF_HEADER_LENGTH; /* Remove the header */ /* Remove the filename component. */ - size -= SVAL(buf, 8); + size -= SVAL(buf, SMF_FILENAME_LEN_OFFSET); - /* The remaining size must be a multiple of 16 - error if not. */ - if((size % 16) != 0) + /* The remaining size must be a multiple of SMF_ENTRY_LENGTH - error if not. */ + if((size % SMF_ENTRY_LENGTH) != 0) { printf("%s: ERROR: read_share_file: share file %s is an incorrect length.\n", progname, fname); @@ -148,6 +148,9 @@ locking version (was %d, should be %d).\n",fname, void *dir; char *s; #endif /* FAST_SHARE_MODES */ +#ifdef USE_OPLOCKS + int oplock_type; +#endif /* USE_OPLOCKS */ int i; struct session_record *ptr; @@ -344,6 +347,10 @@ locking version (was %d, should be %d).\n",fname, t.tv_sec = entry_scanner_p->time.tv_sec; t.tv_usec = entry_scanner_p->time.tv_usec; strcpy(fname, file_scanner_p->file_name); +#ifdef USE_OPLOCKS + oplock_type = entry_scanner_p->op_type; +#endif /* USE_OPLOCKS */ + #else /* FAST_SHARE_MODES */ /* For slow share modes go through all the files in @@ -394,16 +401,19 @@ locking version (was %d, should be %d).\n",fname, strcpy( fname, &buf[10]); close(fd); - base = buf + 10 + SVAL(buf,8); - for( i = 0; i < IVAL(buf, 4); i++) + base = buf + SMF_HEADER_LENGTH + SVAL(buf,SMF_FILENAME_LEN_OFFSET); + for( i = 0; i < IVAL(buf, SMF_NUM_ENTRIES_OFFSET); i++) { - char *p = base + (i*16); + char *p = base + (i*SMF_ENTRY_LENGTH); struct timeval t; - int pid = IVAL(p,12); - int mode = IVAL(p,8); + int pid = IVAL(p,SME_PID_OFFSET); + int mode = IVAL(p,SME_SHAREMODE_OFFSET); - t.tv_sec = IVAL(p,0); - t.tv_usec = IVAL(p,4); + t.tv_sec = IVAL(p,SME_SEC_OFFSET); + t.tv_usec = IVAL(p,SME_USEC_OFFSET); +#ifdef USE_OPLOCKS + oplock_type = SVAL(p,SME_OPLOCK_TYPE_OFFSET); +#endif /* USE_OPLOCKS */ #endif /* FAST_SHARE_MODES */ fname[sizeof(fname)-1] = 0; @@ -411,8 +421,13 @@ locking version (was %d, should be %d).\n",fname, if (firstopen) { firstopen=False; printf("Locked files:\n"); - printf("Pid DenyMode R/W Name\n"); - printf("------------------------------\n"); +#ifdef USE_OPLOCKS + printf("Pid DenyMode R/W Oplock Name\n"); + printf("--------------------------------------------------\n"); +#else /* USE_OPLOCKS */ + printf("Pid DenyMode R/W Name\n"); + printf("----------------------------------\n"); +#endif /* USE_OPLOCKS */ } @@ -427,10 +442,20 @@ locking version (was %d, should be %d).\n",fname, } switch (mode&0xF) { - case 0: printf("RDONLY "); break; - case 1: printf("WRONLY "); break; - case 2: printf("RDWR "); break; + case 0: printf("RDONLY "); break; + case 1: printf("WRONLY "); break; + case 2: printf("RDWR "); break; } +#ifdef USE_OPLOCKS + if((oplock_type & (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) + printf("EXCLUSIVE+BATCH "); + else if (oplock_type & EXCLUSIVE_OPLOCK) + printf("EXCLUSIVE "); + else if (oplock_type & BATCH_OPLOCK) + printf("BATCH "); + else + printf("NONE "); +#endif /* USE_OPLOCKS */ printf(" %s %s",fname,asctime(LocalTime((time_t *)&t.tv_sec))); #ifdef FAST_SHARE_MODES -- cgit From e722d7077695242a7d6c0749b9a63741f660382a Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Sat, 4 Oct 1997 01:07:47 +0000 Subject: nmblookup.c: I've added a -r option. When specified, nmblookup will attempt to bind to port 137. In order for this to work, the user must be root and the port must be available (i.e., nmbd not running). If either condition is not met, nmblookup will default to normal behavior; it will try to bind to a free port above 7999. I also removed an artifact. The -p option was being accepted but falling through to the default, which was the usage message. I removed "p:" from the getopt() list. params.c: Rewritten. The scanning is much more linear, and I found and fixed a few bugs. I don't like the way that the scratch buffer is handled, but I believe that it is an improvement over the previous version. Chris -)----- (This used to be commit 09dc951f2acd67da9d895e8e00c01e7abbbe0960) --- source3/utils/nmblookup.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index aebbc4292c..36905aa5ae 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -35,6 +35,8 @@ extern struct in_addr ipzero; int ServerFD= -1; +int RootPort = 0; + /**************************************************************************** open the socket communication **************************************************************************/ @@ -49,7 +51,10 @@ static BOOL open_sockets(void) return False; } - ServerFD = open_socket_in(SOCK_DGRAM, 0,3,interpret_addr(lp_socket_address())); + ServerFD = open_socket_in( SOCK_DGRAM, + (RootPort ? 137 :0), + 3, + interpret_addr(lp_socket_address()) ); if (ServerFD == -1) return(False); @@ -113,7 +118,7 @@ int main(int argc,char *argv[]) charset_initialise(); - while ((opt = getopt(argc, argv, "p:d:B:i:s:SMh")) != EOF) + while ((opt = getopt(argc, argv, "d:B:i:s:SMrh")) != EOF) switch (opt) { case 'B': @@ -137,6 +142,9 @@ int main(int argc,char *argv[]) case 's': pstrcpy(servicesf, optarg); break; + case 'r': + RootPort = -1; + break; case 'h': usage(); exit(0); -- cgit From 2e92be3aaf01c574d32d1a10e1359888638b68bc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 6 Oct 1997 17:52:25 +0000 Subject: client.c: Changed shadowed variable. locking.c: Removed USE_OPLOCKS - now the default. params.c: Removed unused variable. proto.h: Updated. reply.c: Removed USE_OPLOCKS - now the default. server.c: Removed USE_OPLOCKS - now the default. smb.h: Removed USE_OPLOCKS - now the default. smbparse.c: Changed shadowed variable. status.c: Removed USE_OPLOCKS - now the default. util.c: Removed USE_OPLOCKS - now the default. Jeremy (jallison@whistle.com) (This used to be commit b93509846d6291771787af457500eec8984ee6bd) --- source3/utils/status.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 703105012e..4143244ab4 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -148,9 +148,7 @@ locking version (was %d, should be %d).\n",fname, void *dir; char *s; #endif /* FAST_SHARE_MODES */ -#ifdef USE_OPLOCKS int oplock_type; -#endif /* USE_OPLOCKS */ int i; struct session_record *ptr; @@ -347,9 +345,7 @@ locking version (was %d, should be %d).\n",fname, t.tv_sec = entry_scanner_p->time.tv_sec; t.tv_usec = entry_scanner_p->time.tv_usec; strcpy(fname, file_scanner_p->file_name); -#ifdef USE_OPLOCKS oplock_type = entry_scanner_p->op_type; -#endif /* USE_OPLOCKS */ #else /* FAST_SHARE_MODES */ @@ -411,9 +407,7 @@ locking version (was %d, should be %d).\n",fname, t.tv_sec = IVAL(p,SME_SEC_OFFSET); t.tv_usec = IVAL(p,SME_USEC_OFFSET); -#ifdef USE_OPLOCKS oplock_type = SVAL(p,SME_OPLOCK_TYPE_OFFSET); -#endif /* USE_OPLOCKS */ #endif /* FAST_SHARE_MODES */ fname[sizeof(fname)-1] = 0; @@ -421,13 +415,8 @@ locking version (was %d, should be %d).\n",fname, if (firstopen) { firstopen=False; printf("Locked files:\n"); -#ifdef USE_OPLOCKS printf("Pid DenyMode R/W Oplock Name\n"); printf("--------------------------------------------------\n"); -#else /* USE_OPLOCKS */ - printf("Pid DenyMode R/W Name\n"); - printf("----------------------------------\n"); -#endif /* USE_OPLOCKS */ } @@ -446,7 +435,7 @@ locking version (was %d, should be %d).\n",fname, case 1: printf("WRONLY "); break; case 2: printf("RDWR "); break; } -#ifdef USE_OPLOCKS + if((oplock_type & (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) printf("EXCLUSIVE+BATCH "); else if (oplock_type & EXCLUSIVE_OPLOCK) @@ -455,7 +444,7 @@ locking version (was %d, should be %d).\n",fname, printf("BATCH "); else printf("NONE "); -#endif /* USE_OPLOCKS */ + printf(" %s %s",fname,asctime(LocalTime((time_t *)&t.tv_sec))); #ifdef FAST_SHARE_MODES -- cgit From 805749baab4e79fbdb9897f22b2c801d9dd9efc2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 10 Oct 1997 01:32:26 +0000 Subject: nmblookup.c: Added -A ability to do status on ip address. smb.h: Added defines we will need for NT SMB calls. trans2.c: Fixed SMB_QUERY_FILE_ALT_NAME_INFO return - this is only for short name returns (and only used when you negotiate NT SMB calls to boot !). Jeremy (jallison@whistle.com) (This used to be commit 53915bd160eda8c099482ddcef74d1d7606e752b) --- source3/utils/nmblookup.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 36905aa5ae..63ca156449 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -88,6 +88,8 @@ static void usage(void) printf("\t-B broadcast address the address to use for broadcasts\n"); printf("\t-M searches for a master browser\n"); printf("\t-S lookup node status as well\n"); + printf("\t-r Use root port 137 (Win95 only replies to this)\n"); + printf("\t-A Do a node status on as an IP Address\n"); printf("\n"); } @@ -108,6 +110,7 @@ int main(int argc,char *argv[]) static pstring servicesf = CONFIGFILE; struct in_addr bcast_addr; BOOL got_bcast = False; + BOOL lookup_by_ip = False; DEBUGLEVEL = 1; *lookup = 0; @@ -118,7 +121,7 @@ int main(int argc,char *argv[]) charset_initialise(); - while ((opt = getopt(argc, argv, "d:B:i:s:SMrh")) != EOF) + while ((opt = getopt(argc, argv, "d:B:i:s:SMrhA")) != EOF) switch (opt) { case 'B': @@ -149,6 +152,9 @@ int main(int argc,char *argv[]) usage(); exit(0); break; + case 'A': + lookup_by_ip = True; + break; default: usage(); exit(1); @@ -182,6 +188,16 @@ int main(int argc,char *argv[]) fstrcpy(lookup,argv[i]); + if(lookup_by_ip) + { + strcpy(lookup,"*"); + ip = *interpret_addr2(argv[i]); + printf("Looking up status of %s\n",inet_ntoa(ip)); + name_status(ServerFD,lookup,lookup_type,True,ip,NULL,NULL,NULL); + printf("\n"); + continue; + } + if (find_master) { if (*lookup == '-') { strcpy(lookup,"\01\02__MSBROWSE__\02"); -- cgit From 2259e56a947104b19a1196154af4e43ab15e4b7c Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Mon, 13 Oct 1997 12:21:56 +0000 Subject: byteorder.h : debugging output wasn't (still isn't) perfect. credentials.c lsaparse.c smbparse.c : added DEBUG strings. pipes.c : lost some changes, to do with setup of RPC headers. arg. (This used to be commit 9fdd697d17b68293bb95fd68f44c24f0f5b97f5f) --- source3/utils/smbpasswd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index d20ff42c0e..31ac9e351b 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -396,9 +396,9 @@ static void usage(char *name) /* Set read buffer to 16k for effiecient reads */ setvbuf(fp, readbuf, _IOFBF, sizeof(readbuf)); - /* make sure it is only rw by the owner */ - chmod(pfile, 0600); - + /* need locking permission on smbpasswd file */ + chmod(pfile, 0666); + /* Lock the smbpasswd file for write. */ if ((lockfd = pw_file_lock(pfile, F_WRLCK, 5)) < 0) { err = errno; -- cgit From a25205bfc5baa428e6dbcda64f67e0546cf0a69e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Oct 1997 13:49:50 +0000 Subject: reverted a change made by Luke at his request. Luke, when you don't know what has been changed in the CVS tree I highly recommend you point your browser at: http://samba.anu.edu.au/cgi-bin/cvsweb/samba/source If you click on a filename you can then see all the commits and changes that have been made to it over time. You can also download any version of the file or find the differences between any two versions. All of this is not dependent on the state of your local CVS sandbox, so it can be used to find out the "true" state of the tree at any time. If you suspect some sort of CVS problem (like a change getting reverted) then please use the above URL to work out what has happened. You should be able to see exactly who made what changes and when. (This used to be commit 3fc48246ee0d89ad2f10f050d2d68af53446129f) --- source3/utils/smbpasswd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 31ac9e351b..a4c25417ca 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -396,8 +396,8 @@ static void usage(char *name) /* Set read buffer to 16k for effiecient reads */ setvbuf(fp, readbuf, _IOFBF, sizeof(readbuf)); - /* need locking permission on smbpasswd file */ - chmod(pfile, 0666); + /* make sure it is only rw by the owner */ + chmod(pfile, 0600); /* Lock the smbpasswd file for write. */ if ((lockfd = pw_file_lock(pfile, F_WRLCK, 5)) < 0) { -- cgit From 3e670e4057321911c6674b8abe3c0bdcd684fd09 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 20 Oct 1997 08:46:00 +0000 Subject: a major share modes reorganisation. The shares modes code is now split into separate files. The shared memory implementation is in locking_shm.c. The slow implementation is in locking_slow.c It is all controlled by a struct share_ops structure that has function pointers to the implementation of all the functions needed by a share modes implementation. An initialisation function sets up this structure. This will make adding new implementations easy and clean. This also allowed me to get rid of the ugly code in smbstatus. Now status.c links to the locking code and calls methods in share_ops. I also renamed some things and generally organised things in a much cleaner fashion. Defines and structures specific to each implementation have been moved to the appropriate file and out of smb.h. (This used to be commit 65ab9adaa0d356b8041ed8a507ea52117f2a284e) --- source3/utils/status.c | 311 ++++++++----------------------------------------- 1 file changed, 48 insertions(+), 263 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 4143244ab4..3e349f920a 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -53,80 +53,52 @@ int Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ int Ucrit_MaxPid=0; /* added by OH */ unsigned int Ucrit_IsActive = 0; /* added by OH */ -#ifndef FAST_SHARE_MODES -static char *read_share_file(int fd, char *fname, char *progname) -{ - struct stat sb; - char *buf; - int size; - - if(fstat(fd, &sb) != 0) - { - printf("%s: ERROR: read_share_file: Failed to do stat on share file %s (%s)\n", - progname, fname, strerror(errno)); - return 0; - } - - if(sb.st_size == 0) - { - return 0; - } - - /* Allocate space for the file */ - if((buf = (char *)malloc(sb.st_size)) == NULL) - { - printf("%s: read_share_file: malloc for file size %d fail !\n", - progname, (int)sb.st_size); - return 0; - } - - if(lseek(fd, 0, SEEK_SET) != 0) - { - printf("%s: ERROR: read_share_file: Failed to reset position to 0 \ -for share file %s (%s)\n", progname, fname, strerror(errno)); - if(buf) - free(buf); - return 0; - } +/* we need these because we link to locking*.o */ + void become_root(BOOL save_dir) {} + void unbecome_root(BOOL restore_dir) {} +connection_struct Connections[MAX_CONNECTIONS]; +files_struct Files[MAX_OPEN_FILES]; - if (read(fd,buf,sb.st_size) != sb.st_size) - { - printf("%s: ERROR: read_share_file: Failed to read share file %s (%s)\n", - progname, fname, strerror(errno)); - if(buf) - free(buf); - return 0; - } - if (IVAL(buf,SMF_VERSION_OFFSET) != LOCKING_VERSION) { - printf("%s: ERROR: read_share_file: share file %s has incorrect \ -locking version (was %d, should be %d).\n",fname, - progname, IVAL(buf,SMF_VERSION_OFFSET), LOCKING_VERSION); - if(buf) - free(buf); - return 0; - } +static void print_share_mode(share_mode_entry *e, char *fname) +{ + static int count; + if (count==0) { + printf("Locked files:\n"); + printf("Pid DenyMode R/W Oplock Name\n"); + printf("--------------------------------------------------\n"); + } + count++; + + printf("%-5d ",e->pid); + switch ((e->share_mode>>4)&0xF) { + case DENY_NONE: printf("DENY_NONE "); break; + case DENY_ALL: printf("DENY_ALL "); break; + case DENY_DOS: printf("DENY_DOS "); break; + case DENY_READ: printf("DENY_READ "); break; + case DENY_WRITE:printf("DENY_WRITE "); break; + } + switch (e->share_mode&0xF) { + case 0: printf("RDONLY "); break; + case 1: printf("WRONLY "); break; + case 2: printf("RDWR "); break; + } + + if((e->op_type & + (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == + (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) + printf("EXCLUSIVE+BATCH "); + else if (e->op_type & EXCLUSIVE_OPLOCK) + printf("EXCLUSIVE "); + else if (e->op_type & BATCH_OPLOCK) + printf("BATCH "); + else + printf("NONE "); + + printf(" %s %s",fname,asctime(LocalTime((time_t *)&e->time.tv_sec))); +} - /* Sanity check for file contents */ - size = sb.st_size; - size -= SMF_HEADER_LENGTH; /* Remove the header */ - /* Remove the filename component. */ - size -= SVAL(buf, SMF_FILENAME_LEN_OFFSET); - - /* The remaining size must be a multiple of SMF_ENTRY_LENGTH - error if not. */ - if((size % SMF_ENTRY_LENGTH) != 0) - { - printf("%s: ERROR: read_share_file: share file %s is an incorrect length.\n", - progname, fname); - if(buf) - free(buf); - return 0; - } - - return buf; -} -#endif /* FAST_SHARE_MODES */ int main(int argc, char *argv[]) { @@ -136,20 +108,8 @@ locking version (was %d, should be %d).\n",fname, static pstring servicesf = CONFIGFILE; extern char *optarg; int verbose = 0, brief =0; - BOOL firstopen=True; BOOL processes_only=False; int last_pid=0; -#ifdef FAST_SHARE_MODES - pstring shmem_file_name; - share_mode_record *file_scanner_p; - smb_shm_offset_t *mode_array; - int bytes_free, bytes_used, bytes_overhead, bytes_total; -#else /* FAST_SHARE_MODES */ - void *dir; - char *s; -#endif /* FAST_SHARE_MODES */ - int oplock_type; - int i; struct session_record *ptr; @@ -302,191 +262,16 @@ locking version (was %d, should be %d).\n",fname, printf("\n"); -#ifdef FAST_SHARE_MODES - /******************************************************************* - initialize the shared memory for share_mode management - ******************************************************************/ - - strcpy(shmem_file_name,lp_lockdir()); - trim_string(shmem_file_name,"","/"); - if (!*shmem_file_name) exit(-1); - strcat(shmem_file_name, "/SHARE_MEM_FILE"); - if(!smb_shm_open(shmem_file_name, lp_shmem_size())) exit(-1); - - mode_array = (smb_shm_offset_t *)smb_shm_offset2addr(smb_shm_get_userdef_off()); - if(mode_array == NULL) - { - printf("%s: base of shared memory hash array == 0! Exiting.\n", argv[0]); - smb_shm_close(); - exit(-1); - } - - for( i = 0; i < lp_shmem_hash_size(); i++) - { - smb_shm_lock_hash_entry(i); - if(mode_array[i] == NULL_OFFSET) - { - smb_shm_unlock_hash_entry(i); - continue; - } - file_scanner_p = (share_mode_record *)smb_shm_offset2addr(mode_array[i]); - while((file_scanner_p != 0) && (file_scanner_p->num_share_mode_entries != 0)) - { - share_mode_entry *entry_scanner_p = - (share_mode_entry *)smb_shm_offset2addr( - file_scanner_p->share_mode_entries); - - while(entry_scanner_p != 0) - { - struct timeval t; - int pid = entry_scanner_p->pid; - int mode = entry_scanner_p->share_mode; - - t.tv_sec = entry_scanner_p->time.tv_sec; - t.tv_usec = entry_scanner_p->time.tv_usec; - strcpy(fname, file_scanner_p->file_name); - oplock_type = entry_scanner_p->op_type; - -#else /* FAST_SHARE_MODES */ - - /* For slow share modes go through all the files in - the share mode directory and read the entries in - each. - */ - - dir = opendir(lp_lockdir()); - if (!dir) - { - printf("%s: Unable to open lock directory %s.\n", argv[0], lp_lockdir()); - return(0); - } - while ((s=readdirname(dir))) { - char *buf; - char *base; - int fd; - pstring lname; - uint32 dev,inode; - - if (sscanf(s,"share.%u.%u",&dev,&inode)!=2) continue; - - strcpy(lname,lp_lockdir()); - trim_string(lname,NULL,"/"); - strcat(lname,"/"); - strcat(lname,s); - - fd = open(lname,O_RDWR,0); - if (fd < 0) - { - printf("%s: Unable to open share file %s.\n", argv[0], lname); - continue; - } - - /* Lock the share mode file while we read it. */ - if(fcntl_lock(fd, F_SETLKW, 0, 1, F_WRLCK) == False) - { - printf("%s: Unable to lock open share file %s.\n", argv[0], lname); - close(fd); - continue; - } - - if(( buf = read_share_file( fd, lname, argv[0] )) == NULL) - { - close(fd); - continue; - } - strcpy( fname, &buf[10]); - close(fd); - - base = buf + SMF_HEADER_LENGTH + SVAL(buf,SMF_FILENAME_LEN_OFFSET); - for( i = 0; i < IVAL(buf, SMF_NUM_ENTRIES_OFFSET); i++) - { - char *p = base + (i*SMF_ENTRY_LENGTH); - struct timeval t; - int pid = IVAL(p,SME_PID_OFFSET); - int mode = IVAL(p,SME_SHAREMODE_OFFSET); - - t.tv_sec = IVAL(p,SME_SEC_OFFSET); - t.tv_usec = IVAL(p,SME_USEC_OFFSET); - oplock_type = SVAL(p,SME_OPLOCK_TYPE_OFFSET); -#endif /* FAST_SHARE_MODES */ - - fname[sizeof(fname)-1] = 0; - - if (firstopen) { - firstopen=False; - printf("Locked files:\n"); - printf("Pid DenyMode R/W Oplock Name\n"); - printf("--------------------------------------------------\n"); - } - - - printf("%-5d ",pid); - switch ((mode>>4)&0xF) - { - case DENY_NONE: printf("DENY_NONE "); break; - case DENY_ALL: printf("DENY_ALL "); break; - case DENY_DOS: printf("DENY_DOS "); break; - case DENY_READ: printf("DENY_READ "); break; - case DENY_WRITE:printf("DENY_WRITE "); break; - } - switch (mode&0xF) - { - case 0: printf("RDONLY "); break; - case 1: printf("WRONLY "); break; - case 2: printf("RDWR "); break; - } - - if((oplock_type & (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) - printf("EXCLUSIVE+BATCH "); - else if (oplock_type & EXCLUSIVE_OPLOCK) - printf("EXCLUSIVE "); - else if (oplock_type & BATCH_OPLOCK) - printf("BATCH "); - else - printf("NONE "); - - printf(" %s %s",fname,asctime(LocalTime((time_t *)&t.tv_sec))); - -#ifdef FAST_SHARE_MODES + locking_init(); - entry_scanner_p = (share_mode_entry *)smb_shm_offset2addr( - entry_scanner_p->next_share_mode_entry); - } /* end while entry_scanner_p */ - file_scanner_p = (share_mode_record *)smb_shm_offset2addr( - file_scanner_p->next_offset); - } /* end while file_scanner_p */ - smb_shm_unlock_hash_entry(i); - } /* end for */ - - smb_shm_get_usage(&bytes_free, &bytes_used, &bytes_overhead); - bytes_total = bytes_free + bytes_used + bytes_overhead; - - /******************************************************************* - deinitialize the shared memory for share_mode management - ******************************************************************/ - smb_shm_close(); + if (share_mode_forall(print_share_mode) <= 0) + printf("No locked files\n"); -#else /* FAST_SHARE_MODES */ - } /* end for i */ + printf("\n"); - if(buf) - free(buf); - base = 0; - } /* end while */ - closedir(dir); + share_status(stdout); -#endif /* FAST_SHARE_MODES */ - if (firstopen) - printf("No locked files\n"); -#ifdef FAST_SHARE_MODES - printf("\nShare mode memory usage (bytes):\n"); - printf(" %d(%d%%) free + %d(%d%%) used + %d(%d%%) overhead = %d(100%%) total\n", - bytes_free, (bytes_free * 100)/bytes_total, - bytes_used, (bytes_used * 100)/bytes_total, - bytes_overhead, (bytes_overhead * 100)/bytes_total, - bytes_total); - -#endif /* FAST_SHARE_MODES */ + locking_end(); return (0); } -- cgit From e5c319186d079eeef55a7ee62fac2a993e932938 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 22 Oct 1997 11:02:00 +0000 Subject: Implemented asynchronous DNS lookups in nmbd. I realised this afternoon just how easy it is to add this, so I thought I'd implement it while the idea was fresh. nmbd forks at startup and uses a pipe to talk to its child. The child does the DNS lookups and the file descriptor of the child is added to the main select loop. While I was doing this I discovered a bug in nmbd that explains why the dns proxy option has been so expensive. The DNS cache entries in the WINS list were never being checked, which means we always did a DNS lookup even if we have done it before and it is in cache. I'm sure this used to work (I tested the DNS cache when I added it) so someone broke it :-( Anyway, the async DNS gets rid of the problem completely. I'll commit just the fix to the DNS cache bug to the 1.9.17 tree. You can disable async DNS by adding -DSYNC_DNS to the compile flags. (This used to be commit 178e27de0791c1ff3268cb456ed5c5efc9ac2a01) --- source3/utils/nmblookup.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 63ca156449..d26d199695 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -42,15 +42,6 @@ int RootPort = 0; **************************************************************************/ static BOOL open_sockets(void) { - struct hostent *hp; - - /* get host info */ - if ((hp = Get_Hostbyname(myhostname)) == 0) - { - DEBUG(0,( "Get_Hostbyname: Unknown host. %s\n",myhostname)); - return False; - } - ServerFD = open_socket_in( SOCK_DGRAM, (RootPort ? 137 :0), 3, -- cgit From 205876345537ce80b24cc65dd1b610c22a117767 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 Oct 1997 07:50:28 +0000 Subject: added -U option to nmblookup. This is similar to -B except that it forces the client to send a unicast instead of a broadcast netbios packet. This is useful for diagnostics. (This used to be commit 57e0fac61414c032df35c8a4c0ba4d3a9f55c5b8) --- source3/utils/nmblookup.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index d26d199695..a44dad511e 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -100,6 +100,7 @@ int main(int argc,char *argv[]) int i; static pstring servicesf = CONFIGFILE; struct in_addr bcast_addr; + BOOL use_bcast = True; BOOL got_bcast = False; BOOL lookup_by_ip = False; @@ -112,13 +113,20 @@ int main(int argc,char *argv[]) charset_initialise(); - while ((opt = getopt(argc, argv, "d:B:i:s:SMrhA")) != EOF) + while ((opt = getopt(argc, argv, "d:B:U:i:s:SMrhA")) != EOF) switch (opt) { case 'B': iface_set_default(NULL,optarg,NULL); bcast_addr = *interpret_addr2(optarg); got_bcast = True; + use_bcast = True; + break; + case 'U': + iface_set_default(NULL,optarg,NULL); + bcast_addr = *interpret_addr2(optarg); + got_bcast = True; + use_bcast = False; break; case 'i': fstrcpy(scope,optarg); @@ -172,7 +180,6 @@ int main(int argc,char *argv[]) for (i=optind;i Date: Mon, 27 Oct 1997 14:27:17 +0000 Subject: change the default file permissions on the SHARE_MEM_FILE* to 0644. smbstatus now gets only read permission on the share files and does no locking. also get rid of some unnecessary umask(0) calls. smbd always runs with umask(0) (This used to be commit c6ac10170dbba57dfebc54c50d79cb29d13bb442) --- source3/utils/status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 3e349f920a..f124d79939 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -262,7 +262,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) printf("\n"); - locking_init(); + locking_init(1); if (share_mode_forall(print_share_mode) <= 0) printf("No locked files\n"); -- cgit From c79e0abdd700d978efeb9f013c0dbc2a4a4d76f9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 28 Oct 1997 14:55:47 +0000 Subject: fix cast (This used to be commit af13f5e1788b6f81cfcdaeb85dc709458e3d4816) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index a4c25417ca..cba7754fc9 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -453,7 +453,7 @@ Error was %s\n", argv[0], pwd->pw_name, pfile, strerror(errno)); exit(1); } - sprintf(new_entry, "%s:%u:", pwd->pw_name, pwd->pw_uid); + sprintf(new_entry, "%s:%u:", pwd->pw_name, (unsigned)pwd->pw_uid); p = &new_entry[strlen(new_entry)]; for( i = 0; i < 16; i++) sprintf(&p[i*2], "%02X", new_p16[i]); -- cgit From ecb952f913e0532e4570753e479f8b8de14b0988 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 28 Oct 1997 23:58:31 +0000 Subject: Utility code to produce printer definition files from MS files. Part of code to support Windows 95 automated printer driver installs. Written by Jean-Francois Micouleau . (This used to be commit 6e9f817414d6f7bdcb0ea64170d0db34b62651a5) --- source3/utils/make_printerdef.c | 301 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 301 insertions(+) create mode 100644 source3/utils/make_printerdef.c (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c new file mode 100644 index 0000000000..8b49925ad8 --- /dev/null +++ b/source3/utils/make_printerdef.c @@ -0,0 +1,301 @@ + /* + Unix SMB/Netbios implementation. + Version 1.9. + Create printer definition files. + + Copyright (C) Jean-Francois.Micouleau@utc.fr, 10/26/97 + + 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" + +/* +#define DEBUG +*/ +char *files_to_copy; +char *driverfile; +char buffer[50][255]; +char sub_dir[50][2][255]; + +void usage(char *name) +{ + fprintf(stderr,"%s: printer.def \"Printer Name\"\n", name); +} + +/* + This function split a line in two parts + on both side of the equal sign + "entry=value" +*/ +char *scan(char *chaine,char **entry) +{ + char *value; + char *temp; + int i=0; + + *entry=(char *)malloc(255*sizeof(char)); + value=(char *)malloc(255*sizeof(char)); + strcpy(*entry,chaine); + temp=chaine; + while( temp[i]!='=' && temp[i]!='\0') { + i++; + } + (*entry)[i]='\0'; + strcpy(value,temp+i+1); + return (value); +} + +void build_subdir() +{ + int i=0; + char *entry; + char *data; + + while (*buffer[i]!='\0') { + data=scan(buffer[i],&entry); +#ifdef DEBUG + fprintf(stderr,"\tentry=data %s:%s\n",entry,data); +#endif + + if (strcmp(data,"11")==0) { + strcpy(sub_dir[i][0],entry); + strcpy(sub_dir[i][1],""); + } + if (strcmp(data,"23")==0) { + strcpy(sub_dir[i][0],entry); + strcpy(sub_dir[i][1],"color\\"); + } +#ifdef DEBUG + fprintf(stderr,"\tsubdir %s:%s\n",sub_dir[i][0],sub_dir[i][1]); +#endif + i++; + } +} + +/* + Lockup an entry in a file + Return all the lines between the entry and the next one or the end of file + An entry is something between braces. +*/ +void lookup_entry(FILE *fichier,char *chaine) +{ + int found=0,pointeur=0,i=0; + char *temp,*temp2; + + temp=(char *)malloc(255*sizeof(char)); + temp2=(char *)malloc(255*sizeof(char)); + + *buffer[0]='\0'; + + strcpy(temp2,"["); + strcat(temp2,chaine); + strcat(temp2,"]"); + + rewind(fichier); +#ifdef DEBUG + fprintf(stderr,"\tLooking for %s\n",chaine); +#endif + + while (!feof(fichier) && found==0) { + *temp='\0'; + fgets(temp,255,fichier); + if (strncmp(temp,temp2,strlen(temp2))==0) found=1; + } + + + while (!feof(fichier) && found==1) { + *temp='\0'; + fgets(temp,255,fichier); + if (*temp=='[') { + found=2; + *buffer[pointeur]='\0'; + } + else { + strcpy(buffer[pointeur],temp); + i=strlen(buffer[pointeur])-1; + while (buffer[pointeur][i]=='\r' || buffer[pointeur][i]=='\n') + buffer[pointeur][i--]='\0'; + pointeur++; + } + } +#ifdef DEBUG + fprintf(stderr,"\t\tFound %d entries\n",pointeur-1); +#endif +} + + + +char *find_desc(FILE *fichier,char *text) +{ + char *chaine; + char *long_desc; + char *short_desc; + char *crap; + char *p; + + int found=0; + + chaine=(char *)malloc(255*sizeof(char)); + long_desc=(char *)malloc(40*sizeof(char)); + short_desc=(char *)malloc(13*sizeof(char)); + + while (!feof(fichier) && found==0) + { + fgets(chaine,255,fichier); + + long_desc=strtok(chaine,"="); + crap=strtok(NULL,","); + + p=long_desc; + while(*p!='"' && *p!='\0') + p++; + if (*p=='"' && *(p+1)!='\0') p++; + long_desc=p; + + if (*p!='\0') + { + p++; + while(*p!='\"') + p++; + *p='\0'; + } + if (!strcmp(text,long_desc)) found=1; + } + free(chaine); + while(*crap==' ') crap++; + strcpy(short_desc,crap); + if (found) return(short_desc); + else return(NULL); +} + +void scan_copyfiles(FILE *fichier, char *chaine) +{ + char *part; + int i; + char direc[255]; +#ifdef DEBUG + fprintf(stderr,"In scan_copyfiles Lookup up of %s\n",chaine); +#endif + part=strtok(chaine,", "); + do { + /* If the entry start with a @ then it's a file to copy + else it's an entry refering to files to copy + the main difference is when it's an entry + you can have a directory to append before the file name + */ + if (*part=='@') { + strcpy(files_to_copy,", "); + strcpy(files_to_copy,part); + } else { + lookup_entry(fichier,part); + i=0; + strcpy(direc,""); + while (*sub_dir[i][0]!='\0') { +#ifdef DEBUG + fprintf(stderr,"\tsubdir %s:%s\n",sub_dir[i][0],sub_dir[i][1]); +#endif + if (strcmp(sub_dir[i][0],part)==0) + strcpy(direc,sub_dir[i][1]); + i++; + } + i=0; + while (*buffer[i]!='\0') { + strcat(files_to_copy,", "); + strcat(files_to_copy,direc); + strcat(files_to_copy,buffer[i]); + i++; + } + } + part=strtok(NULL,", "); + } + while (part!=NULL); +} + + +void scan_short_desc(FILE *fichier, char *short_desc) +{ + int i=0; + char *chaine; + char *temp; + char *copyfiles=0,*datasection=0,*datafile=0,*helpfile=0; + + chaine=(char *)malloc(255*sizeof(char)); + temp=(char *)malloc(255*sizeof(char)); + + driverfile=short_desc; + + lookup_entry(fichier,short_desc); + + while(*buffer[i]!='\0') { +#ifdef DEBUG + fprintf(stderr,"\tLookup up of %s\n",buffer[i]); +#endif + if (strncmp(buffer[i],"CopyFiles",9)==0) copyfiles=scan(buffer[i],&temp); + if (strncmp(buffer[i],"DataSection",11)==0) datasection=scan(buffer[i],&temp); + if (strncmp(buffer[i],"DataFile",8)==0) datafile=scan(buffer[i],&temp); + if (strncmp(buffer[i],"DriverFile",10)==0) driverfile=scan(buffer[i],&temp); + if (strncmp(buffer[i],"HelpFile",8)==0) helpfile=scan(buffer[i],&temp); + i++; + } + if (i) fprintf(stderr,"End of section found\n"); + + fprintf(stderr,"CopyFiles: %s\n",copyfiles); + fprintf(stderr,"Datasection: %s\n",datasection); + fprintf(stderr,"Datafile: %s\n",datafile); + fprintf(stderr,"Driverfile: %s\n",driverfile); + fprintf(stderr,"Helpfile: %s\n",helpfile); + if (copyfiles) scan_copyfiles(fichier,copyfiles); +/* if (datasection) scan_copyfiles(fichier,datasection);*/ + if (datafile) scan_copyfiles(fichier,datafile); + if (helpfile) scan_copyfiles(fichier,helpfile); +} + +int main(int argc, char *argv[]) +{ + char *short_desc; + FILE *inf_file; + + if (argc!=3) + { + usage(argv[0]); + return(-1); + } + + inf_file=fopen(argv[1],"r"); + if (!inf_file) + { + fprintf(stderr,"Description file not found, bye\n"); + return(-1); + } + + short_desc=find_desc(inf_file,argv[2]); + if (short_desc==NULL) + { + fprintf(stderr,"Printer not found\n"); + return(-1); + } + else fprintf(stderr,"Found:%s\n",short_desc); + + lookup_entry(inf_file,"DestinationDirs"); + build_subdir(); + + files_to_copy=(char *)malloc(2048*sizeof(char)); + scan_short_desc(inf_file,short_desc); + fprintf(stdout,"%s:%s:%s:",argv[2],short_desc,driverfile); + fprintf(stdout,"%s\n",files_to_copy); + return 0; +} + -- cgit From 87ea4b93ecde16a4156c9c307ad477537a837ef4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 29 Oct 1997 02:59:22 +0000 Subject: damn. We need root privilages to do semaphore operations even if we have done the semget() as root. The problem is that become_root() and unbecome_root() are so slow! I've provided two options. The default is to set the semaphores (but _not_ the shared memory) world writeable so that a become_root() isn't needed. Otherwise you can define SECURE_SEMAPHORES and pay the performance penalty. (This used to be commit 2bbd8d2cbc5cf1901859a181bc9ec29822995e51) --- source3/utils/status.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index f124d79939..1a05f2b1af 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -58,6 +58,7 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ void unbecome_root(BOOL restore_dir) {} connection_struct Connections[MAX_CONNECTIONS]; files_struct Files[MAX_OPEN_FILES]; +struct current_user current_user; static void print_share_mode(share_mode_entry *e, char *fname) -- cgit From d5fdd84ffa78c1ce8211c2c5794b057c72bf1947 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 31 Oct 1997 02:40:55 +0000 Subject: - cleanup some warnings - redo the prototypes (This used to be commit 31dcb51e05914d49d81a3faef354aaf0ab9fa63f) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index cba7754fc9..225b7fde83 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -48,7 +48,7 @@ static int gethexpwd(char *p, char *pwd) return (True); } -struct smb_passwd * +static struct smb_passwd * _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, BOOL *got_valid_nt_entry, long *pwd_seekpos) { -- cgit From 224c40a52335bf1afc7662183900e143307aa5be Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 1 Nov 1997 13:22:16 +0000 Subject: a simple SMB torture tester. This will allow us to evaluate locking techniques more accurately. (This used to be commit 054e3b2ae3a8cfb98fde72becef9b05de34d2ba7) --- source3/utils/torture.c | 316 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 316 insertions(+) create mode 100644 source3/utils/torture.c (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c new file mode 100644 index 0000000000..bc7ebfb335 --- /dev/null +++ b/source3/utils/torture.c @@ -0,0 +1,316 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + SMB torture tester + 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 SYSLOG +#undef SYSLOG +#endif + +#include "includes.h" + +static struct cli_state cli; +static fstring host, workgroup, share, password, username, myname; +static char *sockops=""; + + +static struct timeval tp1,tp2; + +static void start_timer() +{ + gettimeofday(&tp1,NULL); +} + +static double end_timer() +{ + gettimeofday(&tp2,NULL); + return((tp2.tv_sec - tp1.tv_sec) + + (tp2.tv_usec - tp1.tv_usec)*1.0e-6); +} + + +static int open_connection(void) +{ + if (!cli_initialise(&cli) || !cli_connect(&cli, host, NULL)) { + printf("Failed to connect with %s\n", host); + } + + if (!cli_session_request(&cli, host, 0x20, myname)) { + printf("%s rejected the session\n",host); + cli_shutdown(&cli); + return -1; + } + + if (!cli_negprot(&cli)) { + printf("%s rejected the negprot (%s)\n",host, cli_errstr(&cli)); + cli_shutdown(&cli); + return -1; + } + + if (!cli_session_setup(&cli, username, password, strlen(password), + "", 0, workgroup)) { + printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(&cli)); + cli_shutdown(&cli); + return -1; + } + + if (!cli_send_tconX(&cli, share, "A:", password, strlen(password)+1)) { + printf("%s refused tree connect (%s)\n", host, cli_errstr(&cli)); + cli_shutdown(&cli); + return -1; + } + + return 0; +} + + + +static void close_connection(void) +{ + if (!cli_tdis(&cli)) { + printf("tdis failed (%s)\n", cli_errstr(&cli)); + } + + cli_shutdown(&cli); +} + + + + +static BOOL wait_lock(int fnum, uint32 offset, uint32 len) +{ + while (!cli_lock(&cli, fnum, offset, len, -1)) { + int eclass, num; + cli_error(&cli, &eclass, &num); + if (eclass != ERRDOS || num != ERRlock) { + printf("lock failed (%s)\n", + cli_errstr(&cli)); + return False; + } + } + return True; +} + + +static int rw_torture(int numops) +{ + char *lockfname = "\\torture.lck"; + fstring fname; + int fnum; + int fnum2; + int pid2, pid = getpid(); + int i; + + fnum2 = cli_open(&cli, lockfname, O_RDWR | O_EXCL, DENY_NONE); + if (fnum2 == -1) + fnum2 = cli_open(&cli, lockfname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + printf("open of %s failed (%s)\n", lockfname, cli_errstr(&cli)); + return -1; + } + + + for (i=0;i\n"); + + printf("\t-U user%%pass\n"); + printf("\t-N numprocs\n"); + printf("\t-n my_netbios_name\n"); + printf("\t-W workgroup\n"); + printf("\t-o num_operations\n"); + printf("\t-O socket_options\n"); + printf("\n"); + + exit(1); +} + + + +static void run_torture(int numops) +{ + if (open_connection() == 0) { + cli_sockopt(&cli, sockops); + + printf("pid %d OK\n", getpid()); + + rw_torture(numops); + + close_connection(); + } +} + + +static void create_procs(int nprocs, int numops) +{ + int i, status; + + for (i=0;i Date: Sat, 1 Nov 1997 13:28:21 +0000 Subject: set O_CREAT on lock file (This used to be commit 32fecea63b892e0a15c398cfc65d53c4ece74d86) --- source3/utils/torture.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index bc7ebfb335..9363958542 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -117,7 +117,8 @@ static int rw_torture(int numops) int pid2, pid = getpid(); int i; - fnum2 = cli_open(&cli, lockfname, O_RDWR | O_EXCL, DENY_NONE); + fnum2 = cli_open(&cli, lockfname, O_RDWR | O_CREAT | O_EXCL, + DENY_NONE); if (fnum2 == -1) fnum2 = cli_open(&cli, lockfname, O_RDWR, DENY_NONE); if (fnum2 == -1) { -- cgit From 60e82110214469dcbd9d134a527fa534f9df33b9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 1 Nov 1997 23:43:12 +0000 Subject: don't print the progress so often - it slows down the client too much (This used to be commit cc6e7706635ba4bf044ebd5a525113c1b2fd93e3) --- source3/utils/torture.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 9363958542..0eb9a256fc 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -129,7 +129,9 @@ static int rw_torture(int numops) for (i=0;i Date: Thu, 6 Nov 1997 06:50:21 +0000 Subject: no asm/signal.h for linux as this is not portable add auto username from LOGNAME for smbtorture proto fix in ufc.c (This used to be commit f13dbdf307ccffc15a74e2ffa72da666e53a72b6) --- source3/utils/torture.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 0eb9a256fc..f3d76e0ee2 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -261,6 +261,10 @@ static void create_procs(int nprocs, int numops) get_myname(myname,NULL); + if (*username == 0 && getenv("LOGNAME")) { + strcpy(username,getenv("LOGNAME")); + } + argc--; argv++; -- cgit From a90d2061316d19c30d9f14c1e78d6f6266183ce0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Nov 1997 04:02:05 +0000 Subject: added two more sets of tests to the smbtorture test. The tests I added are ones that I know Samba fails. They are: 1) correct support for retaining locks over a close (ie. the server must not use posix semantics) 2) support for lock timeouts 3) the server supports multiple locking contexts on the one SMB connection, distinguished by PID. 4) the server correctly fails overlapping locks made by the same PID (this goes against POSIX behaviour, which is why it is tricky to implement) 5) the server denies unlock requests by an incorrect client PID I've been discussing with Jeremy ways that we can re-implement the locking code to handle these correctly. This test code will be useful to see that we have got it right. (This used to be commit 097781e2992f12c545170c82ada2f4023a9784f5) --- source3/utils/torture.c | 336 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 284 insertions(+), 52 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index f3d76e0ee2..67a363df27 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -25,7 +25,6 @@ #include "includes.h" -static struct cli_state cli; static fstring host, workgroup, share, password, username, myname; static char *sockops=""; @@ -45,62 +44,61 @@ static double end_timer() } -static int open_connection(void) +static BOOL open_connection(struct cli_state *c) { - if (!cli_initialise(&cli) || !cli_connect(&cli, host, NULL)) { + if (!cli_initialise(c) || !cli_connect(c, host, NULL)) { printf("Failed to connect with %s\n", host); + return False; } - if (!cli_session_request(&cli, host, 0x20, myname)) { + if (!cli_session_request(c, host, 0x20, myname)) { printf("%s rejected the session\n",host); - cli_shutdown(&cli); - return -1; + cli_shutdown(c); + return False; } - if (!cli_negprot(&cli)) { - printf("%s rejected the negprot (%s)\n",host, cli_errstr(&cli)); - cli_shutdown(&cli); - return -1; + if (!cli_negprot(c)) { + printf("%s rejected the negprot (%s)\n",host, cli_errstr(c)); + cli_shutdown(c); + return False; } - if (!cli_session_setup(&cli, username, password, strlen(password), + if (!cli_session_setup(c, username, password, strlen(password), "", 0, workgroup)) { - printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(&cli)); - cli_shutdown(&cli); - return -1; + printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c)); + cli_shutdown(c); + return False; } - if (!cli_send_tconX(&cli, share, "A:", password, strlen(password)+1)) { - printf("%s refused tree connect (%s)\n", host, cli_errstr(&cli)); - cli_shutdown(&cli); - return -1; + if (!cli_send_tconX(c, share, "A:", password, strlen(password)+1)) { + printf("%s refused tree connect (%s)\n", host, cli_errstr(c)); + cli_shutdown(c); + return False; } - return 0; + return True; } -static void close_connection(void) +static void close_connection(struct cli_state *c) { - if (!cli_tdis(&cli)) { - printf("tdis failed (%s)\n", cli_errstr(&cli)); + if (!cli_tdis(c)) { + printf("tdis failed (%s)\n", cli_errstr(c)); } - cli_shutdown(&cli); + cli_shutdown(c); } - - -static BOOL wait_lock(int fnum, uint32 offset, uint32 len) +static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len) { - while (!cli_lock(&cli, fnum, offset, len, -1)) { + while (!cli_lock(c, fnum, offset, len, -1)) { int eclass, num; - cli_error(&cli, &eclass, &num); + cli_error(c, &eclass, &num); if (eclass != ERRDOS || num != ERRlock) { printf("lock failed (%s)\n", - cli_errstr(&cli)); + cli_errstr(c)); return False; } } @@ -108,7 +106,7 @@ static BOOL wait_lock(int fnum, uint32 offset, uint32 len) } -static int rw_torture(int numops) +static BOOL rw_torture(struct cli_state *c, int numops) { char *lockfname = "\\torture.lck"; fstring fname; @@ -117,13 +115,13 @@ static int rw_torture(int numops) int pid2, pid = getpid(); int i; - fnum2 = cli_open(&cli, lockfname, O_RDWR | O_CREAT | O_EXCL, + fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE); if (fnum2 == -1) - fnum2 = cli_open(&cli, lockfname, O_RDWR, DENY_NONE); + fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - printf("open of %s failed (%s)\n", lockfname, cli_errstr(&cli)); - return -1; + printf("open of %s failed (%s)\n", lockfname, cli_errstr(c)); + return False; } @@ -134,46 +132,46 @@ static int rw_torture(int numops) } sprintf(fname,"\\torture.%u", n); - if (!wait_lock(fnum2, n*sizeof(int), sizeof(int))) { - return -1; + if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) { + return False; } - fnum = cli_open(&cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL); + fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL); if (fnum == -1) { - printf("open failed (%s)\n", cli_errstr(&cli)); + printf("open failed (%s)\n", cli_errstr(c)); break; } - if (cli_write(&cli, fnum, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) { - printf("write failed (%s)\n", cli_errstr(&cli)); + if (cli_write(c, fnum, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) { + printf("write failed (%s)\n", cli_errstr(c)); } pid2 = 0; - if (cli_read(&cli, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) { - printf("read failed (%s)\n", cli_errstr(&cli)); + if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) { + printf("read failed (%s)\n", cli_errstr(c)); } if (pid2 != pid) { printf("data corruption!\n"); } - if (!cli_close(&cli, fnum)) { - printf("close failed (%s)\n", cli_errstr(&cli)); + if (!cli_close(c, fnum)) { + printf("close failed (%s)\n", cli_errstr(c)); } - if (!cli_unlink(&cli, fname)) { - printf("unlink failed (%s)\n", cli_errstr(&cli)); + if (!cli_unlink(c, fname)) { + printf("unlink failed (%s)\n", cli_errstr(c)); } - if (!cli_unlock(&cli, fnum2, n*sizeof(int), sizeof(int), -1)) { - printf("unlock failed (%s)\n", cli_errstr(&cli)); + if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int), -1)) { + printf("unlock failed (%s)\n", cli_errstr(c)); } } printf("%d\n", i); - return 0; + return True; } static void usage(void) @@ -195,15 +193,246 @@ static void usage(void) static void run_torture(int numops) { - if (open_connection() == 0) { + static struct cli_state cli; + + if (open_connection(&cli)) { cli_sockopt(&cli, sockops); printf("pid %d OK\n", getpid()); - rw_torture(numops); + rw_torture(&cli, numops); + + close_connection(&cli); + } +} + +/* + This test checks for two things: + + 1) correct support for retaining locks over a close (ie. the server + must not use posix semantics) + 2) support for lock timeouts + */ +static void run_locktest1(void) +{ + static struct cli_state cli1, cli2; + char *fname = "\\locktest.lck"; + int fnum1, fnum2, fnum3; + time_t t1, t2; - close_connection(); + if (!open_connection(&cli1) || !open_connection(&cli2)) { + return; } + cli_sockopt(&cli1, sockops); + cli_sockopt(&cli2, sockops); + + printf("starting locktest1\n"); + + cli_unlink(&cli1, fname); + + fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + fnum3 = cli_open(&cli2, fname, O_RDWR, DENY_NONE); + if (fnum3 == -1) { + printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli2)); + return; + } + + if (!cli_lock(&cli1, fnum1, 0, 4, 0)) { + printf("lock1 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + + if (cli_lock(&cli2, fnum3, 0, 4, 0)) { + printf("lock2 succeeded! This is a locking bug\n"); + return; + } else { + int eclass, num; + cli_error(&cli2, &eclass, &num); + if (eclass != ERRDOS || num != ERRlock) { + printf("error should have been ERRDOS/ERRlock (%s)\n", + cli_errstr(&cli2)); + return; + } + } + + + printf("Testing lock timeouts\n"); + t1 = time(NULL); + if (cli_lock(&cli2, fnum3, 0, 4, 10*1000)) { + printf("lock3 succeeded! This is a locking bug\n"); + return; + } else { + int eclass, num; + cli_error(&cli2, &eclass, &num); + if (eclass != ERRDOS || num != ERRlock) { + printf("error should have been ERRDOS/ERRlock (%s)\n", + cli_errstr(&cli2)); + return; + } + } + t2 = time(NULL); + + if (t2 - t1 < 5) { + printf("This server appears not to support timed lock requests\n"); + } + + if (!cli_close(&cli1, fnum2)) { + printf("close1 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + if (cli_lock(&cli2, fnum3, 0, 4, 0)) { + printf("lock4 succeeded! This is a locking bug\n"); + return; + } else { + int eclass, num; + cli_error(&cli2, &eclass, &num); + if (eclass != ERRDOS || num != ERRlock) { + printf("error should have been ERRDOS/ERRlock (%s)\n", + cli_errstr(&cli2)); + return; + } + } + + if (!cli_close(&cli1, fnum1)) { + printf("close2 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + if (!cli_close(&cli2, fnum3)) { + printf("close3 failed (%s)\n", cli_errstr(&cli2)); + return; + } + + if (!cli_unlink(&cli1, fname)) { + printf("unlink failed (%s)\n", cli_errstr(&cli1)); + return; + } + + + close_connection(&cli1); + close_connection(&cli2); + + printf("Passed locktest1\n"); +} + + +/* + This test checks that + + 1) the server supports multiple locking contexts on the one SMB + connection, distinguished by PID. + + 2) the server correctly fails overlapping locks made by the same PID (this + goes against POSIX behaviour, which is why it is tricky to implement) + + 3) the server denies unlock requests by an incorrect client PID +*/ +static void run_locktest2(void) +{ + static struct cli_state cli; + char *fname = "\\locktest.lck"; + int fnum1, fnum2, fnum3; + + if (!open_connection(&cli)) { + return; + } + + cli_sockopt(&cli, sockops); + + printf("starting locktest2\n"); + + cli_unlink(&cli, fname); + + cli_setpid(&cli, 1); + + fnum1 = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli)); + return; + } + + fnum2 = cli_open(&cli, fname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli)); + return; + } + + cli_setpid(&cli, 2); + + fnum3 = cli_open(&cli, fname, O_RDWR, DENY_NONE); + if (fnum3 == -1) { + printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli)); + return; + } + + cli_setpid(&cli, 1); + + if (!cli_lock(&cli, fnum1, 0, 4, 0)) { + printf("lock1 failed (%s)\n", cli_errstr(&cli)); + return; + } + + if (cli_lock(&cli, fnum2, 0, 4, 0)) { + printf("lock2 succeeded! This is a locking bug\n"); + } else { + int eclass, num; + cli_error(&cli, &eclass, &num); + if (eclass != ERRDOS || num != ERRlock) { + printf("error should have been ERRDOS/ERRlock (%s)\n", + cli_errstr(&cli)); + return; + } + } + + cli_setpid(&cli, 2); + + if (cli_unlock(&cli, fnum1, 0, 4, 0)) { + printf("unlock1 succeeded! This is a locking bug\n"); + } + + if (cli_lock(&cli, fnum3, 0, 4, 0)) { + printf("lock3 succeeded! This is a locking bug\n"); + } else { + int eclass, num; + cli_error(&cli, &eclass, &num); + if (eclass != ERRDOS || num != ERRlock) { + printf("error should have been ERRDOS/ERRlock (%s)\n", + cli_errstr(&cli)); + return; + } + } + + cli_setpid(&cli, 1); + + if (!cli_close(&cli, fnum1)) { + printf("close1 failed (%s)\n", cli_errstr(&cli)); + return; + } + + if (!cli_close(&cli, fnum2)) { + printf("close2 failed (%s)\n", cli_errstr(&cli)); + return; + } + + if (!cli_close(&cli, fnum3)) { + printf("close3 failed (%s)\n", cli_errstr(&cli)); + return; + } + + close_connection(&cli); + + printf("locktest2 finished\n"); } @@ -317,6 +546,9 @@ static void create_procs(int nprocs, int numops) create_procs(nprocs, numops); printf("rw_torture: %g secs\n", end_timer()); + run_locktest1(); + run_locktest2(); + return(0); } -- cgit From fbb57e5923a0da03033d3d2084547c12ca351d66 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Nov 1997 05:33:45 +0000 Subject: a few more tests added, including one that tests whether the server understand the full range of byte offsets in locking requests. Samba doesn't (due to the 31 bit limitation in fcntl locking) (This used to be commit af1f408a05a42a7ec5c2f4cc5b67c08b3c6cf61f) --- source3/utils/torture.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 157 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 67a363df27..506f31481c 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -283,7 +283,7 @@ static void run_locktest1(void) t2 = time(NULL); if (t2 - t1 < 5) { - printf("This server appears not to support timed lock requests\n"); + printf("error: This server appears not to support timed lock requests\n"); } if (!cli_close(&cli1, fnum2)) { @@ -436,6 +436,160 @@ static void run_locktest2(void) } +/* + This test checks that + + 1) the server supports the full offset range in lock requests +*/ +static void run_locktest3(int numops) +{ + static struct cli_state cli1, cli2; + char *fname = "\\locktest.lck"; + int fnum1, fnum2, i; + uint32 offset; + +#define NEXT_OFFSET offset += (~(uint32)0) / numops + + if (!open_connection(&cli1) || !open_connection(&cli2)) { + return; + } + cli_sockopt(&cli1, sockops); + cli_sockopt(&cli2, sockops); + + printf("starting locktest3\n"); + + cli_unlink(&cli1, fname); + + fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli2)); + return; + } + + for (offset=i=0;i Date: Sun, 9 Nov 1997 17:30:10 +0000 Subject: attempting to mark up 32 bit error codes, needed for NT domains. separated out smb server-mode password validation into a separate file. added called and calling netbios names to client gen state: referenced section in rfc1002.txt. created workstation trust account checking code in ntclient.c there might be a bug in reply_session_setup_andX. i indented and added { } around single-line if statements: the lm password checking code now doesn't look right (around the GUEST_SESSSETUP bits). *no code semantics have been changed by the indentation process*. (This used to be commit f27966957fa7f16d337a4a58719239d036deab4c) --- source3/utils/torture.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 506f31481c..a0e32ff395 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -46,12 +46,14 @@ static double end_timer() static BOOL open_connection(struct cli_state *c) { - if (!cli_initialise(c) || !cli_connect(c, host, NULL)) { + if (!cli_initialise(c) || !cli_connect(c, host, NULL)) + { printf("Failed to connect with %s\n", host); return False; } - if (!cli_session_request(c, host, 0x20, myname)) { + if (!cli_session_request(c, host, 0x20, myname, 0x0)) + { printf("%s rejected the session\n",host); cli_shutdown(c); return False; -- cgit From 77aec4ae6307c0ad0b843bbf23d64ccb1aaf7476 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 10 Nov 1997 19:23:17 +0000 Subject: Rolled back tree state to 11:59pm 8th November 1997 EST to remove problems. Jeremy (This used to be commit 4a36ac236c2ad634f05efcd0179875d09988614a) --- source3/utils/torture.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index a0e32ff395..506f31481c 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -46,14 +46,12 @@ static double end_timer() static BOOL open_connection(struct cli_state *c) { - if (!cli_initialise(c) || !cli_connect(c, host, NULL)) - { + if (!cli_initialise(c) || !cli_connect(c, host, NULL)) { printf("Failed to connect with %s\n", host); return False; } - if (!cli_session_request(c, host, 0x20, myname, 0x0)) - { + if (!cli_session_request(c, host, 0x20, myname)) { printf("%s rejected the session\n",host); cli_shutdown(c); return False; -- cgit From 30dfa00877514274aef2cd3e1bd954b017beed10 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Nov 1997 02:51:20 +0000 Subject: added code to test the cli_NetServerEnum() function in clientgen.c (This used to be commit 4933ba49b55a9a438b006c977c7ab6f5960065a3) --- source3/utils/torture.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 506f31481c..1e284fb93d 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -590,6 +590,43 @@ static void run_unlinktest(void) +static void browse_callback(char *sname, uint32 stype, char *comment) +{ + printf("\t%20.20s %08x %s\n", sname, stype, comment); +} + + +/* + This test checks the browse list code + +*/ +static void run_browsetest(void) +{ + static struct cli_state cli; + + printf("staring browse test\n"); + + if (!open_connection(&cli)) { + return; + } + + printf("domain list:\n"); + cli_NetServerEnum(&cli, workgroup, + SV_TYPE_DOMAIN_ENUM, + browse_callback); + + printf("machine list:\n"); + cli_NetServerEnum(&cli, workgroup, + SV_TYPE_ALL, + browse_callback); + + close_connection(&cli); + + printf("browse test finished\n"); +} + + + static void create_procs(int nprocs, int numops) { int i, status; @@ -704,6 +741,7 @@ static void create_procs(int nprocs, int numops) run_locktest2(); run_locktest3(numops); run_unlinktest(); + run_browsetest(); return(0); } -- cgit From 9f804556c4d0bb68f9b7acaf2b679bc0a02ea8f9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 17 Nov 1997 19:16:38 +0000 Subject: loadparm.c : Added "veto oplock files" parameter. make_printerdef.c: Fixed warning. quotas.c: Fixed irix root errors. server.c: Fixed oplock reference count bug. smb.h: Added IS_VETO_OPLOCK_PATH(). Jeremy. (This used to be commit c28487df63e29bc0f8d2ece876a07a2a076d4c73) --- source3/utils/make_printerdef.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index 8b49925ad8..2262111273 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -143,7 +143,7 @@ char *find_desc(FILE *fichier,char *text) char *chaine; char *long_desc; char *short_desc; - char *crap; + char *crap = NULL; char *p; int found=0; -- cgit From 6a6653f8152a0caf523639eca913f22431b2211a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 19 Nov 1997 23:50:02 +0000 Subject: changed nmblookup to only set recursion_desired in queries if the -R option is used. (This used to be commit 4561b8242e12c63401d008e7fdb2442457bd366d) --- source3/utils/nmblookup.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index a44dad511e..1f74d7a130 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -77,7 +77,9 @@ static void usage(void) printf("Version %s\n",VERSION); printf("\t-d debuglevel set the debuglevel\n"); printf("\t-B broadcast address the address to use for broadcasts\n"); + printf("\t-U unicast address the address to use for unicast\n"); printf("\t-M searches for a master browser\n"); + printf("\t-R set recursion desired in packet\n"); printf("\t-S lookup node status as well\n"); printf("\t-r Use root port 137 (Win95 only replies to this)\n"); printf("\t-A Do a node status on as an IP Address\n"); @@ -103,7 +105,8 @@ int main(int argc,char *argv[]) BOOL use_bcast = True; BOOL got_bcast = False; BOOL lookup_by_ip = False; - + BOOL recursion_desired = False; + DEBUGLEVEL = 1; *lookup = 0; @@ -113,7 +116,7 @@ int main(int argc,char *argv[]) charset_initialise(); - while ((opt = getopt(argc, argv, "d:B:U:i:s:SMrhA")) != EOF) + while ((opt = getopt(argc, argv, "d:B:U:i:s:SMrhAR")) != EOF) switch (opt) { case 'B': @@ -138,6 +141,9 @@ int main(int argc,char *argv[]) case 'S': find_status = True; break; + case 'R': + recursion_desired = True; + break; case 'd': DEBUGLEVEL = atoi(optarg); break; @@ -213,7 +219,7 @@ int main(int argc,char *argv[]) retries = 1; } - if (name_query(ServerFD,lookup,lookup_type,use_bcast,True, + if (name_query(ServerFD,lookup,lookup_type,use_bcast,recursion_desired, bcast_addr,&ip,NULL)) { printf("%s %s\n",inet_ntoa(ip),lookup); -- cgit From 8bf0f359f3ec440ace0bba6c12ca65d25ba45fd9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Nov 1997 02:41:22 +0000 Subject: added a test for the NT SMBgetatr bug in smbtorture added support for choosing the protocol level in smbtorture (-m option) use -1 for null date in cli_close() get the attributes right in cli_open() (This used to be commit d64d40a6ec57a4a999ae1f39175bcfd86ccb196e) --- source3/utils/torture.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 1e284fb93d..06f9f5f1fb 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -26,6 +26,7 @@ #include "includes.h" static fstring host, workgroup, share, password, username, myname; +static int max_protocol = PROTOCOL_NT1; static char *sockops=""; @@ -57,6 +58,8 @@ static BOOL open_connection(struct cli_state *c) return False; } + c->protocol = max_protocol; + if (!cli_negprot(c)) { printf("%s rejected the negprot (%s)\n",host, cli_errstr(c)); cli_shutdown(c); @@ -184,6 +187,7 @@ static void usage(void) printf("\t-W workgroup\n"); printf("\t-o num_operations\n"); printf("\t-O socket_options\n"); + printf("\t-m maximum protocol\n"); printf("\n"); exit(1); @@ -626,6 +630,40 @@ static void run_browsetest(void) } +/* + This checks how the getatr calls works +*/ +static void run_attrtest(void) +{ + static struct cli_state cli; + int fnum; + struct stat st; + char *fname = "\\attrib.tst"; + + printf("staring attrib test\n"); + + if (!open_connection(&cli)) { + return; + } + + cli_unlink(&cli, fname); + fnum = cli_open(&cli, fname, + O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); + cli_close(&cli, fnum); + if (!cli_stat(&cli, fname, &st)) { + printf("getatr failed (%s)\n", cli_errstr(&cli)); + } + + if (abs(st.st_mtime - time(NULL)) > 2) { + printf("ERROR: SMBgetatr bug. time is %s", + ctime(&st.st_mtime)); + } + + close_connection(&cli); + + printf("attrib test finished\n"); +} + static void create_procs(int nprocs, int numops) { @@ -689,11 +727,14 @@ static void create_procs(int nprocs, int numops) argv++; - while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:")) != EOF) { + while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:")) != EOF) { switch (opt) { case 'W': fstrcpy(workgroup,optarg); break; + case 'm': + max_protocol = interpret_protocol(optarg, max_protocol); + break; case 'N': nprocs = atoi(optarg); break; @@ -742,6 +783,7 @@ static void create_procs(int nprocs, int numops) run_locktest3(numops); run_unlinktest(); run_browsetest(); + run_attrtest(); return(0); } -- cgit From a1c5442abb3bc221157ca3620d35e1a013b26232 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Nov 1997 03:09:59 +0000 Subject: test SMBsetatr as well (This used to be commit 2f29c24ba721e417828efca57011ed45892191a5) --- source3/utils/torture.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 06f9f5f1fb..d5258d2d6a 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -637,7 +637,7 @@ static void run_attrtest(void) { static struct cli_state cli; int fnum; - struct stat st; + time_t t, t2; char *fname = "\\attrib.tst"; printf("staring attrib test\n"); @@ -650,13 +650,30 @@ static void run_attrtest(void) fnum = cli_open(&cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); cli_close(&cli, fnum); - if (!cli_stat(&cli, fname, &st)) { + if (!cli_getatr(&cli, fname, NULL, NULL, &t)) { printf("getatr failed (%s)\n", cli_errstr(&cli)); } - if (abs(st.st_mtime - time(NULL)) > 2) { + if (abs(t - time(NULL)) > 2) { printf("ERROR: SMBgetatr bug. time is %s", - ctime(&st.st_mtime)); + ctime(&t)); + t = time(NULL); + } + + t2 = t-60*60*24; /* 1 day ago */ + + if (!cli_setatr(&cli, fname, 0, t2)) { + printf("setatr failed (%s)\n", cli_errstr(&cli)); + } + + if (!cli_getatr(&cli, fname, NULL, NULL, &t)) { + printf("getatr failed (%s)\n", cli_errstr(&cli)); + } + + if (t != t2) { + printf("ERROR: getatr/setatr bug. times are\n%s", + ctime(&t)); + printf("%s", ctime(&t2)); } close_connection(&cli); -- cgit From c16d132bf95d96e2aa572cb9ba18a68abfbbeb8d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Nov 1997 05:55:44 +0000 Subject: added some QPATHINFO and QFILEINFO tests into smbtorture. This tests for things like midnight access times, sticky create times and word reversed INFO_STANDARD returns (This used to be commit 89141de14edf9e46ab279d2a74a9b026716a0ba8) --- source3/utils/torture.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index d5258d2d6a..fc6d5bcc15 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -682,6 +682,64 @@ static void run_attrtest(void) } +/* + This checks a couple of trans2 calls +*/ +static void run_trans2test(void) +{ + static struct cli_state cli; + int fnum; + uint32 size; + time_t c_time, a_time, m_time; + char *fname = "\\trans2.tst"; + + printf("staring trans2 test\n"); + + if (!open_connection(&cli)) { + return; + } + + cli_unlink(&cli, fname); + fnum = cli_open(&cli, fname, + O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); + if (!cli_qfileinfo(&cli, fnum, &c_time, &a_time, &m_time, &size)) { + printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli)); + } + cli_close(&cli, fnum); + + sleep(2); + + cli_unlink(&cli, fname); + fnum = cli_open(&cli, fname, + O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); + cli_close(&cli, fnum); + + if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size)) { + printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli)); + } else { + if (c_time != m_time) { + printf("create time=%s", ctime(&c_time)); + printf("modify time=%s", ctime(&m_time)); + printf("This system appears to have sticky create times\n"); + } + if (a_time % (60*60) == 0) { + printf("access time=%s", ctime(&a_time)); + printf("This system appears to set a midnight access time\n"); + } + + if (abs(m_time - time(NULL)) > 60) { + printf("ERROR: totally incorrect times - maybe word reversed?\n"); + } + } + + cli_unlink(&cli, fname); + + close_connection(&cli); + + printf("trans2 test finished\n"); +} + + static void create_procs(int nprocs, int numops) { int i, status; @@ -801,6 +859,7 @@ static void create_procs(int nprocs, int numops) run_unlinktest(); run_browsetest(); run_attrtest(); + run_trans2test(); return(0); } -- cgit From 931d0150b0751d2e52cded550061374826214943 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Nov 1997 07:26:42 +0000 Subject: added a SMB_QUERY_FILE_ALL_INFO test into smbtorture W95 doesn't seem to support this call. (This used to be commit 162947c6e672580216c6223a44d25b874f0487ab) --- source3/utils/torture.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index fc6d5bcc15..d1bd6e5f00 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -690,7 +690,7 @@ static void run_trans2test(void) static struct cli_state cli; int fnum; uint32 size; - time_t c_time, a_time, m_time; + time_t c_time, a_time, m_time, w_time; char *fname = "\\trans2.tst"; printf("staring trans2 test\n"); @@ -732,7 +732,20 @@ static void run_trans2test(void) } } + cli_unlink(&cli, fname); + fnum = cli_open(&cli, fname, + O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); + cli_close(&cli, fnum); + if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time, + &w_time, &size)) { + printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); + } else { + if (w_time < 60*60*24*2) { + printf("write time=%s", ctime(&w_time)); + printf("This system appears to set a initial 0 write time\n"); + } + } close_connection(&cli); -- cgit From ebe7c7a173efa32057908af43a5c3d74d8b3739a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 24 Nov 1997 13:44:52 +0000 Subject: added cli_rmdir and cli_mkdir added test in smbtorture for the server updating the directory modify time when a file is added to a directory cleanup in smbtorture so no garbage files are left on the server (This used to be commit 3a5e07f1e994396853e6340e8ef3f4d12bb0243e) --- source3/utils/torture.c | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index d1bd6e5f00..8711af3fe1 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -172,6 +172,9 @@ static BOOL rw_torture(struct cli_state *c, int numops) } } + cli_close(c, fnum2); + cli_unlink(c, lockfname); + printf("%d\n", i); return True; @@ -587,6 +590,9 @@ static void run_unlinktest(void) printf("error: server allowed unlink on an open file\n"); } + cli_close(&cli, fnum); + cli_unlink(&cli, fname); + close_connection(&cli); printf("unlink test finished\n"); @@ -608,7 +614,7 @@ static void run_browsetest(void) { static struct cli_state cli; - printf("staring browse test\n"); + printf("starting browse test\n"); if (!open_connection(&cli)) { return; @@ -640,7 +646,7 @@ static void run_attrtest(void) time_t t, t2; char *fname = "\\attrib.tst"; - printf("staring attrib test\n"); + printf("starting attrib test\n"); if (!open_connection(&cli)) { return; @@ -676,6 +682,8 @@ static void run_attrtest(void) printf("%s", ctime(&t2)); } + cli_unlink(&cli, fname); + close_connection(&cli); printf("attrib test finished\n"); @@ -690,10 +698,12 @@ static void run_trans2test(void) static struct cli_state cli; int fnum; uint32 size; - time_t c_time, a_time, m_time, w_time; + time_t c_time, a_time, m_time, w_time, m_time2; char *fname = "\\trans2.tst"; + char *dname = "\\trans2"; + char *fname2 = "\\trans2\\trans2.tst"; - printf("staring trans2 test\n"); + printf("starting trans2 test\n"); if (!open_connection(&cli)) { return; @@ -727,7 +737,7 @@ static void run_trans2test(void) printf("This system appears to set a midnight access time\n"); } - if (abs(m_time - time(NULL)) > 60) { + if (abs(m_time - time(NULL)) > 60*60*24*7) { printf("ERROR: totally incorrect times - maybe word reversed?\n"); } } @@ -747,6 +757,35 @@ static void run_trans2test(void) } } + cli_unlink(&cli, fname); + + + /* check if the server updates the directory modification time + when creating a new file */ + if (!cli_mkdir(&cli, dname)) { + printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli)); + } + sleep(3); + if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time, + &w_time, &size)) { + printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); + } + + fnum = cli_open(&cli, fname2, + O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); + cli_write(&cli, fnum, (char *)&fnum, 0, sizeof(fnum)); + cli_close(&cli, fnum); + if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2, + &w_time, &size)) { + printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); + } else { + if (m_time2 == m_time) + printf("This system does not update directory modification times\n"); + } + cli_unlink(&cli, fname2); + cli_rmdir(&cli, dname); + + close_connection(&cli); printf("trans2 test finished\n"); -- cgit From 64f0348a3f994334abe64a4d4896109c3c8c9039 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 13 Dec 1997 14:16:07 +0000 Subject: This is it ! The mega-merge of the JRA_NMBD_REWRITE branch back into the main tree. For the cvs logs of all the files starting nmbd_*.c, look in the JRA_NMBD_REWRITE branch. That branch has now been discontinued. Jeremy. (This used to be commit d80b0cb645f81d16734929a0b27a91c6650499bb) --- source3/utils/nmblookup.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 1f74d7a130..b14887afab 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -186,9 +186,10 @@ int main(int argc,char *argv[]) for (i=optind;i\n",inet_ntoa(ip_list[j]),lookup, lookup_type); + + /* We can only do find_status if the ip address returned + was valid - ie. name_query returned true. + */ + if (find_status) { + printf("Looking up status of %s\n",inet_ntoa(ip_list[0])); + name_status(ServerFD,lookup,lookup_type,True,ip_list[0],NULL,NULL,NULL); + printf("\n"); + } + } else { + printf("name_query failed to find name %s\n", lookup); } } - + return(0); } -- cgit From 0a5073e985847acac11979771bdc04308a903107 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Thu, 1 Jan 1998 13:55:28 +0000 Subject: fixes to make_printerdef.c to generate a correct printers.def file changes to ipc.c to use new printers.def file (This used to be commit 52e275c4ccc1b7f0c2ef8d12d28065898a1c89c9) --- source3/utils/make_printerdef.c | 125 +++++++++++++++++++++++++++++++--------- 1 file changed, 97 insertions(+), 28 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index 2262111273..6f605c41f8 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -23,10 +23,10 @@ #include "includes.h" /* -#define DEBUG +#define DEBUGIT */ char *files_to_copy; -char *driverfile; +char *driverfile, *datafile, *helpfile, *languagemonitor, *datatype; char buffer[50][255]; char sub_dir[50][2][255]; @@ -66,7 +66,7 @@ void build_subdir() while (*buffer[i]!='\0') { data=scan(buffer[i],&entry); -#ifdef DEBUG +#ifdef DEBUGIT fprintf(stderr,"\tentry=data %s:%s\n",entry,data); #endif @@ -78,7 +78,7 @@ void build_subdir() strcpy(sub_dir[i][0],entry); strcpy(sub_dir[i][1],"color\\"); } -#ifdef DEBUG +#ifdef DEBUGIT fprintf(stderr,"\tsubdir %s:%s\n",sub_dir[i][0],sub_dir[i][1]); #endif i++; @@ -105,7 +105,7 @@ void lookup_entry(FILE *fichier,char *chaine) strcat(temp2,"]"); rewind(fichier); -#ifdef DEBUG +#ifdef DEBUGIT fprintf(stderr,"\tLooking for %s\n",chaine); #endif @@ -131,7 +131,7 @@ void lookup_entry(FILE *fichier,char *chaine) pointeur++; } } -#ifdef DEBUG +#ifdef DEBUGIT fprintf(stderr,"\t\tFound %d entries\n",pointeur-1); #endif } @@ -150,7 +150,7 @@ char *find_desc(FILE *fichier,char *text) chaine=(char *)malloc(255*sizeof(char)); long_desc=(char *)malloc(40*sizeof(char)); - short_desc=(char *)malloc(13*sizeof(char)); + short_desc=(char *)malloc(40*sizeof(char)); while (!feof(fichier) && found==0) { @@ -172,13 +172,14 @@ char *find_desc(FILE *fichier,char *text) p++; *p='\0'; } - if (!strcmp(text,long_desc)) found=1; + if (!strcmp(text,long_desc)) + found=1; } free(chaine); + if (!found || !crap) return(NULL); while(*crap==' ') crap++; strcpy(short_desc,crap); - if (found) return(short_desc); - else return(NULL); + return(short_desc); } void scan_copyfiles(FILE *fichier, char *chaine) @@ -186,10 +187,10 @@ void scan_copyfiles(FILE *fichier, char *chaine) char *part; int i; char direc[255]; -#ifdef DEBUG +#ifdef DEBUGIT fprintf(stderr,"In scan_copyfiles Lookup up of %s\n",chaine); #endif - part=strtok(chaine,", "); + part=strtok(chaine,","); do { /* If the entry start with a @ then it's a file to copy else it's an entry refering to files to copy @@ -197,14 +198,15 @@ void scan_copyfiles(FILE *fichier, char *chaine) you can have a directory to append before the file name */ if (*part=='@') { - strcpy(files_to_copy,", "); - strcpy(files_to_copy,part); + if (strlen(files_to_copy) != 0) + strcat(files_to_copy,","); + strcat(files_to_copy,&part[1]); } else { lookup_entry(fichier,part); i=0; strcpy(direc,""); while (*sub_dir[i][0]!='\0') { -#ifdef DEBUG +#ifdef DEBUGIT fprintf(stderr,"\tsubdir %s:%s\n",sub_dir[i][0],sub_dir[i][1]); #endif if (strcmp(sub_dir[i][0],part)==0) @@ -213,13 +215,14 @@ void scan_copyfiles(FILE *fichier, char *chaine) } i=0; while (*buffer[i]!='\0') { - strcat(files_to_copy,", "); + if (strlen(files_to_copy) != 0) + strcat(files_to_copy,","); strcat(files_to_copy,direc); strcat(files_to_copy,buffer[i]); i++; } } - part=strtok(NULL,", "); + part=strtok(NULL,","); } while (part!=NULL); } @@ -230,26 +233,87 @@ void scan_short_desc(FILE *fichier, char *short_desc) int i=0; char *chaine; char *temp; - char *copyfiles=0,*datasection=0,*datafile=0,*helpfile=0; + char *copyfiles=0,*datasection=0; + helpfile=0; + languagemonitor=0; + datatype="RAW"; chaine=(char *)malloc(255*sizeof(char)); temp=(char *)malloc(255*sizeof(char)); driverfile=short_desc; + datafile=short_desc; lookup_entry(fichier,short_desc); while(*buffer[i]!='\0') { -#ifdef DEBUG +#ifdef DEBUGIT fprintf(stderr,"\tLookup up of %s\n",buffer[i]); #endif - if (strncmp(buffer[i],"CopyFiles",9)==0) copyfiles=scan(buffer[i],&temp); - if (strncmp(buffer[i],"DataSection",11)==0) datasection=scan(buffer[i],&temp); - if (strncmp(buffer[i],"DataFile",8)==0) datafile=scan(buffer[i],&temp); - if (strncmp(buffer[i],"DriverFile",10)==0) driverfile=scan(buffer[i],&temp); - if (strncmp(buffer[i],"HelpFile",8)==0) helpfile=scan(buffer[i],&temp); + if (strncmp(buffer[i],"CopyFiles",9)==0) + copyfiles=scan(buffer[i],&temp); + else if (strncmp(buffer[i],"DataSection",11)==0) + datasection=scan(buffer[i],&temp); + else if (strncmp(buffer[i],"DataFile",8)==0) + datafile=scan(buffer[i],&temp); + else if (strncmp(buffer[i],"DriverFile",10)==0) + driverfile=scan(buffer[i],&temp); + else if (strncmp(buffer[i],"HelpFile",8)==0) + helpfile=scan(buffer[i],&temp); + else if (strncmp(buffer[i],"LanguageMonitor",15)==0) + languagemonitor=scan(buffer[i],&temp); + else if (strncmp(buffer[i],"DefaultDataType",15)==0) + datatype=scan(buffer[i],&temp); i++; } + + if (datasection) { + lookup_entry(fichier,datasection); + + i = 0; + while(*buffer[i]!='\0') { +#ifdef DEBUGIT + fprintf(stderr,"\tLookup up of %s\n",buffer[i]); +#endif + if (strncmp(buffer[i],"CopyFiles",9)==0) + copyfiles=scan(buffer[i],&temp); + else if (strncmp(buffer[i],"DataSection",11)==0) + datasection=scan(buffer[i],&temp); + else if (strncmp(buffer[i],"DataFile",8)==0) + datafile=scan(buffer[i],&temp); + else if (strncmp(buffer[i],"DriverFile",10)==0) + driverfile=scan(buffer[i],&temp); + else if (strncmp(buffer[i],"HelpFile",8)==0) + helpfile=scan(buffer[i],&temp); + else if (strncmp(buffer[i],"LanguageMonitor",15)==0) + languagemonitor=scan(buffer[i],&temp); + else if (strncmp(buffer[i],"DefaultDataType",15)==0) + datatype=scan(buffer[i],&temp); + i++; + } + } + + if (languagemonitor && (*languagemonitor == '%')) { + ++languagemonitor; + languagemonitor[strlen(languagemonitor)-1] = '\0'; + lookup_entry(fichier,"Strings"); + i = 0; + while(*buffer[i]!='\0') { +#ifdef DEBUGIT + fprintf(stderr,"\tLookup up of %s\n",buffer[i]); +#endif + if (strncmp(buffer[i],languagemonitor,strlen(languagemonitor))==0) + { + temp = strtok(buffer[i],"="); + temp = strtok(NULL,","); + if (*temp == '"') ++temp; + strcpy(languagemonitor,temp); + break; + } + i++; + } + } + if (i) fprintf(stderr,"End of section found\n"); fprintf(stderr,"CopyFiles: %s\n",copyfiles); @@ -257,10 +321,8 @@ void scan_short_desc(FILE *fichier, char *short_desc) fprintf(stderr,"Datafile: %s\n",datafile); fprintf(stderr,"Driverfile: %s\n",driverfile); fprintf(stderr,"Helpfile: %s\n",helpfile); + fprintf(stderr,"LanguageMonitor: %s\n",languagemonitor); if (copyfiles) scan_copyfiles(fichier,copyfiles); -/* if (datasection) scan_copyfiles(fichier,datasection);*/ - if (datafile) scan_copyfiles(fichier,datafile); - if (helpfile) scan_copyfiles(fichier,helpfile); } int main(int argc, char *argv[]) @@ -293,8 +355,15 @@ int main(int argc, char *argv[]) build_subdir(); files_to_copy=(char *)malloc(2048*sizeof(char)); + *files_to_copy='\0'; scan_short_desc(inf_file,short_desc); - fprintf(stdout,"%s:%s:%s:",argv[2],short_desc,driverfile); + fprintf(stdout,"%s:%s:%s:", + argv[2],driverfile,datafile); + fprintf(stdout,"%s:", + helpfile?helpfile:""); + fprintf(stdout,"%s:", + languagemonitor?languagemonitor:""); + fprintf(stdout,"%s:",datatype); fprintf(stdout,"%s\n",files_to_copy); return 0; } -- cgit From 153a95a33852a1e7b4c9ff1f6e67798cfa493073 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Sat, 3 Jan 1998 05:12:10 +0000 Subject: added printout of file list to stderr so you know what files you need to copy to your printer$ share (This used to be commit bdfa5c709986051e78198c68c5a90358fdfa780e) --- source3/utils/make_printerdef.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index 6f605c41f8..ef890163f0 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -190,6 +190,7 @@ void scan_copyfiles(FILE *fichier, char *chaine) #ifdef DEBUGIT fprintf(stderr,"In scan_copyfiles Lookup up of %s\n",chaine); #endif + fprintf(stderr,"\nCopy the following files to your printer$ share location:\n"); part=strtok(chaine,","); do { /* If the entry start with a @ then it's a file to copy @@ -201,6 +202,7 @@ void scan_copyfiles(FILE *fichier, char *chaine) if (strlen(files_to_copy) != 0) strcat(files_to_copy,","); strcat(files_to_copy,&part[1]); + fprintf(stderr,"%s\n",&part[1]); } else { lookup_entry(fichier,part); i=0; @@ -219,12 +221,14 @@ void scan_copyfiles(FILE *fichier, char *chaine) strcat(files_to_copy,","); strcat(files_to_copy,direc); strcat(files_to_copy,buffer[i]); + fprintf(stderr,"%s%s\n",direc,buffer[i]); i++; } } part=strtok(NULL,","); } while (part!=NULL); + fprintf(stderr,"\n"); } -- cgit From fec28f2defa17974b2eaafdd10599cf37850ca16 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 16 Jan 1998 06:29:38 +0000 Subject: Makefile: Added new codepage - 866. charset.c: Supporting code for codepage 866. clientutil.c: Fix compile bug in little-used #define. includes.h: Supporting code for codepage 866. make_smbcodepage.c: Supporting code for codepage 866. pcap.c: Fix bug for lpstat. Jeremy. (This used to be commit 6040d7a39e5d5ab426905aa79b871df815fb9b62) --- source3/utils/make_smbcodepage.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c index b4cb152334..06bc694e20 100644 --- a/source3/utils/make_smbcodepage.c +++ b/source3/utils/make_smbcodepage.c @@ -167,7 +167,7 @@ int do_compile(int codepage, char *input_file, char *output_file) FILE *fp = NULL; uint32 size = 0; char *buf = NULL; - char output_buf[CODEPAGE_HEADER_SIZE + 512]; + char output_buf[CODEPAGE_HEADER_SIZE + 4 * MAXCODEPAGELINES]; int num_lines = 0; int i = 0; struct stat st; @@ -223,11 +223,11 @@ The maximum size I will believe is 100k.\n", prog_name, size); num_lines = clean_data( &buf, &size); - /* There can be a maximum of 128 lines. */ - if(num_lines > 128) + /* There can be a maximum of MAXCODEPAGELINES lines. */ + if(num_lines > MAXCODEPAGELINES) { - fprintf(stderr, "%s: There can be a maximum 128 lines of data in a codepage \ -definition file. File %s has %d.\n", prog_name, input_file, num_lines); + fprintf(stderr, "%s: There can be a maximum %d lines of data in a codepage \ +definition file. File %s has %d.\n", prog_name, MAXCODEPAGELINES, input_file, num_lines); exit(1); } -- cgit From 12d50e30ec7d898db43bffec5953c2c414e0a330 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 21 Jan 1998 09:17:51 +0000 Subject: fix problems with using inf files from HP for DesignJet 750C (C3195A) (This used to be commit 4e258eecf7088d78b285440ca87386987196eaec) --- source3/utils/make_printerdef.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index ef890163f0..ce61f460ff 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -157,7 +157,7 @@ char *find_desc(FILE *fichier,char *text) fgets(chaine,255,fichier); long_desc=strtok(chaine,"="); - crap=strtok(NULL,","); + crap=strtok(NULL,",\r"); p=long_desc; while(*p!='"' && *p!='\0') @@ -217,6 +217,9 @@ void scan_copyfiles(FILE *fichier, char *chaine) } i=0; while (*buffer[i]!='\0') { + part = &buffer[i][strlen(buffer[i])-1]; + if (*part == '=') + *part = '\0'; if (strlen(files_to_copy) != 0) strcat(files_to_copy,","); strcat(files_to_copy,direc); -- cgit From 55f400bd84f26027f5ec9b7fa06b22895de7557c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 22 Jan 1998 13:27:43 +0000 Subject: This is *not* a big change (although it looks like one). This is merely updating the Copyright statements from 1997 to 1998. It's a once a year thing :-). NO OTHER CHANGES WERE MADE. Jeremy. (This used to be commit b9c16977231efb274e08856f7f3f4408dad6d96c) --- source3/utils/make_printerdef.c | 2 +- source3/utils/make_smbcodepage.c | 2 +- source3/utils/nmblookup.c | 2 +- source3/utils/smbpasswd.c | 2 +- source3/utils/status.c | 2 +- source3/utils/testparm.c | 2 +- source3/utils/testprns.c | 2 +- source3/utils/torture.c | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index ce61f460ff..a38b6b4285 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -3,7 +3,7 @@ Version 1.9. Create printer definition files. - Copyright (C) Jean-Francois.Micouleau@utc.fr, 10/26/97 + Copyright (C) Jean-Francois.Micouleau@utc.fr, 10/26/97 - 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 diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c index 06bc694e20..409d199640 100644 --- a/source3/utils/make_smbcodepage.c +++ b/source3/utils/make_smbcodepage.c @@ -3,7 +3,7 @@ Version 1.9. Create codepage files from codepage_def.XXX files. - Copyright (C) Jeremy Allison 1997 + Copyright (C) Jeremy Allison 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 diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index b14887afab..5cd5a869a9 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. NBT client - used to lookup netbios names - Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Andrew Tridgell 1994-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 diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 225b7fde83..598944baa5 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -1,6 +1,6 @@ /* * Unix SMB/Netbios implementation. Version 1.9. smbpasswd module. Copyright - * (C) Jeremy Allison 1995-1997. + * (C) Jeremy Allison 1995-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 diff --git a/source3/utils/status.c b/source3/utils/status.c index 1a05f2b1af..401dd25c89 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. status reporting - Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Andrew Tridgell 1994-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 diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index ca364cb8c9..cc35d2d530 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. Test validity of smb.conf - Copyright (C) Karl Auer 1993, 1994-1997 + Copyright (C) Karl Auer 1993, 1994-1998 Extensively modified by Andrew Tridgell, 1995 diff --git a/source3/utils/testprns.c b/source3/utils/testprns.c index 4a2ddb7c63..caa9e2740a 100644 --- a/source3/utils/testprns.c +++ b/source3/utils/testprns.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. test printer setup - Copyright (C) Karl Auer 1993, 1994-1997 + Copyright (C) Karl Auer 1993, 1994-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 diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 8711af3fe1..049a414eb9 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. SMB torture tester - Copyright (C) Andrew Tridgell 1997 + 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 -- cgit From 458a678fd2bdd3345b37765cc6de5702c917ab50 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Fri, 23 Jan 1998 07:59:29 +0000 Subject: changes to correctly use some HP printer inf files (This used to be commit ab894c3e1de582864ad9c0f6ae797b73b4c2ba41) --- source3/utils/make_printerdef.c | 185 +++++++++++++++++++++++++++++++--------- 1 file changed, 146 insertions(+), 39 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index a38b6b4285..723c4fdf51 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -25,9 +25,11 @@ /* #define DEBUGIT */ + char *files_to_copy; char *driverfile, *datafile, *helpfile, *languagemonitor, *datatype; char buffer[50][255]; +char sbuffer[50][255]; char sub_dir[50][2][255]; void usage(char *name) @@ -35,6 +37,40 @@ void usage(char *name) fprintf(stderr,"%s: printer.def \"Printer Name\"\n", name); } +char *myfgets(char *s, int n, FILE *stream) +{ + char *LString1; + char *LString2; + char *temp; + char String[255]; + char NewString[255]; + int i; + + fgets(s,n,stream); + while (LString1 = strchr(s,'%')) { + if (!(LString2 = strchr(LString1+1,'%'))) break; + *LString2 = '\0'; + strcpy(String,LString1+1); + i = 0; + while(*sbuffer[i]!='\0') { + if (strncmp(sbuffer[i],String,strlen(String))==0) + { + strcpy(String,sbuffer[i]); + if (temp = strchr(String,'=')) ++temp; + strcpy(String,temp); + break; + } + i++; + } + *LString1 = '\0'; + strcpy(NewString,s); + strcat(NewString,String); + strcat(NewString,LString2+1); + strcpy(s, NewString); + } + return(s); +} + /* This function split a line in two parts on both side of the equal sign @@ -85,6 +121,56 @@ void build_subdir() } } +/* + Lockup Strings entry in a file + Return all the lines between the entry and the next one or the end of file + An entry is something between braces. +*/ +void lookup_strings(FILE *fichier) +{ + int found=0,pointeur=0,i=0; + char *temp,*temp2; + + temp=(char *)malloc(255*sizeof(char)); + temp2=(char *)malloc(255*sizeof(char)); + + *sbuffer[0]='\0'; + + strcpy(temp2,"[Strings]"); + + rewind(fichier); +#ifdef DEBUGIT + fprintf(stderr,"\tLooking for Strings\n"); +#endif + + while (!feof(fichier) && found==0) { + *temp='\0'; + fgets(temp,255,fichier); + if (strncmp(temp,temp2,strlen(temp2))==0) found=1; + } + + + while (!feof(fichier) && found==1) { + *temp='\0'; + fgets(temp,255,fichier); + if (*temp=='[') { + found=2; + *sbuffer[pointeur]='\0'; + } + else { + strcpy(sbuffer[pointeur],temp); + i=strlen(sbuffer[pointeur])-1; + while (sbuffer[pointeur][i]=='\r' || sbuffer[pointeur][i]=='\n') + sbuffer[pointeur][i--]='\0'; + pointeur++; + } + } +#ifdef DEBUGIT + fprintf(stderr,"\t\tFound %d entries\n",pointeur-1); +#endif +} + + /* Lockup an entry in a file Return all the lines between the entry and the next one or the end of file @@ -111,14 +197,14 @@ void lookup_entry(FILE *fichier,char *chaine) while (!feof(fichier) && found==0) { *temp='\0'; - fgets(temp,255,fichier); + myfgets(temp,255,fichier); if (strncmp(temp,temp2,strlen(temp2))==0) found=1; } while (!feof(fichier) && found==1) { *temp='\0'; - fgets(temp,255,fichier); + myfgets(temp,255,fichier); if (*temp=='[') { found=2; *buffer[pointeur]='\0'; @@ -136,8 +222,6 @@ void lookup_entry(FILE *fichier,char *chaine) #endif } - - char *find_desc(FILE *fichier,char *text) { char *chaine; @@ -151,10 +235,15 @@ char *find_desc(FILE *fichier,char *text) chaine=(char *)malloc(255*sizeof(char)); long_desc=(char *)malloc(40*sizeof(char)); short_desc=(char *)malloc(40*sizeof(char)); + if (!chaine || !long_desc || !short_desc) { + fprintf(stderr,"Unable to malloc memory\n"); + exit(1); + } + rewind(fichier); while (!feof(fichier) && found==0) { - fgets(chaine,255,fichier); + myfgets(chaine,255,fichier); long_desc=strtok(chaine,"="); crap=strtok(NULL,",\r"); @@ -185,6 +274,7 @@ char *find_desc(FILE *fichier,char *text) void scan_copyfiles(FILE *fichier, char *chaine) { char *part; + char *mpart; int i; char direc[255]; #ifdef DEBUGIT @@ -217,9 +307,38 @@ void scan_copyfiles(FILE *fichier, char *chaine) } i=0; while (*buffer[i]!='\0') { - part = &buffer[i][strlen(buffer[i])-1]; - if (*part == '=') - *part = '\0'; +/* + * HP inf files have strange entries that this attempts to address + * Entries in the Copy sections normally have only a single file name + * on each line. I have seen the following format in various HP inf files: + * + * pscript.hlp = pscript.hl_ + * hpdcmon.dll,hpdcmon.dl_ + * ctl3dv2.dll,ctl3dv2.dl_,ctl3dv2.tmp + * + * In the first 2 cases you want the first file name - in the last case + * you only want the last file name (at least that is what a Win95 + * machine sent). This may still be wrong but at least I get the same list + * of files as seen on a printer test page. + */ + part = strchr(buffer[i],'='); + if (part) { + *part = '\0'; + while (--part > buffer[i]) + if ((*part == ' ') || (*part =='\t')) *part = '\0'; + else break; + } else { + part = strchr(buffer[i],','); + if (part) { + if (mpart = strrchr(part+1,',')) { + strcpy(buffer[i],mpart+1); + } else + *part = '\0'; + while (--part > buffer[i]) + if ((*part == ' ') || (*part =='\t')) *part = '\0'; + else break; + } + } if (strlen(files_to_copy) != 0) strcat(files_to_copy,","); strcat(files_to_copy,direc); @@ -257,19 +376,19 @@ void scan_short_desc(FILE *fichier, char *short_desc) #ifdef DEBUGIT fprintf(stderr,"\tLookup up of %s\n",buffer[i]); #endif - if (strncmp(buffer[i],"CopyFiles",9)==0) + if (strncasecmp(buffer[i],"CopyFiles",9)==0) copyfiles=scan(buffer[i],&temp); - else if (strncmp(buffer[i],"DataSection",11)==0) + else if (strncasecmp(buffer[i],"DataSection",11)==0) datasection=scan(buffer[i],&temp); - else if (strncmp(buffer[i],"DataFile",8)==0) + else if (strncasecmp(buffer[i],"DataFile",8)==0) datafile=scan(buffer[i],&temp); - else if (strncmp(buffer[i],"DriverFile",10)==0) + else if (strncasecmp(buffer[i],"DriverFile",10)==0) driverfile=scan(buffer[i],&temp); - else if (strncmp(buffer[i],"HelpFile",8)==0) + else if (strncasecmp(buffer[i],"HelpFile",8)==0) helpfile=scan(buffer[i],&temp); - else if (strncmp(buffer[i],"LanguageMonitor",15)==0) + else if (strncasecmp(buffer[i],"LanguageMonitor",15)==0) languagemonitor=scan(buffer[i],&temp); - else if (strncmp(buffer[i],"DefaultDataType",15)==0) + else if (strncasecmp(buffer[i],"DefaultDataType",15)==0) datatype=scan(buffer[i],&temp); i++; } @@ -282,43 +401,29 @@ void scan_short_desc(FILE *fichier, char *short_desc) #ifdef DEBUGIT fprintf(stderr,"\tLookup up of %s\n",buffer[i]); #endif - if (strncmp(buffer[i],"CopyFiles",9)==0) + if (strncasecmp(buffer[i],"CopyFiles",9)==0) copyfiles=scan(buffer[i],&temp); - else if (strncmp(buffer[i],"DataSection",11)==0) + else if (strncasecmp(buffer[i],"DataSection",11)==0) datasection=scan(buffer[i],&temp); - else if (strncmp(buffer[i],"DataFile",8)==0) + else if (strncasecmp(buffer[i],"DataFile",8)==0) datafile=scan(buffer[i],&temp); - else if (strncmp(buffer[i],"DriverFile",10)==0) + else if (strncasecmp(buffer[i],"DriverFile",10)==0) driverfile=scan(buffer[i],&temp); - else if (strncmp(buffer[i],"HelpFile",8)==0) + else if (strncasecmp(buffer[i],"HelpFile",8)==0) helpfile=scan(buffer[i],&temp); - else if (strncmp(buffer[i],"LanguageMonitor",15)==0) + else if (strncasecmp(buffer[i],"LanguageMonitor",15)==0) languagemonitor=scan(buffer[i],&temp); - else if (strncmp(buffer[i],"DefaultDataType",15)==0) + else if (strncasecmp(buffer[i],"DefaultDataType",15)==0) datatype=scan(buffer[i],&temp); i++; } } - if (languagemonitor && (*languagemonitor == '%')) { - ++languagemonitor; - languagemonitor[strlen(languagemonitor)-1] = '\0'; - lookup_entry(fichier,"Strings"); - i = 0; - while(*buffer[i]!='\0') { -#ifdef DEBUGIT - fprintf(stderr,"\tLookup up of %s\n",buffer[i]); -#endif - if (strncmp(buffer[i],languagemonitor,strlen(languagemonitor))==0) - { - temp = strtok(buffer[i],"="); - temp = strtok(NULL,","); + if (languagemonitor) { + temp = strtok(languagemonitor,","); if (*temp == '"') ++temp; strcpy(languagemonitor,temp); - break; - } - i++; - } + if (temp = strchr(languagemonitor,'"')) *temp = '\0'; } if (i) fprintf(stderr,"End of section found\n"); @@ -350,6 +455,8 @@ int main(int argc, char *argv[]) return(-1); } + lookup_strings(inf_file); + short_desc=find_desc(inf_file,argv[2]); if (short_desc==NULL) { -- cgit From 46c795da5d8b7d46e0e2806b86c97a3e2b34be26 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 23 Jan 1998 08:35:15 +0000 Subject: Fixed warnings with gcc (assignments inside if statements). Jeremy. (This used to be commit 1a9e25d3bc610a1d49241e2fe39530813d983882) --- source3/utils/make_printerdef.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index 723c4fdf51..adf3b4c3e6 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -47,7 +47,7 @@ char *myfgets(char *s, int n, FILE *stream) int i; fgets(s,n,stream); - while (LString1 = strchr(s,'%')) { + while ((LString1 = strchr(s,'%')) != NULL) { if (!(LString2 = strchr(LString1+1,'%'))) break; *LString2 = '\0'; strcpy(String,LString1+1); @@ -56,7 +56,7 @@ char *myfgets(char *s, int n, FILE *stream) if (strncmp(sbuffer[i],String,strlen(String))==0) { strcpy(String,sbuffer[i]); - if (temp = strchr(String,'=')) ++temp; + if ((temp = strchr(String,'=')) != NULL) ++temp; strcpy(String,temp); break; } @@ -330,7 +330,7 @@ void scan_copyfiles(FILE *fichier, char *chaine) } else { part = strchr(buffer[i],','); if (part) { - if (mpart = strrchr(part+1,',')) { + if ((mpart = strrchr(part+1,','))!=NULL) { strcpy(buffer[i],mpart+1); } else *part = '\0'; @@ -423,7 +423,7 @@ void scan_short_desc(FILE *fichier, char *short_desc) temp = strtok(languagemonitor,","); if (*temp == '"') ++temp; strcpy(languagemonitor,temp); - if (temp = strchr(languagemonitor,'"')) *temp = '\0'; + if ((temp = strchr(languagemonitor,'"'))!=NULL) *temp = '\0'; } if (i) fprintf(stderr,"End of section found\n"); -- cgit From 834ef5624421dfdb4665012ea43aa37d092efe40 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 24 Feb 1998 17:59:34 +0000 Subject: nmbd_incomingdgrams.c: Fix for typo. nmbd_sendannounce.c: Remote announcement was announcing to the wrong name ! nmblookup.c: Fix for substitutions not seeing hostname. testparm.c: Fix for substitutions not seeing hostname. wsmbstatus.c: Fix for substitutions not seeing hostname. util.c: Change read_udp_socket to use sockaddr_in rather than dubiously messing around with an opaque data type (sockaddr). Jeremy. (This used to be commit 776ccf5c0641b5aa300236c2612b5f2761d1179f) --- source3/utils/nmblookup.c | 3 ++- source3/utils/testparm.c | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 5cd5a869a9..a73a35cd56 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -170,12 +170,13 @@ int main(int argc,char *argv[]) exit(1); } + init_structs(); + if (!lp_load(servicesf,True)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); } load_interfaces(); - init_structs(); if (!open_sockets()) return(1); if (!got_bcast) diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index cc35d2d530..a35a3fd71e 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -38,6 +38,7 @@ /* these live in util.c */ extern FILE *dbf; extern int DEBUGLEVEL; +extern pstring myhostname; int main(int argc, char *argv[]) { @@ -60,6 +61,12 @@ extern int DEBUGLEVEL; printf("Load smb config files from %s\n",configfile); + if(!get_myname(myhostname,NULL)) + { + printf("Failed to get my hostname.\n"); + return(1); + } + if (!lp_load(configfile,False)) { printf("Error loading services.\n"); -- cgit From 4c6230afd2f144322c07c7e4c46147d3e5d2ddde Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 11 Mar 1998 17:44:27 +0000 Subject: fix core dumps on Solaris 2.5 systems found by Orn Asgeirsson (This used to be commit bafc7768925109d0e8e87152054d37ec3f4e7fdd) --- source3/utils/make_printerdef.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index adf3b4c3e6..514773eb48 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -428,12 +428,18 @@ void scan_short_desc(FILE *fichier, char *short_desc) if (i) fprintf(stderr,"End of section found\n"); - fprintf(stderr,"CopyFiles: %s\n",copyfiles); - fprintf(stderr,"Datasection: %s\n",datasection); - fprintf(stderr,"Datafile: %s\n",datafile); - fprintf(stderr,"Driverfile: %s\n",driverfile); - fprintf(stderr,"Helpfile: %s\n",helpfile); - fprintf(stderr,"LanguageMonitor: %s\n",languagemonitor); + fprintf(stderr,"CopyFiles: %s\n", + copyfiles?copyfiles:"(null)"); + fprintf(stderr,"Datasection: %s\n", + datasection?datasection:"(null)"); + fprintf(stderr,"Datafile: %s\n", + datafile?datafile:"(null)"); + fprintf(stderr,"Driverfile: %s\n", + driverfile?driverfile:"(null)"); + fprintf(stderr,"Helpfile: %s\n", + helpfile?helpfile:"(null)"); + fprintf(stderr,"LanguageMonitor: %s\n", + languagemonitor?languagemonitor:"(null)"); if (copyfiles) scan_copyfiles(fichier,copyfiles); } -- cgit From fdeea341ed1bae670382e45eb731db1b5838ad21 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Mar 1998 21:11:04 +0000 Subject: "For I have laboured mightily on Luke's code, and hath broken all I saw" - the book of Jeremy, chapter 1 :-). So here is the mega-merge of the NTDOM branch server code. It doesn't include the new client side pieces, we'll look at that later. This should give the same functionality, server wise, as the NTDOM branch does, only merged into the main branch. Any fixes to domain controler functionality should be added to the main branch, not the NTDOM branch. This code compiles without warnings on gcc2.8, but will need further testing before we are sure all the working functionality of the NTDOM server branch has been correctly carried over. I hereby declare the server side of the NTDOM branch dead (and all who sail in her :-). Jeremy. (This used to be commit 118ba4d77a33248e762a2cf843fb7cbc906ee6e7) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 598944baa5..7ab8d8a0db 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -400,7 +400,7 @@ static void usage(char *name) chmod(pfile, 0600); /* Lock the smbpasswd file for write. */ - if ((lockfd = pw_file_lock(pfile, F_WRLCK, 5)) < 0) { + if ((lockfd = pw_file_lock(fileno(fp), F_WRLCK, 5)) < 0) { err = errno; fprintf(stderr, "%s: Failed to lock password file %s.\n", argv[0], pfile); -- cgit From b85346942e7d785af718b68d61b208cb457a2b27 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Mar 1998 08:27:41 +0000 Subject: another makeover of loadparm to support new stuff in swat and testparm. In particular I added: - ability to optionally save default values of all parameters when calling lp_load(). This can then be used to save only non-default parameters in lp_dump(). This makes the saved smb.conf (and viewed parameters in testparm) much shorter - ability to not load ipc share in lp_load() - separators in parm_table[] so parameters can be grouped logically. - flag to mark parameters that are local but which should be also viewed as global as far as parameters editing is concerned (This used to be commit f9af35da26e58fb0b644b5f0169f1c212230047a) --- source3/utils/nmblookup.c | 2 +- source3/utils/status.c | 2 +- source3/utils/testparm.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index a73a35cd56..4c9132ee75 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -172,7 +172,7 @@ int main(int argc,char *argv[]) init_structs(); - if (!lp_load(servicesf,True)) { + if (!lp_load(servicesf,True,False,False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); } diff --git a/source3/utils/status.c b/source3/utils/status.c index 401dd25c89..7c89ad6d63 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -152,7 +152,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) get_myname(myhostname, NULL); - if (!lp_load(servicesf,False)) { + if (!lp_load(servicesf,False,False,False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); return (-1); } diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index a35a3fd71e..0cc76066bb 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -67,7 +67,7 @@ extern pstring myhostname; return(1); } - if (!lp_load(configfile,False)) + if (!lp_load(configfile,False,True,False)) { printf("Error loading services.\n"); return(1); -- cgit From d360320618fe3a7f53ac1f05ee3ac54323a03c82 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 15 Mar 1998 02:37:52 +0000 Subject: - added the ability to kill off individual connections from SWAT (from the status page) - split the claim_connection() code into its own file - fixed the claim_connection() code to lock the file when manipulating it - always claim a null connection at startup - fixed a bug in the pidfile code (This used to be commit abd4a17e21d12be3d1747e94ceb1915abaf135e3) --- source3/utils/status.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 7c89ad6d63..f99fe9e561 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -199,6 +199,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) { if (fread(&crec,sizeof(crec),1,f) != 1) break; + if (crec.cnum == -1) continue; if ( crec.magic == 0x280267 && process_exists(crec.pid) && Ucrit_checkUsername(uidtoname(crec.uid)) /* added by OH */ ) -- cgit From 59d7006b05bb301e36f786b047b90ab9ef5be122 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 17 Mar 1998 11:44:16 +0000 Subject: - added "Full View"/"Normal View" on the "view config" page - added the ability to auto-refresh the status page. There is a problem with this (it can kill inetd!). Hopefully we can fix that. (This used to be commit 4488d8932fa072bf8a3ae236ab666618051b5e83) --- source3/utils/testparm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 0cc76066bb..83d4d7fbb5 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -89,7 +89,7 @@ extern pstring myhostname; printf("Press enter to see a dump of your service definitions\n"); fflush(stdout); getc(stdin); - lp_dump(stdout); + lp_dump(stdout,False); } if (argc == 4) -- cgit From 7abbf368f908cacdb2978e33069e49755e54faa8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 19 Mar 1998 20:06:47 +0000 Subject: Adding the same changes to HEAD as were added to BRANCH_1_9_18. Changed smbpasswd to be client-server for a normal user, rather than accessing the private/smbpasswd file directly (it still accesses this file directly when run as root, so root can add users/change a users password without knowing the old password). A shakeout of this change is that smbpasswd can now be used to change a users password on a remote NT machine (yep - you heard that one right - we can now change a NT password from UNIX !!!!!). Jeremy. (This used to be commit 20770b6f1c25288e90d3e0d215afa7f0809ce124) --- source3/utils/smbpasswd.c | 379 ++++++++++++++++++++++++++++++---------------- 1 file changed, 247 insertions(+), 132 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 7ab8d8a0db..5b5f86c5e1 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -19,11 +19,23 @@ #include "includes.h" -/* Static buffers we will return. */ -static struct smb_passwd pw_buf; -static pstring user_name; -static unsigned char smbpwd[16]; -static unsigned char smbntpwd[16]; +/* + * Password changing error codes. + */ + +struct +{ + int err; + char *message; +} pw_change_errmap[] = +{ + {5, "User has insufficient privilege" }, + {86, "The specified password is invalid" }, + {2226, "Operation only permitted on a Primary Domain Controller" }, + {2243, "The password cannot be changed" }, + {2246, "The password is too short" }, + {0, NULL} +}; static int gethexpwd(char *p, char *pwd) { @@ -52,6 +64,12 @@ static struct smb_passwd * _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, BOOL *got_valid_nt_entry, long *pwd_seekpos) { + /* Static buffers we will return. */ + static struct smb_passwd pw_buf; + static pstring user_name; + static unsigned char smbpwd[16]; + static unsigned char smbntpwd[16]; + char linebuf[256]; unsigned char c; unsigned char *p; @@ -198,14 +216,21 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, /* * Print command usage on stderr and die. */ -static void usage(char *name) +static void usage(char *name, BOOL is_root) { - fprintf(stderr, "Usage is : %s [-add] [username] [password]\n", name); + if(is_root) + fprintf(stderr, "Usage is : %s [-a] [username] [password]\n\ +%s: [-r machine] [username] [password]\n%s: [-h]", name, name, name); + else + fprintf(stderr, "Usage is : %s [-h] [-r machine] [password]\n", name); exit(1); } - int main(int argc, char **argv) +int main(int argc, char **argv) { + extern char *optarg; + extern int optind; + char *prog_name; int real_uid; struct passwd *pwd; fstring old_passwd; @@ -218,9 +243,7 @@ static void usage(char *name) struct smb_passwd *smb_pwent; FILE *fp; BOOL valid_old_pwd = False; - BOOL got_valid_nt_entry = False; - BOOL add_user = False; - int add_pass = 0; + BOOL got_valid_nt_entry = False; long seekpos; int pwfd; char ascii_p16[66]; @@ -229,103 +252,141 @@ static void usage(char *name) int lockfd = -1; char *pfile = SMB_PASSWD_FILE; char readbuf[16 * 1024]; - + BOOL is_root = False; + pstring user_name; + char *remote_machine = NULL; + BOOL add_user = False; + BOOL got_new_pass = False; + pstring servicesf = CONFIGFILE; + + new_passwd[0] = '\0'; + user_name[0] = '\0'; + + memset(old_passwd, '\0', sizeof(old_passwd)); + memset(new_passwd, '\0', sizeof(old_passwd)); + + prog_name = argv[0]; + TimeInit(); - setup_logging(argv[0],True); + setup_logging(prog_name,True); charset_initialise(); - -#ifndef DEBUG_PASSWORD - /* Check the effective uid */ - if (geteuid() != 0) { - fprintf(stderr, "%s: Must be setuid root.\n", argv[0]); - exit(1); + + if (!lp_load(servicesf,True,False,False)) { + fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n", prog_name, servicesf); } -#endif - + + codepage_initialise(lp_client_code_page()); + /* Get the real uid */ real_uid = getuid(); - /* Deal with usage problems */ - if (real_uid == 0) - { - /* As root we can change anothers password and add a user. */ - if (argc > 4 ) - usage(argv[0]); - } - else if (argc == 2 || argc > 3) - { - fprintf(stderr, "%s: Only root can set anothers password.\n", argv[0]); - usage(argv[0]); + /* Check the effective uid */ + if ((geteuid() == 0) && (real_uid != 0)) { + fprintf(stderr, "%s: Must *NOT* be setuid root.\n", prog_name); + exit(1); } - - if (real_uid == 0 && (argc > 1)) - { - /* We are root - check if we should add the user */ - if ((argv[1][0] == '-') && (argv[1][1] == 'a')) + + is_root = (real_uid == 0); + + while ((c = getopt(argc, argv, "ahr:")) != EOF) { + switch(c) { + case 'a': add_user = True; + break; + case 'r': + remote_machine = optarg; + break; + case 'h': + default: + usage(prog_name, is_root); + } + } - if(add_user && (argc <= 2 || argc > 4)) - usage(argv[0]); + argc -= optind; + argv += optind; - /* root can specify password on command-line */ - if (argc == (add_user ? 4 : 3)) - { - /* -a argument (add_user): new password is 3rd argument. */ - /* no -a argument (add_user): new password is 2nd argument */ + /* + * Ensure add_user and remote machine are + * not both set. + */ + if(add_user && (remote_machine != NULL)) + usage(prog_name, True); + + if( is_root ) { + + /* + * Deal with root - can add a user, but only locally. + */ + + switch(argc) { + case 0: + break; + case 1: + /* If we are root we can change another's password. */ + pstrcpy(user_name, argv[0]); + break; + case 2: + pstrcpy(user_name, argv[0]); + fstrcpy(new_passwd, argv[1]); + got_new_pass = True; + break; + default: + usage(prog_name, True); + } - add_pass = add_user ? 3 : 2; + if(*user_name) + pwd = getpwnam(user_name); + else { + if((pwd = getpwuid(real_uid)) != NULL) + pstrcpy( user_name, pwd->pw_name); } - /* If we are root we can change another's password. */ - strncpy(user_name, add_user ? argv[2] : argv[1], sizeof(user_name) - 1); - user_name[sizeof(user_name) - 1] = '\0'; + } else { - pwd = getpwnam(user_name); - } - else - { - /* non-root can specify old pass / new pass on command-line */ - if (argc == 3) - { - /* non-root specifies new password as 2nd argument */ - add_pass = 2; + if(add_user) { + fprintf(stderr, "%s: Only root can set anothers password.\n", prog_name); + usage(prog_name, False); } - pwd = getpwuid(real_uid); - } - - if (pwd == 0) { - fprintf(stderr, "%s: Unable to get UNIX password entry for user.\n", argv[0]); - exit(1); - } + if(argc > 1) + usage(prog_name, False); - /* If we are root we don't ask for the old password. */ - old_passwd[0] = '\0'; - if (real_uid != 0) - { - if (add_pass) - { - /* old password, as non-root, is 1st argument */ - strncpy(old_passwd, argv[1], sizeof(fstring)); + if(argc == 1) { + fstrcpy(new_passwd, argv[0]); + got_new_pass = True; } - else - { - p = getpass("Old SMB password:"); - strncpy(old_passwd, p, sizeof(fstring)); - } - old_passwd[sizeof(fstring)-1] = '\0'; + + if((pwd = getpwuid(real_uid)) != NULL) + pstrcpy( user_name, pwd->pw_name); + + /* + * A non-root user is always setting a password + * via a remote machine (even if that machine is + * localhost). + */ + + if(remote_machine == NULL) + remote_machine = "127.0.0.1"; + } + + if (*user_name == '\0') { + fprintf(stderr, "%s: Unable to get a user name for password change.\n", prog_name); + exit(1); } - if (add_pass) - { - /* new password is specified on the command line */ - strncpy(new_passwd, argv[add_user ? 3 : 2], sizeof(new_passwd) - 1); - new_passwd[sizeof(new_passwd) - 1] = '\0'; + /* + * If we are root we don't ask for the old password (unless it's on a + * remote machine. + */ + + if (remote_machine != NULL) { + p = getpass("Old SMB password:"); + fstrcpy(old_passwd, p); } - else - { + + if (!got_new_pass) { new_passwd[0] = '\0'; p = getpass("New SMB password:"); @@ -337,17 +398,96 @@ static void usage(char *name) if (strncmp(p, new_passwd, sizeof(fstring)-1)) { - fprintf(stderr, "%s: Mismatch - password unchanged.\n", argv[0]); + fprintf(stderr, "%s: Mismatch - password unchanged.\n", prog_name); exit(1); } } - if (new_passwd[0] == '\0') - { + if (new_passwd[0] == '\0') { printf("Password not set\n"); exit(0); } + + /* + * Now do things differently depending on if we're changing the + * password on a remote machine. Remember - a normal user is + * always using this code, looping back to the local smbd. + */ + + if(remote_machine != NULL) { + struct cli_state cli; + struct in_addr ip; + fstring myname; + + if(get_myname(myname,NULL) == False) { + fprintf(stderr, "%s: unable to get my hostname.\n", prog_name ); + exit(1); + } + + if(!resolve_name( remote_machine, &ip)) { + fprintf(stderr, "%s: unable to find an IP address for machine %s.\n", + prog_name, remote_machine ); + exit(1); + } + + if (!cli_initialise(&cli) || !cli_connect(&cli, remote_machine, &ip)) { + fprintf(stderr, "%s: unable to connect to SMB server on machine %s.\n", + prog_name, remote_machine ); + exit(1); + } + + if (!cli_session_request(&cli, remote_machine, 0x20, myname)) { + fprintf(stderr, "%s: machine %s rejected the session setup.\n", + prog_name, remote_machine ); + cli_shutdown(&cli); + exit(1); + } + + cli.protocol = PROTOCOL_NT1; + + if (!cli_negprot(&cli)) { + fprintf(stderr, "%s: machine %s rejected the negotiate protocol.\n", + prog_name, remote_machine ); + cli_shutdown(&cli); + exit(1); + } + if (!cli_session_setup(&cli, user_name, old_passwd, strlen(old_passwd), + "", 0, "")) { + fprintf(stderr, "%s: machine %s rejected the session setup.\n", + prog_name, remote_machine ); + cli_shutdown(&cli); + exit(1); + } + + if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) { + fprintf(stderr, "%s: machine %s rejected the tconX on the IPC$ share.\n", + prog_name, remote_machine ); + cli_shutdown(&cli); + exit(1); + } + + if(!cli_oem_change_password(&cli, user_name, new_passwd, old_passwd)) { + fstring error_message; + + sprintf(error_message, " with code %d", cli.error); + + for(i = 0; pw_change_errmap[i].message != NULL; i++) { + if (pw_change_errmap[i].err == cli.error) { + fstrcpy( error_message, pw_change_errmap[i].message); + break; + } + } + fprintf(stderr, "%s: machine %s rejected the password change: %s.\n", + prog_name, remote_machine, error_message ); + cli_shutdown(&cli); + exit(1); + } + + cli_shutdown(&cli); + exit(0); + } + /* Calculate the MD4 hash (NT compatible) of the old and new passwords */ memset(old_nt_p16, '\0', 16); E_md4hash((uchar *)old_passwd, old_nt_p16); @@ -387,9 +527,9 @@ static void usage(char *name) if (!fp) { err = errno; fprintf(stderr, "%s: Failed to open password file %s.\n", - argv[0], pfile); + prog_name, pfile); errno = err; - perror(argv[0]); + perror(prog_name); exit(err); } @@ -403,19 +543,19 @@ static void usage(char *name) if ((lockfd = pw_file_lock(fileno(fp), F_WRLCK, 5)) < 0) { err = errno; fprintf(stderr, "%s: Failed to lock password file %s.\n", - argv[0], pfile); + prog_name, pfile); fclose(fp); errno = err; - perror(argv[0]); + perror(prog_name); exit(err); } /* Get the smb passwd entry for this user */ - smb_pwent = _my_get_smbpwnam(fp, pwd->pw_name, &valid_old_pwd, + smb_pwent = _my_get_smbpwnam(fp, user_name, &valid_old_pwd, &got_valid_nt_entry, &seekpos); if (smb_pwent == NULL) { if(add_user == False) { fprintf(stderr, "%s: Failed to find entry for user %s in file %s.\n", - argv[0], pwd->pw_name, pfile); + prog_name, pwd->pw_name, pfile); fclose(fp); pw_file_unlock(lockfd); exit(1); @@ -435,7 +575,7 @@ static void usage(char *name) if((offpos = lseek(fd, 0, SEEK_END)) == -1) { fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ -Error was %s\n", argv[0], pwd->pw_name, pfile, strerror(errno)); +Error was %s\n", prog_name, pwd->pw_name, pfile, strerror(errno)); fclose(fp); pw_file_unlock(lockfd); exit(1); @@ -447,7 +587,7 @@ Error was %s\n", argv[0], pwd->pw_name, pfile, strerror(errno)); strlen(pwd->pw_shell) + 1; if((new_entry = (char *)malloc( new_entry_length )) == 0) { fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ -Error was %s\n", argv[0], pwd->pw_name, pfile, strerror(errno)); +Error was %s\n", prog_name, pwd->pw_name, pfile, strerror(errno)); fclose(fp); pw_file_unlock(lockfd); exit(1); @@ -467,12 +607,12 @@ Error was %s\n", argv[0], pwd->pw_name, pfile, strerror(errno)); pwd->pw_dir, pwd->pw_shell); if(write(fd, new_entry, strlen(new_entry)) != strlen(new_entry)) { fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ -Error was %s\n", argv[0], pwd->pw_name, pfile, strerror(errno)); +Error was %s\n", prog_name, pwd->pw_name, pfile, strerror(errno)); /* Remove the entry we just wrote. */ if(ftruncate(fd, offpos) == -1) { fprintf(stderr, "%s: ERROR failed to ftruncate file %s. \ Error was %s. Password file may be corrupt ! Please examine by hand !\n", - argv[0], pwd->pw_name, strerror(errno)); + prog_name, pwd->pw_name, strerror(errno)); } fclose(fp); pw_file_unlock(lockfd); @@ -488,35 +628,10 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n", add_user = False; } - /* If we are root or the password is 'NO PASSWORD' then - we don't need to check the old password. */ - if (real_uid != 0) { - if (valid_old_pwd == False) { - fprintf(stderr, "%s: User %s has no old SMB password.\n", argv[0], pwd->pw_name); - } - /* Check the old Lanman password - NULL means 'NO PASSWORD' */ - if (smb_pwent->smb_passwd != NULL) { - if (memcmp(old_p16, smb_pwent->smb_passwd, 16)) { - fprintf(stderr, "%s: Couldn't change password.\n", argv[0]); - fclose(fp); - pw_file_unlock(lockfd); - exit(1); - } - } - /* Check the NT password if it exists */ - if (smb_pwent->smb_nt_passwd != NULL) { - if (memcmp(old_nt_p16, smb_pwent->smb_nt_passwd, 16)) { - fprintf(stderr, "%s: Couldn't change password.\n", argv[0]); - fclose(fp); - pw_file_unlock(lockfd); - exit(1); - } - } - } /* - * If we get here either we were root or the old password checked out - * ok. + * We are root - just write the new password. */ + /* Create the 32 byte representation of the new p16 */ for (i = 0; i < 16; i++) { sprintf(&ascii_p16[i * 2], "%02X", (uchar) new_p16[i]); @@ -537,10 +652,10 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n", if (ret != seekpos - 1) { err = errno; fprintf(stderr, "%s: seek fail on file %s.\n", - argv[0], pfile); + prog_name, pfile); fclose(fp); errno = err; - perror(argv[0]); + perror(prog_name); pw_file_unlock(lockfd); exit(1); } @@ -548,16 +663,16 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n", if (read(pwfd, &c, 1) != 1) { err = errno; fprintf(stderr, "%s: read fail on file %s.\n", - argv[0], pfile); + prog_name, pfile); fclose(fp); errno = err; - perror(argv[0]); + perror(prog_name); pw_file_unlock(lockfd); exit(1); } if (c != ':') { fprintf(stderr, "%s: sanity check on passwd file %s failed.\n", - argv[0], pfile); + prog_name, pfile); fclose(fp); pw_file_unlock(lockfd); exit(1); @@ -566,10 +681,10 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n", if (write(pwfd, ascii_p16, writelen) != writelen) { err = errno; fprintf(stderr, "%s: write fail in file %s.\n", - argv[0], pfile); + prog_name, pfile); fclose(fp); errno = err; - perror(argv[0]); + perror(prog_name); pw_file_unlock(lockfd); exit(err); } -- cgit From 93b3c5813638d37f53717ec42feff408b8765e23 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 22 Mar 1998 01:31:50 +0000 Subject: - added a check for broken RH5 include files. With the standard RH5 includes (ie. unpatched RH5) Samba gets file corruption because of the incorrect definition of the shmid_ds structure. Updating your RH5 installation of glibc-devel fixes this. - don't try to fcntl_lock() a read-only fd in shmem.c - allow level 0 debug messages to get through in smbstatus (This used to be commit 45553771f90087a12db0153524146d42155d1d3f) --- source3/utils/status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index f99fe9e561..40bafbe0c2 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -120,7 +120,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) charset_initialise(); DEBUGLEVEL = 0; - dbf = fopen("/dev/null","w"); + dbf = stderr; if (getuid() != geteuid()) { printf("smbstatus should not be run setuid\n"); -- cgit From 5d7c8375e4ffb017ef0f9eed7e619e533b3e8d12 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 24 Mar 1998 00:37:53 +0000 Subject: clientgen.c ipc.c smbpasswd.c: Fixes for warnings (from Herb). quotas.c: Linux quota fix. util.c: Ensure smb_read_error is zero in all calls that can set it. lib/rpc/include/rpc_misc.h lib/rpc/include/rpc_netlogon.h lib/rpc/parse/parse_misc.c lib/rpc/parse/parse_net.c lib/rpc/server/srv_netlog.c : Modify Luke's code to call SamOEMhash(). Jeremy. (This used to be commit 7f749708383b8b36c3f23a5fbc5cbdf39bc8e555) --- source3/utils/smbpasswd.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 5b5f86c5e1..9a244a28b5 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -248,6 +248,7 @@ int main(int argc, char **argv) int pwfd; char ascii_p16[66]; char c; + int ch; int ret, i, err, writelen; int lockfd = -1; char *pfile = SMB_PASSWD_FILE; @@ -257,6 +258,7 @@ int main(int argc, char **argv) char *remote_machine = NULL; BOOL add_user = False; BOOL got_new_pass = False; + BOOL machine_account = False; pstring servicesf = CONFIGFILE; new_passwd[0] = '\0'; @@ -290,14 +292,17 @@ int main(int argc, char **argv) is_root = (real_uid == 0); - while ((c = getopt(argc, argv, "ahr:")) != EOF) { - switch(c) { + while ((ch = getopt(argc, argv, "ahr:m:")) != EOF) { + switch(ch) { case 'a': add_user = True; break; case 'r': remote_machine = optarg; break; + case 'm': + machine_account = True; + break; case 'h': default: usage(prog_name, is_root); @@ -314,6 +319,14 @@ int main(int argc, char **argv) if(add_user && (remote_machine != NULL)) usage(prog_name, True); + /* + * If we are adding a machine account then pretend + * we already have the new password, we will be using + * the machinename as the password. + */ + if(add_user && machine_account) + got_new_pass = True; + if( is_root ) { /* @@ -488,6 +501,24 @@ int main(int argc, char **argv) exit(0); } + /* + * Check for a machine account flag - make sure the username ends in + * a '$' etc.... + */ + + if(machine_account) { + int username_len = strlen(user_name); + if(username_len >= sizeof(pstring) - 1) { + fprintf(stderr, "%s: machine account name too long.\n", user_name); + exit(1); + } + + if(user_name[username_len] != '$') { + user_name[username_len] = '$'; + user_name[username_len+1] = '\0'; + } + } + /* Calculate the MD4 hash (NT compatible) of the old and new passwords */ memset(old_nt_p16, '\0', 16); E_md4hash((uchar *)old_passwd, old_nt_p16); @@ -575,13 +606,13 @@ int main(int argc, char **argv) if((offpos = lseek(fd, 0, SEEK_END)) == -1) { fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ -Error was %s\n", prog_name, pwd->pw_name, pfile, strerror(errno)); +Error was %s\n", prog_name, user_name, pfile, strerror(errno)); fclose(fp); pw_file_unlock(lockfd); exit(1); } - new_entry_length = strlen(pwd->pw_name) + 1 + 15 + 1 + + new_entry_length = strlen(user_name) + 1 + 15 + 1 + 32 + 1 + 32 + 1 + strlen(pwd->pw_gecos) + 1 + strlen(pwd->pw_dir) + 1 + strlen(pwd->pw_shell) + 1; -- cgit From 242e7ae4d66dffe73e427871d9626c7f49231d2d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 24 Mar 1998 21:04:36 +0000 Subject: Updated smbpasswd to allow root to add machine accounts, and allow root to disable users and set them to "NO PASSWORD". Not quite finished with machine account stuff yet, but everything compiles. Jeremy. (This used to be commit c66966ff00b0968f765e62b679279b7417988df9) --- source3/utils/smbpasswd.c | 279 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 229 insertions(+), 50 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 9a244a28b5..e3237a0b3c 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -37,6 +37,10 @@ struct {0, NULL} }; +/****************************************************** + Convert a hex password. +*******************************************************/ + static int gethexpwd(char *p, char *pwd) { int i; @@ -60,6 +64,10 @@ static int gethexpwd(char *p, char *pwd) return (True); } +/****************************************************** + Find a password entry by name. +*******************************************************/ + static struct smb_passwd * _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, BOOL *got_valid_nt_entry, long *pwd_seekpos) @@ -76,6 +84,8 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, long uidval; long linebuf_len; + pw_buf.acct_ctrl = ACB_NORMAL; + /* * Scan the file, a line at a time and check if the name matches. */ @@ -159,6 +169,8 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, *got_valid_nt_entry = False; pw_buf.smb_nt_passwd = NULL; /* No NT password (yet)*/ + pw_buf.acct_ctrl |= ACB_DISABLED; + /* Now check if the NT compatible password is available. */ p += 33; /* Move to the first character of the line after @@ -184,6 +196,7 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, if (!strncasecmp((char *)p, "NO PASSWORD", 11)) { pw_buf.smb_passwd = NULL; /* No password */ + pw_buf.acct_ctrl |= ACB_PWNOTREQ; } else { if(!gethexpwd((char *)p,(char *)smbpwd)) return False; @@ -207,25 +220,126 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, if (gethexpwd((char *)p,(char *)smbntpwd)) pw_buf.smb_nt_passwd = smbntpwd; } + + p += 33; /* Move to the first character of the line after + the NT password. */ } + + /* + * Check if the account type bits have been encoded after the + * NT password (in the form [NDHTUWSLXI]). + */ + + if (*p == '[') { + BOOL finished = False; + + pw_buf.acct_ctrl = 0; + + for(p++;*p && !finished; p++) { + switch (*p) { + case 'N': + /* 'N'o password. */ + pw_buf.acct_ctrl |= ACB_PWNOTREQ; + break; + case 'D': + /* 'D'isabled. */ + pw_buf.acct_ctrl |= ACB_DISABLED; + break; + case 'H': + /* 'H'omedir required. */ + pw_buf.acct_ctrl |= ACB_HOMDIRREQ; + break; + case 'T': + /* 'T'emp account. */ + pw_buf.acct_ctrl |= ACB_TEMPDUP; + break; + case 'U': + /* 'U'ser account (normal). */ + pw_buf.acct_ctrl |= ACB_NORMAL; + break; + case 'M': + /* 'M'NS logon user account. What is this ? */ + pw_buf.acct_ctrl |= ACB_MNS; + break; + case 'W': + /* 'W'orkstation account. */ + pw_buf.acct_ctrl |= ACB_WSTRUST; + break; + case 'S': + /* 'S'erver account. */ + pw_buf.acct_ctrl |= ACB_SVRTRUST; + break; + case 'L': + /* 'L'ocked account. */ + pw_buf.acct_ctrl |= ACB_AUTOLOCK; + break; + case 'X': + /* No 'X'piry. */ + pw_buf.acct_ctrl |= ACB_PWNOEXP; + break; + case 'I': + /* 'I'nterdomain trust account. */ + pw_buf.acct_ctrl |= ACB_DOMTRUST; + break; + + case ':': + case '\n': + case '\0': + case ']': + default: + finished = True; + } + } + + /* Must have some account type set. */ + if(pw_buf.acct_ctrl == 0) + pw_buf.acct_ctrl = ACB_NORMAL; + + } else { + /* 'Old' style file. Fake up based on user name. */ + /* + * Currently machine accounts are kept in the same + * password file as 'normal accounts'. If this changes + * we will have to fix this code. JRA. + */ + if(pw_buf.smb_name[strlen(pw_buf.smb_name) - 1] == '$') { + pw_buf.acct_ctrl &= ~ACB_NORMAL; + pw_buf.acct_ctrl |= ACB_WSTRUST; + } + } return &pw_buf; } return NULL; } -/* - * Print command usage on stderr and die. - */ +/********************************************************** + Allocate an unused uid in the smbpasswd file to a new + machine account. +***********************************************************/ + +int get_machine_uid(void) +{ + return 65534; +} + +/********************************************************* + Print command usage on stderr and die. +**********************************************************/ + static void usage(char *name, BOOL is_root) { if(is_root) - fprintf(stderr, "Usage is : %s [-a] [username] [password]\n\ -%s: [-r machine] [username] [password]\n%s: [-h]", name, name, name); + fprintf(stderr, "Usage is : %s [-a] [-d] [-m] [-n] [username] [password]\n\ +%s: [-r machine] [username] [password]\n%s: [-h]\n", name, name, name); else fprintf(stderr, "Usage is : %s [-h] [-r machine] [password]\n", name); exit(1); } +/********************************************************* + Start here. +**********************************************************/ + int main(int argc, char **argv) { extern char *optarg; @@ -233,9 +347,8 @@ int main(int argc, char **argv) char *prog_name; int real_uid; struct passwd *pwd; + struct passwd machine_account_pwd; fstring old_passwd; - uchar old_p16[16]; - uchar old_nt_p16[16]; fstring new_passwd; uchar new_p16[16]; uchar new_nt_p16[16]; @@ -255,17 +368,20 @@ int main(int argc, char **argv) char readbuf[16 * 1024]; BOOL is_root = False; pstring user_name; + pstring machine_gcos_name; char *remote_machine = NULL; BOOL add_user = False; BOOL got_new_pass = False; BOOL machine_account = False; + BOOL disable_user = False; + BOOL set_no_password = False; pstring servicesf = CONFIGFILE; new_passwd[0] = '\0'; user_name[0] = '\0'; memset(old_passwd, '\0', sizeof(old_passwd)); - memset(new_passwd, '\0', sizeof(old_passwd)); + memset(new_passwd, '\0', sizeof(new_passwd)); prog_name = argv[0]; @@ -292,16 +408,37 @@ int main(int argc, char **argv) is_root = (real_uid == 0); - while ((ch = getopt(argc, argv, "ahr:m:")) != EOF) { + while ((ch = getopt(argc, argv, "adhmnr:")) != EOF) { switch(ch) { case 'a': - add_user = True; + if(is_root) + add_user = True; + else + usage(prog_name, is_root); + break; + case 'd': + if(is_root) { + disable_user = True; + got_new_pass = True; + strcpy(new_passwd, "XXXXXX"); + } else + usage(prog_name, is_root); break; + case 'n': + if(is_root) { + set_no_password = True; + got_new_pass = True; + strcpy(new_passwd, "NO PASSWORD"); + } else + usage(prog_name, is_root); case 'r': remote_machine = optarg; break; case 'm': - machine_account = True; + if(is_root) + machine_account = True; + else + usage(prog_name, is_root); break; case 'h': default: @@ -319,14 +456,6 @@ int main(int argc, char **argv) if(add_user && (remote_machine != NULL)) usage(prog_name, True); - /* - * If we are adding a machine account then pretend - * we already have the new password, we will be using - * the machinename as the password. - */ - if(add_user && machine_account) - got_new_pass = True; - if( is_root ) { /* @@ -389,6 +518,19 @@ int main(int argc, char **argv) exit(1); } + /* + * If we are adding a machine account then pretend + * we already have the new password, we will be using + * the machinename as the password. + */ + + if(add_user && machine_account) { + got_new_pass = True; + strncpy(new_passwd, user_name, sizeof(fstring)); + new_passwd[sizeof(fstring)-1] = '\0'; + strlower(new_passwd); + } + /* * If we are root we don't ask for the old password (unless it's on a * remote machine. @@ -516,29 +658,37 @@ int main(int argc, char **argv) if(user_name[username_len] != '$') { user_name[username_len] = '$'; user_name[username_len+1] = '\0'; - } + } + + /* + * Setup the pwd struct to point to known + * values for a machine account (it doesn't + * exist in /etc/passwd). + */ + + pwd = &machine_account_pwd; + pwd->pw_name = user_name; + sprintf(machine_gcos_name, "Machine account for %s", user_name); + pwd->pw_gecos = machine_gcos_name; + pwd->pw_dir = ""; + pwd->pw_shell = ""; + pwd->pw_uid = get_machine_uid(); + } - /* Calculate the MD4 hash (NT compatible) of the old and new passwords */ - memset(old_nt_p16, '\0', 16); - E_md4hash((uchar *)old_passwd, old_nt_p16); + /* Calculate the MD4 hash (NT compatible) of the new password. */ memset(new_nt_p16, '\0', 16); E_md4hash((uchar *) new_passwd, new_nt_p16); - /* Mangle the passwords into Lanman format */ - old_passwd[14] = '\0'; - strupper(old_passwd); + /* Mangle the password into Lanman format */ new_passwd[14] = '\0'; strupper(new_passwd); /* - * Calculate the SMB (lanman) hash functions of both old and new passwords. + * Calculate the SMB (lanman) hash functions of the new password. */ - memset(old_p16, '\0', 16); - E_P16((uchar *) old_passwd, old_p16); - memset(new_p16, '\0', 16); E_P16((uchar *) new_passwd, new_p16); @@ -580,6 +730,7 @@ int main(int argc, char **argv) perror(prog_name); exit(err); } + /* Get the smb passwd entry for this user */ smb_pwent = _my_get_smbpwnam(fp, user_name, &valid_old_pwd, &got_valid_nt_entry, &seekpos); @@ -619,19 +770,31 @@ Error was %s\n", prog_name, user_name, pfile, strerror(errno)); if((new_entry = (char *)malloc( new_entry_length )) == 0) { fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ Error was %s\n", prog_name, pwd->pw_name, pfile, strerror(errno)); - fclose(fp); pw_file_unlock(lockfd); + fclose(fp); exit(1); } sprintf(new_entry, "%s:%u:", pwd->pw_name, (unsigned)pwd->pw_uid); p = &new_entry[strlen(new_entry)]; - for( i = 0; i < 16; i++) - sprintf(&p[i*2], "%02X", new_p16[i]); - p += 32; - *p++ = ':'; - for( i = 0; i < 16; i++) - sprintf(&p[i*2], "%02X", new_nt_p16[i]); + if(disable_user) { + memcpy(p, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 32); + p += 32; + *p++ = ':'; + memcpy(p, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 32); + } else if (set_no_password) { + memcpy(p, "NO PASSWORDXXXXXXXXXXXXXXXXXXXXX", 32); + p += 32; + *p++ = ':'; + memcpy(p, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 32); + } else { + for( i = 0; i < 16; i++) + sprintf(&p[i*2], "%02X", new_p16[i]); + p += 32; + *p++ = ':'; + for( i = 0; i < 16; i++) + sprintf(&p[i*2], "%02X", new_nt_p16[i]); + } p += 32; *p++ = ':'; sprintf(p, "%s:%s:%s\n", pwd->pw_gecos, @@ -645,13 +808,13 @@ Error was %s\n", prog_name, pwd->pw_name, pfile, strerror(errno)); Error was %s. Password file may be corrupt ! Please examine by hand !\n", prog_name, pwd->pw_name, strerror(errno)); } - fclose(fp); pw_file_unlock(lockfd); + fclose(fp); exit(1); } - fclose(fp); pw_file_unlock(lockfd); + fclose(fp); exit(0); } } else { @@ -664,14 +827,26 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n", */ /* Create the 32 byte representation of the new p16 */ - for (i = 0; i < 16; i++) { - sprintf(&ascii_p16[i * 2], "%02X", (uchar) new_p16[i]); + if(disable_user) { + memcpy(ascii_p16, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 32); + } else if (set_no_password) { + memcpy(ascii_p16, "NO PASSWORDXXXXXXXXXXXXXXXXXXXXX", 32); + } else { + for (i = 0; i < 16; i++) { + sprintf(&ascii_p16[i * 2], "%02X", (uchar) new_p16[i]); + } } if(got_valid_nt_entry) { /* Add on the NT md4 hash */ ascii_p16[32] = ':'; - for (i = 0; i < 16; i++) { - sprintf(&ascii_p16[(i * 2)+33], "%02X", (uchar) new_nt_p16[i]); + if(disable_user) { + memcpy(&ascii_p16[33], "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 32); + } else if (set_no_password) { + memcpy(&ascii_p16[33], "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 32); + } else { + for (i = 0; i < 16; i++) { + sprintf(&ascii_p16[(i * 2)+33], "%02X", (uchar) new_nt_p16[i]); + } } } /* @@ -684,10 +859,10 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n", err = errno; fprintf(stderr, "%s: seek fail on file %s.\n", prog_name, pfile); - fclose(fp); errno = err; perror(prog_name); pw_file_unlock(lockfd); + fclose(fp); exit(1); } /* Sanity check - ensure the character is a ':' */ @@ -695,17 +870,17 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n", err = errno; fprintf(stderr, "%s: read fail on file %s.\n", prog_name, pfile); - fclose(fp); errno = err; perror(prog_name); pw_file_unlock(lockfd); + fclose(fp); exit(1); } if (c != ':') { fprintf(stderr, "%s: sanity check on passwd file %s failed.\n", prog_name, pfile); - fclose(fp); pw_file_unlock(lockfd); + fclose(fp); exit(1); } writelen = (got_valid_nt_entry) ? 65 : 32; @@ -713,15 +888,19 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n", err = errno; fprintf(stderr, "%s: write fail in file %s.\n", prog_name, pfile); - fclose(fp); errno = err; perror(prog_name); pw_file_unlock(lockfd); + fclose(fp); exit(err); } - fclose(fp); pw_file_unlock(lockfd); - printf("Password changed\n"); + fclose(fp); + if(disable_user) + printf("User %s disabled.\n", user_name); + else if (set_no_password) + printf("User %s - set to no password.\n", user_name); + else + printf("Password changed for user %s.\n", user_name); return 0; } - -- cgit From 8c5c093b9692a31530e1858e676c9843b5472083 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 24 Mar 1998 21:44:49 +0000 Subject: Added writing of '[XXX]' account control bits into gcos field when adding a user via smbpasswd. Jeremy. (This used to be commit 607c64fadbf8c33459444466630f676800cba5ee) --- source3/utils/smbpasswd.c | 55 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index e3237a0b3c..db7f4c12e2 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -237,6 +237,12 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, for(p++;*p && !finished; p++) { switch (*p) { +#if 0 + /* + * Hmmm. Don't allow these to be set/read independently + * of the actual password fields. We don't want a mismatch. + * JRA. + */ case 'N': /* 'N'o password. */ pw_buf.acct_ctrl |= ACB_PWNOTREQ; @@ -245,6 +251,7 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, /* 'D'isabled. */ pw_buf.acct_ctrl |= ACB_DISABLED; break; +#endif case 'H': /* 'H'omedir required. */ pw_buf.acct_ctrl |= ACB_HOMDIRREQ; @@ -312,6 +319,41 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, return NULL; } +/********************************************************** + Encode the account control bits into a string. +**********************************************************/ + +char *encode_acct_ctrl(uint16 acct_ctrl) +{ + static fstring acct_str; + char *p = acct_str; + + *p++ = '['; + + if(acct_ctrl & ACB_HOMDIRREQ) + *p++ = 'H'; + if(acct_ctrl & ACB_TEMPDUP) + *p++ = 'T'; + if(acct_ctrl & ACB_NORMAL) + *p++ = 'U'; + if(acct_ctrl & ACB_MNS) + *p++ = 'M'; + if(acct_ctrl & ACB_WSTRUST) + *p++ = 'W'; + if(acct_ctrl & ACB_SVRTRUST) + *p++ = 'S'; + if(acct_ctrl & ACB_AUTOLOCK) + *p++ = 'L'; + if(acct_ctrl & ACB_PWNOEXP) + *p++ = 'X'; + if(acct_ctrl & ACB_DOMTRUST) + *p++ = 'I'; + + *p++ = ']'; + *p = '\0'; + return acct_str; +} + /********************************************************** Allocate an unused uid in the smbpasswd file to a new machine account. @@ -368,7 +410,7 @@ int main(int argc, char **argv) char readbuf[16 * 1024]; BOOL is_root = False; pstring user_name; - pstring machine_gcos_name; + pstring machine_dir_name; char *remote_machine = NULL; BOOL add_user = False; BOOL got_new_pass = False; @@ -668,9 +710,9 @@ int main(int argc, char **argv) pwd = &machine_account_pwd; pwd->pw_name = user_name; - sprintf(machine_gcos_name, "Machine account for %s", user_name); - pwd->pw_gecos = machine_gcos_name; - pwd->pw_dir = ""; + sprintf(machine_dir_name, "Machine account for %s", user_name); + pwd->pw_gecos = ""; + pwd->pw_dir = machine_dir_name; pwd->pw_shell = ""; pwd->pw_uid = get_machine_uid(); @@ -749,6 +791,7 @@ int main(int argc, char **argv) int new_entry_length; char *new_entry; long offpos; + uint16 acct_ctrl = (machine_account ? ACB_SVRTRUST : ACB_NORMAL); /* The add user write needs to be atomic - so get the fd from the fp and do a raw write() call. @@ -764,7 +807,7 @@ Error was %s\n", prog_name, user_name, pfile, strerror(errno)); } new_entry_length = strlen(user_name) + 1 + 15 + 1 + - 32 + 1 + 32 + 1 + strlen(pwd->pw_gecos) + + 32 + 1 + 32 + 1 + sizeof(fstring) + 1 + strlen(pwd->pw_dir) + 1 + strlen(pwd->pw_shell) + 1; if((new_entry = (char *)malloc( new_entry_length )) == 0) { @@ -797,7 +840,7 @@ Error was %s\n", prog_name, pwd->pw_name, pfile, strerror(errno)); } p += 32; *p++ = ':'; - sprintf(p, "%s:%s:%s\n", pwd->pw_gecos, + sprintf(p, "%s:%s:%s\n", encode_acct_ctrl(acct_ctrl), pwd->pw_dir, pwd->pw_shell); if(write(fd, new_entry, strlen(new_entry)) != strlen(new_entry)) { fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ -- cgit From 1edcbd31fc8a24a97069496fa6959bb4927edebd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 26 Mar 1998 02:14:40 +0000 Subject: smbpass.c: Made unknown accounts ending in '$' server accounts, not workstation. smbpasswd.c: Added code to count down from last machine account to add correct uid when adding a machine account. Jeremy. (This used to be commit 0601a41993d6ea4fb2a186b7ca55b2f3a6f6a53d) --- source3/utils/smbpasswd.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index db7f4c12e2..3a81a98718 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -359,9 +359,27 @@ char *encode_acct_ctrl(uint16 acct_ctrl) machine account. ***********************************************************/ -int get_machine_uid(void) +int get_new_machine_uid(void) { - return 65534; + int next_uid_start; + FILE *fp; + struct smb_passwd *smbpw; + + if(sizeof(uid_t) == 2) + next_uid_start = 65533; + + if(sizeof(uid_t) == 4) + next_uid_start = 0x7fffffff; + + fp = startsmbpwent(False); + while((smbpw = getsmbpwent(fp)) != NULL) { + if(!(smbpw->acct_ctrl & ACB_SVRTRUST)) + continue; + + next_uid_start = MIN(next_uid_start, (smbpw->smb_userid-1)); + } + endsmbpwent(fp); + return next_uid_start; } /********************************************************* @@ -372,7 +390,7 @@ static void usage(char *name, BOOL is_root) { if(is_root) fprintf(stderr, "Usage is : %s [-a] [-d] [-m] [-n] [username] [password]\n\ -%s: [-r machine] [username] [password]\n%s: [-h]\n", name, name, name); +%s: [-R ] [-r machine] [username] [password]\n%s: [-h]\n", name, name, name); else fprintf(stderr, "Usage is : %s [-h] [-r machine] [password]\n", name); exit(1); @@ -450,7 +468,7 @@ int main(int argc, char **argv) is_root = (real_uid == 0); - while ((ch = getopt(argc, argv, "adhmnr:")) != EOF) { + while ((ch = getopt(argc, argv, "adhmnr:R:")) != EOF) { switch(ch) { case 'a': if(is_root) @@ -476,6 +494,12 @@ int main(int argc, char **argv) case 'r': remote_machine = optarg; break; + case 'R': + if(is_root) { + lp_set_name_resolve_order(optarg); + break; + } else + usage(prog_name, is_root); case 'm': if(is_root) machine_account = True; @@ -714,7 +738,7 @@ int main(int argc, char **argv) pwd->pw_gecos = ""; pwd->pw_dir = machine_dir_name; pwd->pw_shell = ""; - pwd->pw_uid = get_machine_uid(); + pwd->pw_uid = get_new_machine_uid(); } -- cgit From 039761b05c2a1708ce6b247a058cc3d55f652a37 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 26 Mar 1998 02:22:08 +0000 Subject: Added the ability to differentiate between workstation and server accounts when adding machine account types. Jeremy. (This used to be commit a402b5070f72d7a6948cc9885228efae16f6617d) --- source3/utils/smbpasswd.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 3a81a98718..f733f99be2 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -373,10 +373,8 @@ int get_new_machine_uid(void) fp = startsmbpwent(False); while((smbpw = getsmbpwent(fp)) != NULL) { - if(!(smbpw->acct_ctrl & ACB_SVRTRUST)) - continue; - - next_uid_start = MIN(next_uid_start, (smbpw->smb_userid-1)); + if((smbpw->acct_ctrl & (ACB_SVRTRUST|ACB_WSTRUST))) + next_uid_start = MIN(next_uid_start, (smbpw->smb_userid-1)); } endsmbpwent(fp); return next_uid_start; @@ -389,7 +387,7 @@ int get_new_machine_uid(void) static void usage(char *name, BOOL is_root) { if(is_root) - fprintf(stderr, "Usage is : %s [-a] [-d] [-m] [-n] [username] [password]\n\ + fprintf(stderr, "Usage is : %s [-a] [-d] [-m] [-w] [-n] [username] [password]\n\ %s: [-R ] [-r machine] [username] [password]\n%s: [-h]\n", name, name, name); else fprintf(stderr, "Usage is : %s [-h] [-r machine] [password]\n", name); @@ -433,6 +431,7 @@ int main(int argc, char **argv) BOOL add_user = False; BOOL got_new_pass = False; BOOL machine_account = False; + BOOL server_machine_account = False; BOOL disable_user = False; BOOL set_no_password = False; pstring servicesf = CONFIGFILE; @@ -468,7 +467,7 @@ int main(int argc, char **argv) is_root = (real_uid == 0); - while ((ch = getopt(argc, argv, "adhmnr:R:")) != EOF) { + while ((ch = getopt(argc, argv, "adhmnr:R:w")) != EOF) { switch(ch) { case 'a': if(is_root) @@ -501,9 +500,11 @@ int main(int argc, char **argv) } else usage(prog_name, is_root); case 'm': - if(is_root) + case 'w': + if(is_root) { machine_account = True; - else + server_machine_account = (ch == 'm'); + } else usage(prog_name, is_root); break; case 'h': @@ -734,7 +735,8 @@ int main(int argc, char **argv) pwd = &machine_account_pwd; pwd->pw_name = user_name; - sprintf(machine_dir_name, "Machine account for %s", user_name); + sprintf(machine_dir_name, "%s machine account for %s", + server_machine_account ? "Server" : "Workstation", user_name); pwd->pw_gecos = ""; pwd->pw_dir = machine_dir_name; pwd->pw_shell = ""; @@ -815,7 +817,8 @@ int main(int argc, char **argv) int new_entry_length; char *new_entry; long offpos; - uint16 acct_ctrl = (machine_account ? ACB_SVRTRUST : ACB_NORMAL); + uint16 acct_ctrl = (machine_account ? + ( server_machine_account ? ACB_SVRTRUST : ACB_WSTRUST) : ACB_NORMAL); /* The add user write needs to be atomic - so get the fd from the fp and do a raw write() call. -- cgit From 6cd35ce945a0ff3e9c787ec12ef81161a6aecbe4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 26 Mar 1998 19:11:31 +0000 Subject: client.c: Fixed problem where debug level on command line was overridden by smb.conf. smbpasswd.c: Removed bugs I put in yesterday (thanks Luke :-) and added error message reporting for remote password changing. Jeremy. (This used to be commit 6a3394a285a250d1029cdd545dd0bf832284555a) --- source3/utils/smbpasswd.c | 92 +++++++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 34 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index f733f99be2..b03385769c 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -37,6 +37,39 @@ struct {0, NULL} }; +/****************************************************** + Return an error message for a remote password change. +*******************************************************/ + +char *get_error_message(struct cli_state *cli) +{ + static fstring error_message; + int errclass; + int errnum; + int i; + + /* + * Errors are of two kinds - smb errors, + * dealt with by cli_errstr, and rap + * errors, whose error code is in cli.error. + */ + + cli_error(cli, &errclass, &errnum); + if(errclass != 0) + return cli_errstr(cli); + + sprintf(error_message, "code %d", cli->error); + + for(i = 0; pw_change_errmap[i].message != NULL; i++) { + if (pw_change_errmap[i].err == cli->error) { + fstrcpy( error_message, pw_change_errmap[i].message); + break; + } + } + + return error_message; +} + /****************************************************** Convert a hex password. *******************************************************/ @@ -387,10 +420,10 @@ int get_new_machine_uid(void) static void usage(char *name, BOOL is_root) { if(is_root) - fprintf(stderr, "Usage is : %s [-a] [-d] [-m] [-w] [-n] [username] [password]\n\ -%s: [-R ] [-r machine] [username] [password]\n%s: [-h]\n", name, name, name); + fprintf(stderr, "Usage is : %s [-D DEBUGLEVEL] [-a] [-d] [-m] [-n] [username] [password]\n\ +%s: [-R ] [-D DEBUGLEVEL] [-r machine] [username] [password]\n%s: [-h]\n", name, name, name); else - fprintf(stderr, "Usage is : %s [-h] [-r machine] [password]\n", name); + fprintf(stderr, "Usage is : %s [-h] [-D DEBUGLEVEL] [-r machine] [password]\n", name); exit(1); } @@ -402,6 +435,7 @@ int main(int argc, char **argv) { extern char *optarg; extern int optind; + extern int DEBUGLEVEL; char *prog_name; int real_uid; struct passwd *pwd; @@ -431,7 +465,6 @@ int main(int argc, char **argv) BOOL add_user = False; BOOL got_new_pass = False; BOOL machine_account = False; - BOOL server_machine_account = False; BOOL disable_user = False; BOOL set_no_password = False; pstring servicesf = CONFIGFILE; @@ -467,7 +500,7 @@ int main(int argc, char **argv) is_root = (real_uid == 0); - while ((ch = getopt(argc, argv, "adhmnr:R:w")) != EOF) { + while ((ch = getopt(argc, argv, "adhmnr:R:D:")) != EOF) { switch(ch) { case 'a': if(is_root) @@ -483,6 +516,9 @@ int main(int argc, char **argv) } else usage(prog_name, is_root); break; + case 'D': + DEBUGLEVEL = atoi(optarg); + break; case 'n': if(is_root) { set_no_password = True; @@ -500,10 +536,8 @@ int main(int argc, char **argv) } else usage(prog_name, is_root); case 'm': - case 'w': if(is_root) { machine_account = True; - server_machine_account = (ch == 'm'); } else usage(prog_name, is_root); break; @@ -651,16 +685,18 @@ int main(int argc, char **argv) prog_name, remote_machine ); exit(1); } - + + cli.error = 0; + if (!cli_initialise(&cli) || !cli_connect(&cli, remote_machine, &ip)) { - fprintf(stderr, "%s: unable to connect to SMB server on machine %s.\n", - prog_name, remote_machine ); + fprintf(stderr, "%s: unable to connect to SMB server on machine %s. Error was : %s.\n", + prog_name, remote_machine, get_error_message(&cli) ); exit(1); } if (!cli_session_request(&cli, remote_machine, 0x20, myname)) { - fprintf(stderr, "%s: machine %s rejected the session setup.\n", - prog_name, remote_machine ); + fprintf(stderr, "%s: machine %s rejected the session setup. Error was : %s.\n", + prog_name, remote_machine, get_error_message(&cli) ); cli_shutdown(&cli); exit(1); } @@ -668,40 +704,30 @@ int main(int argc, char **argv) cli.protocol = PROTOCOL_NT1; if (!cli_negprot(&cli)) { - fprintf(stderr, "%s: machine %s rejected the negotiate protocol.\n", - prog_name, remote_machine ); + fprintf(stderr, "%s: machine %s rejected the negotiate protocol. Error was : %s.\n", + prog_name, remote_machine, get_error_message(&cli) ); cli_shutdown(&cli); exit(1); } if (!cli_session_setup(&cli, user_name, old_passwd, strlen(old_passwd), "", 0, "")) { - fprintf(stderr, "%s: machine %s rejected the session setup.\n", - prog_name, remote_machine ); + fprintf(stderr, "%s: machine %s rejected the session setup. Error was : %s.\n", + prog_name, remote_machine, get_error_message(&cli) ); cli_shutdown(&cli); exit(1); } if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) { - fprintf(stderr, "%s: machine %s rejected the tconX on the IPC$ share.\n", - prog_name, remote_machine ); + fprintf(stderr, "%s: machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", + prog_name, remote_machine, get_error_message(&cli) ); cli_shutdown(&cli); exit(1); } if(!cli_oem_change_password(&cli, user_name, new_passwd, old_passwd)) { - fstring error_message; - - sprintf(error_message, " with code %d", cli.error); - - for(i = 0; pw_change_errmap[i].message != NULL; i++) { - if (pw_change_errmap[i].err == cli.error) { - fstrcpy( error_message, pw_change_errmap[i].message); - break; - } - } - fprintf(stderr, "%s: machine %s rejected the password change: %s.\n", - prog_name, remote_machine, error_message ); + fprintf(stderr, "%s: machine %s rejected the password change: Error was : %s.\n", + prog_name, remote_machine, get_error_message(&cli) ); cli_shutdown(&cli); exit(1); } @@ -735,8 +761,7 @@ int main(int argc, char **argv) pwd = &machine_account_pwd; pwd->pw_name = user_name; - sprintf(machine_dir_name, "%s machine account for %s", - server_machine_account ? "Server" : "Workstation", user_name); + sprintf(machine_dir_name, "Workstation machine account for %s", user_name); pwd->pw_gecos = ""; pwd->pw_dir = machine_dir_name; pwd->pw_shell = ""; @@ -817,8 +842,7 @@ int main(int argc, char **argv) int new_entry_length; char *new_entry; long offpos; - uint16 acct_ctrl = (machine_account ? - ( server_machine_account ? ACB_SVRTRUST : ACB_WSTRUST) : ACB_NORMAL); + uint16 acct_ctrl = (machine_account ? ACB_WSTRUST : ACB_NORMAL); /* The add user write needs to be atomic - so get the fd from the fp and do a raw write() call. -- cgit From 852dc76c60b08c3dbb86ba38b7c3c968b1b228dd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 30 Mar 1998 20:12:12 +0000 Subject: Added extra remote password changing error codes from lmerr.h on NT. Jeremy. (This used to be commit 38391b51cd9e1e9fc7e4b77335ed2c7f6befc8c6) --- source3/utils/smbpasswd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index b03385769c..22271b75de 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -32,8 +32,11 @@ struct {5, "User has insufficient privilege" }, {86, "The specified password is invalid" }, {2226, "Operation only permitted on a Primary Domain Controller" }, - {2243, "The password cannot be changed" }, - {2246, "The password is too short" }, + {2242, "The password of this user has expired." }, + {2243, "The password of this user cannot change." }, + {2244, "This password cannot be used now (password history conflict)." }, + {2245, "The password is shorter than required." }, + {2246, "The password of this user is too recent to change."}, {0, NULL} }; -- cgit From db55744684ba35e2c1c9763da56353d82a9252bc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Apr 1998 17:44:02 +0000 Subject: Added check for getpwnam returning NULL. Jeremy. (This used to be commit 81cbfaacb11747830354f4a58be441015fe19ba8) --- source3/utils/smbpasswd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 22271b75de..425308bec6 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -582,9 +582,13 @@ int main(int argc, char **argv) usage(prog_name, True); } - if(*user_name) - pwd = getpwnam(user_name); - else { + if(*user_name) { + if((pwd = getpwnam(user_name)) == NULL) { + fprintf(stderr, "%s: User \"%s\" was not found in system password file.\n", + prog_name, user_name); + exit(1); + } + } else { if((pwd = getpwuid(real_uid)) != NULL) pstrcpy( user_name, pwd->pw_name); } -- cgit From af80d8e98f2f74939d680c6abc21e3f40b927f31 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 9 Apr 1998 20:48:48 +0000 Subject: Makefile, loadparm.c, server.c, smb.h, util.c: Patch from stn@techfak.uni-kiel.de (Stefan Nehlsen) to get homes from the NIS+ map. smbpasswd.c: Tidy up of cli_state structure. Jeremy. (This used to be commit fc2295e0f5729585fdb3ee47edb290851d4071c5) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 425308bec6..2433fa1bb4 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -693,7 +693,7 @@ int main(int argc, char **argv) exit(1); } - cli.error = 0; + memset(&cli, '\0', sizeof(struct cli_state)); if (!cli_initialise(&cli) || !cli_connect(&cli, remote_machine, &ip)) { fprintf(stderr, "%s: unable to connect to SMB server on machine %s. Error was : %s.\n", -- cgit From fc9065b3606cbe1b11fe009b117195abbcf07fad Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 12 Apr 1998 02:53:17 +0000 Subject: some hacks to the torture code (This used to be commit 02786747ee6774f617d95b08a5c5912bf86e7586) --- source3/utils/torture.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 049a414eb9..c7fded6b3f 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -116,7 +116,8 @@ static BOOL rw_torture(struct cli_state *c, int numops) int fnum; int fnum2; int pid2, pid = getpid(); - int i; + int i, j; + char buf[1024]; fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE); @@ -149,6 +150,14 @@ static BOOL rw_torture(struct cli_state *c, int numops) printf("write failed (%s)\n", cli_errstr(c)); } + for (j=0;j<50;j++) { + if (cli_write(c, fnum, (char *)buf, + sizeof(pid)+(j*sizeof(buf)), + sizeof(buf)) != sizeof(buf)) { + printf("write failed (%s)\n", cli_errstr(c)); + } + } + pid2 = 0; if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) { -- cgit From cac6a060af598bf94e6414b06e7365ec51ca360e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Apr 1998 19:24:06 +0000 Subject: Changes to allow Samba to be compiled with -Wstrict-prototypes with gcc. (Not a big change although it looks like it :-). Jeremy. (This used to be commit cd2613c57261456485fe4eeecfda209ada70de8e) --- source3/utils/make_printerdef.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index 514773eb48..0c3cb633af 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -94,7 +94,7 @@ char *scan(char *chaine,char **entry) return (value); } -void build_subdir() +void build_subdir(void) { int i=0; char *entry; -- cgit From 2a53d6f7077de596265a3e73e79827392054142c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 14 Apr 1998 00:41:59 +0000 Subject: Modified interfaces to getting smb password entries from get_smbpwd_entry (now an internal function to smbpass.c) to a more UNIX-like : getsmbpwnam() - get entry by name. getsmbpwuid() - get entry by uid. Changed the type returned by the smbpasswd enumeration functions to be a void * so that people don't come to depend on it being a FILE *. These abstractions should make it much easier to replace the smbpasswd file with a better backend in future. Other files changed are to match the above changes. Jeremy. (This used to be commit 1161cfb7f2b0d5a6d3e2b524a14a6f325ce70efb) --- source3/utils/smbpasswd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 2433fa1bb4..b569ba96b3 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -398,7 +398,7 @@ char *encode_acct_ctrl(uint16 acct_ctrl) int get_new_machine_uid(void) { int next_uid_start; - FILE *fp; + void *vp; struct smb_passwd *smbpw; if(sizeof(uid_t) == 2) @@ -407,12 +407,12 @@ int get_new_machine_uid(void) if(sizeof(uid_t) == 4) next_uid_start = 0x7fffffff; - fp = startsmbpwent(False); - while((smbpw = getsmbpwent(fp)) != NULL) { + vp = startsmbpwent(False); + while((smbpw = getsmbpwent(vp)) != NULL) { if((smbpw->acct_ctrl & (ACB_SVRTRUST|ACB_WSTRUST))) next_uid_start = MIN(next_uid_start, (smbpw->smb_userid-1)); } - endsmbpwent(fp); + endsmbpwent(vp); return next_uid_start; } -- cgit From 041a292c439189206f1c35de94893dd51a1fda33 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 15 Apr 1998 20:00:41 +0000 Subject: ipc.c: Fix for printer queue spinning with Win95. nmbd.c: Fix for always overwriting log despite append setting. smb.h: Addition of last time password changed entry to account info. smbpass.c: Changes to support last time changed field in smbpasswd file. smbpasswd.c: Changes to support last time changed field in smbpasswd file. util.c: Fix for always overwriting log despite append setting. Jeremy. (This used to be commit eb4fe9ecdf539209efab07dc992447ea7370cf93) --- source3/utils/smbpasswd.c | 89 ++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 43 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index b569ba96b3..ca59ae52e9 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -106,7 +106,7 @@ static int gethexpwd(char *p, char *pwd) static struct smb_passwd * _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, - BOOL *got_valid_nt_entry, long *pwd_seekpos) + BOOL *got_valid_nt_entry, BOOL *got_valid_last_change_time, long *pwd_seekpos) { /* Static buffers we will return. */ static struct smb_passwd pw_buf; @@ -121,6 +121,9 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, long linebuf_len; pw_buf.acct_ctrl = ACB_NORMAL; + *got_valid_last_change_time = False; + *got_valid_nt_entry = False; + *valid_old_pwd = False; /* * Scan the file, a line at a time and check if the name matches. @@ -337,7 +340,31 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, /* Must have some account type set. */ if(pw_buf.acct_ctrl == 0) pw_buf.acct_ctrl = ACB_NORMAL; - + + /* Now try and get the last change time. */ + if(*p == ']') + p++; + if(*p == ':') { + p++; + if(*p && StrnCaseCmp( p, "LCT-", 4)) { + int i; + p += 4; + for(i = 0; i < 8; i++) { + if(p[i] == '\0' || !isxdigit(p[i])) + break; + } + if(i == 8) { + /* + * p points at 8 characters of hex digits - + * read into a time_t as the seconds since + * 1970 that the password was last changed. + */ + pw_buf.last_change_time = (time_t)strtol(p, NULL, 16); + *got_valid_last_change_time = True; + } /* i == 8 */ + } /* *p && StrnCaseCmp() */ + } /* *p == ':' */ + } else { /* 'Old' style file. Fake up based on user name. */ /* @@ -355,41 +382,6 @@ _my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, return NULL; } -/********************************************************** - Encode the account control bits into a string. -**********************************************************/ - -char *encode_acct_ctrl(uint16 acct_ctrl) -{ - static fstring acct_str; - char *p = acct_str; - - *p++ = '['; - - if(acct_ctrl & ACB_HOMDIRREQ) - *p++ = 'H'; - if(acct_ctrl & ACB_TEMPDUP) - *p++ = 'T'; - if(acct_ctrl & ACB_NORMAL) - *p++ = 'U'; - if(acct_ctrl & ACB_MNS) - *p++ = 'M'; - if(acct_ctrl & ACB_WSTRUST) - *p++ = 'W'; - if(acct_ctrl & ACB_SVRTRUST) - *p++ = 'S'; - if(acct_ctrl & ACB_AUTOLOCK) - *p++ = 'L'; - if(acct_ctrl & ACB_PWNOEXP) - *p++ = 'X'; - if(acct_ctrl & ACB_DOMTRUST) - *p++ = 'I'; - - *p++ = ']'; - *p = '\0'; - return acct_str; -} - /********************************************************** Allocate an unused uid in the smbpasswd file to a new machine account. @@ -454,7 +446,7 @@ int main(int argc, char **argv) BOOL got_valid_nt_entry = False; long seekpos; int pwfd; - char ascii_p16[66]; + pstring ascii_p16; char c; int ch; int ret, i, err, writelen; @@ -467,6 +459,7 @@ int main(int argc, char **argv) char *remote_machine = NULL; BOOL add_user = False; BOOL got_new_pass = False; + BOOL got_valid_last_change_time = False; BOOL machine_account = False; BOOL disable_user = False; BOOL set_no_password = False; @@ -833,7 +826,7 @@ int main(int argc, char **argv) /* Get the smb passwd entry for this user */ smb_pwent = _my_get_smbpwnam(fp, user_name, &valid_old_pwd, - &got_valid_nt_entry, &seekpos); + &got_valid_nt_entry, &got_valid_last_change_time, &seekpos); if (smb_pwent == NULL) { if(add_user == False) { fprintf(stderr, "%s: Failed to find entry for user %s in file %s.\n", @@ -866,6 +859,7 @@ Error was %s\n", prog_name, user_name, pfile, strerror(errno)); new_entry_length = strlen(user_name) + 1 + 15 + 1 + 32 + 1 + 32 + 1 + sizeof(fstring) + + 1 + 13 + 1 + strlen(pwd->pw_dir) + 1 + strlen(pwd->pw_shell) + 1; if((new_entry = (char *)malloc( new_entry_length )) == 0) { @@ -898,8 +892,8 @@ Error was %s\n", prog_name, pwd->pw_name, pfile, strerror(errno)); } p += 32; *p++ = ':'; - sprintf(p, "%s:%s:%s\n", encode_acct_ctrl(acct_ctrl), - pwd->pw_dir, pwd->pw_shell); + sprintf(p, "%s:TLC-%08X:%s:%s\n", encode_acct_ctrl(acct_ctrl), + (uint32)time(NULL), pwd->pw_dir, pwd->pw_shell); if(write(fd, new_entry, strlen(new_entry)) != strlen(new_entry)) { fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ Error was %s\n", prog_name, pwd->pw_name, pfile, strerror(errno)); @@ -924,7 +918,8 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n", } /* - * We are root - just write the new password. + * We are root - just write the new password + * and the valid last change time. */ /* Create the 32 byte representation of the new p16 */ @@ -950,6 +945,13 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n", } } } + ascii_p16[65] = ':'; + ascii_p16[66] = '\0'; + if(got_valid_last_change_time) { + strcpy(&ascii_p16[66], encode_acct_ctrl(smb_pwent->acct_ctrl)); + sprintf(&ascii_p16[strlen(ascii_p16)], ":TLC-%08X", (uint32)time(NULL)); + } + /* * Do an atomic write into the file at the position defined by * seekpos. @@ -984,7 +986,8 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n", fclose(fp); exit(1); } - writelen = (got_valid_nt_entry) ? 65 : 32; + writelen = (got_valid_nt_entry) ? + ( got_valid_last_change_time ? strlen(ascii_p16) : 65) : 32; if (write(pwfd, ascii_p16, writelen) != writelen) { err = errno; fprintf(stderr, "%s: write fail in file %s.\n", -- cgit From 373d7c62577c13e1a85043844953a8d779858432 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 17 Apr 1998 19:29:51 +0000 Subject: Changing of machine passwords now works !!!!!! smbdes.c: Added cred_hash3. smbpasswd.c: Fixes for adding a machine account (needs more work). lib/rpc/server/srv_netlog.c: Turn on the machine password changing code by default (calls cred_hash3). Jeremy. (This used to be commit 50aa513b969c6e41911aeee8207b065f93af0beb) --- source3/utils/smbpasswd.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index ca59ae52e9..97a38977dc 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -576,6 +576,25 @@ int main(int argc, char **argv) } if(*user_name) { + + if(machine_account) { + int username_len = strlen(user_name); + if(username_len >= sizeof(pstring) - 1) { + fprintf(stderr, "%s: machine account name too long.\n", user_name); + exit(1); + } + + if(user_name[username_len-1] != '$') { + user_name[username_len] = '$'; + user_name[username_len+1] = '\0'; + } + } + + /* + * Setup the pwd struct to point to known + * values for a machine account (it doesn't + * exist in /etc/passwd). + */ if((pwd = getpwnam(user_name)) == NULL) { fprintf(stderr, "%s: User \"%s\" was not found in system password file.\n", prog_name, user_name); @@ -630,6 +649,8 @@ int main(int argc, char **argv) strncpy(new_passwd, user_name, sizeof(fstring)); new_passwd[sizeof(fstring)-1] = '\0'; strlower(new_passwd); + if(new_passwd[strlen(new_passwd)-1] == '$') + new_passwd[strlen(new_passwd)-1] = '\0'; } /* @@ -741,17 +762,7 @@ int main(int argc, char **argv) * a '$' etc.... */ - if(machine_account) { - int username_len = strlen(user_name); - if(username_len >= sizeof(pstring) - 1) { - fprintf(stderr, "%s: machine account name too long.\n", user_name); - exit(1); - } - - if(user_name[username_len] != '$') { - user_name[username_len] = '$'; - user_name[username_len+1] = '\0'; - } + if(machine_account && !pwd) { /* * Setup the pwd struct to point to known -- cgit From f9a96f060bdc8d045748b5f7e31d177e43e8810a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 17 Apr 1998 22:44:01 +0000 Subject: clientgen.c: Changes 'cli_xxx_' calls to use the following regularized parameter syntax: setup, setup_count, max_setup_count, params, params_count, max_params_count, data, data_count, max_data_count, (and if a reply is needed) *reply_params, *reply_data_len *reply_data, *reply_data_len This allows the pointers and the lengths that relate to these pointers to be next to each other in the parameter list. This makes seeing what you are passing to these functions much easier to see. Getting ready for adding the lib/rpc/client functions needed to do security=domain. torture.c: Fixed it so it uses / rather than \\ internally for the //machine/share syntax. Jeremy. (This used to be commit 38350ea8b949d0908497490898ff04df7591ccac) --- source3/utils/torture.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index c7fded6b3f..ede801afe9 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -32,12 +32,12 @@ static char *sockops=""; static struct timeval tp1,tp2; -static void start_timer() +static void start_timer(void) { gettimeofday(&tp1,NULL); } -static double end_timer() +static double end_timer(void) { gettimeofday(&tp2,NULL); return((tp2.tv_sec - tp1.tv_sec) + @@ -191,7 +191,7 @@ static BOOL rw_torture(struct cli_state *c, int numops) static void usage(void) { - printf("Usage: smbtorture \\\\server\\share \n"); + printf("Usage: smbtorture //server/share \n"); printf("\t-U user%%pass\n"); printf("\t-N numprocs\n"); @@ -841,12 +841,16 @@ static void create_procs(int nprocs, int numops) usage(); } - if (strncmp(argv[1], "\\\\", 2)) { + for(p = argv[1]; *p; p++) + if(*p == '\\') + *p = '/'; + + if (strncmp(argv[1], "//", 2)) { usage(); } fstrcpy(host, &argv[1][2]); - p = strchr(&host[2],'\\'); + p = strchr(&host[2],'/'); if (!p) { usage(); } -- cgit From 6733e2b36e00ccbe8df363651ecc98ba42d53cee Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 18 Apr 1998 02:00:39 +0000 Subject: includes.h: Added John's redhat fix for QSORT_CAST. smbpass.c: Added lock depth code so calls to pw_file_lock() can be nested. Fixed codedump problems in add_smbpwd_entry(). smbpasswd.c: Removed all the code that manipulated the password file directly. Now *all* smbpasswd file changes are done through the interfaces defined in smbpass.c This should make the life of people adding alternate backend databases *much* easier. lib/rpc/server/srv_netlog.c: Removed debug messages used to debug machine password changing. Jeremy. (This used to be commit c9f61be08f3691a6421734d8b026a295d9cbd6ba) --- source3/utils/smbpasswd.c | 585 +++++----------------------------------------- 1 file changed, 56 insertions(+), 529 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 97a38977dc..cf9cd54ef3 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -73,341 +73,6 @@ char *get_error_message(struct cli_state *cli) return error_message; } -/****************************************************** - Convert a hex password. -*******************************************************/ - -static int gethexpwd(char *p, char *pwd) -{ - int i; - unsigned char lonybble, hinybble; - char *hexchars = "0123456789ABCDEF"; - char *p1, *p2; - for (i = 0; i < 32; i += 2) { - hinybble = toupper(p[i]); - lonybble = toupper(p[i + 1]); - - p1 = strchr(hexchars, hinybble); - p2 = strchr(hexchars, lonybble); - if (!p1 || !p2) - return (False); - - hinybble = PTR_DIFF(p1, hexchars); - lonybble = PTR_DIFF(p2, hexchars); - - pwd[i / 2] = (hinybble << 4) | lonybble; - } - return (True); -} - -/****************************************************** - Find a password entry by name. -*******************************************************/ - -static struct smb_passwd * -_my_get_smbpwnam(FILE * fp, char *name, BOOL * valid_old_pwd, - BOOL *got_valid_nt_entry, BOOL *got_valid_last_change_time, long *pwd_seekpos) -{ - /* Static buffers we will return. */ - static struct smb_passwd pw_buf; - static pstring user_name; - static unsigned char smbpwd[16]; - static unsigned char smbntpwd[16]; - - char linebuf[256]; - unsigned char c; - unsigned char *p; - long uidval; - long linebuf_len; - - pw_buf.acct_ctrl = ACB_NORMAL; - *got_valid_last_change_time = False; - *got_valid_nt_entry = False; - *valid_old_pwd = False; - - /* - * Scan the file, a line at a time and check if the name matches. - */ - while (!feof(fp)) { - linebuf[0] = '\0'; - *pwd_seekpos = ftell(fp); - - fgets(linebuf, 256, fp); - if (ferror(fp)) - return NULL; - - /* - * Check if the string is terminated with a newline - if not - * then we must keep reading and discard until we get one. - */ - linebuf_len = strlen(linebuf); - if (linebuf[linebuf_len - 1] != '\n') { - c = '\0'; - while (!ferror(fp) && !feof(fp)) { - c = fgetc(fp); - if (c == '\n') - break; - } - } else - linebuf[linebuf_len - 1] = '\0'; - - if ((linebuf[0] == 0) && feof(fp)) - break; - /* - * The line we have should be of the form :- - * - * username:uid:[32hex bytes]:....other flags presently - * ignored.... - * - * or, - * - * username:uid:[32hex bytes]:[32hex bytes]:....ignored.... - * - * if Windows NT compatible passwords are also present. - */ - - if (linebuf[0] == '#' || linebuf[0] == '\0') - continue; - p = (unsigned char *) strchr(linebuf, ':'); - if (p == NULL) - continue; - /* - * As 256 is shorter than a pstring we don't need to check - * length here - if this ever changes.... - */ - strncpy(user_name, linebuf, PTR_DIFF(p, linebuf)); - user_name[PTR_DIFF(p, linebuf)] = '\0'; - if (!strequal(user_name, name)) - continue; - - /* User name matches - get uid and password */ - p++; /* Go past ':' */ - if (!isdigit(*p)) - return (False); - - uidval = atoi((char *) p); - while (*p && isdigit(*p)) - p++; - - if (*p != ':') - return (False); - - /* - * Now get the password value - this should be 32 hex digits - * which are the ascii representations of a 16 byte string. - * Get two at a time and put them into the password. - */ - p++; - *pwd_seekpos += PTR_DIFF(p, linebuf); /* Save exact position - * of passwd in file - - * this is used by - * smbpasswd.c */ - if (*p == '*' || *p == 'X') { - /* Password deliberately invalid - end here. */ - *valid_old_pwd = False; - *got_valid_nt_entry = False; - pw_buf.smb_nt_passwd = NULL; /* No NT password (yet)*/ - - pw_buf.acct_ctrl |= ACB_DISABLED; - - /* Now check if the NT compatible password is - available. */ - p += 33; /* Move to the first character of the line after - the lanman password. */ - if ((linebuf_len >= (PTR_DIFF(p, linebuf) + 33)) && (p[32] == ':')) { - /* NT Entry was valid - even if 'X' or '*', can be overwritten */ - *got_valid_nt_entry = True; - if (*p != '*' && *p != 'X') { - if (gethexpwd((char *)p,(char *)smbntpwd)) - pw_buf.smb_nt_passwd = smbntpwd; - } - } - pw_buf.smb_name = user_name; - pw_buf.smb_userid = uidval; - pw_buf.smb_passwd = NULL; /* No password */ - return (&pw_buf); - } - if (linebuf_len < (PTR_DIFF(p, linebuf) + 33)) - return (False); - - if (p[32] != ':') - return (False); - - if (!strncasecmp((char *)p, "NO PASSWORD", 11)) { - pw_buf.smb_passwd = NULL; /* No password */ - pw_buf.acct_ctrl |= ACB_PWNOTREQ; - } else { - if(!gethexpwd((char *)p,(char *)smbpwd)) - return False; - pw_buf.smb_passwd = smbpwd; - } - - pw_buf.smb_name = user_name; - pw_buf.smb_userid = uidval; - pw_buf.smb_nt_passwd = NULL; - *got_valid_nt_entry = False; - *valid_old_pwd = True; - - /* Now check if the NT compatible password is - available. */ - p += 33; /* Move to the first character of the line after - the lanman password. */ - if ((linebuf_len >= (PTR_DIFF(p, linebuf) + 33)) && (p[32] == ':')) { - /* NT Entry was valid - even if 'X' or '*', can be overwritten */ - *got_valid_nt_entry = True; - if (*p != '*' && *p != 'X') { - if (gethexpwd((char *)p,(char *)smbntpwd)) - pw_buf.smb_nt_passwd = smbntpwd; - } - - p += 33; /* Move to the first character of the line after - the NT password. */ - } - - /* - * Check if the account type bits have been encoded after the - * NT password (in the form [NDHTUWSLXI]). - */ - - if (*p == '[') { - BOOL finished = False; - - pw_buf.acct_ctrl = 0; - - for(p++;*p && !finished; p++) { - switch (*p) { -#if 0 - /* - * Hmmm. Don't allow these to be set/read independently - * of the actual password fields. We don't want a mismatch. - * JRA. - */ - case 'N': - /* 'N'o password. */ - pw_buf.acct_ctrl |= ACB_PWNOTREQ; - break; - case 'D': - /* 'D'isabled. */ - pw_buf.acct_ctrl |= ACB_DISABLED; - break; -#endif - case 'H': - /* 'H'omedir required. */ - pw_buf.acct_ctrl |= ACB_HOMDIRREQ; - break; - case 'T': - /* 'T'emp account. */ - pw_buf.acct_ctrl |= ACB_TEMPDUP; - break; - case 'U': - /* 'U'ser account (normal). */ - pw_buf.acct_ctrl |= ACB_NORMAL; - break; - case 'M': - /* 'M'NS logon user account. What is this ? */ - pw_buf.acct_ctrl |= ACB_MNS; - break; - case 'W': - /* 'W'orkstation account. */ - pw_buf.acct_ctrl |= ACB_WSTRUST; - break; - case 'S': - /* 'S'erver account. */ - pw_buf.acct_ctrl |= ACB_SVRTRUST; - break; - case 'L': - /* 'L'ocked account. */ - pw_buf.acct_ctrl |= ACB_AUTOLOCK; - break; - case 'X': - /* No 'X'piry. */ - pw_buf.acct_ctrl |= ACB_PWNOEXP; - break; - case 'I': - /* 'I'nterdomain trust account. */ - pw_buf.acct_ctrl |= ACB_DOMTRUST; - break; - - case ':': - case '\n': - case '\0': - case ']': - default: - finished = True; - } - } - - /* Must have some account type set. */ - if(pw_buf.acct_ctrl == 0) - pw_buf.acct_ctrl = ACB_NORMAL; - - /* Now try and get the last change time. */ - if(*p == ']') - p++; - if(*p == ':') { - p++; - if(*p && StrnCaseCmp( p, "LCT-", 4)) { - int i; - p += 4; - for(i = 0; i < 8; i++) { - if(p[i] == '\0' || !isxdigit(p[i])) - break; - } - if(i == 8) { - /* - * p points at 8 characters of hex digits - - * read into a time_t as the seconds since - * 1970 that the password was last changed. - */ - pw_buf.last_change_time = (time_t)strtol(p, NULL, 16); - *got_valid_last_change_time = True; - } /* i == 8 */ - } /* *p && StrnCaseCmp() */ - } /* *p == ':' */ - - } else { - /* 'Old' style file. Fake up based on user name. */ - /* - * Currently machine accounts are kept in the same - * password file as 'normal accounts'. If this changes - * we will have to fix this code. JRA. - */ - if(pw_buf.smb_name[strlen(pw_buf.smb_name) - 1] == '$') { - pw_buf.acct_ctrl &= ~ACB_NORMAL; - pw_buf.acct_ctrl |= ACB_WSTRUST; - } - } - return &pw_buf; - } - return NULL; -} - -/********************************************************** - Allocate an unused uid in the smbpasswd file to a new - machine account. -***********************************************************/ - -int get_new_machine_uid(void) -{ - int next_uid_start; - void *vp; - struct smb_passwd *smbpw; - - if(sizeof(uid_t) == 2) - next_uid_start = 65533; - - if(sizeof(uid_t) == 4) - next_uid_start = 0x7fffffff; - - vp = startsmbpwent(False); - while((smbpw = getsmbpwent(vp)) != NULL) { - if((smbpw->acct_ctrl & (ACB_SVRTRUST|ACB_WSTRUST))) - next_uid_start = MIN(next_uid_start, (smbpw->smb_userid-1)); - } - endsmbpwent(vp); - return next_uid_start; -} - /********************************************************* Print command usage on stderr and die. **********************************************************/ @@ -434,7 +99,6 @@ int main(int argc, char **argv) char *prog_name; int real_uid; struct passwd *pwd; - struct passwd machine_account_pwd; fstring old_passwd; fstring new_passwd; uchar new_p16[16]; @@ -442,28 +106,18 @@ int main(int argc, char **argv) char *p; struct smb_passwd *smb_pwent; FILE *fp; - BOOL valid_old_pwd = False; - BOOL got_valid_nt_entry = False; - long seekpos; - int pwfd; - pstring ascii_p16; - char c; int ch; - int ret, i, err, writelen; - int lockfd = -1; - char *pfile = SMB_PASSWD_FILE; - char readbuf[16 * 1024]; + int err; BOOL is_root = False; pstring user_name; - pstring machine_dir_name; char *remote_machine = NULL; BOOL add_user = False; BOOL got_new_pass = False; - BOOL got_valid_last_change_time = False; BOOL machine_account = False; BOOL disable_user = False; BOOL set_no_password = False; pstring servicesf = CONFIGFILE; + void *vp; new_passwd[0] = '\0'; user_name[0] = '\0'; @@ -758,26 +412,14 @@ int main(int argc, char **argv) } /* - * Check for a machine account flag - make sure the username ends in - * a '$' etc.... + * Check for a machine account. */ if(machine_account && !pwd) { - - /* - * Setup the pwd struct to point to known - * values for a machine account (it doesn't - * exist in /etc/passwd). - */ - - pwd = &machine_account_pwd; - pwd->pw_name = user_name; - sprintf(machine_dir_name, "Workstation machine account for %s", user_name); - pwd->pw_gecos = ""; - pwd->pw_dir = machine_dir_name; - pwd->pw_shell = ""; - pwd->pw_uid = get_new_machine_uid(); - + fprintf(stderr, "%s: User %s does not exist in system password file \ +(usually /etc/passwd). Cannot add machine account without a valid system user.\n", + prog_name, user_name); + exit(1); } /* Calculate the MD4 hash (NT compatible) of the new password. */ @@ -797,130 +439,64 @@ int main(int argc, char **argv) E_P16((uchar *) new_passwd, new_p16); /* - * Open the smbpaswd file XXXX - we need to parse smb.conf to get the - * filename + * Open the smbpaswd file. */ - fp = fopen(pfile, "r+"); - if (!fp && errno == ENOENT) { - fp = fopen(pfile, "w"); + vp = startsmbpwent(True); + if (!vp && errno == ENOENT) { + fp = fopen(lp_smb_passwd_file(), "w"); if (fp) { fprintf(fp, "# Samba SMB password file\n"); fclose(fp); - fp = fopen(pfile, "r+"); + vp = startsmbpwent(True); } } if (!fp) { err = errno; fprintf(stderr, "%s: Failed to open password file %s.\n", - prog_name, pfile); + prog_name, lp_smb_passwd_file()); errno = err; perror(prog_name); exit(err); } - /* Set read buffer to 16k for effiecient reads */ - setvbuf(fp, readbuf, _IOFBF, sizeof(readbuf)); - - /* make sure it is only rw by the owner */ - chmod(pfile, 0600); - - /* Lock the smbpasswd file for write. */ - if ((lockfd = pw_file_lock(fileno(fp), F_WRLCK, 5)) < 0) { - err = errno; - fprintf(stderr, "%s: Failed to lock password file %s.\n", - prog_name, pfile); - fclose(fp); - errno = err; - perror(prog_name); - exit(err); - } - /* Get the smb passwd entry for this user */ - smb_pwent = _my_get_smbpwnam(fp, user_name, &valid_old_pwd, - &got_valid_nt_entry, &got_valid_last_change_time, &seekpos); + smb_pwent = getsmbpwnam(user_name); if (smb_pwent == NULL) { if(add_user == False) { - fprintf(stderr, "%s: Failed to find entry for user %s in file %s.\n", - prog_name, pwd->pw_name, pfile); - fclose(fp); - pw_file_unlock(lockfd); + fprintf(stderr, "%s: Failed to find entry for user %s.\n", + prog_name, pwd->pw_name); + endsmbpwent(vp); exit(1); } /* Create a new smb passwd entry and set it to the given password. */ { - int fd; - int new_entry_length; - char *new_entry; - long offpos; - uint16 acct_ctrl = (machine_account ? ACB_WSTRUST : ACB_NORMAL); - - /* The add user write needs to be atomic - so get the fd from - the fp and do a raw write() call. - */ - fd = fileno(fp); - - if((offpos = lseek(fd, 0, SEEK_END)) == -1) { - fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ -Error was %s\n", prog_name, user_name, pfile, strerror(errno)); - fclose(fp); - pw_file_unlock(lockfd); - exit(1); - } + struct smb_passwd new_smb_pwent; - new_entry_length = strlen(user_name) + 1 + 15 + 1 + - 32 + 1 + 32 + 1 + sizeof(fstring) + - 1 + 13 + - 1 + strlen(pwd->pw_dir) + 1 + - strlen(pwd->pw_shell) + 1; - if((new_entry = (char *)malloc( new_entry_length )) == 0) { - fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ -Error was %s\n", prog_name, pwd->pw_name, pfile, strerror(errno)); - pw_file_unlock(lockfd); - fclose(fp); - exit(1); - } + new_smb_pwent.smb_userid = pwd->pw_uid; + new_smb_pwent.smb_name = pwd->pw_name; + new_smb_pwent.smb_passwd = NULL; + new_smb_pwent.smb_nt_passwd = NULL; + new_smb_pwent.acct_ctrl = (machine_account ? ACB_WSTRUST : ACB_NORMAL); - sprintf(new_entry, "%s:%u:", pwd->pw_name, (unsigned)pwd->pw_uid); - p = &new_entry[strlen(new_entry)]; if(disable_user) { - memcpy(p, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 32); - p += 32; - *p++ = ':'; - memcpy(p, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 32); + new_smb_pwent.acct_ctrl |= ACB_DISABLED; } else if (set_no_password) { - memcpy(p, "NO PASSWORDXXXXXXXXXXXXXXXXXXXXX", 32); - p += 32; - *p++ = ':'; - memcpy(p, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 32); + new_smb_pwent.acct_ctrl |= ACB_PWNOTREQ; } else { - for( i = 0; i < 16; i++) - sprintf(&p[i*2], "%02X", new_p16[i]); - p += 32; - *p++ = ':'; - for( i = 0; i < 16; i++) - sprintf(&p[i*2], "%02X", new_nt_p16[i]); + new_smb_pwent.smb_passwd = new_p16; + new_smb_pwent.smb_nt_passwd = new_nt_p16; } - p += 32; - *p++ = ':'; - sprintf(p, "%s:TLC-%08X:%s:%s\n", encode_acct_ctrl(acct_ctrl), - (uint32)time(NULL), pwd->pw_dir, pwd->pw_shell); - if(write(fd, new_entry, strlen(new_entry)) != strlen(new_entry)) { - fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \ -Error was %s\n", prog_name, pwd->pw_name, pfile, strerror(errno)); - /* Remove the entry we just wrote. */ - if(ftruncate(fd, offpos) == -1) { - fprintf(stderr, "%s: ERROR failed to ftruncate file %s. \ -Error was %s. Password file may be corrupt ! Please examine by hand !\n", - prog_name, pwd->pw_name, strerror(errno)); - } - pw_file_unlock(lockfd); - fclose(fp); + + if(add_smbpwd_entry(&new_smb_pwent) == False) { + fprintf(stderr, "%s: Failed to add entry for user %s.\n", + prog_name, pwd->pw_name); + endsmbpwent(vp); exit(1); } - pw_file_unlock(lockfd); - fclose(fp); + endsmbpwent(vp); + printf("%s: Added user %s.\n", prog_name, user_name); exit(0); } } else { @@ -933,84 +509,35 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n", * and the valid last change time. */ - /* Create the 32 byte representation of the new p16 */ if(disable_user) { - memcpy(ascii_p16, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 32); + /* + * This currently won't work as it means changing + * the length of the record. JRA. + */ + smb_pwent->acct_ctrl |= ACB_DISABLED; + smb_pwent->smb_passwd = NULL; + smb_pwent->smb_nt_passwd = NULL; } else if (set_no_password) { - memcpy(ascii_p16, "NO PASSWORDXXXXXXXXXXXXXXXXXXXXX", 32); + /* + * This currently won't work as it means changing + * the length of the record. JRA. + */ + smb_pwent->acct_ctrl |= ACB_PWNOTREQ; + smb_pwent->smb_passwd = NULL; + smb_pwent->smb_nt_passwd = NULL; } else { - for (i = 0; i < 16; i++) { - sprintf(&ascii_p16[i * 2], "%02X", (uchar) new_p16[i]); - } - } - if(got_valid_nt_entry) { - /* Add on the NT md4 hash */ - ascii_p16[32] = ':'; - if(disable_user) { - memcpy(&ascii_p16[33], "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 32); - } else if (set_no_password) { - memcpy(&ascii_p16[33], "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 32); - } else { - for (i = 0; i < 16; i++) { - sprintf(&ascii_p16[(i * 2)+33], "%02X", (uchar) new_nt_p16[i]); - } - } - } - ascii_p16[65] = ':'; - ascii_p16[66] = '\0'; - if(got_valid_last_change_time) { - strcpy(&ascii_p16[66], encode_acct_ctrl(smb_pwent->acct_ctrl)); - sprintf(&ascii_p16[strlen(ascii_p16)], ":TLC-%08X", (uint32)time(NULL)); + smb_pwent->smb_passwd = new_p16; + smb_pwent->smb_nt_passwd = new_nt_p16; } - /* - * Do an atomic write into the file at the position defined by - * seekpos. - */ - pwfd = fileno(fp); - ret = lseek(pwfd, seekpos - 1, SEEK_SET); - if (ret != seekpos - 1) { - err = errno; - fprintf(stderr, "%s: seek fail on file %s.\n", - prog_name, pfile); - errno = err; - perror(prog_name); - pw_file_unlock(lockfd); - fclose(fp); + if(mod_smbpwd_entry(smb_pwent) == False) { + fprintf(stderr, "%s: Failed to modify entry for user %s.\n", + prog_name, pwd->pw_name); + endsmbpwent(vp); exit(1); } - /* Sanity check - ensure the character is a ':' */ - if (read(pwfd, &c, 1) != 1) { - err = errno; - fprintf(stderr, "%s: read fail on file %s.\n", - prog_name, pfile); - errno = err; - perror(prog_name); - pw_file_unlock(lockfd); - fclose(fp); - exit(1); - } - if (c != ':') { - fprintf(stderr, "%s: sanity check on passwd file %s failed.\n", - prog_name, pfile); - pw_file_unlock(lockfd); - fclose(fp); - exit(1); - } - writelen = (got_valid_nt_entry) ? - ( got_valid_last_change_time ? strlen(ascii_p16) : 65) : 32; - if (write(pwfd, ascii_p16, writelen) != writelen) { - err = errno; - fprintf(stderr, "%s: write fail in file %s.\n", - prog_name, pfile); - errno = err; - perror(prog_name); - pw_file_unlock(lockfd); - fclose(fp); - exit(err); - } - pw_file_unlock(lockfd); - fclose(fp); + + endsmbpwent(vp); if(disable_user) printf("User %s disabled.\n", user_name); else if (set_no_password) -- cgit From 002a47de8e0cf03c79cedbed2db52f391001f459 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 23 Apr 1998 20:12:17 +0000 Subject: clientgen.c: Added rap error codes to cli_error, moved from smbpasswd.c password.c: Changed global cli -> pw_cli, removed strtok (bad strtok, bad :-) use in security=server, started to extend security=domain code. smbpasswd.c: Removed rap error code functions. Jeremy. (This used to be commit 0f00b8fce1a5cad7f8c212568fa33f09986e5bd6) --- source3/utils/smbpasswd.c | 66 +++++------------------------------------------ 1 file changed, 6 insertions(+), 60 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index cf9cd54ef3..91ccb609bb 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -19,60 +19,6 @@ #include "includes.h" -/* - * Password changing error codes. - */ - -struct -{ - int err; - char *message; -} pw_change_errmap[] = -{ - {5, "User has insufficient privilege" }, - {86, "The specified password is invalid" }, - {2226, "Operation only permitted on a Primary Domain Controller" }, - {2242, "The password of this user has expired." }, - {2243, "The password of this user cannot change." }, - {2244, "This password cannot be used now (password history conflict)." }, - {2245, "The password is shorter than required." }, - {2246, "The password of this user is too recent to change."}, - {0, NULL} -}; - -/****************************************************** - Return an error message for a remote password change. -*******************************************************/ - -char *get_error_message(struct cli_state *cli) -{ - static fstring error_message; - int errclass; - int errnum; - int i; - - /* - * Errors are of two kinds - smb errors, - * dealt with by cli_errstr, and rap - * errors, whose error code is in cli.error. - */ - - cli_error(cli, &errclass, &errnum); - if(errclass != 0) - return cli_errstr(cli); - - sprintf(error_message, "code %d", cli->error); - - for(i = 0; pw_change_errmap[i].message != NULL; i++) { - if (pw_change_errmap[i].err == cli->error) { - fstrcpy( error_message, pw_change_errmap[i].message); - break; - } - } - - return error_message; -} - /********************************************************* Print command usage on stderr and die. **********************************************************/ @@ -365,13 +311,13 @@ int main(int argc, char **argv) if (!cli_initialise(&cli) || !cli_connect(&cli, remote_machine, &ip)) { fprintf(stderr, "%s: unable to connect to SMB server on machine %s. Error was : %s.\n", - prog_name, remote_machine, get_error_message(&cli) ); + prog_name, remote_machine, cli_errstr(&cli) ); exit(1); } if (!cli_session_request(&cli, remote_machine, 0x20, myname)) { fprintf(stderr, "%s: machine %s rejected the session setup. Error was : %s.\n", - prog_name, remote_machine, get_error_message(&cli) ); + prog_name, remote_machine, cli_errstr(&cli) ); cli_shutdown(&cli); exit(1); } @@ -380,7 +326,7 @@ int main(int argc, char **argv) if (!cli_negprot(&cli)) { fprintf(stderr, "%s: machine %s rejected the negotiate protocol. Error was : %s.\n", - prog_name, remote_machine, get_error_message(&cli) ); + prog_name, remote_machine, cli_errstr(&cli) ); cli_shutdown(&cli); exit(1); } @@ -388,21 +334,21 @@ int main(int argc, char **argv) if (!cli_session_setup(&cli, user_name, old_passwd, strlen(old_passwd), "", 0, "")) { fprintf(stderr, "%s: machine %s rejected the session setup. Error was : %s.\n", - prog_name, remote_machine, get_error_message(&cli) ); + prog_name, remote_machine, cli_errstr(&cli) ); cli_shutdown(&cli); exit(1); } if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) { fprintf(stderr, "%s: machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", - prog_name, remote_machine, get_error_message(&cli) ); + prog_name, remote_machine, cli_errstr(&cli) ); cli_shutdown(&cli); exit(1); } if(!cli_oem_change_password(&cli, user_name, new_passwd, old_passwd)) { fprintf(stderr, "%s: machine %s rejected the password change: Error was : %s.\n", - prog_name, remote_machine, get_error_message(&cli) ); + prog_name, remote_machine, cli_errstr(&cli) ); cli_shutdown(&cli); exit(1); } -- cgit From e7ac86607c80912e55ac7179b100cea22749c16f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 25 Apr 1998 01:12:08 +0000 Subject: This looks like a big change but really isn't. It is changing the global variables "myname" and "myworkgroup" to "global_myname" and "global_myworkgroup" respectively. This is to make it very explicit when we are messing with a global (don't ask - it makes the domain client code much clearer :-). Jeremy. (This used to be commit 866406bfe399cf757c8275093dacd5ce4843afa0) --- source3/utils/smbpasswd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 91ccb609bb..8086253349 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -19,6 +19,8 @@ #include "includes.h" +extern pstring global_myname; + /********************************************************* Print command usage on stderr and die. **********************************************************/ @@ -294,9 +296,8 @@ int main(int argc, char **argv) if(remote_machine != NULL) { struct cli_state cli; struct in_addr ip; - fstring myname; - if(get_myname(myname,NULL) == False) { + if(get_myname(global_myname,NULL) == False) { fprintf(stderr, "%s: unable to get my hostname.\n", prog_name ); exit(1); } @@ -315,7 +316,7 @@ int main(int argc, char **argv) exit(1); } - if (!cli_session_request(&cli, remote_machine, 0x20, myname)) { + if (!cli_session_request(&cli, remote_machine, 0x20, global_myname)) { fprintf(stderr, "%s: machine %s rejected the session setup. Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli) ); cli_shutdown(&cli); -- cgit From 90177708aaf5bf17d689979701b5f0156b8a2fa4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 29 Apr 1998 22:27:26 +0000 Subject: Makefile: Added files to smbpasswd.c. loadparm.c: Patch from tim@quiknet.com for static string problems. server.c: Setup global_myname. smbpass.c: Fix up locking. Add machine_password_delete() call. smbpasswd.c: Added provisional code to add to a domain. lib/rpc/client/cli_login.c: Fixed incorrect cred_hash3 call when setting machine password. lib/rpc/server/srv_netlog.c: Fixed incorrect cred_hash3 call when setting machine password. Jeremy. (This used to be commit 6a7164233e3bf9d6bb57c44a53204068e454ae5c) --- source3/utils/smbpasswd.c | 282 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 266 insertions(+), 16 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 8086253349..338c0d5650 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -19,7 +19,11 @@ #include "includes.h" +extern pstring myhostname; extern pstring global_myname; +extern fstring global_myworkgroup; + +static char *prog_name; /********************************************************* Print command usage on stderr and die. @@ -29,12 +33,224 @@ static void usage(char *name, BOOL is_root) { if(is_root) fprintf(stderr, "Usage is : %s [-D DEBUGLEVEL] [-a] [-d] [-m] [-n] [username] [password]\n\ -%s: [-R ] [-D DEBUGLEVEL] [-r machine] [username] [password]\n%s: [-h]\n", name, name, name); +%s: [-R ] [-D DEBUGLEVEL] [-j DOMAINNAME] [-r machine] [username] [password]\n%s: [-h]\n", name, name, name); else fprintf(stderr, "Usage is : %s [-h] [-D DEBUGLEVEL] [-r machine] [password]\n", name); exit(1); } +/********************************************************* +Join a domain. +**********************************************************/ + +static int setup_account( char *domain, char *remote_machine, + unsigned char orig_machine_passwd_hash[16], + unsigned char new_machine_passwd_hash[16]) +{ + struct in_addr dest_ip; + struct cli_state cli; + + memset(&cli, '\0', sizeof(struct cli_state)); + if(cli_initialise(&cli) == False) { + fprintf(stderr, "%s: unable to initialize client connection.\n", prog_name); + return 1; + } + + if(!resolve_name( remote_machine, &dest_ip)) { + fprintf(stderr, "%s: Can't resolve address for %s\n", prog_name, remote_machine); + return 1; + } + + if (ismyip(dest_ip)) { + fprintf(stderr,"%s: Machine %s is one of our addresses. Cannot add to ourselves.\n", prog_name, + remote_machine); + return 1; + } + + if (!cli_connect(&cli, remote_machine, &dest_ip)) { + fprintf(stderr, "%s: unable to connect to SMB server on \ +machine %s. Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli) ); + return 1; + } + + if (!cli_session_request(&cli, remote_machine, 0x20, global_myname)) { + fprintf(stderr, "%s: machine %s rejected the session setup. \ +Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli) ); + cli_shutdown(&cli); + return 1; + } + + cli.protocol = PROTOCOL_NT1; + + if (!cli_negprot(&cli)) { + fprintf(stderr, "%s: machine %s rejected the negotiate protocol. \ +Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli) ); + cli_shutdown(&cli); + return 1; + } + if (cli.protocol != PROTOCOL_NT1) { + fprintf(stderr, "%s: machine %s didn't negotiate NT protocol.\n", prog_name, remote_machine); + cli_shutdown(&cli); + return 1; + } + + /* + * Do an anonymous session setup. + */ + + if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) { + fprintf(stderr, "%s: machine %s rejected the session setup. \ +Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli) ); + cli_shutdown(&cli); + return 1; + } + + if (!(cli.sec_mode & 1)) { + fprintf(stderr, "%s: machine %s isn't in user level security mode\n", prog_name, remote_machine); + cli_shutdown(&cli); + return 1; + } + + if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) { + fprintf(stderr, "%s: machine %s rejected the tconX on the IPC$ share. \ +Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli) ); + cli_shutdown(&cli); + return 1; + } + + /* + * Ok - we have an anonymous connection to the IPC$ share. + * Now start the NT Domain stuff :-). + */ + + if(cli_nt_session_open(&cli, PIPE_NETLOGON, False) == False) { + fprintf(stderr, "%s: unable to open the domain client session to \ +machine %s. Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli)); + cli_nt_session_close(&cli); + cli_ulogoff(&cli); + cli_shutdown(&cli); + return 1; + } + + if(cli_nt_setup_creds(&cli, orig_machine_passwd_hash) == False) { + fprintf(stderr, "%s: unable to setup the PDC credentials to machine \ +%s. Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli)); + cli_nt_session_close(&cli); + cli_ulogoff(&cli); + cli_shutdown(&cli); + return 1; + } + + if( cli_nt_srv_pwset( &cli,new_machine_passwd_hash ) == False) { + fprintf(stderr, "%s: unable to change password for machine %s in domain \ +%s to Domain controller %s. Error was %s.\n", prog_name, global_myname, domain, remote_machine, + cli_errstr(&cli)); + cli_close(&cli, cli.nt_pipe_fnum); + cli_ulogoff(&cli); + cli_shutdown(&cli); + return 1; + } + + cli_nt_session_close(&cli); + cli_ulogoff(&cli); + cli_shutdown(&cli); + + return 0; +} + +/********************************************************* +Join a domain. +**********************************************************/ + +static int join_domain( char *domain, char *remote) +{ + fstring remote_machine; + char *p; + fstring machine_passwd; + unsigned char machine_passwd_hash[16]; + unsigned char new_machine_passwd_hash[16]; + void *vp; + int ret = 1; + + fstrcpy(remote_machine, remote ? remote : ""); + fstrcpy(machine_passwd, global_myname); + strlower(machine_passwd); + E_md4hash( machine_passwd, machine_passwd_hash); + + generate_random_buffer( new_machine_passwd_hash, 16, True); + + /* Ensure that we are not trying to join a + domain if we are locally set up as a domain + controller. */ + + if(lp_domain_controller() && strequal(lp_workgroup(), domain)) { + fprintf(stderr, "%s: Cannot join domain %s as we already configured as domain controller \ +for that domain.\n", prog_name, domain); + return 1; + } + + /* + * Write the new machine password. + */ + + /* + * Get the machine account password. + */ + if((vp = machine_password_lock( domain, global_myname, True)) == NULL) { + fprintf(stderr, "%s: unable to open the machine account password file for \ +machine %s in domain %s.\n", prog_name, global_myname, domain); + return 1; + } + + if(!set_machine_account_password( vp, new_machine_passwd_hash)) { + fprintf(stderr, "%s: unable to read the machine account password for \ +machine %s in domain %s.\n", prog_name, global_myname, domain); + machine_password_unlock(vp); + return 1; + } + + machine_password_unlock(vp); + + /* + * If we are given a remote machine assume this is the PDC. + */ + + if(remote != NULL) { + strupper(remote_machine); + ret = setup_account( domain, remote_machine, machine_passwd_hash, new_machine_passwd_hash); + if(ret == 0) + printf("%s: Joined domain %s.\n", prog_name, domain); + } else { + /* + * Treat each name in the 'password server =' line as a potential + * PDC/BDC. Contact each in turn and try and authenticate and + * change the machine account password. + */ + + p = lp_passwordserver(); + + if(!*p) + fprintf(stderr, "%s: No password server list given in smb.conf - \ +unable to join domain.\n", prog_name); + + while(p && next_token( &p, remote_machine, LIST_SEP)) { + + strupper(remote_machine); + if(setup_account( domain, remote_machine, machine_passwd_hash, new_machine_passwd_hash) == 0) { + printf("%s: Joined domain %s.\n", prog_name, domain); + return 0; + } + } + } + + if(ret) { + machine_password_delete( domain, global_myname); + fprintf(stderr,"%s: Unable to join domain %s.\n", prog_name, domain); + } + + return ret; +} + /********************************************************* Start here. **********************************************************/ @@ -44,7 +260,6 @@ int main(int argc, char **argv) extern char *optarg; extern int optind; extern int DEBUGLEVEL; - char *prog_name; int real_uid; struct passwd *pwd; fstring old_passwd; @@ -59,11 +274,13 @@ int main(int argc, char **argv) BOOL is_root = False; pstring user_name; char *remote_machine = NULL; - BOOL add_user = False; - BOOL got_new_pass = False; - BOOL machine_account = False; - BOOL disable_user = False; - BOOL set_no_password = False; + BOOL add_user = False; + BOOL got_new_pass = False; + BOOL machine_account = False; + BOOL disable_user = False; + BOOL set_no_password = False; + BOOL joining_domain = False; + char *new_domain = NULL; pstring servicesf = CONFIGFILE; void *vp; @@ -84,7 +301,26 @@ int main(int argc, char **argv) if (!lp_load(servicesf,True,False,False)) { fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n", prog_name, servicesf); } + + if(!get_myname(myhostname,NULL)) { + fprintf(stderr, "%s: unable to get my hostname.\n", prog_name ); + exit(1); + } + + /* + * Set the machine NETBIOS name if not already + * set from the config file. + */ + if (!*global_myname) + { + fstrcpy( global_myname, myhostname ); + p = strchr( global_myname, '.' ); + if (p) + *p = 0; + } + strupper( global_myname ); + codepage_initialise(lp_client_code_page()); /* Get the real uid */ @@ -98,7 +334,7 @@ int main(int argc, char **argv) is_root = (real_uid == 0); - while ((ch = getopt(argc, argv, "adhmnr:R:D:")) != EOF) { + while ((ch = getopt(argc, argv, "adhmnj:r:R:D:")) != EOF) { switch(ch) { case 'a': if(is_root) @@ -139,6 +375,14 @@ int main(int argc, char **argv) } else usage(prog_name, is_root); break; + case 'j': + if(is_root) { + new_domain = optarg; + strupper(new_domain); + joining_domain = True; + } else + usage(prog_name, is_root); + break; case 'h': default: usage(prog_name, is_root); @@ -149,13 +393,24 @@ int main(int argc, char **argv) argv += optind; /* - * Ensure add_user and remote machine are + * Ensure add_user and either remote machine or join domain are * not both set. */ - if(add_user && (remote_machine != NULL)) + + if(add_user && ((remote_machine != NULL) || joining_domain)) + usage(prog_name, True); + + /* + * Deal with joining a domain. + */ + if(joining_domain && argc != 0) usage(prog_name, True); - if( is_root ) { + if(joining_domain) { + return join_domain( new_domain, remote_machine); + } + + if(is_root) { /* * Deal with root - can add a user, but only locally. @@ -297,11 +552,6 @@ int main(int argc, char **argv) struct cli_state cli; struct in_addr ip; - if(get_myname(global_myname,NULL) == False) { - fprintf(stderr, "%s: unable to get my hostname.\n", prog_name ); - exit(1); - } - if(!resolve_name( remote_machine, &ip)) { fprintf(stderr, "%s: unable to find an IP address for machine %s.\n", prog_name, remote_machine ); -- cgit From 3eae1e3f8e53c51f638b1b381085f29feea1c517 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 30 Apr 1998 01:39:22 +0000 Subject: Added patch from Bruce Tenison to allow encrypted passwords to be stored over time, allowing a smbpasswd file migration. Adds new parameter "update encrypted". Will also add to 1.9.18 branch. Docs update to follow. Jeremy. (This used to be commit 5d3e874d780d595415cc27a7f5945fc2e694c3ac) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 338c0d5650..050be7e9b8 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -727,7 +727,7 @@ int main(int argc, char **argv) smb_pwent->smb_nt_passwd = new_nt_p16; } - if(mod_smbpwd_entry(smb_pwent) == False) { + if(mod_smbpwd_entry(smb_pwent,True) == False) { fprintf(stderr, "%s: Failed to modify entry for user %s.\n", prog_name, pwd->pw_name); endsmbpwent(vp); -- cgit From 51f88b4f7c0b87dd4a8932168c512b29a4915045 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 7 May 1998 02:06:53 +0000 Subject: Fixed changed calls to machine password locking code. Jeremy. (This used to be commit dfdc9b0b1e47717b83e54f1cf726e40122cf9baf) --- source3/utils/smbpasswd.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 050be7e9b8..cc883ff51b 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -169,7 +169,6 @@ static int join_domain( char *domain, char *remote) fstring machine_passwd; unsigned char machine_passwd_hash[16]; unsigned char new_machine_passwd_hash[16]; - void *vp; int ret = 1; fstrcpy(remote_machine, remote ? remote : ""); @@ -196,20 +195,20 @@ for that domain.\n", prog_name, domain); /* * Get the machine account password. */ - if((vp = machine_password_lock( domain, global_myname, True)) == NULL) { + if(!machine_password_lock( domain, global_myname, True)) { fprintf(stderr, "%s: unable to open the machine account password file for \ machine %s in domain %s.\n", prog_name, global_myname, domain); return 1; } - if(!set_machine_account_password( vp, new_machine_passwd_hash)) { + if(!set_machine_account_password( new_machine_passwd_hash)) { fprintf(stderr, "%s: unable to read the machine account password for \ machine %s in domain %s.\n", prog_name, global_myname, domain); - machine_password_unlock(vp); + machine_password_unlock(); return 1; } - machine_password_unlock(vp); + machine_password_unlock(); /* * If we are given a remote machine assume this is the PDC. -- cgit From b543829dfceae6781624bebe11a2365c34e2d159 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Thu, 7 May 1998 19:59:32 +0000 Subject: moving gethexpwd into util.c, because it's used in both smbpass.c and ldap.c (This used to be commit abe261b2f5ea7036e7be6230876176d134ef4ee4) --- source3/utils/smbpasswd.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index cc883ff51b..2504727bd6 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -637,13 +637,13 @@ int main(int argc, char **argv) /* * Open the smbpaswd file. */ - vp = startsmbpwent(True); + vp = startsampwent(True); if (!vp && errno == ENOENT) { fp = fopen(lp_smb_passwd_file(), "w"); if (fp) { fprintf(fp, "# Samba SMB password file\n"); fclose(fp); - vp = startsmbpwent(True); + vp = startsampwent(True); } } if (!fp) { @@ -656,12 +656,12 @@ int main(int argc, char **argv) } /* Get the smb passwd entry for this user */ - smb_pwent = getsmbpwnam(user_name); + smb_pwent = getsampwnam(user_name); if (smb_pwent == NULL) { if(add_user == False) { fprintf(stderr, "%s: Failed to find entry for user %s.\n", prog_name, pwd->pw_name); - endsmbpwent(vp); + endsampwent(vp); exit(1); } @@ -684,14 +684,14 @@ int main(int argc, char **argv) new_smb_pwent.smb_nt_passwd = new_nt_p16; } - if(add_smbpwd_entry(&new_smb_pwent) == False) { + if(add_sampwd_entry(&new_smb_pwent) == False) { fprintf(stderr, "%s: Failed to add entry for user %s.\n", prog_name, pwd->pw_name); - endsmbpwent(vp); + endsampwent(vp); exit(1); } - endsmbpwent(vp); + endsampwent(vp); printf("%s: Added user %s.\n", prog_name, user_name); exit(0); } @@ -726,14 +726,14 @@ int main(int argc, char **argv) smb_pwent->smb_nt_passwd = new_nt_p16; } - if(mod_smbpwd_entry(smb_pwent,True) == False) { + if(mod_sampwd_entry(smb_pwent,True) == False) { fprintf(stderr, "%s: Failed to modify entry for user %s.\n", prog_name, pwd->pw_name); - endsmbpwent(vp); + endsampwent(vp); exit(1); } - endsmbpwent(vp); + endsampwent(vp); if(disable_user) printf("User %s disabled.\n", user_name); else if (set_no_password) -- cgit From 3dfc0c847240ac7e12c39f4ed9c31a888949ade1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 11 May 1998 06:38:36 +0000 Subject: changed to use slprintf() instead of sprintf() just about everywhere. I've implemented slprintf() as a bounds checked sprintf() using mprotect() and a non-writeable page. This should prevent any sprintf based security holes. (This used to be commit ee09e9dadb69aaba5a751dd20ccc6d587d841bd6) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 2504727bd6..77dcfb0d43 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -174,7 +174,7 @@ static int join_domain( char *domain, char *remote) fstrcpy(remote_machine, remote ? remote : ""); fstrcpy(machine_passwd, global_myname); strlower(machine_passwd); - E_md4hash( machine_passwd, machine_passwd_hash); + E_md4hash((uchar *)machine_passwd, machine_passwd_hash); generate_random_buffer( new_machine_passwd_hash, 16, True); -- cgit From f004d84f683673b7cb167320e3e78a3fcefdfd07 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Mon, 11 May 1998 15:56:01 +0000 Subject: ldap back-end database development Makefile: created PASSBD_OBJ group includes.h: added #ifdef USE_LDAP to #include headers ldap.c: - renamed "_machine" to "_trust" everywhere. - added sam_passwd support routines - removed get_ldappwd_entry function: replaced with get_sampwd_entry - removed getldappwnam/uid: replaced with getsampwnam/uid - other messing about bits which are probably going to annoy the hell out of jean-francois (sorry!) mkproto.awk: - added stuff to wrap ldap.c protos with #ifdef USE_LDAP - added uid_t and gid_t return results to the prototype generation passdb.c: - created getsam21pwent, add_sam21pwd_entry, mod_sam21pwd_entry. - modified getsampwnam/uid and created getsam21pwnam/rid functions to replace the local get_smbpwd_entry() and get_ldappwd_entry() functions, which jeremy didn't like anyway because they were dual-purpose. - added utility routines which are or may be useful to all the password database routines. password.c: - renamed "machine_" to "trust_" everywhere. smbpass.c: - removed get_smbpwd_entry function: replaced it with get_sampwd_entry functions in passdb.c - moved code that decoded acct_ctrl into passdb.c - moved encode_acct_ctrl into passdb.c - removed getsmbpwnam/uid: replaced with getsampwnam/uid - renamed "machine_" to "trust_" everywhere. smbpasswd.c: - renamed "machine_" to "trust_" everywhere. util.c: - moved gethexpwd function into passdb.c lib/rpc/server/srv_util.c: - moved user_rid_to_uid, group_rid_to_rid etc etc into passdb.c (This used to be commit 673ab50c4c2c25db355d90efde3a6bfbb4d8369e) --- source3/utils/smbpasswd.c | 48 +++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 77dcfb0d43..d58d6396c1 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -44,8 +44,8 @@ Join a domain. **********************************************************/ static int setup_account( char *domain, char *remote_machine, - unsigned char orig_machine_passwd_hash[16], - unsigned char new_machine_passwd_hash[16]) + unsigned char orig_trust_passwd_hash[16], + unsigned char new_trust_passwd_hash[16]) { struct in_addr dest_ip; struct cli_state cli; @@ -132,7 +132,7 @@ machine %s. Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli)); return 1; } - if(cli_nt_setup_creds(&cli, orig_machine_passwd_hash) == False) { + if(cli_nt_setup_creds(&cli, orig_trust_passwd_hash) == False) { fprintf(stderr, "%s: unable to setup the PDC credentials to machine \ %s. Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli)); cli_nt_session_close(&cli); @@ -141,7 +141,7 @@ machine %s. Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli)); return 1; } - if( cli_nt_srv_pwset( &cli,new_machine_passwd_hash ) == False) { + if( cli_nt_srv_pwset( &cli,new_trust_passwd_hash ) == False) { fprintf(stderr, "%s: unable to change password for machine %s in domain \ %s to Domain controller %s. Error was %s.\n", prog_name, global_myname, domain, remote_machine, cli_errstr(&cli)); @@ -166,17 +166,17 @@ static int join_domain( char *domain, char *remote) { fstring remote_machine; char *p; - fstring machine_passwd; - unsigned char machine_passwd_hash[16]; - unsigned char new_machine_passwd_hash[16]; + fstring trust_passwd; + unsigned char trust_passwd_hash[16]; + unsigned char new_trust_passwd_hash[16]; int ret = 1; fstrcpy(remote_machine, remote ? remote : ""); - fstrcpy(machine_passwd, global_myname); - strlower(machine_passwd); - E_md4hash((uchar *)machine_passwd, machine_passwd_hash); + fstrcpy(trust_passwd, global_myname); + strlower(trust_passwd); + E_md4hash( (uchar *)trust_passwd, trust_passwd_hash); - generate_random_buffer( new_machine_passwd_hash, 16, True); + generate_random_buffer( new_trust_passwd_hash, 16, True); /* Ensure that we are not trying to join a domain if we are locally set up as a domain @@ -195,20 +195,20 @@ for that domain.\n", prog_name, domain); /* * Get the machine account password. */ - if(!machine_password_lock( domain, global_myname, True)) { + if(!trust_password_lock( domain, global_myname, True)) { fprintf(stderr, "%s: unable to open the machine account password file for \ machine %s in domain %s.\n", prog_name, global_myname, domain); return 1; } - if(!set_machine_account_password( new_machine_passwd_hash)) { + if(!set_trust_account_password( new_trust_passwd_hash)) { fprintf(stderr, "%s: unable to read the machine account password for \ machine %s in domain %s.\n", prog_name, global_myname, domain); - machine_password_unlock(); + trust_password_unlock(); return 1; } - machine_password_unlock(); + trust_password_unlock(); /* * If we are given a remote machine assume this is the PDC. @@ -216,7 +216,7 @@ machine %s in domain %s.\n", prog_name, global_myname, domain); if(remote != NULL) { strupper(remote_machine); - ret = setup_account( domain, remote_machine, machine_passwd_hash, new_machine_passwd_hash); + ret = setup_account( domain, remote_machine, trust_passwd_hash, new_trust_passwd_hash); if(ret == 0) printf("%s: Joined domain %s.\n", prog_name, domain); } else { @@ -235,7 +235,7 @@ unable to join domain.\n", prog_name); while(p && next_token( &p, remote_machine, LIST_SEP)) { strupper(remote_machine); - if(setup_account( domain, remote_machine, machine_passwd_hash, new_machine_passwd_hash) == 0) { + if(setup_account( domain, remote_machine, trust_passwd_hash, new_trust_passwd_hash) == 0) { printf("%s: Joined domain %s.\n", prog_name, domain); return 0; } @@ -243,7 +243,7 @@ unable to join domain.\n", prog_name); } if(ret) { - machine_password_delete( domain, global_myname); + trust_password_delete( domain, global_myname); fprintf(stderr,"%s: Unable to join domain %s.\n", prog_name, domain); } @@ -275,7 +275,7 @@ int main(int argc, char **argv) char *remote_machine = NULL; BOOL add_user = False; BOOL got_new_pass = False; - BOOL machine_account = False; + BOOL trust_account = False; BOOL disable_user = False; BOOL set_no_password = False; BOOL joining_domain = False; @@ -370,7 +370,7 @@ int main(int argc, char **argv) usage(prog_name, is_root); case 'm': if(is_root) { - machine_account = True; + trust_account = True; } else usage(prog_name, is_root); break; @@ -433,7 +433,7 @@ int main(int argc, char **argv) if(*user_name) { - if(machine_account) { + if(trust_account) { int username_len = strlen(user_name); if(username_len >= sizeof(pstring) - 1) { fprintf(stderr, "%s: machine account name too long.\n", user_name); @@ -500,7 +500,7 @@ int main(int argc, char **argv) * the machinename as the password. */ - if(add_user && machine_account) { + if(add_user && trust_account) { got_new_pass = True; strncpy(new_passwd, user_name, sizeof(fstring)); new_passwd[sizeof(fstring)-1] = '\0'; @@ -611,7 +611,7 @@ int main(int argc, char **argv) * Check for a machine account. */ - if(machine_account && !pwd) { + if(trust_account && !pwd) { fprintf(stderr, "%s: User %s does not exist in system password file \ (usually /etc/passwd). Cannot add machine account without a valid system user.\n", prog_name, user_name); @@ -673,7 +673,7 @@ int main(int argc, char **argv) new_smb_pwent.smb_name = pwd->pw_name; new_smb_pwent.smb_passwd = NULL; new_smb_pwent.smb_nt_passwd = NULL; - new_smb_pwent.acct_ctrl = (machine_account ? ACB_WSTRUST : ACB_NORMAL); + new_smb_pwent.acct_ctrl = (trust_account ? ACB_WSTRUST : ACB_NORMAL); if(disable_user) { new_smb_pwent.acct_ctrl |= ACB_DISABLED; -- cgit From 05eb22f77c21f8027e64b0caddefa4d9f030f95f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 11 May 1998 17:53:37 +0000 Subject: reply.c: Added code to not overwrite sesssetup_user when in share level security and null session setup done. smbpasswd.c: Fix from Gerald Carter to fix incorrect use of pointer. Jeremy. (This used to be commit 69ace0760986a6e892cd5b25ca85930b65e38c45) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index d58d6396c1..5060d80d3d 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -646,7 +646,7 @@ int main(int argc, char **argv) vp = startsampwent(True); } } - if (!fp) { + if (!vp) { err = errno; fprintf(stderr, "%s: Failed to open password file %s.\n", prog_name, lp_smb_passwd_file()); -- cgit From f888868f46a5418bac9ab528497136c152895305 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 May 1998 00:55:32 +0000 Subject: This is a security audit change of the main source. It removed all ocurrences of the following functions : sprintf strcpy strcat The replacements are slprintf, safe_strcpy and safe_strcat. It should not be possible to use code in Samba that uses sprintf, strcpy or strcat, only the safe_equivalents. Once Andrew has fixed the slprintf implementation then this code will be moved back to the 1.9.18 code stream. Jeremy. (This used to be commit 2d774454005f0b54e5684cf618da7060594dfcbb) --- source3/utils/make_printerdef.c | 92 ++++++++++++++++++++-------------------- source3/utils/make_smbcodepage.c | 4 +- source3/utils/nmblookup.c | 4 +- source3/utils/smbpasswd.c | 4 +- source3/utils/status.c | 8 ++-- source3/utils/testparm.c | 4 +- source3/utils/torture.c | 10 ++--- 7 files changed, 63 insertions(+), 63 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index 0c3cb633af..4745127175 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -28,9 +28,9 @@ char *files_to_copy; char *driverfile, *datafile, *helpfile, *languagemonitor, *datatype; -char buffer[50][255]; -char sbuffer[50][255]; -char sub_dir[50][2][255]; +char buffer[50][sizeof(pstring)]; +char sbuffer[50][sizeof(pstring)]; +char sub_dir[50][2][sizeof(pstring)]; void usage(char *name) { @@ -42,31 +42,31 @@ char *myfgets(char *s, int n, FILE *stream) char *LString1; char *LString2; char *temp; - char String[255]; - char NewString[255]; + pstring String; + pstring NewString; int i; fgets(s,n,stream); while ((LString1 = strchr(s,'%')) != NULL) { if (!(LString2 = strchr(LString1+1,'%'))) break; *LString2 = '\0'; - strcpy(String,LString1+1); + pstrcpy(String,LString1+1); i = 0; while(*sbuffer[i]!='\0') { if (strncmp(sbuffer[i],String,strlen(String))==0) { - strcpy(String,sbuffer[i]); + pstrcpy(String,sbuffer[i]); if ((temp = strchr(String,'=')) != NULL) ++temp; - strcpy(String,temp); + pstrcpy(String,temp); break; } i++; } *LString1 = '\0'; - strcpy(NewString,s); - strcat(NewString,String); - strcat(NewString,LString2+1); - strcpy(s, NewString); + pstrcpy(NewString,s); + pstrcat(NewString,String); + pstrcat(NewString,LString2+1); + pstrcpy(s, NewString); } return(s); } @@ -82,15 +82,15 @@ char *scan(char *chaine,char **entry) char *temp; int i=0; - *entry=(char *)malloc(255*sizeof(char)); - value=(char *)malloc(255*sizeof(char)); - strcpy(*entry,chaine); + *entry=(char *)malloc(sizeof(pstring)); + value=(char *)malloc(sizeof(pstring)); + pstrcpy(*entry,chaine); temp=chaine; while( temp[i]!='=' && temp[i]!='\0') { i++; } (*entry)[i]='\0'; - strcpy(value,temp+i+1); + pstrcpy(value,temp+i+1); return (value); } @@ -107,12 +107,12 @@ void build_subdir(void) #endif if (strcmp(data,"11")==0) { - strcpy(sub_dir[i][0],entry); - strcpy(sub_dir[i][1],""); + pstrcpy(sub_dir[i][0],entry); + pstrcpy(sub_dir[i][1],""); } if (strcmp(data,"23")==0) { - strcpy(sub_dir[i][0],entry); - strcpy(sub_dir[i][1],"color\\"); + pstrcpy(sub_dir[i][0],entry); + pstrcpy(sub_dir[i][1],"color\\"); } #ifdef DEBUGIT fprintf(stderr,"\tsubdir %s:%s\n",sub_dir[i][0],sub_dir[i][1]); @@ -131,12 +131,12 @@ void lookup_strings(FILE *fichier) int found=0,pointeur=0,i=0; char *temp,*temp2; - temp=(char *)malloc(255*sizeof(char)); - temp2=(char *)malloc(255*sizeof(char)); + temp=(char *)malloc(sizeof(pstring)); + temp2=(char *)malloc(sizeof(pstring)); *sbuffer[0]='\0'; - strcpy(temp2,"[Strings]"); + pstrcpy(temp2,"[Strings]"); rewind(fichier); #ifdef DEBUGIT @@ -158,7 +158,7 @@ void lookup_strings(FILE *fichier) *sbuffer[pointeur]='\0'; } else { - strcpy(sbuffer[pointeur],temp); + pstrcpy(sbuffer[pointeur],temp); i=strlen(sbuffer[pointeur])-1; while (sbuffer[pointeur][i]=='\r' || sbuffer[pointeur][i]=='\n') sbuffer[pointeur][i--]='\0'; @@ -181,14 +181,14 @@ void lookup_entry(FILE *fichier,char *chaine) int found=0,pointeur=0,i=0; char *temp,*temp2; - temp=(char *)malloc(255*sizeof(char)); - temp2=(char *)malloc(255*sizeof(char)); + temp=(char *)malloc(sizeof(pstring)); + temp2=(char *)malloc(sizeof(pstring)); *buffer[0]='\0'; - strcpy(temp2,"["); - strcat(temp2,chaine); - strcat(temp2,"]"); + pstrcpy(temp2,"["); + pstrcat(temp2,chaine); + pstrcat(temp2,"]"); rewind(fichier); #ifdef DEBUGIT @@ -210,7 +210,7 @@ void lookup_entry(FILE *fichier,char *chaine) *buffer[pointeur]='\0'; } else { - strcpy(buffer[pointeur],temp); + pstrcpy(buffer[pointeur],temp); i=strlen(buffer[pointeur])-1; while (buffer[pointeur][i]=='\r' || buffer[pointeur][i]=='\n') buffer[pointeur][i--]='\0'; @@ -232,9 +232,9 @@ char *find_desc(FILE *fichier,char *text) int found=0; - chaine=(char *)malloc(255*sizeof(char)); - long_desc=(char *)malloc(40*sizeof(char)); - short_desc=(char *)malloc(40*sizeof(char)); + chaine=(char *)malloc(sizeof(pstring)); + long_desc=(char *)malloc(sizeof(pstring)); + short_desc=(char *)malloc(sizeof(pstring)); if (!chaine || !long_desc || !short_desc) { fprintf(stderr,"Unable to malloc memory\n"); exit(1); @@ -267,7 +267,7 @@ char *find_desc(FILE *fichier,char *text) free(chaine); if (!found || !crap) return(NULL); while(*crap==' ') crap++; - strcpy(short_desc,crap); + pstrcpy(short_desc,crap); return(short_desc); } @@ -276,7 +276,7 @@ void scan_copyfiles(FILE *fichier, char *chaine) char *part; char *mpart; int i; - char direc[255]; + pstring direc; #ifdef DEBUGIT fprintf(stderr,"In scan_copyfiles Lookup up of %s\n",chaine); #endif @@ -290,19 +290,19 @@ void scan_copyfiles(FILE *fichier, char *chaine) */ if (*part=='@') { if (strlen(files_to_copy) != 0) - strcat(files_to_copy,","); - strcat(files_to_copy,&part[1]); + pstrcat(files_to_copy,","); + pstrcat(files_to_copy,&part[1]); fprintf(stderr,"%s\n",&part[1]); } else { lookup_entry(fichier,part); i=0; - strcpy(direc,""); + pstrcpy(direc,""); while (*sub_dir[i][0]!='\0') { #ifdef DEBUGIT fprintf(stderr,"\tsubdir %s:%s\n",sub_dir[i][0],sub_dir[i][1]); #endif if (strcmp(sub_dir[i][0],part)==0) - strcpy(direc,sub_dir[i][1]); + pstrcpy(direc,sub_dir[i][1]); i++; } i=0; @@ -331,7 +331,7 @@ void scan_copyfiles(FILE *fichier, char *chaine) part = strchr(buffer[i],','); if (part) { if ((mpart = strrchr(part+1,','))!=NULL) { - strcpy(buffer[i],mpart+1); + pstrcpy(buffer[i],mpart+1); } else *part = '\0'; while (--part > buffer[i]) @@ -340,9 +340,9 @@ void scan_copyfiles(FILE *fichier, char *chaine) } } if (strlen(files_to_copy) != 0) - strcat(files_to_copy,","); - strcat(files_to_copy,direc); - strcat(files_to_copy,buffer[i]); + pstrcat(files_to_copy,","); + pstrcat(files_to_copy,direc); + pstrcat(files_to_copy,buffer[i]); fprintf(stderr,"%s%s\n",direc,buffer[i]); i++; } @@ -364,8 +364,8 @@ void scan_short_desc(FILE *fichier, char *short_desc) helpfile=0; languagemonitor=0; datatype="RAW"; - chaine=(char *)malloc(255*sizeof(char)); - temp=(char *)malloc(255*sizeof(char)); + chaine=(char *)malloc(sizeof(pstring)); + temp=(char *)malloc(sizeof(pstring)); driverfile=short_desc; datafile=short_desc; @@ -422,7 +422,7 @@ void scan_short_desc(FILE *fichier, char *short_desc) if (languagemonitor) { temp = strtok(languagemonitor,","); if (*temp == '"') ++temp; - strcpy(languagemonitor,temp); + pstrcpy(languagemonitor,temp); if ((temp = strchr(languagemonitor,'"'))!=NULL) *temp = '\0'; } diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c index 409d199640..ce45a7bc60 100644 --- a/source3/utils/make_smbcodepage.c +++ b/source3/utils/make_smbcodepage.c @@ -64,7 +64,7 @@ void read_line( char **buf, char *line_buf, int size) int clean_data( char **buf, uint32 *size) { - char linebuf[512]; + pstring linebuf; char *p = *buf; int num_lines = 0; char *newbuf = (char *)malloc( *size + 1); @@ -94,7 +94,7 @@ int clean_data( char **buf, uint32 *size) if(*cp == '\0') continue; - strcpy(newbuf_p, cp); + pstrcpy(newbuf_p, cp); num_lines++; newbuf_p += (strlen(newbuf_p) + 1); } diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 4c9132ee75..59d5771c5d 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -196,7 +196,7 @@ int main(int argc,char *argv[]) if(lookup_by_ip) { - strcpy(lookup,"*"); + fstrcpy(lookup,"*"); ip = *interpret_addr2(argv[i]); printf("Looking up status of %s\n",inet_ntoa(ip)); name_status(ServerFD,lookup,lookup_type,True,ip,NULL,NULL,NULL); @@ -206,7 +206,7 @@ int main(int argc,char *argv[]) if (find_master) { if (*lookup == '-') { - strcpy(lookup,"\01\02__MSBROWSE__\02"); + fstrcpy(lookup,"\01\02__MSBROWSE__\02"); lookup_type = 1; } else { lookup_type = 0x1d; diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 5060d80d3d..3737d82042 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -345,7 +345,7 @@ int main(int argc, char **argv) if(is_root) { disable_user = True; got_new_pass = True; - strcpy(new_passwd, "XXXXXX"); + fstrcpy(new_passwd, "XXXXXX"); } else usage(prog_name, is_root); break; @@ -356,7 +356,7 @@ int main(int argc, char **argv) if(is_root) { set_no_password = True; got_new_pass = True; - strcpy(new_passwd, "NO PASSWORD"); + fstrcpy(new_passwd, "NO PASSWORD"); } else usage(prog_name, is_root); case 'r': diff --git a/source3/utils/status.c b/source3/utils/status.c index 40bafbe0c2..d4753d589d 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -139,7 +139,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) processes_only = 1; break; case 's': - strcpy(servicesf, optarg); + pstrcpy(servicesf, optarg); break; case 'u': /* added by OH */ Ucrit_addUsername(optarg); /* added by OH */ @@ -162,10 +162,10 @@ static void print_share_mode(share_mode_entry *e, char *fname) printf("lockdir = %s\n", *lp_lockdir() ? lp_lockdir() : "NULL"); } - strcpy(fname,lp_lockdir()); + pstrcpy(fname,lp_lockdir()); standard_sub_basic(fname); trim_string(fname,"","/"); - strcat(fname,"/STATUS..LCK"); + pstrcat(fname,"/STATUS..LCK"); f = fopen(fname,"r"); if (!f) { @@ -281,7 +281,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) /* added by OH */ void Ucrit_addUsername(pstring username) { - strcpy(Ucrit_username, username); + pstrcpy(Ucrit_username, username); if(strlen(Ucrit_username) > 0) Ucrit_IsActive = 1; } diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 83d4d7fbb5..f37c7376fd 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -52,9 +52,9 @@ extern pstring myhostname; charset_initialise(); if (argc < 2) - strcpy(configfile,CONFIGFILE); + pstrcpy(configfile,CONFIGFILE); else - strcpy(configfile,argv[1]); + pstrcpy(configfile,argv[1]); dbf = stdout; DEBUGLEVEL = 2; diff --git a/source3/utils/torture.c b/source3/utils/torture.c index ede801afe9..1abfee0541 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -134,7 +134,7 @@ static BOOL rw_torture(struct cli_state *c, int numops) if (i % 10 == 0) { printf("%d\r", i); fflush(stdout); } - sprintf(fname,"\\torture.%u", n); + slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n); if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) { return False; @@ -860,7 +860,7 @@ static void create_procs(int nprocs, int numops) get_myname(myname,NULL); if (*username == 0 && getenv("LOGNAME")) { - strcpy(username,getenv("LOGNAME")); + pstrcpy(username,getenv("LOGNAME")); } argc--; @@ -888,11 +888,11 @@ static void create_procs(int nprocs, int numops) fstrcpy(myname, optarg); break; case 'U': - strcpy(username,optarg); + pstrcpy(username,optarg); p = strchr(username,'%'); if (p) { *p = 0; - strcpy(password, p+1); + pstrcpy(password, p+1); gotpass = 1; } break; @@ -906,7 +906,7 @@ static void create_procs(int nprocs, int numops) while (!gotpass) { p = getpass("Password:"); if (p) { - strcpy(password, p); + pstrcpy(password, p); gotpass = 1; } } -- cgit From ee9a61841ac10d32d869a3893bc690c66f2bb1bb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 May 1998 22:11:24 +0000 Subject: includes.h: SunOS doesn't have strcasecmp, solaris versions prior to 2.6 don't have vsnprintf. locking_slow.c: slight tidy. make_smbcodepage.c: Use safe_strcpy instead of pstrcpy. nmbd_winsserver.c: Use pstrcpy instead of fstrcpy. smbmount.c: Fixed reported bug. util.c: Removed old fstrcpy/fstrcat functions. Jeremy. (This used to be commit f257d2e4bafd3944cca737699913a8d868279ca6) --- source3/utils/make_smbcodepage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c index ce45a7bc60..b0970a7d25 100644 --- a/source3/utils/make_smbcodepage.c +++ b/source3/utils/make_smbcodepage.c @@ -94,7 +94,7 @@ int clean_data( char **buf, uint32 *size) if(*cp == '\0') continue; - pstrcpy(newbuf_p, cp); + safe_strcpy(newbuf_p, cp, *size - (newbuf_p - newbuf)); num_lines++; newbuf_p += (strlen(newbuf_p) + 1); } -- cgit From 94a39bd9a2bfd3c87596cc1311860b7f840b1634 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 15 May 1998 23:10:46 +0000 Subject: Change getpwnam to Get_Pwnam(xx , True) to allow lazy matching in /etc/passwd. Fix from "Mike Black" . Jeremy. (This used to be commit 0146883f8568de4642087bb769b0381c3217d792) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 3737d82042..35283b824b 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -451,7 +451,7 @@ int main(int argc, char **argv) * values for a machine account (it doesn't * exist in /etc/passwd). */ - if((pwd = getpwnam(user_name)) == NULL) { + if((pwd = Get_Pwnam(user_name, True)) == NULL) { fprintf(stderr, "%s: User \"%s\" was not found in system password file.\n", prog_name, user_name); exit(1); -- cgit From ffab54750f0eec202895670dd9293ee4aa3eb475 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 18 May 1998 21:30:57 +0000 Subject: chgpasswd.c: Changed back to getsmb... from getsam... ldap.c: Stoped dummy_function being prototyped. loadparm.c: Fixed slprintf sizes. nisppass.c: Fixed safe_strcpy sizes. nmbd_processlogon.c: Changed back to getsmb... from getsam... nttrans.c: Just a dump of new code. passdb.c: Moved stuff around a lot - stopped any lookups by rid. This needs to be indirected through a function table (soon). password.c: Changed back to getsmb... from getsam... reply.c: Changed back to getsmb... from getsam... slprintf.c: Fixed prototype problems. smb.h: Fixed prototype problems. smbpass.c: Changed to getsmbfile.... smbpasswd.c: Changed back to getsmb... from getsam... lib/rpc/server/srv_netlog.c: Changed back to getsmb... from getsam... lib/rpc/server/srv_samr.c: Fixed rid lookup - use uid or gid lookup. lib/rpc/server/srv_util.c: Changed back to getsmb... from getsam... Jeremy. (This used to be commit 7d332b2493d2089d09521250fc9b72d8953307c0) --- source3/utils/smbpasswd.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 35283b824b..c01f29f94f 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -637,13 +637,13 @@ int main(int argc, char **argv) /* * Open the smbpaswd file. */ - vp = startsampwent(True); + vp = startsmbpwent(True); if (!vp && errno == ENOENT) { fp = fopen(lp_smb_passwd_file(), "w"); if (fp) { fprintf(fp, "# Samba SMB password file\n"); fclose(fp); - vp = startsampwent(True); + vp = startsmbpwent(True); } } if (!vp) { @@ -656,12 +656,12 @@ int main(int argc, char **argv) } /* Get the smb passwd entry for this user */ - smb_pwent = getsampwnam(user_name); + smb_pwent = getsmbpwnam(user_name); if (smb_pwent == NULL) { if(add_user == False) { fprintf(stderr, "%s: Failed to find entry for user %s.\n", prog_name, pwd->pw_name); - endsampwent(vp); + endsmbpwent(vp); exit(1); } @@ -684,14 +684,14 @@ int main(int argc, char **argv) new_smb_pwent.smb_nt_passwd = new_nt_p16; } - if(add_sampwd_entry(&new_smb_pwent) == False) { + if(add_smbpwd_entry(&new_smb_pwent) == False) { fprintf(stderr, "%s: Failed to add entry for user %s.\n", prog_name, pwd->pw_name); - endsampwent(vp); + endsmbpwent(vp); exit(1); } - endsampwent(vp); + endsmbpwent(vp); printf("%s: Added user %s.\n", prog_name, user_name); exit(0); } @@ -726,14 +726,14 @@ int main(int argc, char **argv) smb_pwent->smb_nt_passwd = new_nt_p16; } - if(mod_sampwd_entry(smb_pwent,True) == False) { + if(mod_smbpwd_entry(smb_pwent,True) == False) { fprintf(stderr, "%s: Failed to modify entry for user %s.\n", prog_name, pwd->pw_name); - endsampwent(vp); + endsmbpwent(vp); exit(1); } - endsampwent(vp); + endsmbpwent(vp); if(disable_user) printf("User %s disabled.\n", user_name); else if (set_no_password) -- cgit From 118827376f8ccedb455e81b7d2b3bff029cde457 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 18 May 1998 23:57:28 +0000 Subject: Abstracted all the crappy password interfaces through an indirect function table, selectable at compile time. This should make the code that implements all the password functions much cleaner, as it's now very clear exactly what a particular password database needs to provide to Samba. Jeremy. (This used to be commit 27ca536ad974242524c12f7100e419d9e7f9647f) --- source3/utils/smbpasswd.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index c01f29f94f..8e744c8641 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -297,8 +297,14 @@ int main(int argc, char **argv) charset_initialise(); + if(!initialize_password_db()) { + fprintf(stderr, "%s: Can't setup password database vectors.\n", prog_name); + exit(1); + } + if (!lp_load(servicesf,True,False,False)) { fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n", prog_name, servicesf); + exit(1); } if(!get_myname(myhostname,NULL)) { -- cgit From d1d010a99526020f834f4a909bd24ce1c8f7993a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 22 May 1998 01:51:14 +0000 Subject: Put a do_global_tests() function that will be expanded to test all the heuristics we know about for validating smb.conf file. Jeremy. (This used to be commit 76dec5b04e9c3b4b727bf9a44d31acf32b4b6b4c) --- source3/utils/testparm.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index f37c7376fd..c980fd1758 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -40,6 +40,22 @@ extern FILE *dbf; extern int DEBUGLEVEL; extern pstring myhostname; +/*********************************************** + Here we do a set of 'hard coded' checks for bad + configuration settings. +************************************************/ + +void do_global_checks(void) +{ + if(lp_security() > SEC_SHARE && lp_revalidate(-1)) + printf("WARNING: the 'revalidate' parameter is ignored in all but \ +'security=share' mode.\n"); + + if( lp_wins_support() && *lp_wins_server() ) + printf("ERROR: both 'wins support = true' and 'wins server = ' \ +cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); +} + int main(int argc, char *argv[]) { pstring configfile; @@ -76,6 +92,8 @@ extern pstring myhostname; printf("Loaded services file OK.\n"); + do_global_checks(); + for (s=0;s<1000;s++) if (VALID_SNUM(s)) if (strlen(lp_servicename(s)) > 8) { -- cgit From 9bd7e1e8870da87ea6f3c9e78933beeb08b65a0c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 27 May 1998 00:30:52 +0000 Subject: loadparm.c: Added machine password timeout parameter - set to 7 days be default. password.c: Added code to tell server.c when machine password needs changing. server.c: Change machine password in idle cycles if it needs it. smbpassfile.c: Fixed up length calculations for machine password file. smbpasswd.c: Moved domain joining code/machine password changing code. lib/rpc/client/cli_netlogon.c: And this is where it now lives. Jeremy. (This used to be commit b8fedca6191de96159df0d1d17082d82e8e44773) --- source3/utils/smbpasswd.c | 192 +++++++--------------------------------------- 1 file changed, 27 insertions(+), 165 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 8e744c8641..c9742fc498 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -43,157 +43,30 @@ static void usage(char *name, BOOL is_root) Join a domain. **********************************************************/ -static int setup_account( char *domain, char *remote_machine, - unsigned char orig_trust_passwd_hash[16], - unsigned char new_trust_passwd_hash[16]) -{ - struct in_addr dest_ip; - struct cli_state cli; - - memset(&cli, '\0', sizeof(struct cli_state)); - if(cli_initialise(&cli) == False) { - fprintf(stderr, "%s: unable to initialize client connection.\n", prog_name); - return 1; - } - - if(!resolve_name( remote_machine, &dest_ip)) { - fprintf(stderr, "%s: Can't resolve address for %s\n", prog_name, remote_machine); - return 1; - } - - if (ismyip(dest_ip)) { - fprintf(stderr,"%s: Machine %s is one of our addresses. Cannot add to ourselves.\n", prog_name, - remote_machine); - return 1; - } - - if (!cli_connect(&cli, remote_machine, &dest_ip)) { - fprintf(stderr, "%s: unable to connect to SMB server on \ -machine %s. Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli) ); - return 1; - } - - if (!cli_session_request(&cli, remote_machine, 0x20, global_myname)) { - fprintf(stderr, "%s: machine %s rejected the session setup. \ -Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli) ); - cli_shutdown(&cli); - return 1; - } - - cli.protocol = PROTOCOL_NT1; - - if (!cli_negprot(&cli)) { - fprintf(stderr, "%s: machine %s rejected the negotiate protocol. \ -Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli) ); - cli_shutdown(&cli); - return 1; - } - if (cli.protocol != PROTOCOL_NT1) { - fprintf(stderr, "%s: machine %s didn't negotiate NT protocol.\n", prog_name, remote_machine); - cli_shutdown(&cli); - return 1; - } - - /* - * Do an anonymous session setup. - */ - - if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) { - fprintf(stderr, "%s: machine %s rejected the session setup. \ -Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli) ); - cli_shutdown(&cli); - return 1; - } - - if (!(cli.sec_mode & 1)) { - fprintf(stderr, "%s: machine %s isn't in user level security mode\n", prog_name, remote_machine); - cli_shutdown(&cli); - return 1; - } - - if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) { - fprintf(stderr, "%s: machine %s rejected the tconX on the IPC$ share. \ -Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli) ); - cli_shutdown(&cli); - return 1; - } - - /* - * Ok - we have an anonymous connection to the IPC$ share. - * Now start the NT Domain stuff :-). - */ - - if(cli_nt_session_open(&cli, PIPE_NETLOGON, False) == False) { - fprintf(stderr, "%s: unable to open the domain client session to \ -machine %s. Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli)); - cli_nt_session_close(&cli); - cli_ulogoff(&cli); - cli_shutdown(&cli); - return 1; - } - - if(cli_nt_setup_creds(&cli, orig_trust_passwd_hash) == False) { - fprintf(stderr, "%s: unable to setup the PDC credentials to machine \ -%s. Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli)); - cli_nt_session_close(&cli); - cli_ulogoff(&cli); - cli_shutdown(&cli); - return 1; - } - - if( cli_nt_srv_pwset( &cli,new_trust_passwd_hash ) == False) { - fprintf(stderr, "%s: unable to change password for machine %s in domain \ -%s to Domain controller %s. Error was %s.\n", prog_name, global_myname, domain, remote_machine, - cli_errstr(&cli)); - cli_close(&cli, cli.nt_pipe_fnum); - cli_ulogoff(&cli); - cli_shutdown(&cli); - return 1; - } - - cli_nt_session_close(&cli); - cli_ulogoff(&cli); - cli_shutdown(&cli); - - return 0; -} - -/********************************************************* -Join a domain. -**********************************************************/ - static int join_domain( char *domain, char *remote) { - fstring remote_machine; - char *p; + pstring remote_machine; fstring trust_passwd; - unsigned char trust_passwd_hash[16]; - unsigned char new_trust_passwd_hash[16]; - int ret = 1; + unsigned char orig_trust_passwd_hash[16]; + BOOL ret; - fstrcpy(remote_machine, remote ? remote : ""); + pstrcpy(remote_machine, remote ? remote : ""); fstrcpy(trust_passwd, global_myname); strlower(trust_passwd); - E_md4hash( (uchar *)trust_passwd, trust_passwd_hash); - - generate_random_buffer( new_trust_passwd_hash, 16, True); + E_md4hash( (uchar *)trust_passwd, orig_trust_passwd_hash); /* Ensure that we are not trying to join a domain if we are locally set up as a domain controller. */ if(lp_domain_controller() && strequal(lp_workgroup(), domain)) { - fprintf(stderr, "%s: Cannot join domain %s as we already configured as domain controller \ -for that domain.\n", prog_name, domain); + fprintf(stderr, "%s: Cannot join domain %s as we already configured as \ +domain controller for that domain.\n", prog_name, domain); return 1; } /* - * Write the new machine password. - */ - - /* - * Get the machine account password. + * Create the machine account password file. */ if(!trust_password_lock( domain, global_myname, True)) { fprintf(stderr, "%s: unable to open the machine account password file for \ @@ -201,53 +74,42 @@ machine %s in domain %s.\n", prog_name, global_myname, domain); return 1; } - if(!set_trust_account_password( new_trust_passwd_hash)) { - fprintf(stderr, "%s: unable to read the machine account password for \ + /* + * Write the old machine account password. + */ + + if(!set_trust_account_password( orig_trust_passwd_hash)) { + fprintf(stderr, "%s: unable to write the machine account password for \ machine %s in domain %s.\n", prog_name, global_myname, domain); trust_password_unlock(); return 1; } - trust_password_unlock(); - /* * If we are given a remote machine assume this is the PDC. */ - if(remote != NULL) { - strupper(remote_machine); - ret = setup_account( domain, remote_machine, trust_passwd_hash, new_trust_passwd_hash); - if(ret == 0) - printf("%s: Joined domain %s.\n", prog_name, domain); - } else { - /* - * Treat each name in the 'password server =' line as a potential - * PDC/BDC. Contact each in turn and try and authenticate and - * change the machine account password. - */ - - p = lp_passwordserver(); + if(remote == NULL) + pstrcpy(remote_machine, lp_passwordserver()); - if(!*p) - fprintf(stderr, "%s: No password server list given in smb.conf - \ + if(!*remote_machine) { + fprintf(stderr, "%s: No password server list given in smb.conf - \ unable to join domain.\n", prog_name); - - while(p && next_token( &p, remote_machine, LIST_SEP)) { - - strupper(remote_machine); - if(setup_account( domain, remote_machine, trust_passwd_hash, new_trust_passwd_hash) == 0) { - printf("%s: Joined domain %s.\n", prog_name, domain); - return 0; - } - } + trust_password_unlock(); + return 1; } - if(ret) { + ret = change_trust_account_password( domain, remote_machine); + trust_password_unlock(); + + if(!ret) { trust_password_delete( domain, global_myname); fprintf(stderr,"%s: Unable to join domain %s.\n", prog_name, domain); + } else { + printf("%s: Joined domain %s.\n", prog_name, domain); } - return ret; + return (int)ret; } /********************************************************* -- cgit From c069bd8eea3b41b338a9add7271ab9440d5f1e3c Mon Sep 17 00:00:00 2001 From: Paul Blackman Date: Sat, 30 May 1998 02:25:11 +0000 Subject: This change ensures that only the processes/locked files that belong to -uUsername are printed when running 'smbstatus -uUsername' PaulB (This used to be commit da08e486871992043c2650e6aac304cd29ba693c) --- source3/utils/status.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index d4753d589d..0a53dee62a 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -71,32 +71,34 @@ static void print_share_mode(share_mode_entry *e, char *fname) } count++; - printf("%-5d ",e->pid); - switch ((e->share_mode>>4)&0xF) { - case DENY_NONE: printf("DENY_NONE "); break; - case DENY_ALL: printf("DENY_ALL "); break; - case DENY_DOS: printf("DENY_DOS "); break; - case DENY_READ: printf("DENY_READ "); break; - case DENY_WRITE:printf("DENY_WRITE "); break; - } - switch (e->share_mode&0xF) { - case 0: printf("RDONLY "); break; - case 1: printf("WRONLY "); break; - case 2: printf("RDWR "); break; - } + if (Ucrit_checkPid(e->pid)) { + printf("%-5d ",e->pid); + switch ((e->share_mode>>4)&0xF) { + case DENY_NONE: printf("DENY_NONE "); break; + case DENY_ALL: printf("DENY_ALL "); break; + case DENY_DOS: printf("DENY_DOS "); break; + case DENY_READ: printf("DENY_READ "); break; + case DENY_WRITE:printf("DENY_WRITE "); break; + } + switch (e->share_mode&0xF) { + case 0: printf("RDONLY "); break; + case 1: printf("WRONLY "); break; + case 2: printf("RDWR "); break; + } - if((e->op_type & - (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == - (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) + if((e->op_type & + (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == + (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) printf("EXCLUSIVE+BATCH "); - else if (e->op_type & EXCLUSIVE_OPLOCK) + else if (e->op_type & EXCLUSIVE_OPLOCK) printf("EXCLUSIVE "); - else if (e->op_type & BATCH_OPLOCK) + else if (e->op_type & BATCH_OPLOCK) printf("BATCH "); - else + else printf("NONE "); - printf(" %s %s",fname,asctime(LocalTime((time_t *)&e->time.tv_sec))); + printf(" %s %s",fname,asctime(LocalTime((time_t *)&e->time.tv_sec))); + } } -- cgit From 59d07445b61e26321e3a1770c13756ac5948aabb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 14 Jul 1998 21:23:59 +0000 Subject: loadparm.c: With apologies to Charlton Heston and Pierre Boule. "You damn fools, you finally did it". Changed default security mode to be security=user. Yes this is a big (although small in code) change. It's something we've been discussing for a while, to finally wean people off the legacy security=share mode which is *never* what you want. Jeremy. nmbd_incomingrequests.c: Bug fix for nmbd core dumps caused by overrun. Found by . nttrans.c: More NT smb stuff. reply.c: Unlink will overwrite an existing file. Well you learn something new about POSIX every day. :-). server.c: Tidyup unreadable code. smbpasswd.c: Code to allow -U remote_username to allow ordinary users to change remote passwords if their NT username is different from their UNIX username. Patch from . Jeremy. (This used to be commit 4eccb47cfb3c8907a6558b6ea9a02b0184458e34) --- source3/utils/smbpasswd.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index c9742fc498..f9b9506297 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -33,9 +33,9 @@ static void usage(char *name, BOOL is_root) { if(is_root) fprintf(stderr, "Usage is : %s [-D DEBUGLEVEL] [-a] [-d] [-m] [-n] [username] [password]\n\ -%s: [-R ] [-D DEBUGLEVEL] [-j DOMAINNAME] [-r machine] [username] [password]\n%s: [-h]\n", name, name, name); +%s: [-R ] [-D DEBUGLEVEL] [-j DOMAINNAME] [-r machine] [-U remote_username] [username] [password]\n%s: [-h]\n", name, name, name); else - fprintf(stderr, "Usage is : %s [-h] [-D DEBUGLEVEL] [-r machine] [password]\n", name); + fprintf(stderr, "Usage is : %s [-h] [-D DEBUGLEVEL] [-r machine] [-U remote_username] [password]\n", name); exit(1); } @@ -134,6 +134,7 @@ int main(int argc, char **argv) int err; BOOL is_root = False; pstring user_name; + BOOL remote_user_name = False; char *remote_machine = NULL; BOOL add_user = False; BOOL got_new_pass = False; @@ -201,7 +202,7 @@ int main(int argc, char **argv) is_root = (real_uid == 0); - while ((ch = getopt(argc, argv, "adhmnj:r:R:D:")) != EOF) { + while ((ch = getopt(argc, argv, "adhmnj:r:R:D:U:")) != EOF) { switch(ch) { case 'a': if(is_root) @@ -250,6 +251,10 @@ int main(int argc, char **argv) } else usage(prog_name, is_root); break; + case 'U': + remote_user_name = True; + pstrcpy(user_name, optarg); + break; case 'h': default: usage(prog_name, is_root); @@ -259,6 +264,11 @@ int main(int argc, char **argv) argc -= optind; argv += optind; + if (!is_root && remote_user_name && !remote_machine) { + fprintf(stderr, "%s: You can only use -U with -r.\n", prog_name); + usage(prog_name, False); + } + /* * Ensure add_user and either remote machine or join domain are * not both set. @@ -314,12 +324,7 @@ int main(int argc, char **argv) } } - /* - * Setup the pwd struct to point to known - * values for a machine account (it doesn't - * exist in /etc/passwd). - */ - if((pwd = Get_Pwnam(user_name, True)) == NULL) { + if(!remote_machine && ((pwd = Get_Pwnam(user_name, True)) == NULL)) { fprintf(stderr, "%s: User \"%s\" was not found in system password file.\n", prog_name, user_name); exit(1); @@ -344,7 +349,7 @@ int main(int argc, char **argv) got_new_pass = True; } - if((pwd = getpwuid(real_uid)) != NULL) + if(!remote_user_name && ((pwd = getpwuid(real_uid)) != NULL)) pstrcpy( user_name, pwd->pw_name); /* -- cgit From f5866fd4ba8da9acde87c7f9da8f1a242540e287 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 22 Jul 1998 13:59:19 +0000 Subject: Fixed bug found by Richard Sharpe. After increasing files_struct size by MAX_OPEN_DIRECTORIES for nttrans I forgot to update the code that enumerates the array. Created new MAX_FNUMS in local.h, changed all code that iterates through the files_struct array to use this. (sorry Richard). Jeremy. (This used to be commit 339b10222269d71c7a493cc08b7b1bfd35fd55fc) --- source3/utils/status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 0a53dee62a..97f2ab3cde 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -57,7 +57,7 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ void become_root(BOOL save_dir) {} void unbecome_root(BOOL restore_dir) {} connection_struct Connections[MAX_CONNECTIONS]; -files_struct Files[MAX_OPEN_FILES]; +files_struct Files[MAX_FNUMS]; struct current_user current_user; -- cgit From 981e1b0f7e5d41b59785f03a2f32d601a4fe7e13 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Fri, 24 Jul 1998 01:08:31 +0000 Subject: Updates smbstatus to have a -S and -L flag. Also updated the documentation :-) The code is ugly, we need to rewrite smbstatus someday. (This used to be commit a2a9f55a76fc16ef1d4656332ef6b1b455bb6259) --- source3/utils/status.c | 156 +++++++++++++++++++++++++++---------------------- 1 file changed, 87 insertions(+), 69 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 97f2ab3cde..2900d3acbe 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -22,6 +22,10 @@ 12 aug 96: Erik.Devriendt@te6.siemens.be added support for shared memory implementation of share mode locking + + 21-Jul-1998: rsharpe@ns.aus.com (Richard Sharpe) + Added -L (locks only) -S (shares only) flags and code + */ /* @@ -53,11 +57,14 @@ int Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ int Ucrit_MaxPid=0; /* added by OH */ unsigned int Ucrit_IsActive = 0; /* added by OH */ +int shares_only = 0; /* Added by RJS */ +int locks_only = 0; /* Added by RJS */ + /* we need these because we link to locking*.o */ void become_root(BOOL save_dir) {} void unbecome_root(BOOL restore_dir) {} connection_struct Connections[MAX_CONNECTIONS]; -files_struct Files[MAX_FNUMS]; +files_struct Files[MAX_OPEN_FILES]; struct current_user current_user; @@ -129,7 +136,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) return(1); } - while ((c = getopt(argc, argv, "pds:u:b")) != EOF) { + while ((c = getopt(argc, argv, "pdLSs:u:b")) != EOF) { switch (c) { case 'b': brief = 1; @@ -137,9 +144,15 @@ static void print_share_mode(share_mode_entry *e, char *fname) case 'd': verbose = 1; break; + case 'L': + locks_only = 1; + break; case 'p': processes_only = 1; break; + case 'S': + shares_only = 1; + break; case 's': pstrcpy(servicesf, optarg); break; @@ -147,7 +160,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) Ucrit_addUsername(optarg); /* added by OH */ break; default: - fprintf(stderr, "Usage: %s [-d] [-p] [-s configfile] [-u username]\n", *argv); /* changed by OH */ + fprintf(stderr, "Usage: %s [-d] [-L] [-p] [-S] [-s configfile] [-u username]\n", *argv); /* changed by OH */ return (-1); } } @@ -182,74 +195,76 @@ static void print_share_mode(share_mode_entry *e, char *fname) uid = getuid(); - if (!processes_only) { - printf("\nSamba version %s\n",VERSION); + if (!locks_only) { - if (brief) - { - printf("PID Username Machine Time logged in\n"); - printf("-------------------------------------------------------------------\n"); - } - else - { - printf("Service uid gid pid machine\n"); - printf("----------------------------------------------\n"); + if (!processes_only) { + printf("\nSamba version %s\n",VERSION); + + if (brief) + { + printf("PID Username Machine Time logged in\n"); + printf("-------------------------------------------------------------------\n"); + } + else + { + printf("Service uid gid pid machine\n"); + printf("----------------------------------------------\n"); + } } - } - while (!feof(f)) - { - if (fread(&crec,sizeof(crec),1,f) != 1) - break; - if (crec.cnum == -1) continue; - if ( crec.magic == 0x280267 && process_exists(crec.pid) - && Ucrit_checkUsername(uidtoname(crec.uid)) /* added by OH */ - ) + while (!feof(f)) { - if (brief) - { - ptr=srecs; - while (ptr!=NULL) - { - if ((ptr->pid==crec.pid)&&(strncmp(ptr->machine,crec.machine,30)==0)) - { - if (ptr->start > crec.start) - ptr->start=crec.start; - break; - } - ptr=ptr->next; - } - if (ptr==NULL) + if (fread(&crec,sizeof(crec),1,f) != 1) + break; + if (crec.cnum == -1) continue; + if ( crec.magic == 0x280267 && process_exists(crec.pid) + && Ucrit_checkUsername(uidtoname(crec.uid)) /* added by OH */ + ) { - ptr=(struct session_record *) malloc(sizeof(struct session_record)); - ptr->uid=crec.uid; - ptr->pid=crec.pid; - ptr->start=crec.start; - strncpy(ptr->machine,crec.machine,30); - ptr->machine[30]='\0'; - ptr->next=srecs; - srecs=ptr; - } - } - else - { - Ucrit_addPid(crec.pid); /* added by OH */ - if (processes_only) { - if (last_pid != crec.pid) - printf("%d\n",crec.pid); - last_pid = crec.pid; /* XXXX we can still get repeats, have to + if (brief) + { + ptr=srecs; + while (ptr!=NULL) + { + if ((ptr->pid==crec.pid)&&(strncmp(ptr->machine,crec.machine,30)==0)) + { + if (ptr->start > crec.start) + ptr->start=crec.start; + break; + } + ptr=ptr->next; + } + if (ptr==NULL) + { + ptr=(struct session_record *) malloc(sizeof(struct session_record)); + ptr->uid=crec.uid; + ptr->pid=crec.pid; + ptr->start=crec.start; + strncpy(ptr->machine,crec.machine,30); + ptr->machine[30]='\0'; + ptr->next=srecs; + srecs=ptr; + } + } + else + { + Ucrit_addPid(crec.pid); /* added by OH */ + if (processes_only) { + if (last_pid != crec.pid) + printf("%d\n",crec.pid); + last_pid = crec.pid; /* XXXX we can still get repeats, have to add a sort at some time */ + } + else + printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", + crec.name,uidtoname(crec.uid),gidtoname(crec.gid),crec.pid, + crec.machine,crec.addr, + asctime(LocalTime(&crec.start))); + } } - else - printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", - crec.name,uidtoname(crec.uid),gidtoname(crec.gid),crec.pid, - crec.machine,crec.addr, - asctime(LocalTime(&crec.start))); - } } - } - fclose(f); - + fclose(f); + } if (processes_only) exit(0); if (brief) @@ -266,16 +281,19 @@ static void print_share_mode(share_mode_entry *e, char *fname) printf("\n"); - locking_init(1); + if (!shares_only) { - if (share_mode_forall(print_share_mode) <= 0) - printf("No locked files\n"); + locking_init(1); - printf("\n"); + if (share_mode_forall(print_share_mode) <= 0) + printf("No locked files\n"); + + printf("\n"); - share_status(stdout); + share_status(stdout); - locking_end(); + locking_end(); + } return (0); } -- cgit From 64578c0589a3a741f81fb55c16eeb882128da00b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 29 Jul 1998 03:08:05 +0000 Subject: merge from the autoconf2 branch to the main branch (This used to be commit 3bda7ac417107a7b01d91805ca71c4330657ed21) --- source3/utils/nmblookup.c | 4 +--- source3/utils/status.c | 4 +--- source3/utils/torture.c | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 59d5771c5d..551d453dba 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -20,9 +20,7 @@ */ -#ifdef SYSLOG -#undef SYSLOG -#endif +#define NO_SYSLOG #include "includes.h" diff --git a/source3/utils/status.c b/source3/utils/status.c index 2900d3acbe..8ece6ed4c1 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -32,9 +32,7 @@ * This program reports current SMB connections */ -#ifdef SYSLOG -#undef SYSLOG -#endif +#define NO_SYSLOG #include "includes.h" diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 1abfee0541..53226d00e6 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -19,9 +19,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef SYSLOG -#undef SYSLOG -#endif +#define NO_SYSLOG #include "includes.h" -- cgit From 59e2e2c7d8df317c17b860a4f924c791e8dbbca8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 9 Aug 1998 14:58:51 +0000 Subject: a few more things compile. I'll do the rest tomorrow. (This used to be commit b92ce41c54fa187bce3287257996f7a3e9c9b9ff) --- source3/utils/smbrun.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 source3/utils/smbrun.c (limited to 'source3/utils') diff --git a/source3/utils/smbrun.c b/source3/utils/smbrun.c new file mode 100644 index 0000000000..2a94ac3235 --- /dev/null +++ b/source3/utils/smbrun.c @@ -0,0 +1,92 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + external program running routine + Copyright (C) Andrew Tridgell 1992-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. +*/ + +#include "includes.h" + + +/******************************************************************* +close the low 3 fd's and open dev/null in their place +********************************************************************/ +static void close_fds(void) +{ + int fd; + int i; + close(0); close(1); close(2); + /* try and use up these file descriptors, so silly + library routines writing to stdout etc won't cause havoc */ + for (i=0;i<3;i++) { + fd = open("/dev/null",O_RDWR,0); + if (fd < 0) fd = open("/dev/null",O_WRONLY,0); + if (fd != i) return; + } +} + + +/* +This is a wrapper around the system() call to allow commands to run correctly +as non root from a program which is switching between root and non-root + +It takes 3 arguments as uid,gid,command and runs command after +becoming a non-root user */ + int main(int argc,char *argv[]) +{ + int uid,gid; + + close_fds(); + + if (argc != 4) exit(2); + + uid = atoi(argv[1]); + gid = atoi(argv[2]); + + /* first become root - we may need to do this in order to lose + our privilages! */ +#ifdef HAVE_SETRESUID + setresgid(0,0,0); + setresuid(0,0,0); +#else + setuid(0); + seteuid(0); +#endif + +#ifdef HAVE_SETRESUID + setresgid(gid,gid,gid); + setresuid(uid,uid,uid); +#else + setgid(gid); + setegid(gid); + setuid(uid); + seteuid(uid); +#endif + + + /* paranoia :-) */ + if (getuid() != uid) + return(3); + + if (geteuid() != getuid()) + return(4); + + /* this is to make sure that the system() call doesn't run forever */ + alarm(30); + + return(system(argv[3])); +} -- cgit From 65a29b0ca56a78148b415fd817af245afc2bb0b9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Aug 1998 01:25:32 +0000 Subject: the rest of the binaries now compile and link (This used to be commit 7fecc3d5a2fb641237f24a3f39c6556fde648a8a) --- source3/utils/status.c | 67 +++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 8ece6ed4c1..225f1712fe 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -66,6 +66,40 @@ files_struct Files[MAX_OPEN_FILES]; struct current_user current_user; +/* added by OH */ +static void Ucrit_addUsername(char *username) +{ + pstrcpy(Ucrit_username, username); + if(strlen(Ucrit_username) > 0) + Ucrit_IsActive = 1; +} + +static unsigned int Ucrit_checkUsername(char *username) +{ + if ( !Ucrit_IsActive) return 1; + if (strcmp(Ucrit_username,username) ==0) return 1; + return 0; +} + +static void Ucrit_addPid(int pid) +{ + int i; + if ( !Ucrit_IsActive) return; + for (i=0;i 0) - Ucrit_IsActive = 1; -} - -unsigned int Ucrit_checkUsername(pstring username) -{ - if ( !Ucrit_IsActive) return 1; - if (strcmp(Ucrit_username,username) ==0) return 1; - return 0; -} - -void Ucrit_addPid(int pid) -{ - int i; - if ( !Ucrit_IsActive) return; - for (i=0;i Date: Thu, 13 Aug 1998 16:32:20 +0000 Subject: return to old behaviour of dumping ALL parameters (This used to be commit aa5648ce833a13b202e4d3e5304494c3bab6855f) --- source3/utils/testparm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index c980fd1758..6f4ea23136 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -107,7 +107,7 @@ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); printf("Press enter to see a dump of your service definitions\n"); fflush(stdout); getc(stdin); - lp_dump(stdout,False); + lp_dump(stdout,True); } if (argc == 4) -- cgit From b9623ab59e813131b1ed3f51616a46e719d59c21 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 14 Aug 1998 17:38:29 +0000 Subject: this is the bug change to using connection_struct* instead of cnum. Connections[] is now a local array in server.c I might have broken something with this change. In particular the oplock code is suspect and some .dll files aren't being oplocked when I expected them to be. I'll look at it after I've got some sleep. (This used to be commit c7ee025ead4a85b6fa44a832047b878451845fb6) --- source3/utils/status.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 225f1712fe..848f87623e 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -61,9 +61,7 @@ int locks_only = 0; /* Added by RJS */ /* we need these because we link to locking*.o */ void become_root(BOOL save_dir) {} void unbecome_root(BOOL restore_dir) {} -connection_struct Connections[MAX_CONNECTIONS]; files_struct Files[MAX_OPEN_FILES]; -struct current_user current_user; /* added by OH */ -- cgit From e13aeea928dd89373cfaf3916c96f853c1227884 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 15 Aug 1998 01:19:26 +0000 Subject: configure: Changes for extra headers. configure.in: Source for header changes. client/clitar.c: Fixed isXXX macros & debugs for gcc pedantic compile. include/config.h.in: Added MEMSET, BZERO, MEMORY, RPCSVC_YPCLNT, STRINGS headers. include/includes.h: Headers for the above. include/smb.h: Made SIGNAL_CAST POSIX by default void (*)(int). lib/access.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/charset.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/debug.c: Fixed signal functs. lib/kanji.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/smbrun.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/util.c: Fixed isXXX macros & debugs for gcc pedantic compile. libsmb/namequery.c: Fixed isXXX macros & debugs for gcc pedantic compile. locking/shmem.c: Fixed isXXX macros & debugs for gcc pedantic compile. locking/shmem_sysv.c: Fixed error messages in sysV stuff. nmbd/asyncdns.c: Fixed signal functs. nmbd/nmbd.c: Fixed isXXX macros & debugs for gcc pedantic compile. passdb/passdb.c: Fixed isXXX macros & debugs for gcc pedantic compile. passdb/smbpassfile.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/chgpasswd.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/ipc.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/nttrans.c: Fixed fsp code path. smbd/password.c: fixed HAVE_YP_GET_DEFAULT_DOMAIN problem. smbd/printing.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/reply.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/server.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/trans2.c: Fixed core dump bug. smbd/uid.c: Fixed isXXX macros & debugs for gcc pedantic compile. Jeremy. (This used to be commit 1b9cbcd02e575dc0a95fa589f720df30a4acc46b) --- source3/utils/make_smbcodepage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c index b0970a7d25..86c9df3a18 100644 --- a/source3/utils/make_smbcodepage.c +++ b/source3/utils/make_smbcodepage.c @@ -127,7 +127,7 @@ BOOL parse_byte(char *buf, unsigned char *bp) BOOL parse_bool(char *buf, unsigned char *bp) { - if(isdigit(*buf)) + if(isdigit((int)*buf)) { char *endptr = NULL; -- cgit From 127655cc888ac40332d4e8e5b94aab03f5120aae Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 15 Aug 1998 07:27:34 +0000 Subject: this checkin gets rid of the global Files[] array and makes it local in files.c it should now be faily easy to expand the default MAX_OPEN_FILES to many thousands. (This used to be commit b088c804f98908eb02f05ab2f2e8a61691a0a582) --- source3/utils/status.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 848f87623e..737700639b 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -61,7 +61,6 @@ int locks_only = 0; /* Added by RJS */ /* we need these because we link to locking*.o */ void become_root(BOOL save_dir) {} void unbecome_root(BOOL restore_dir) {} -files_struct Files[MAX_OPEN_FILES]; /* added by OH */ -- cgit From 852519282d43d7d12c103c01ca979952f041d683 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 20 Aug 1998 03:11:46 +0000 Subject: testparm now prints a warning if the lock directory doesn't have 0644 permissions. (This used to be commit 10303a78d4b12a03166db89202759cd745c516c5) --- source3/utils/testparm.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 6f4ea23136..c7cbab91b8 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -47,13 +47,24 @@ extern pstring myhostname; void do_global_checks(void) { - if(lp_security() > SEC_SHARE && lp_revalidate(-1)) - printf("WARNING: the 'revalidate' parameter is ignored in all but \ + struct stat st; + if (lp_security() > SEC_SHARE && lp_revalidate(-1)) { + printf("WARNING: the 'revalidate' parameter is ignored in all but \ 'security=share' mode.\n"); + } - if( lp_wins_support() && *lp_wins_server() ) - printf("ERROR: both 'wins support = true' and 'wins server = ' \ + if (lp_wins_support() && *lp_wins_server()) { + printf("ERROR: both 'wins support = true' and 'wins server = ' \ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); + } + + if (!directory_exist(lp_lockdir(), &st)) { + printf("ERROR: lock directory %s does not exist\n", + lp_lockdir()); + } else if ((st.st_mode & 0666) != 0644) { + printf("WARNING: lock directory %s should have permissions 0644 for browsing to work\n", + lp_lockdir()); + } } int main(int argc, char *argv[]) -- cgit From cc32fc2af0a8cd2cd7cab5a14cc6e956dbb500ab Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 21 Aug 1998 07:25:57 +0000 Subject: silly me. perms on lock dir should be 755 not 644. (This used to be commit 930a4292e95947d20696b7ce08bbb936442fe327) --- source3/utils/testparm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index c7cbab91b8..e4c627d954 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -61,7 +61,7 @@ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); if (!directory_exist(lp_lockdir(), &st)) { printf("ERROR: lock directory %s does not exist\n", lp_lockdir()); - } else if ((st.st_mode & 0666) != 0644) { + } else if ((st.st_mode & 0777) != 0755) { printf("WARNING: lock directory %s should have permissions 0644 for browsing to work\n", lp_lockdir()); } -- cgit From 1a5a571b416395fce30660968792af397fd548d0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 21 Aug 1998 07:29:42 +0000 Subject: and get the message right ... (This used to be commit 0d641d0cebfbd8cc6015d2361e088ce0410c5d20) --- source3/utils/testparm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index e4c627d954..a5205878cc 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -62,7 +62,7 @@ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); printf("ERROR: lock directory %s does not exist\n", lp_lockdir()); } else if ((st.st_mode & 0777) != 0755) { - printf("WARNING: lock directory %s should have permissions 0644 for browsing to work\n", + printf("WARNING: lock directory %s should have permissions 0755 for browsing to work\n", lp_lockdir()); } } -- cgit From 085c66aea549bcd89158336a8088c7563b7ebb36 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 25 Aug 1998 06:42:09 +0000 Subject: some smbtorture hacks (random IPC calls) (This used to be commit b32a346a1c50ba40224b8165e08e78867be2d376) --- source3/utils/torture.c | 64 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 53226d00e6..164bc4f743 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -71,7 +71,9 @@ static BOOL open_connection(struct cli_state *c) return False; } - if (!cli_send_tconX(c, share, "A:", password, strlen(password)+1)) { + if (!cli_send_tconX(c, share, + strstr(share,"IPC$")?"IPC":"A:", + password, strlen(password)+1)) { printf("%s refused tree connect (%s)\n", host, cli_errstr(c)); cli_shutdown(c); return False; @@ -230,7 +232,7 @@ static void run_torture(int numops) static void run_locktest1(void) { static struct cli_state cli1, cli2; - char *fname = "\\locktest.lck"; + char *fname = "\\lockt1.lck"; int fnum1, fnum2, fnum3; time_t t1, t2; @@ -355,7 +357,7 @@ static void run_locktest1(void) static void run_locktest2(void) { static struct cli_state cli; - char *fname = "\\locktest.lck"; + char *fname = "\\lockt2.lck"; int fnum1, fnum2, fnum3; if (!open_connection(&cli)) { @@ -458,7 +460,7 @@ static void run_locktest2(void) static void run_locktest3(int numops) { static struct cli_state cli1, cli2; - char *fname = "\\locktest.lck"; + char *fname = "\\lockt3.lck"; int fnum1, fnum2, i; uint32 offset; @@ -605,6 +607,57 @@ static void run_unlinktest(void) printf("unlink test finished\n"); } +/* generate a random buffer */ +void rand_buf(char *buf, int len) +{ + while (len--) { + *buf = random(); + buf++; + } +} + +/* send random IPC commands */ +static void run_randomipc(void) +{ + char *rparam = NULL; + char *rdata = NULL; + int rdrcnt,rprcnt; + pstring param; + int api, param_len, i; + static struct cli_state cli; + struct { + int api, level; + char *format; + char *subformat; + int len; + } foo; + + printf("starting random ipc test\n"); + + if (!open_connection(&cli)) { + return; + } + + for (i=0;i<1000;i++) { + api = random() % 500; + param_len = random() % 64; + + rand_buf(param, param_len); + + SSVAL(param,0,api); + + cli_api(&cli, + param, param_len, 8, + NULL, 0, BUFFER_SIZE, + &rparam, &rprcnt, + &rdata, &rdrcnt); + } + + close_connection(&cli); + + printf("finished random ipc test\n"); +} + static void browse_callback(char *sname, uint32 stype, char *comment) @@ -613,6 +666,7 @@ static void browse_callback(char *sname, uint32 stype, char *comment) } + /* This test checks the browse list code @@ -912,6 +966,8 @@ static void create_procs(int nprocs, int numops) printf("host=%s share=%s user=%s myname=%s\n", host, share, username, myname); + run_randomipc(); + start_timer(); create_procs(nprocs, numops); printf("rw_torture: %g secs\n", end_timer()); -- cgit From 61b5fd6f32e9ccb612df1354a3e3b3bed5f2b808 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 31 Aug 1998 03:11:42 +0000 Subject: bounds check next_token() to prevent possible buffer overflows (This used to be commit 3eade55dc7c842bdc50205c330802d211fae54d3) --- source3/utils/make_smbcodepage.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c index 86c9df3a18..155ed5aeb5 100644 --- a/source3/utils/make_smbcodepage.c +++ b/source3/utils/make_smbcodepage.c @@ -244,7 +244,7 @@ definition file. File %s has %d.\n", prog_name, MAXCODEPAGELINES, input_file, nu unsigned char b = 0; /* Get the 'lower' value. */ - if(!next_token(&p, token_buf, NULL)) + if(!next_token(&p, token_buf, NULL, sizeof(token_buf))) parse_error(buf, "cannot parse first value"); if(!parse_byte( token_buf, &b)) parse_error(buf, "first value doesn't resolve to a byte"); @@ -253,7 +253,7 @@ definition file. File %s has %d.\n", prog_name, MAXCODEPAGELINES, input_file, nu SCVAL(output_buf,CODEPAGE_HEADER_SIZE+(i*4),b); /* Get the 'upper' value. */ - if(!next_token(&p, token_buf, NULL)) + if(!next_token(&p, token_buf, NULL, sizeof(token_buf))) parse_error(buf, "cannot parse second value"); if(!parse_byte( token_buf, &b)) parse_error(buf, "second value doesn't resolve to a byte"); @@ -262,7 +262,7 @@ definition file. File %s has %d.\n", prog_name, MAXCODEPAGELINES, input_file, nu SCVAL(output_buf,CODEPAGE_HEADER_SIZE+(i*4) + 1,b); /* Get the 'upper to lower' value. */ - if(!next_token(&p, token_buf, NULL)) + if(!next_token(&p, token_buf, NULL, sizeof(token_buf))) parse_error(buf, "cannot parse third value"); if(!parse_bool( token_buf, &b)) parse_error(buf, "third value doesn't resolve to a boolean"); @@ -271,7 +271,7 @@ definition file. File %s has %d.\n", prog_name, MAXCODEPAGELINES, input_file, nu SCVAL(output_buf,CODEPAGE_HEADER_SIZE+(i*4) + 2,b); /* Get the 'lower to upper' value. */ - if(!next_token(&p, token_buf, NULL)) + if(!next_token(&p, token_buf, NULL, sizeof(token_buf))) parse_error(buf, "cannot parse fourth value"); if(!parse_bool( token_buf, &b)) parse_error(buf, "fourth value doesn't resolve to a boolean"); -- cgit From 18556274139cc5a00593471bd745354d98a35303 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 1 Sep 1998 20:11:54 +0000 Subject: More abstraction of file system data types, to move to a 64 bit file interface for the NT SMB's. Created a new define, SMB_STRUCT_STAT that currently is defined to be struct stat - this wil change to a user defined type containing 64 bit info when the correct wrappers are written for 64 bit stat(), fstat() and lstat() calls. Also changed all sys_xxxx() calls that were previously just wrappers to the same call prefixed by a dos_to_unix() call into dos_xxxx() calls. This makes it explicit when a pathname translation is being done, and when it is not. Now, all sys_xxx() calls are meant to be wrappers to mask OS differences, and not silently converting filenames on the fly. Jeremy. (This used to be commit 28aa182dbffaa4ffd86047e608400de4b26e80eb) --- source3/utils/make_smbcodepage.c | 4 ++-- source3/utils/testparm.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c index 155ed5aeb5..97dfb715b0 100644 --- a/source3/utils/make_smbcodepage.c +++ b/source3/utils/make_smbcodepage.c @@ -170,7 +170,7 @@ int do_compile(int codepage, char *input_file, char *output_file) char output_buf[CODEPAGE_HEADER_SIZE + 4 * MAXCODEPAGELINES]; int num_lines = 0; int i = 0; - struct stat st; + SMB_STRUCT_STAT st; /* Get the size of the input file. Read the entire thing into memory. */ if(stat((char *)input_file, &st)!= 0) @@ -310,7 +310,7 @@ definition file. File %s has %d.\n", prog_name, MAXCODEPAGELINES, input_file, nu int do_decompile( int codepage, char *input_file, char *output_file) { uint32 size = 0; - struct stat st; + SMB_STRUCT_STAT st; char header_buf[CODEPAGE_HEADER_SIZE]; char *buf = NULL; FILE *fp = NULL; diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index a5205878cc..d41e8b9f66 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -47,7 +47,7 @@ extern pstring myhostname; void do_global_checks(void) { - struct stat st; + SMB_STRUCT_STAT st; if (lp_security() > SEC_SHARE && lp_revalidate(-1)) { printf("WARNING: the 'revalidate' parameter is ignored in all but \ 'security=share' mode.\n"); -- cgit From 7bb86c1b132bce31a006ea9768a54db7a45fe1a5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 3 Sep 1998 18:40:31 +0000 Subject: Ok - this is the 64 bit widening check in. It changes the configure to check for stat64 and friends, and then changes much of Samba to use the data type SMB_OFF_T for file size information. stat/fstat/lstat/lseek/ftruncate have now become sys_stat etc. to hide the 64 bit calls if needed. Note that this still does not expose 64 bit functionality to the client, as the changes to the reply_xxx smb's are not yet done. This code change should make these changes possible. Still to do before full 64 bit-ness to the client: fcntl lock code. statfs code widening of dev_t and ino_t (now possible due to SMB_DEV_T and SMB_OFF_T types being in place). Let me know if wierd things happen after this check-in and I'll fix them :-). Jeremy. (This used to be commit 14500936c321d15995c963766aac67bf1f4e3824) --- source3/utils/make_smbcodepage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c index 97dfb715b0..67cd3d4f6f 100644 --- a/source3/utils/make_smbcodepage.c +++ b/source3/utils/make_smbcodepage.c @@ -173,7 +173,7 @@ int do_compile(int codepage, char *input_file, char *output_file) SMB_STRUCT_STAT st; /* Get the size of the input file. Read the entire thing into memory. */ - if(stat((char *)input_file, &st)!= 0) + 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)); @@ -318,7 +318,7 @@ int do_decompile( int codepage, char *input_file, char *output_file) int i = 0; /* Get the size of the input file. Read the entire thing into memory. */ - if(stat((char *)input_file, &st)!= 0) + 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)); -- cgit From e9ea36e4d2270bd7d32da12ef6d6e2299641582d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 5 Sep 1998 05:07:05 +0000 Subject: tridge the destroyer returns! prompted by the interpret_security() dead code that Jean-Francois pointed out I added a make target "finddead" that finds potentially dead (ie. unused) code. It spat out 304 function names ... I went through these are deleted many of them, making others static (finddead also reports functions that are used only in the local file). in doing this I have almost certainly deleted some useful code. I may have even prevented compilation with some compile options. I apologise. I decided it was better to get rid of this code now and add back the one or two functions that are needed than to keep all this baggage. So, if I have done a bit too much "destroying" then let me know. Keep the swearing to a minimum :) One bit I didn't do is the ubibt code. Chris, can you look at that? Heaps of unused functions there. Can they be made static? (This used to be commit 2204475c87f3024ea8fd1fbd7385b2def617a46f) --- source3/utils/make_printerdef.c | 18 +++++++++--------- source3/utils/make_smbcodepage.c | 16 ++++++++-------- source3/utils/testparm.c | 3 +-- source3/utils/torture.c | 2 +- 4 files changed, 19 insertions(+), 20 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index 4745127175..76545b9903 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -32,12 +32,12 @@ char buffer[50][sizeof(pstring)]; char sbuffer[50][sizeof(pstring)]; char sub_dir[50][2][sizeof(pstring)]; -void usage(char *name) +static void usage(char *name) { fprintf(stderr,"%s: printer.def \"Printer Name\"\n", name); } -char *myfgets(char *s, int n, FILE *stream) +static char *myfgets(char *s, int n, FILE *stream) { char *LString1; char *LString2; @@ -76,7 +76,7 @@ char *myfgets(char *s, int n, FILE *stream) on both side of the equal sign "entry=value" */ -char *scan(char *chaine,char **entry) +static char *scan(char *chaine,char **entry) { char *value; char *temp; @@ -94,7 +94,7 @@ char *scan(char *chaine,char **entry) return (value); } -void build_subdir(void) +static void build_subdir(void) { int i=0; char *entry; @@ -126,7 +126,7 @@ void build_subdir(void) Return all the lines between the entry and the next one or the end of file An entry is something between braces. */ -void lookup_strings(FILE *fichier) +static void lookup_strings(FILE *fichier) { int found=0,pointeur=0,i=0; char *temp,*temp2; @@ -176,7 +176,7 @@ void lookup_strings(FILE *fichier) Return all the lines between the entry and the next one or the end of file An entry is something between braces. */ -void lookup_entry(FILE *fichier,char *chaine) +static void lookup_entry(FILE *fichier,char *chaine) { int found=0,pointeur=0,i=0; char *temp,*temp2; @@ -222,7 +222,7 @@ void lookup_entry(FILE *fichier,char *chaine) #endif } -char *find_desc(FILE *fichier,char *text) +static char *find_desc(FILE *fichier,char *text) { char *chaine; char *long_desc; @@ -271,7 +271,7 @@ char *find_desc(FILE *fichier,char *text) return(short_desc); } -void scan_copyfiles(FILE *fichier, char *chaine) +static void scan_copyfiles(FILE *fichier, char *chaine) { char *part; char *mpart; @@ -354,7 +354,7 @@ void scan_copyfiles(FILE *fichier, char *chaine) } -void scan_short_desc(FILE *fichier, char *short_desc) +static void scan_short_desc(FILE *fichier, char *short_desc) { int i=0; char *chaine; diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c index 67cd3d4f6f..0653fd31f1 100644 --- a/source3/utils/make_smbcodepage.c +++ b/source3/utils/make_smbcodepage.c @@ -28,7 +28,7 @@ static char *prog_name = NULL; * Print program usage and die. */ -void codepage_usage(char *progname) +static void codepage_usage(char *progname) { fprintf(stderr, "Usage is : %s [c|d] \n", progname); @@ -40,7 +40,7 @@ void codepage_usage(char *progname) * terminated. */ -void read_line( char **buf, char *line_buf, int size) +static void read_line( char **buf, char *line_buf, int size) { char *p = *buf; int num = 0; @@ -62,7 +62,7 @@ void read_line( char **buf, char *line_buf, int size) * Returns the number of lines copied. */ -int clean_data( char **buf, uint32 *size) +static int clean_data( char **buf, uint32 *size) { pstring linebuf; char *p = *buf; @@ -108,7 +108,7 @@ int clean_data( char **buf, uint32 *size) * Parse a byte from a codepage file. */ -BOOL parse_byte(char *buf, unsigned char *bp) +static BOOL parse_byte(char *buf, unsigned char *bp) { unsigned int b; char *endptr = NULL; @@ -125,7 +125,7 @@ BOOL parse_byte(char *buf, unsigned char *bp) * Parse a bool from a codepage file. */ -BOOL parse_bool(char *buf, unsigned char *bp) +static BOOL parse_bool(char *buf, unsigned char *bp) { if(isdigit((int)*buf)) { @@ -151,7 +151,7 @@ BOOL parse_bool(char *buf, unsigned char *bp) * Print a parse error and exit. */ -void parse_error(char *buf, char *msg) +static void parse_error(char *buf, char *msg) { fprintf(stderr, "%s: %s whilst parsing line \n%s\n", prog_name, msg, buf); @@ -162,7 +162,7 @@ void parse_error(char *buf, char *msg) * Create a compiled codepage file from a codepage definition file. */ -int do_compile(int codepage, char *input_file, char *output_file) +static int do_compile(int codepage, char *input_file, char *output_file) { FILE *fp = NULL; uint32 size = 0; @@ -307,7 +307,7 @@ definition file. File %s has %d.\n", prog_name, MAXCODEPAGELINES, input_file, nu * Placeholder for now. */ -int do_decompile( int codepage, char *input_file, char *output_file) +static int do_decompile( int codepage, char *input_file, char *output_file) { uint32 size = 0; SMB_STRUCT_STAT st; diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index d41e8b9f66..6697dc7fd9 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -44,8 +44,7 @@ extern pstring myhostname; Here we do a set of 'hard coded' checks for bad configuration settings. ************************************************/ - -void do_global_checks(void) +static void do_global_checks(void) { SMB_STRUCT_STAT st; if (lp_security() > SEC_SHARE && lp_revalidate(-1)) { diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 164bc4f743..2bee5f3769 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -608,7 +608,7 @@ static void run_unlinktest(void) } /* generate a random buffer */ -void rand_buf(char *buf, int len) +static void rand_buf(char *buf, int len) { while (len--) { *buf = random(); -- cgit From f6044c87c021342d68d614d59bc8dacd32d223b9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 5 Sep 1998 13:24:20 +0000 Subject: some cleanups to use ZERO_STRUCT() and friends (This used to be commit 7b154dc4313324dfad6cf0117b8ce246bf12bf16) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index f9b9506297..03553b0ea9 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -430,7 +430,7 @@ int main(int argc, char **argv) exit(1); } - memset(&cli, '\0', sizeof(struct cli_state)); + ZERO_STRUCT(cli); if (!cli_initialise(&cli) || !cli_connect(&cli, remote_machine, &ip)) { fprintf(stderr, "%s: unable to connect to SMB server on machine %s. Error was : %s.\n", -- cgit From e649750cb4d2d2577f0577b1d7a87ae4daf8fb6f Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Mon, 21 Sep 1998 09:07:08 +0000 Subject: major autoconf clean-up fix problems in builds with srcdir!=builddir (This used to be commit 1ffc3b807a3f80644c974b454ff5e6f68e89b546) --- source3/utils/dummy.in | 1 + 1 file changed, 1 insertion(+) create mode 100644 source3/utils/dummy.in (limited to 'source3/utils') diff --git a/source3/utils/dummy.in b/source3/utils/dummy.in new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/source3/utils/dummy.in @@ -0,0 +1 @@ + -- cgit From dc36d8768aa13000c48b520f09f6678ea9ffbf28 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 Sep 1998 22:33:13 +0000 Subject: Integration of Anders Blomdell 's smbpasswd changes. Not exactly the same as his code - several changes. Jeremy. (This used to be commit e96747a8e3b9ea5a79c4258e55d7e8f3bf0bf193) --- source3/utils/smbpasswd.c | 138 ++++++++++++++++++++++++++++++---------------- 1 file changed, 90 insertions(+), 48 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 03553b0ea9..b97b0c765f 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -32,7 +32,7 @@ static char *prog_name; static void usage(char *name, BOOL is_root) { if(is_root) - fprintf(stderr, "Usage is : %s [-D DEBUGLEVEL] [-a] [-d] [-m] [-n] [username] [password]\n\ + fprintf(stderr, "Usage is : %s [-D DEBUGLEVEL] [-a] [-d] [-e] [-m] [-n] [username] [password]\n\ %s: [-R ] [-D DEBUGLEVEL] [-j DOMAINNAME] [-r machine] [-U remote_username] [username] [password]\n%s: [-h]\n", name, name, name); else fprintf(stderr, "Usage is : %s [-h] [-D DEBUGLEVEL] [-r machine] [-U remote_username] [password]\n", name); @@ -112,6 +112,56 @@ unable to join domain.\n", prog_name); return (int)ret; } +/************************************************************* + Utility function to create password hashes. +*************************************************************/ + +static void create_new_hashes( char *new_passwd, uchar *new_p16, uchar *new_nt_p16) +{ + memset(new_nt_p16, '\0', 16); + E_md4hash((uchar *) new_passwd, new_nt_p16); + + /* Mangle the password into Lanman format */ + new_passwd[14] = '\0'; + strupper(new_passwd); + + /* + * Calculate the SMB (lanman) hash functions of the new password. + */ + + memset(new_p16, '\0', 16); + E_P16((uchar *) new_passwd, new_p16); +} + +/************************************************************* + Utility function to prompt for new password. +*************************************************************/ + +static void prompt_for_new_password(char *new_passwd) +{ + char *p; + + new_passwd[0] = '\0'; + + p = getpass("New SMB password:"); + + strncpy(new_passwd, p, sizeof(fstring)); + new_passwd[sizeof(fstring)-1] = '\0'; + + p = getpass("Retype new SMB password:"); + + if (strncmp(p, new_passwd, sizeof(fstring)-1)) + { + fprintf(stderr, "%s: Mismatch - password unchanged.\n", prog_name); + exit(1); + } + + if (new_passwd[0] == '\0') { + printf("Password not set\n"); + exit(0); + } +} + /********************************************************* Start here. **********************************************************/ @@ -140,6 +190,7 @@ int main(int argc, char **argv) BOOL got_new_pass = False; BOOL trust_account = False; BOOL disable_user = False; + BOOL enable_user = False; BOOL set_no_password = False; BOOL joining_domain = False; char *new_domain = NULL; @@ -202,7 +253,7 @@ int main(int argc, char **argv) is_root = (real_uid == 0); - while ((ch = getopt(argc, argv, "adhmnj:r:R:D:U:")) != EOF) { + while ((ch = getopt(argc, argv, "adehmnj:r:R:D:U:")) != EOF) { switch(ch) { case 'a': if(is_root) @@ -218,6 +269,14 @@ int main(int argc, char **argv) } else usage(prog_name, is_root); break; + case 'e': + if(is_root) { + enable_user = True; + got_new_pass = True; + fstrcpy(new_passwd, "XXXXXX"); + } else + usage(prog_name, is_root); + break; case 'D': DEBUGLEVEL = atoi(optarg); break; @@ -337,7 +396,17 @@ int main(int argc, char **argv) } else { if(add_user) { - fprintf(stderr, "%s: Only root can set anothers password.\n", prog_name); + fprintf(stderr, "%s: Only root can add a user.\n", prog_name); + usage(prog_name, False); + } + + if(disable_user) { + fprintf(stderr, "%s: Only root can disable a user.\n", prog_name); + usage(prog_name, False); + } + + if(enable_user) { + fprintf(stderr, "%s: Only root can enable a user.\n", prog_name); usage(prog_name, False); } @@ -392,22 +461,8 @@ int main(int argc, char **argv) fstrcpy(old_passwd, p); } - if (!got_new_pass) { - new_passwd[0] = '\0'; - - p = getpass("New SMB password:"); - - strncpy(new_passwd, p, sizeof(fstring)); - new_passwd[sizeof(fstring)-1] = '\0'; - - p = getpass("Retype new SMB password:"); - - if (strncmp(p, new_passwd, sizeof(fstring)-1)) - { - fprintf(stderr, "%s: Mismatch - password unchanged.\n", prog_name); - exit(1); - } - } + if (!got_new_pass) + prompt_for_new_password(new_passwd); if (new_passwd[0] == '\0') { printf("Password not set\n"); @@ -493,25 +548,14 @@ int main(int argc, char **argv) /* Calculate the MD4 hash (NT compatible) of the new password. */ - memset(new_nt_p16, '\0', 16); - E_md4hash((uchar *) new_passwd, new_nt_p16); - - /* Mangle the password into Lanman format */ - new_passwd[14] = '\0'; - strupper(new_passwd); - - /* - * Calculate the SMB (lanman) hash functions of the new password. - */ - - memset(new_p16, '\0', 16); - E_P16((uchar *) new_passwd, new_p16); - + create_new_hashes( new_passwd, new_p16, new_nt_p16); + /* * Open the smbpaswd file. */ vp = startsmbpwent(True); if (!vp && errno == ENOENT) { + fprintf(stderr,"%s: smbpasswd file did not exist - attempting to create it.\n", prog_name); fp = fopen(lp_smb_passwd_file(), "w"); if (fp) { fprintf(fp, "# Samba SMB password file\n"); @@ -578,23 +622,19 @@ int main(int argc, char **argv) * and the valid last change time. */ - if(disable_user) { - /* - * This currently won't work as it means changing - * the length of the record. JRA. - */ + if(disable_user) smb_pwent->acct_ctrl |= ACB_DISABLED; - smb_pwent->smb_passwd = NULL; - smb_pwent->smb_nt_passwd = NULL; - } else if (set_no_password) { - /* - * This currently won't work as it means changing - * the length of the record. JRA. - */ + else if (enable_user) { + if(smb_pwent->smb_passwd == NULL) { + prompt_for_new_password(new_passwd); + create_new_hashes( new_passwd, new_p16, new_nt_p16); + smb_pwent->smb_passwd = new_p16; + smb_pwent->smb_nt_passwd = new_nt_p16; + } + smb_pwent->acct_ctrl &= ~ACB_DISABLED; + } else if (set_no_password) smb_pwent->acct_ctrl |= ACB_PWNOTREQ; - smb_pwent->smb_passwd = NULL; - smb_pwent->smb_nt_passwd = NULL; - } else { + else { smb_pwent->smb_passwd = new_p16; smb_pwent->smb_nt_passwd = new_nt_p16; } @@ -609,6 +649,8 @@ int main(int argc, char **argv) endsmbpwent(vp); if(disable_user) printf("User %s disabled.\n", user_name); + else if(enable_user) + printf("User %s enabled.\n", user_name); else if (set_no_password) printf("User %s - set to no password.\n", user_name); else -- cgit From 66d5d73a5d75e88a77970f7b27687b8354ab2e80 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 25 Sep 1998 21:01:52 +0000 Subject: added rpcclient program (This used to be commit aa38f39d67fade4dfd7badb7a9b39c833a1dd1ca) --- source3/utils/smbpasswd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index b97b0c765f..3ed3a11ba4 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -196,6 +196,8 @@ int main(int argc, char **argv) char *new_domain = NULL; pstring servicesf = CONFIGFILE; void *vp; + struct nmb_name calling, called; + new_passwd[0] = '\0'; user_name[0] = '\0'; @@ -493,7 +495,11 @@ int main(int argc, char **argv) exit(1); } - if (!cli_session_request(&cli, remote_machine, 0x20, global_myname)) { + make_nmb_name(&calling, global_myname , 0x0 , scope); + make_nmb_name(&called , remote_machine, 0x20, scope); + + if (!cli_session_request(&cli, &calling, &called)) + { fprintf(stderr, "%s: machine %s rejected the session setup. Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli) ); cli_shutdown(&cli); -- cgit From ff07b2e4a37f23af90a27456a116b773ae3bbf97 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 25 Sep 1998 21:20:37 +0000 Subject: added wksinfo command to rpcclient, which don't work too good. (This used to be commit 8d23da91cbd74a45a5b030688fd89d88a25738dc) --- source3/utils/smbpasswd.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 3ed3a11ba4..8953b6d138 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -19,6 +19,7 @@ #include "includes.h" +extern pstring scope; extern pstring myhostname; extern pstring global_myname; extern fstring global_myworkgroup; -- cgit From 5f7ee360567a6b4e1a6f43ff01da057d2998fef8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 25 Sep 1998 23:40:49 +0000 Subject: Makefile.in: Fixed bug with continuation line causing proto to fail. Added $(PROGS) $(SPROGS) as targets for make clean. acconfig.h: Added HAVE_IRIX_SPECIFIC_CAPABILITIES. configure.in: Added sys/capability.h header check. Added function checks for srandom random srand rand. Added HAVE_IRIX_SPECIFIC_CAPABILITIES test. includes.h: Added #include . ntdomain.h: Moved struct acct_info into here from smb.h smb.h: Added KERNEL_OPLOCK_CAPABILITY define. Moved enum action_type into rpcclient.h Moved struct cli_state into client.h Moved struct nt_client_info, struct tar_client_info, struct client_info into rpcclient.h lib/genrand.c: Changed to use sys_random() & friends. lib/smbrun.c: Lose capabilities after fork. lib/system.c: Added set_process_capability(), set_inherited_process_capability() sys_random(), sys_srandom(). lib/util.c: Added Ander's EFBIG lock check to fcntl_lock for 64 bit access to an 32 bit mounted NFS filesystem. nmbd/nmbd.c: Changed to use sys_random() & friends. nmbd/nmbd_browsesync.c: Changed to use sys_random() & friends. passdb/ldap.c: Missed one pdb_encode_acct_ctrl call. passdb/passdb.c: Changed to Ander's code for ' ' characters. passdb/smbpass.c: Added Ander's code to reset ACB_PWNOTREQ. script/mkproto.awk: Added 'long' to prototypes. smbd/chgpasswd.c: Lose capabilities after fork. smbd/open.c: Do the mmap *after* the kernel oplock. smbd/oplock.c: Removed stub code from kernel oplock path. Added set_process_capability(), set_inherited_process_capability() calls. smbd/reply.c: Initialize count = 0, offset = 0. smbd/server.c: Added set_process_capability(), set_inherited_process_capability() calls. tests/summary.c: Ensure we have RANDOM or RAND. utils/smbpasswd.c: Added Ander's code to reset ACB_PWNOTREQ. utils/torture.c: Changed to use sys_random() & friends. Jeremy. (This used to be commit e8be306f23963ac00b1a383ebe0cc1421529fb02) --- source3/utils/smbpasswd.c | 8 ++++++-- source3/utils/torture.c | 10 +++++----- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 8953b6d138..2ac44fbdec 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -639,9 +639,13 @@ int main(int argc, char **argv) smb_pwent->smb_nt_passwd = new_nt_p16; } smb_pwent->acct_ctrl &= ~ACB_DISABLED; - } else if (set_no_password) + } else if (set_no_password) { smb_pwent->acct_ctrl |= ACB_PWNOTREQ; - else { + /* This is needed to preserve ACB_PWNOTREQ in mod_smbfilepwd_entry */ + smb_pwent->smb_passwd = NULL; + smb_pwent->smb_nt_passwd = NULL; + } else { + smb_pwent->acct_ctrl &= ~ACB_PWNOTREQ; smb_pwent->smb_passwd = new_p16; smb_pwent->smb_nt_passwd = new_nt_p16; } diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 2bee5f3769..3e29c5a00a 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -130,7 +130,7 @@ static BOOL rw_torture(struct cli_state *c, int numops) for (i=0;i Date: Sun, 27 Sep 1998 08:29:50 +0000 Subject: Fixed up more possibly uninitialized variables. Now only two compilation warnings seem to be left. Luke may want to check the changes I made. (This used to be commit 2456c95c1664a57aa939695c884ec666ec8168ec) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 2ac44fbdec..e5e5424a2b 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -173,7 +173,7 @@ int main(int argc, char **argv) extern int optind; extern int DEBUGLEVEL; int real_uid; - struct passwd *pwd; + struct passwd *pwd = NULL; fstring old_passwd; fstring new_passwd; uchar new_p16[16]; -- cgit From cf971f88ac188eec353a7fb021744b8076cc4eb7 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Mon, 28 Sep 1998 00:14:36 +0000 Subject: automated generation of .dummy files for each subdirectory; dummy.in files are no longer needed, and new directories will be taken care of automatically, at configure (or config.status --recheck) time (This used to be commit 237a8e5fe62d757c04b8207cbbee4df1470cfe4e) --- source3/utils/dummy.in | 1 - 1 file changed, 1 deletion(-) delete mode 100644 source3/utils/dummy.in (limited to 'source3/utils') diff --git a/source3/utils/dummy.in b/source3/utils/dummy.in deleted file mode 100644 index 8b13789179..0000000000 --- a/source3/utils/dummy.in +++ /dev/null @@ -1 +0,0 @@ - -- cgit From cf3a9741dc7427efb97eff09a3c197a906ce6767 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 28 Sep 1998 21:43:48 +0000 Subject: Changes to test in configure if capabilities are enabled on a system. Changes to get Samba to compile cleanly with the IRIX compiler with the options : -fullwarn -woff 1209,1174 (the -woff options are to turn off warnings about unused function parameters and controlling loop expressions being constants). Split prototype generation as we hit a limit in IRIX nawk. Removed "." code in smbd/filename.c (yet again :-). Jeremy. (This used to be commit e0567433bd72aec17bf5a54cc292701095d25f09) --- source3/utils/make_printerdef.c | 2 -- source3/utils/nmblookup.c | 7 +++---- source3/utils/status.c | 4 +--- 3 files changed, 4 insertions(+), 9 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index 76545b9903..aad5bc56f4 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -357,14 +357,12 @@ static void scan_copyfiles(FILE *fichier, char *chaine) static void scan_short_desc(FILE *fichier, char *short_desc) { int i=0; - char *chaine; char *temp; char *copyfiles=0,*datasection=0; helpfile=0; languagemonitor=0; datatype="RAW"; - chaine=(char *)malloc(sizeof(pstring)); temp=(char *)malloc(sizeof(pstring)); driverfile=short_desc; diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 551d453dba..477d6590f0 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -185,7 +185,7 @@ int main(int argc,char *argv[]) for (i=optind;i Date: Mon, 28 Sep 1998 23:55:09 +0000 Subject: Fixed problems found in lint pass over the old code by . These were the problems that still existed in the 2.0 branch. Jeremy. (This used to be commit 3fd28812f75f2311a114ff905143634e3bbb1fac) --- source3/utils/make_printerdef.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index aad5bc56f4..c64ce64bbf 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -84,6 +84,12 @@ static char *scan(char *chaine,char **entry) *entry=(char *)malloc(sizeof(pstring)); value=(char *)malloc(sizeof(pstring)); + + if(*entry == NULL || value == NULL) { + fprintf(stderr,"scan: malloc fail !\n"); + exit(1); + } + pstrcpy(*entry,chaine); temp=chaine; while( temp[i]!='=' && temp[i]!='\0') { @@ -134,6 +140,11 @@ static void lookup_strings(FILE *fichier) temp=(char *)malloc(sizeof(pstring)); temp2=(char *)malloc(sizeof(pstring)); + if(temp == NULL || temp2 == NULL) { + fprintf(stderr,"lookup_strings: malloc fail !\n"); + exit(1); + } + *sbuffer[0]='\0'; pstrcpy(temp2,"[Strings]"); @@ -184,6 +195,11 @@ static void lookup_entry(FILE *fichier,char *chaine) temp=(char *)malloc(sizeof(pstring)); temp2=(char *)malloc(sizeof(pstring)); + if(temp == NULL || temp2 == NULL) { + fprintf(stderr,"lookup_entry: malloc fail !\n"); + exit(1); + } + *buffer[0]='\0'; pstrcpy(temp2,"["); @@ -236,7 +252,7 @@ static char *find_desc(FILE *fichier,char *text) long_desc=(char *)malloc(sizeof(pstring)); short_desc=(char *)malloc(sizeof(pstring)); if (!chaine || !long_desc || !short_desc) { - fprintf(stderr,"Unable to malloc memory\n"); + fprintf(stderr,"find_desc: Unable to malloc memory\n"); exit(1); } @@ -363,7 +379,10 @@ static void scan_short_desc(FILE *fichier, char *short_desc) helpfile=0; languagemonitor=0; datatype="RAW"; - temp=(char *)malloc(sizeof(pstring)); + if((temp=(char *)malloc(sizeof(pstring))) == NULL) { + fprintf(stderr, "scan_short_desc: malloc fail !\n"); + exit(1); + } driverfile=short_desc; datafile=short_desc; @@ -472,7 +491,10 @@ int main(int argc, char *argv[]) lookup_entry(inf_file,"DestinationDirs"); build_subdir(); - files_to_copy=(char *)malloc(2048*sizeof(char)); + if((files_to_copy=(char *)malloc(2048*sizeof(char))) == NULL) { + fprintf(stderr, "%s: malloc fail.\n", argv[0] ); + exit(1); + } *files_to_copy='\0'; scan_short_desc(inf_file,short_desc); fprintf(stdout,"%s:%s:%s:", -- cgit From 495eedb14fb4f00c2dbfe4ee530e535b32236e77 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 2 Oct 1998 12:38:45 +0000 Subject: some changes in smbtorture as a result of clientgen interface changes for smbwrapper note that Lukes client changes broke smbtorture. This doesn't fix it, but at least I didn't break it more than it was. (This used to be commit 252b52091c11d8a6cc9c70f32671aee865ae7b41) --- source3/utils/torture.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 3e29c5a00a..1cf1f2fe4d 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -773,7 +773,7 @@ static void run_trans2test(void) cli_unlink(&cli, fname); fnum = cli_open(&cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); - if (!cli_qfileinfo(&cli, fnum, &c_time, &a_time, &m_time, &size)) { + if (!cli_qfileinfo(&cli, fnum, &c_time, &a_time, &m_time, &size, NULL)) { printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli)); } cli_close(&cli, fnum); @@ -785,7 +785,7 @@ static void run_trans2test(void) O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); cli_close(&cli, fnum); - if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size)) { + if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) { printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli)); } else { if (c_time != m_time) { @@ -809,7 +809,7 @@ static void run_trans2test(void) O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); cli_close(&cli, fnum); if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time, - &w_time, &size)) { + &w_time, &size, NULL)) { printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } else { if (w_time < 60*60*24*2) { @@ -828,7 +828,7 @@ static void run_trans2test(void) } sleep(3); if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time, - &w_time, &size)) { + &w_time, &size, NULL)) { printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } @@ -837,7 +837,7 @@ static void run_trans2test(void) cli_write(&cli, fnum, (char *)&fnum, 0, sizeof(fnum)); cli_close(&cli, fnum); if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2, - &w_time, &size)) { + &w_time, &size, NULL)) { printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } else { if (m_time2 == m_time) -- cgit From bdbc959a9afd7fab159f235551c25139763af100 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 2 Oct 1998 18:45:07 +0000 Subject: - static function "create_new_hashes" was identical to "nt_lm_owf_gen". create_new_hashes didn't zero the buffer for the md4hash: nt_lm_owf_gen did, because jeremy sorted this out a couple of days ago. call nt_lm_owf_gen instead. - call SMBOWFencrypt from SMBencrypt and SMBNTencrypt. - added #ifdef DEBUG_PASSWORD debug password calls. (This used to be commit a4e7cc3e46b713aa0ae55de74a1c70921bef578d) --- source3/utils/smbpasswd.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index e5e5424a2b..5ea0854230 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -113,27 +113,6 @@ unable to join domain.\n", prog_name); return (int)ret; } -/************************************************************* - Utility function to create password hashes. -*************************************************************/ - -static void create_new_hashes( char *new_passwd, uchar *new_p16, uchar *new_nt_p16) -{ - memset(new_nt_p16, '\0', 16); - E_md4hash((uchar *) new_passwd, new_nt_p16); - - /* Mangle the password into Lanman format */ - new_passwd[14] = '\0'; - strupper(new_passwd); - - /* - * Calculate the SMB (lanman) hash functions of the new password. - */ - - memset(new_p16, '\0', 16); - E_P16((uchar *) new_passwd, new_p16); -} - /************************************************************* Utility function to prompt for new password. *************************************************************/ @@ -555,7 +534,7 @@ int main(int argc, char **argv) /* Calculate the MD4 hash (NT compatible) of the new password. */ - create_new_hashes( new_passwd, new_p16, new_nt_p16); + nt_lm_owf_gen( new_passwd, new_nt_p16, new_p16); /* * Open the smbpaswd file. @@ -634,7 +613,7 @@ int main(int argc, char **argv) else if (enable_user) { if(smb_pwent->smb_passwd == NULL) { prompt_for_new_password(new_passwd); - create_new_hashes( new_passwd, new_p16, new_nt_p16); + nt_lm_owf_gen( new_passwd, new_nt_p16, new_p16); smb_pwent->smb_passwd = new_p16; smb_pwent->smb_nt_passwd = new_nt_p16; } -- cgit From f651787785c0a8f2884e254723eeb26512a76e2a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 3 Oct 1998 12:33:34 +0000 Subject: added lseek() support for directories (This used to be commit 67ca971b0b00b5256b0af2c1c5777c393f9cef0b) --- source3/utils/torture.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 1cf1f2fe4d..e7bd347993 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -758,7 +758,7 @@ static void run_trans2test(void) { static struct cli_state cli; int fnum; - uint32 size; + size_t size; time_t c_time, a_time, m_time, w_time, m_time2; char *fname = "\\trans2.tst"; char *dname = "\\trans2"; @@ -773,7 +773,7 @@ static void run_trans2test(void) cli_unlink(&cli, fname); fnum = cli_open(&cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); - if (!cli_qfileinfo(&cli, fnum, &c_time, &a_time, &m_time, &size, NULL)) { + if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time)) { printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli)); } cli_close(&cli, fnum); -- cgit From 40984f6b55212c710f6a7c7b940a785b2b607985 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 4 Oct 1998 12:00:40 +0000 Subject: - modified resolve_name() to take a name_type - cleaned up resolve_name() (split into separate functions for each resolver) - if can't find local master then use #1B name - support listing of foreign workgroups in /smb/ (This used to be commit a4e607c17d1119925c9d0e1d05e0fe81e9a2d1aa) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 5ea0854230..bce5d7512f 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -461,7 +461,7 @@ int main(int argc, char **argv) struct cli_state cli; struct in_addr ip; - if(!resolve_name( remote_machine, &ip)) { + if(!resolve_name( remote_machine, &ip, 0x20)) { fprintf(stderr, "%s: unable to find an IP address for machine %s.\n", prog_name, remote_machine ); exit(1); -- cgit From 4750ce1760a39100f71e74ce8b88a925fef4c42f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 8 Oct 1998 02:28:21 +0000 Subject: use 1 second resolution calls if possible (This used to be commit 349469221a84658048790d7567b4fcea43c0b759) --- source3/utils/torture.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index e7bd347993..b49ad61263 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -809,7 +809,7 @@ static void run_trans2test(void) O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); cli_close(&cli, fnum); if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time, - &w_time, &size, NULL)) { + &w_time, &size, NULL, NULL)) { printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } else { if (w_time < 60*60*24*2) { @@ -828,7 +828,7 @@ static void run_trans2test(void) } sleep(3); if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time, - &w_time, &size, NULL)) { + &w_time, &size, NULL, NULL)) { printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } @@ -837,7 +837,7 @@ static void run_trans2test(void) cli_write(&cli, fnum, (char *)&fnum, 0, sizeof(fnum)); cli_close(&cli, fnum); if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2, - &w_time, &size, NULL)) { + &w_time, &size, NULL, NULL)) { printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } else { if (m_time2 == m_time) -- cgit From 788263ba2f749c5bb1546ca6c9363fd508e94280 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 8 Oct 1998 06:21:33 +0000 Subject: - fixed a bunch of warnings and minor errors - got smbtorture to compile - removed %D from some of lukes code - Luke, what is %D? it ain't portable anyway (This used to be commit 91597c12fb593f49b23c7cea5b64dbb89a0428b3) --- source3/utils/torture.c | 90 ++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 53 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index b49ad61263..94c94966df 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -45,12 +45,17 @@ static double end_timer(void) static BOOL open_connection(struct cli_state *c) { + struct nmb_name called, calling; + if (!cli_initialise(c) || !cli_connect(c, host, NULL)) { printf("Failed to connect with %s\n", host); return False; } - if (!cli_session_request(c, host, 0x20, myname)) { + make_nmb_name(&calling, myname, 0x0, ""); + make_nmb_name(&called , host, 0x20, ""); + + if (!cli_session_request(c, &calling, &called)) { printf("%s rejected the session\n",host); cli_shutdown(c); return False; @@ -94,16 +99,30 @@ static void close_connection(struct cli_state *c) } +/* check if the server produced the expected error code */ +static BOOL check_error(struct cli_state *c, + uint8 eclass, uint32 ecode, uint32 nterr) +{ + uint8 class; + uint32 num; + int eno; + eno = cli_error(c, &eclass, &num); + if ((eclass != class || ecode != num) && + num != (nterr&0xFFFFFF)) { + printf("unexpected error code class=%d code=%d\n", + (int)class, (int)num); + printf(" expected %d/%d %d\n", + (int)eclass, (int)ecode, (int)nterr); + return False; + } + return True; +} + + static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len) { while (!cli_lock(c, fnum, offset, len, -1)) { - int eclass, num; - cli_error(c, &eclass, &num); - if (eclass != ERRDOS || num != ERRlock) { - printf("lock failed (%s)\n", - cli_errstr(c)); - return False; - } + if (!check_error(c, ERRDOS, ERRlock, 0)) return False; } return True; } @@ -272,13 +291,7 @@ static void run_locktest1(void) printf("lock2 succeeded! This is a locking bug\n"); return; } else { - int eclass, num; - cli_error(&cli2, &eclass, &num); - if (eclass != ERRDOS || num != ERRlock) { - printf("error should have been ERRDOS/ERRlock (%s)\n", - cli_errstr(&cli2)); - return; - } + if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return; } @@ -288,13 +301,7 @@ static void run_locktest1(void) printf("lock3 succeeded! This is a locking bug\n"); return; } else { - int eclass, num; - cli_error(&cli2, &eclass, &num); - if (eclass != ERRDOS || num != ERRlock) { - printf("error should have been ERRDOS/ERRlock (%s)\n", - cli_errstr(&cli2)); - return; - } + if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return; } t2 = time(NULL); @@ -311,13 +318,7 @@ static void run_locktest1(void) printf("lock4 succeeded! This is a locking bug\n"); return; } else { - int eclass, num; - cli_error(&cli2, &eclass, &num); - if (eclass != ERRDOS || num != ERRlock) { - printf("error should have been ERRDOS/ERRlock (%s)\n", - cli_errstr(&cli2)); - return; - } + if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return; } if (!cli_close(&cli1, fnum1)) { @@ -402,13 +403,7 @@ static void run_locktest2(void) if (cli_lock(&cli, fnum2, 0, 4, 0)) { printf("lock2 succeeded! This is a locking bug\n"); } else { - int eclass, num; - cli_error(&cli, &eclass, &num); - if (eclass != ERRDOS || num != ERRlock) { - printf("error should have been ERRDOS/ERRlock (%s)\n", - cli_errstr(&cli)); - return; - } + if (!check_error(&cli, ERRDOS, ERRlock, 0)) return; } cli_setpid(&cli, 2); @@ -420,13 +415,7 @@ static void run_locktest2(void) if (cli_lock(&cli, fnum3, 0, 4, 0)) { printf("lock3 succeeded! This is a locking bug\n"); } else { - int eclass, num; - cli_error(&cli, &eclass, &num); - if (eclass != ERRDOS || num != ERRlock) { - printf("error should have been ERRDOS/ERRlock (%s)\n", - cli_errstr(&cli)); - return; - } + if (!check_error(&cli, ERRDOS, ERRlock, 0)) return; } cli_setpid(&cli, 1); @@ -625,12 +614,6 @@ static void run_randomipc(void) pstring param; int api, param_len, i; static struct cli_state cli; - struct { - int api, level; - char *format; - char *subformat; - int len; - } foo; printf("starting random ipc test\n"); @@ -660,7 +643,8 @@ static void run_randomipc(void) -static void browse_callback(char *sname, uint32 stype, char *comment) +static void browse_callback(const char *sname, uint32 stype, + const char *comment) { printf("\t%20.20s %08x %s\n", sname, stype, comment); } @@ -809,7 +793,7 @@ static void run_trans2test(void) O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); cli_close(&cli, fnum); if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time, - &w_time, &size, NULL, NULL)) { + &w_time, &size, NULL)) { printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } else { if (w_time < 60*60*24*2) { @@ -828,7 +812,7 @@ static void run_trans2test(void) } sleep(3); if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time, - &w_time, &size, NULL, NULL)) { + &w_time, &size, NULL)) { printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } @@ -837,7 +821,7 @@ static void run_trans2test(void) cli_write(&cli, fnum, (char *)&fnum, 0, sizeof(fnum)); cli_close(&cli, fnum); if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2, - &w_time, &size, NULL, NULL)) { + &w_time, &size, NULL)) { printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } else { if (m_time2 == m_time) -- cgit From a813f38e2dc894b548c23dea2bef98cef7d4f4e9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 8 Oct 1998 06:49:00 +0000 Subject: - don't generate 0 params in torture - handle 0 params in ipc.c (This used to be commit c0dc8e87f0d56444a8ddff0817a94065ca295847) --- source3/utils/torture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 94c94966df..fb320e8b66 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -623,7 +623,7 @@ static void run_randomipc(void) for (i=0;i<1000;i++) { api = sys_random() % 500; - param_len = sys_random() % 64; + param_len = (sys_random() % 64) + 4; rand_buf(param, param_len); -- cgit From 6909350ed9b87875ee40191b2e636c6049749195 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Thu, 8 Oct 1998 23:57:46 +0000 Subject: dce/rpc (This used to be commit 62fdeef1b79c5c4c9bf0e860881651711bb80b9a) --- source3/utils/torture.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index fb320e8b66..8199006068 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -165,12 +165,12 @@ static BOOL rw_torture(struct cli_state *c, int numops) break; } - if (cli_write(c, fnum, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) { + if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) { printf("write failed (%s)\n", cli_errstr(c)); } for (j=0;j<50;j++) { - if (cli_write(c, fnum, (char *)buf, + if (cli_write(c, fnum, 0, (char *)buf, sizeof(pid)+(j*sizeof(buf)), sizeof(buf)) != sizeof(buf)) { printf("write failed (%s)\n", cli_errstr(c)); @@ -818,7 +818,7 @@ static void run_trans2test(void) fnum = cli_open(&cli, fname2, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); - cli_write(&cli, fnum, (char *)&fnum, 0, sizeof(fnum)); + cli_write(&cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum)); cli_close(&cli, fnum); if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL)) { -- cgit From bc747b8a077d22344aa03bbba202f5137b59284d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 14 Oct 1998 16:45:24 +0000 Subject: set recursion desired for bcast name query (This used to be commit 53805112f1a301f77cda93b68e6fa3054895f20f) --- source3/utils/nmblookup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 477d6590f0..971715f327 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -218,7 +218,8 @@ int main(int argc,char *argv[]) sscanf(p+1,"%x",&lookup_type); } - if ((ip_list = name_query(ServerFD,lookup,lookup_type,use_bcast,recursion_desired, + if ((ip_list = name_query(ServerFD,lookup,lookup_type,use_bcast, + use_bcast?True:recursion_desired, bcast_addr,&count,NULL))) { for (j=0;j\n",inet_ntoa(ip_list[j]),lookup, lookup_type); -- cgit From bad4e66489075fd5365e1bfdd8d1b8b633ae0004 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 16 Oct 1998 23:08:10 +0000 Subject: added maxfid test (This used to be commit 710027a88a62565fbbe9eb5787e924d019906841) --- source3/utils/torture.c | 77 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 11 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 8199006068..dd5cf04cc5 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -106,7 +106,7 @@ static BOOL check_error(struct cli_state *c, uint8 class; uint32 num; int eno; - eno = cli_error(c, &eclass, &num); + eno = cli_error(c, &class, &num); if ((eclass != class || ecode != num) && num != (nterr&0xFFFFFF)) { printf("unexpected error code class=%d code=%d\n", @@ -596,6 +596,59 @@ static void run_unlinktest(void) printf("unlink test finished\n"); } + +/* +test how many open files this server supports on the one socket +*/ +static void run_maxfidtest(int n) +{ + static struct cli_state cli; + char *template = "\\maxfid.%d.%d"; + fstring fname; + int fnum; + int retries=4; + + srandom(getpid()); + + while (!open_connection(&cli) && retries--) msleep(random() % 2000); + + if (retries <= 0) { + printf("failed to connect\n"); + return; + } + + cli_sockopt(&cli, sockops); + + printf("starting maxfid test\n"); + + fnum = 0; + while (1) { + slprintf(fname,sizeof(fname)-1,template, fnum,getpid()); + if (cli_open(&cli, fname, + O_RDWR|O_CREAT|O_TRUNC, DENY_NONE) == + -1) { + printf("open of %s failed (%s)\n", + fname, cli_errstr(&cli)); + printf("maximum fnum is %d\n", fnum); + break; + } + fnum++; + } + + printf("cleaning up\n"); + while (fnum > n) { + fnum--; + slprintf(fname,sizeof(fname)-1,template, fnum,getpid()); + if (cli_unlink(&cli, fname)) { + printf("unlink of %s failed (%s)\n", + fname, cli_errstr(&cli)); + } + } + + printf("maxfid test finished\n"); + close_connection(&cli); +} + /* generate a random buffer */ static void rand_buf(char *buf, int len) { @@ -621,9 +674,9 @@ static void run_randomipc(void) return; } - for (i=0;i<1000;i++) { + for (i=0;i<50000;i++) { api = sys_random() % 500; - param_len = (sys_random() % 64) + 4; + param_len = (sys_random() % 64); rand_buf(param, param_len); @@ -837,7 +890,7 @@ static void run_trans2test(void) } -static void create_procs(int nprocs, int numops) +static void create_procs(int nprocs, int numops, void (*fn)(int )) { int i, status; @@ -845,7 +898,7 @@ static void create_procs(int nprocs, int numops) if (fork() == 0) { int mypid = getpid(); sys_srandom(mypid ^ time(NULL)); - run_torture(numops); + fn(numops); _exit(0); } } @@ -950,12 +1003,6 @@ static void create_procs(int nprocs, int numops) printf("host=%s share=%s user=%s myname=%s\n", host, share, username, myname); - run_randomipc(); - - start_timer(); - create_procs(nprocs, numops); - printf("rw_torture: %g secs\n", end_timer()); - run_locktest1(); run_locktest2(); run_locktest3(numops); @@ -964,6 +1011,14 @@ static void create_procs(int nprocs, int numops) run_attrtest(); run_trans2test(); + create_procs(nprocs, numops, run_maxfidtest); + + start_timer(); + create_procs(nprocs, numops, run_torture); + printf("rw_torture: %g secs\n", end_timer()); + + run_randomipc(); + return(0); } -- cgit From e4678f5d1de6d2bddb7dd33e9361e1eafbf61d6c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 20 Oct 1998 06:46:25 +0000 Subject: fixed a connection bug in torture test (This used to be commit 2b892130dfc1938e93e69e490a8a9e9ed57a1971) --- source3/utils/torture.c | 77 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 11 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index dd5cf04cc5..3ef4d5133f 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -47,37 +47,38 @@ static BOOL open_connection(struct cli_state *c) { struct nmb_name called, calling; + ZERO_STRUCTP(c); + + make_nmb_name(&calling, myname, 0x0, ""); + make_nmb_name(&called , host, 0x20, ""); + if (!cli_initialise(c) || !cli_connect(c, host, NULL)) { printf("Failed to connect with %s\n", host); return False; } - make_nmb_name(&calling, myname, 0x0, ""); - make_nmb_name(&called , host, 0x20, ""); - if (!cli_session_request(c, &calling, &called)) { - printf("%s rejected the session\n",host); cli_shutdown(c); + printf("%s rejected the session\n",host); return False; } - c->protocol = max_protocol; - if (!cli_negprot(c)) { printf("%s rejected the negprot (%s)\n",host, cli_errstr(c)); cli_shutdown(c); return False; } - if (!cli_session_setup(c, username, password, strlen(password), - "", 0, workgroup)) { - printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c)); + if (!cli_session_setup(c, username, + password, strlen(password), + password, strlen(password), + workgroup)) { cli_shutdown(c); + printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c)); return False; } - if (!cli_send_tconX(c, share, - strstr(share,"IPC$")?"IPC":"A:", + if (!cli_send_tconX(c, share, "?????", password, strlen(password)+1)) { printf("%s refused tree connect (%s)\n", host, cli_errstr(c)); cli_shutdown(c); @@ -555,6 +556,59 @@ static void run_locktest3(int numops) } +/* +test whether fnums and tids open on one VC are available on another (a major +security hole) +*/ +static void run_fdpasstest(void) +{ + static struct cli_state cli1, cli2; + char *fname = "\\fdpass.tst"; + int fnum1; + pstring buf; + + if (!open_connection(&cli1) || !open_connection(&cli2)) { + return; + } + cli_sockopt(&cli1, sockops); + cli_sockopt(&cli2, sockops); + + printf("starting fdpasstest\n"); + + cli_unlink(&cli1, fname); + + fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + if (cli_write(&cli1, fnum1, 0, "hello world\n", 0, 13) != 13) { + printf("write failed (%s)\n", cli_errstr(&cli1)); + return; + } + + cli2.vuid = cli1.vuid; + cli2.cnum = cli1.cnum; + cli2.pid = cli1.pid; + + + if (cli_read(&cli2, fnum1, buf, 0, 13) == 13) { + printf("read succeeded! nasty security hole [%s]\n", + buf); + return; + } + + cli_close(&cli1, fnum1); + cli_unlink(&cli1, fname); + + close_connection(&cli1); + close_connection(&cli2); + + printf("finished fdpasstest\n"); +} + + /* This test checks that @@ -1003,6 +1057,7 @@ static void create_procs(int nprocs, int numops, void (*fn)(int )) printf("host=%s share=%s user=%s myname=%s\n", host, share, username, myname); + run_fdpasstest(); run_locktest1(); run_locktest2(); run_locktest3(numops); -- cgit From a0512ce5ff104bd2d2d11b3e3167d214615a9fbf Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Thu, 22 Oct 1998 22:19:08 +0000 Subject: rpctorture command (This used to be commit b4ae65e2d0582274d67d02ea190f6d3d83b48594) --- source3/utils/rpctorture.c | 520 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 520 insertions(+) create mode 100644 source3/utils/rpctorture.c (limited to 'source3/utils') diff --git a/source3/utils/rpctorture.c b/source3/utils/rpctorture.c new file mode 100644 index 0000000000..d1f0063a43 --- /dev/null +++ b/source3/utils/rpctorture.c @@ -0,0 +1,520 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + SMB client + Copyright (C) Andrew Tridgell 1994-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. +*/ + +#ifdef SYSLOG +#undef SYSLOG +#endif + +#include "includes.h" + +#ifndef REGISTER +#define REGISTER 0 +#endif + +extern pstring scope; +extern pstring global_myname; + +extern pstring user_socket_options; + + +extern pstring debugf; +extern int DEBUGLEVEL; + + +extern file_info def_finfo; + +#define CNV_LANG(s) dos2unix_format(s,False) +#define CNV_INPUT(s) unix2dos_format(s,True) + +static struct cli_state smbcli; +struct cli_state *smb_cli = &smbcli; + +FILE *out_hnd; + +static pstring password; /* local copy only, if one is entered */ + +/**************************************************************************** +initialise smb client structure +****************************************************************************/ +void rpcclient_init(void) +{ + bzero(smb_cli, sizeof(smb_cli)); + cli_initialise(smb_cli); + smb_cli->capabilities |= CAP_NT_SMBS; +} + +/**************************************************************************** +make smb client connection +****************************************************************************/ +static BOOL rpcclient_connect(struct client_info *info) +{ + struct nmb_name calling; + struct nmb_name called; + + make_nmb_name(&called , dns_to_netbios_name(info->dest_host ), info->name_type, scope); + make_nmb_name(&calling, dns_to_netbios_name(info->myhostname), 0x0 , scope); + + if (!cli_establish_connection(smb_cli, + info->dest_host, &info->dest_ip, + &calling, &called, + info->share, info->svc_type, + False, True)) + { + DEBUG(0,("rpcclient_connect: connection failed\n")); + cli_shutdown(smb_cli); + return False; + } + + return True; +} + +/**************************************************************************** +stop the smb connection(s?) +****************************************************************************/ +static void rpcclient_stop(void) +{ + cli_shutdown(smb_cli); +} + +/**************************************************************************** + log in as an nt user, log out again. +****************************************************************************/ +void run_ntlogin_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) +{ + pstring cmd; + int i; + + /* establish connections. nothing to stop these being re-established. */ + rpcclient_connect(cli_info); + + DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd)); + if (cli->fd <= 0) + { + fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n", + cli_info->dest_host, cli_info->name_type); + return; + } + + for (i = 0; i < num_ops; i++) + { + slprintf(cmd, sizeof(cmd)-1, "%s %s", cli->user_name, password); + set_first_token(cmd); + + cmd_netlogon_login_test(cli_info); + } + + rpcclient_stop(); + +} + +/**************************************************************************** + runs n simultaneous functions. +****************************************************************************/ +static void create_procs(int nprocs, int numops, + struct client_info *cli_info, struct cli_state *cli, + void (*fn)(int, struct client_info *, struct cli_state *)) +{ + int i, status; + + for (i=0;i [-d debuglevel] [-l log] ", + pname); + + fprintf(out_hnd, "\nVersion %s\n",VERSION); + fprintf(out_hnd, "\t-d debuglevel set the debuglevel\n"); + fprintf(out_hnd, "\t-l log basename. Basename for log/debug files\n"); + fprintf(out_hnd, "\t-n netbios name. Use this name as my netbios name\n"); + fprintf(out_hnd, "\t-m max protocol set the max protocol level\n"); + fprintf(out_hnd, "\t-I dest IP use this IP to connect to\n"); + fprintf(out_hnd, "\t-E write messages to stderr instead of stdout\n"); + fprintf(out_hnd, "\t-U username set the network username\n"); + fprintf(out_hnd, "\t-W workgroup set the workgroup name\n"); + fprintf(out_hnd, "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n"); + fprintf(out_hnd, "\n"); +} + +enum client_action +{ + CLIENT_NONE, + CLIENT_IPC, + CLIENT_SVC +}; + +/**************************************************************************** + main program +****************************************************************************/ + int main(int argc,char *argv[]) +{ + char *pname = argv[0]; + int opt; + extern FILE *dbf; + extern char *optarg; + extern int optind; + static pstring servicesf = CONFIGFILE; + pstring term_code; + BOOL got_pass = False; + char *cmd_str=""; + mode_t myumask = 0755; + enum client_action cli_action = CLIENT_NONE; + int nprocs = 1; + int numops = 100; + + struct client_info cli_info; + + out_hnd = stdout; + + rpcclient_init(); + +#ifdef KANJI + pstrcpy(term_code, KANJI); +#else /* KANJI */ + *term_code = 0; +#endif /* KANJI */ + + if (!lp_load(servicesf,True, False, False)) + { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); + } + + codepage_initialise(lp_client_code_page()); + + DEBUGLEVEL = 0; + + cli_info.put_total_size = 0; + cli_info.put_total_time_ms = 0; + cli_info.get_total_size = 0; + cli_info.get_total_time_ms = 0; + + cli_info.dir_total = 0; + cli_info.newer_than = 0; + cli_info.archive_level = 0; + cli_info.print_mode = 1; + + cli_info.translation = False; + cli_info.recurse_dir = False; + cli_info.lowercase = False; + cli_info.prompt = True; + cli_info.abort_mget = True; + + cli_info.dest_ip.s_addr = 0; + cli_info.name_type = 0x20; + + pstrcpy(cli_info.cur_dir , "\\"); + pstrcpy(cli_info.file_sel, ""); + pstrcpy(cli_info.base_dir, ""); + pstrcpy(smb_cli->domain, ""); + pstrcpy(smb_cli->user_name, ""); + pstrcpy(cli_info.myhostname, ""); + pstrcpy(cli_info.dest_host, ""); + + pstrcpy(cli_info.svc_type, "A:"); + pstrcpy(cli_info.share, ""); + pstrcpy(cli_info.service, ""); + + pstrcpy(cli_info.dom.level3_sid, ""); + pstrcpy(cli_info.dom.level3_dom, ""); + pstrcpy(cli_info.dom.level5_sid, ""); + pstrcpy(cli_info.dom.level5_dom, ""); + + smb_cli->nt_pipe_fnum = 0xffff; + + setup_logging(pname, True); + + TimeInit(); + charset_initialise(); + + myumask = umask(0); + umask(myumask); + + if (!get_myname(global_myname, NULL)) + { + fprintf(stderr, "Failed to get my hostname.\n"); + } + + password[0] = 0; + + if (argc < 2) + { + usage(pname); + exit(1); + } + + if (*argv[1] != '-') + { + pstrcpy(cli_info.service, argv[1]); + /* Convert any '/' characters in the service name to '\' characters */ + string_replace( cli_info.service, '/','\\'); + argc--; + argv++; + + DEBUG(1,("service: %s\n", cli_info.service)); + + if (count_chars(cli_info.service,'\\') < 3) + { + usage(pname); + printf("\n%s: Not enough '\\' characters in service\n", cli_info.service); + exit(1); + } + + /* + if (count_chars(cli_info.service,'\\') > 3) + { + usage(pname); + printf("\n%s: Too many '\\' characters in service\n", cli_info.service); + exit(1); + } + */ + + if (argc > 1 && (*argv[1] != '-')) + { + got_pass = True; + pstrcpy(password,argv[1]); + memset(argv[1],'X',strlen(argv[1])); + argc--; + argv++; + } + + cli_action = CLIENT_SVC; + } + + while ((opt = getopt(argc, argv,"s:B:O:M:S:i:N:o:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF) + { + switch (opt) + { + case 'm': + { + /* FIXME ... max_protocol seems to be funny here */ + + int max_protocol = 0; + max_protocol = interpret_protocol(optarg,max_protocol); + fprintf(stderr, "max protocol not currently supported\n"); + break; + } + + case 'O': + { + pstrcpy(user_socket_options,optarg); + break; + } + + case 'S': + { + pstrcpy(cli_info.dest_host,optarg); + strupper(cli_info.dest_host); + cli_action = CLIENT_IPC; + break; + } + + case 'B': + { + iface_set_default(NULL,optarg,NULL); + break; + } + + case 'i': + { + pstrcpy(scope, optarg); + break; + } + + case 'U': + { + char *lp; + pstrcpy(smb_cli->user_name,optarg); + if ((lp=strchr(smb_cli->user_name,'%'))) + { + *lp = 0; + pstrcpy(password,lp+1); + got_pass = True; + memset(strchr(optarg,'%')+1,'X',strlen(password)); + } + break; + } + + case 'W': + { + pstrcpy(smb_cli->domain,optarg); + break; + } + + case 'E': + { + dbf = stderr; + break; + } + + case 'I': + { + cli_info.dest_ip = *interpret_addr2(optarg); + if (zero_ip(cli_info.dest_ip)) + { + exit(1); + } + break; + } + + case 'N': + { + nprocs = atoi(optarg); + break; + } + + case 'o': + { + numops = atoi(optarg); + break; + } + + case 'n': + { + fstrcpy(global_myname, optarg); + break; + } + + case 'd': + { + if (*optarg == 'A') + DEBUGLEVEL = 10000; + else + DEBUGLEVEL = atoi(optarg); + break; + } + + case 'l': + { + slprintf(debugf, sizeof(debugf)-1, + "%s.client",optarg); + break; + } + + case 'c': + { + cmd_str = optarg; + got_pass = True; + break; + } + + case 'h': + { + usage(pname); + exit(0); + break; + } + + case 's': + { + pstrcpy(servicesf, optarg); + break; + } + + case 't': + { + pstrcpy(term_code, optarg); + break; + } + + default: + { + usage(pname); + exit(1); + break; + } + } + } + + if (cli_action == CLIENT_NONE) + { + usage(pname); + exit(1); + } + + strupper(global_myname); + fstrcpy(cli_info.myhostname, global_myname); + + DEBUG(3,("%s client started (version %s)\n",timestring(),VERSION)); + + if (*smb_cli->domain == 0) + { + pstrcpy(smb_cli->domain,lp_workgroup()); + } + strupper(smb_cli->domain); + + load_interfaces(); + + if (cli_action == CLIENT_IPC) + { + pstrcpy(cli_info.share, "IPC$"); + pstrcpy(cli_info.svc_type, "IPC"); + } + + fstrcpy(cli_info.mach_acct, cli_info.myhostname); + strupper(cli_info.mach_acct); + fstrcat(cli_info.mach_acct, "$"); + + /* set the password cache info */ + if (got_pass) + { + if (password[0] == 0) + { + pwd_set_nullpwd(&(smb_cli->pwd)); + } + else + { + pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ + } + } + else + { + char *pwd = getpass("Enter Password:"); + safe_strcpy(password, pwd, sizeof(password)); + pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ + } + + if (password[0] != 0) + { + create_procs(nprocs, numops, &cli_info, smb_cli, run_ntlogin_test); + } + + fflush(out_hnd); + + return(0); +} -- cgit From f0d3a44ffaac2ec5b3299f092d1334d5ada015f2 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Thu, 22 Oct 1998 22:54:00 +0000 Subject: enumeration tests (files, sessions, shares, connections). hey, you can see how many connections succeed while the rpctorture command is running! (This used to be commit c1bf8f109932a3387fa7b8b4265a3eda52d3e0a3) --- source3/utils/rpctorture.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/rpctorture.c b/source3/utils/rpctorture.c index d1f0063a43..118be4d598 100644 --- a/source3/utils/rpctorture.c +++ b/source3/utils/rpctorture.c @@ -94,6 +94,36 @@ static void rpcclient_stop(void) cli_shutdown(smb_cli); } +/**************************************************************************** + log in as an nt user, log out again. +****************************************************************************/ +void run_enums_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) +{ + int i; + + /* establish connections. nothing to stop these being re-established. */ + rpcclient_connect(cli_info); + + DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd)); + if (cli->fd <= 0) + { + fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n", + cli_info->dest_host, cli_info->name_type); + return; + } + + for (i = 0; i < num_ops; i++) + { + cmd_srv_enum_sess(cli_info); + cmd_srv_enum_shares(cli_info); + cmd_srv_enum_files(cli_info); + cmd_srv_enum_conn(cli_info); + } + + rpcclient_stop(); + +} + /**************************************************************************** log in as an nt user, log out again. ****************************************************************************/ @@ -509,6 +539,8 @@ enum client_action pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ } + create_procs(nprocs, numops, &cli_info, smb_cli, run_enums_test); + if (password[0] != 0) { create_procs(nprocs, numops, &cli_info, smb_cli, run_ntlogin_test); -- cgit From 95056761c8137aa0d0d4f04e862efa7fa94e064c Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Thu, 22 Oct 1998 23:05:55 +0000 Subject: torture debug. (This used to be commit 97609596647dea39c061bdf972411a86f7294521) --- source3/utils/rpctorture.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/rpctorture.c b/source3/utils/rpctorture.c index 118be4d598..50030bcadc 100644 --- a/source3/utils/rpctorture.c +++ b/source3/utils/rpctorture.c @@ -99,6 +99,7 @@ static void rpcclient_stop(void) ****************************************************************************/ void run_enums_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) { + pstring cmd; int i; /* establish connections. nothing to stop these being re-established. */ @@ -114,9 +115,22 @@ void run_enums_test(int num_ops, struct client_info *cli_info, struct cli_state for (i = 0; i < num_ops; i++) { + set_first_token(""); cmd_srv_enum_sess(cli_info); + set_first_token(""); cmd_srv_enum_shares(cli_info); + set_first_token(""); cmd_srv_enum_files(cli_info); + + if (password[0] != 0) + { + slprintf(cmd, sizeof(cmd)-1, "1"); + set_first_token(cmd); + } + else + { + set_first_token(""); + } cmd_srv_enum_conn(cli_info); } -- cgit From fb556e14f3b47d5a1f465589084e8b30d84af8ca Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 24 Oct 1998 08:08:05 +0000 Subject: volker was concerned about unique inode numbers and smbsh. This set of changes uses the unique index number from a SMB_QUERY_FILE_ALL_INFO to try to provide inode numbers. If it is 0 then use the hash of the filename as before. (This used to be commit 2565ccf9de9d5e80fdb5bcadbc7130faba386d95) --- source3/utils/torture.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 3ef4d5133f..81fa33fc75 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -864,7 +864,8 @@ static void run_trans2test(void) cli_unlink(&cli, fname); fnum = cli_open(&cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); - if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time)) { + if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time, + NULL, NULL)) { printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli)); } cli_close(&cli, fnum); @@ -900,7 +901,7 @@ static void run_trans2test(void) O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); cli_close(&cli, fnum); if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time, - &w_time, &size, NULL)) { + &w_time, &size, NULL, NULL)) { printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } else { if (w_time < 60*60*24*2) { @@ -919,7 +920,7 @@ static void run_trans2test(void) } sleep(3); if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time, - &w_time, &size, NULL)) { + &w_time, &size, NULL, NULL)) { printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } @@ -928,7 +929,7 @@ static void run_trans2test(void) cli_write(&cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum)); cli_close(&cli, fnum); if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2, - &w_time, &size, NULL)) { + &w_time, &size, NULL, NULL)) { printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } else { if (m_time2 == m_time) -- cgit From ba91cb69be52f1dea802e1ed0f8bda30b0a25cb4 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Mon, 26 Oct 1998 23:21:37 +0000 Subject: Here is the simple debug parser and the debug2html converter. Still to do: * Debug message filtering. * I need to add all this to Makefile.in (If it looks at all strange I'll ask for help.) If you want to compile debug2html, you'll need to do it by hand until I make the changes to Makefile.in. Sorry. Chris -)----- (This used to be commit fae161b9051c3ea8aa129bdb3df11d215007723d) --- source3/utils/debug2html.c | 239 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 239 insertions(+) create mode 100644 source3/utils/debug2html.c (limited to 'source3/utils') diff --git a/source3/utils/debug2html.c b/source3/utils/debug2html.c new file mode 100644 index 0000000000..ff891f0385 --- /dev/null +++ b/source3/utils/debug2html.c @@ -0,0 +1,239 @@ +/* ========================================================================== ** + * debug2html.c + * + * Copyright (C) 1998 by Christopher R. Hertel + * + * Email: crh@ubiqx.mn.org + * + * -------------------------------------------------------------------------- ** + * Parse Samba debug logs (2.0 & greater) and output the results as HTML. + * -------------------------------------------------------------------------- ** + * + * 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. + * + * -------------------------------------------------------------------------- ** + * This program provides an example of the use of debugparse.c, and also + * does a decent job of converting Samba logs into HTML. + * -------------------------------------------------------------------------- ** + * + * $Log: debug2html.c,v $ + * Revision 1.1 1998/10/26 23:21:37 crh + * Here is the simple debug parser and the debug2html converter. Still to do: + * + * * Debug message filtering. + * * I need to add all this to Makefile.in + * (If it looks at all strange I'll ask for help.) + * + * If you want to compile debug2html, you'll need to do it by hand until I + * make the changes to Makefile.in. Sorry. + * + * Chris -)----- + * + * ========================================================================== ** + */ + +#include "debugparse.h" + +/* -------------------------------------------------------------------------- ** + * The size of the read buffer. + */ + +#define BSIZE 1024 + +/* -------------------------------------------------------------------------- ** + * Functions... + */ + +static dbg_Token modechange( dbg_Token new, dbg_Token mode ) + /* ------------------------------------------------------------------------ ** + * Handle a switch between header and message printing. + * + * Input: new - The token value of the current token. This indicates + * the lexical item currently being recognized. + * mode - The current mode. This is either dbg_null or + * dbg_message. It could really be any toggle + * (true/false, etc.) + * + * Output: The new mode. This will be the same as the input mode unless + * there was a transition in or out of message processing. + * + * Notes: The purpose of the mode value is to mark the beginning and end + * of the message text block. In order to show the text in its + * correct format, it must be included within a
 block.
+   *
+   * ------------------------------------------------------------------------ **
+   */
+  {
+  switch( new )
+    {
+    case dbg_null:
+    case dbg_ignore:
+      return( mode );
+    case dbg_message:
+      if( dbg_message != mode )
+        {
+        /* Switching to message mode. */
+        (void)printf( "
\n" );
+        return( dbg_message );
+        }
+      break;
+    default:
+      if( dbg_message == mode )
+        {
+        /* Switching out of message mode. */
+        (void)printf( "
\n\n" ); + return( dbg_null ); + } + } + + return( mode ); + } /* modechange */ + +static void newblock( dbg_Token old, dbg_Token new ) + /* ------------------------------------------------------------------------ ** + * Handle the transition between tokens. + * + * Input: old - The previous token. + * new - The current token. + * + * Output: none. + * + * Notes: This is called whenever there is a transition from one token + * type to another. It first prints the markup tags that close + * the previous token, and then the markup tags for the new + * token. + * + * ------------------------------------------------------------------------ ** + */ + { + switch( old ) + { + case dbg_timestamp: + (void)printf( ", " ); + break; + case dbg_level: + (void)printf( "]\n " ); + break; + case dbg_sourcefile: + (void)printf( ":" ); + break; + case dbg_lineno: + (void)printf( ")" ); + break; + } + + switch( new ) + { + case dbg_timestamp: + (void)printf( "[" ); + break; + case dbg_level: + (void)printf( "" ); + break; + case dbg_lineno: + (void)printf( "(" ); + break; + } + } /* newblock */ + +static void charprint( dbg_Token tok, int c ) + /* ------------------------------------------------------------------------ ** + * Filter the input characters to determine what goes to output. + * + * Input: tok - The token value of the current character. + * c - The current character. + * + * Output: none. + * + * ------------------------------------------------------------------------ ** + */ + { + switch( tok ) + { + case dbg_ignore: + case dbg_header: + break; + case dbg_null: + case dbg_eof: + (void)putchar( '\n' ); + break; + default: + switch( c ) + { + case '<': + (void)printf( "<" ); + break; + case '>': + (void)printf( ">" ); + break; + case '&': + (void)printf( "&" ); + break; + case '\"': + (void)printf( """ ); + break; + default: + (void)putchar( c ); + break; + } + } + } /* charprint */ + +int main( int argc, char *argv[] ) + /* ------------------------------------------------------------------------ ** + * This simple program scans and parses Samba debug logs, and produces HTML + * output. + * + * Input: argc - Currently ignored. + * argv - Currently ignored. + * + * Output: Always zero. + * + * Notes: The HTML output is sent to stdout. + * + * ------------------------------------------------------------------------ ** + */ + { + int i; + int len; + char bufr[BSIZE]; + dbg_Token old = dbg_null, + new = dbg_null, + state = dbg_null, + mode = dbg_null; + + (void)printf( "\n" ); + (void)printf( "\n\n" ); + (void)printf( " Samba Debug Output\n\n\n\n" ); + + while( (len = fread( bufr, 1, BSIZE, stdin )) > 0 ) + { + for( i = 0; i < len; i++ ) + { + old = new; + new = dbg_char2token( &state, bufr[i] ); + if( new != old ) + { + mode = modechange( new, mode ); + newblock( old, new ); + } + charprint( new, bufr[i] ); + } + } + (void)modechange( dbg_eof, mode ); + + (void)printf( "\n\n" ); + return( 0 ); + } /* main */ -- cgit From e04759fbabde02c97f362e541380921d86a6af57 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Tue, 27 Oct 1998 23:28:29 +0000 Subject: Fixed a small bug in debug2html. It wasn't properly checking EOF. The current status is "it works". I need to add some syntax error recovery and a usage message. Basic stuff. I've also modified Makefile.in. If you want to compile it you'll have to do a 'make debug2html', as I used smbtorture as a model. We can decide later if this tool is useful enough to be compiled always. BTW, a 'make realclean' fails because the bin directory isn't empty. That's because it doesn't delete optionally compiled files such as smbtorture and debug2html (and because of the CVS subdirectory, but I think that's only a problem for developers). Chris -)----- (This used to be commit e86fd87a3806f4c161a8f887bbdd4d400ae56ac2) --- source3/utils/debug2html.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/debug2html.c b/source3/utils/debug2html.c index ff891f0385..1763cf38b6 100644 --- a/source3/utils/debug2html.c +++ b/source3/utils/debug2html.c @@ -29,6 +29,22 @@ * -------------------------------------------------------------------------- ** * * $Log: debug2html.c,v $ + * Revision 1.2 1998/10/27 23:28:29 crh + * Fixed a small bug in debug2html. It wasn't properly checking EOF. The + * current status is "it works". I need to add some syntax error recovery + * and a usage message. Basic stuff. + * + * I've also modified Makefile.in. If you want to compile it you'll have to + * do a 'make debug2html', as I used smbtorture as a model. We can decide + * later if this tool is useful enough to be compiled always. + * + * BTW, a 'make realclean' fails because the bin directory isn't empty. + * That's because it doesn't delete optionally compiled files such as + * smbtorture and debug2html (and because of the CVS subdirectory, but I + * think that's only a problem for developers). + * + * Chris -)----- + * * Revision 1.1 1998/10/26 23:21:37 crh * Here is the simple debug parser and the debug2html converter. Still to do: * @@ -218,7 +234,8 @@ int main( int argc, char *argv[] ) (void)printf( "\n\n" ); (void)printf( " Samba Debug Output\n\n\n\n" ); - while( (len = fread( bufr, 1, BSIZE, stdin )) > 0 ) + while( (!feof( stdin )) + && ((len = fread( bufr, 1, BSIZE, stdin )) > 0) ) { for( i = 0; i < len; i++ ) { -- cgit From f97ceef7ec64842fe7cf240cd787d67e388ab3c7 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 28 Oct 1998 20:33:35 +0000 Subject: I've moved the debugparse module files into the ubiqx directory because I know that 'make proto' will ignore them there. The debugparse.h header file is included in includes.h, and includes.h is included in debugparse.c, so all of the pieces "see" each other. I've compiled and tested this, and it does seem to work. It's the same compromise model I used when adding the ubiqx modules into the system, which is why I put it all into the same directory. Chris -)----- (This used to be commit b6888faacdba035e1b608a404a71d93791de2d52) --- source3/utils/debug2html.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/debug2html.c b/source3/utils/debug2html.c index 1763cf38b6..00c6306fcf 100644 --- a/source3/utils/debug2html.c +++ b/source3/utils/debug2html.c @@ -29,19 +29,14 @@ * -------------------------------------------------------------------------- ** * * $Log: debug2html.c,v $ - * Revision 1.2 1998/10/27 23:28:29 crh - * Fixed a small bug in debug2html. It wasn't properly checking EOF. The - * current status is "it works". I need to add some syntax error recovery - * and a usage message. Basic stuff. - * - * I've also modified Makefile.in. If you want to compile it you'll have to - * do a 'make debug2html', as I used smbtorture as a model. We can decide - * later if this tool is useful enough to be compiled always. - * - * BTW, a 'make realclean' fails because the bin directory isn't empty. - * That's because it doesn't delete optionally compiled files such as - * smbtorture and debug2html (and because of the CVS subdirectory, but I - * think that's only a problem for developers). + * Revision 1.3 1998/10/28 20:33:35 crh + * I've moved the debugparse module files into the ubiqx directory because I + * know that 'make proto' will ignore them there. The debugparse.h header + * file is included in includes.h, and includes.h is included in debugparse.c, + * so all of the pieces "see" each other. I've compiled and tested this, + * and it does seem to work. It's the same compromise model I used when + * adding the ubiqx modules into the system, which is why I put it all into + * the same directory. * * Chris -)----- * @@ -137,7 +132,7 @@ static void newblock( dbg_Token old, dbg_Token new ) switch( old ) { case dbg_timestamp: - (void)printf( ", " ); + (void)printf( "," ); break; case dbg_level: (void)printf( "]\n " ); @@ -156,7 +151,7 @@ static void newblock( dbg_Token old, dbg_Token new ) (void)printf( "[" ); break; case dbg_level: - (void)printf( "" ); + (void)printf( " " ); break; case dbg_lineno: (void)printf( "(" ); -- cgit From 8851d1a1509a877a1b4a080060292c62a9665315 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 30 Oct 1998 23:53:04 +0000 Subject: Fix suggested by Nicholas.S.Jenkins@cdc.com - connect to the password change server as anonymous - you don't need to have logged on as the user to do the password change. Doh ! (Why didn't *I* think of that one.... :-). Jeremy. (This used to be commit dd3bb250a6fb6020d32ea35d7a3d3301d7f9764b) --- source3/utils/smbpasswd.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index bce5d7512f..883acd0941 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -495,8 +495,13 @@ int main(int argc, char **argv) exit(1); } - if (!cli_session_setup(&cli, user_name, old_passwd, strlen(old_passwd), - "", 0, "")) { + /* + * We should connect as the anonymous user here, in case + * the server has "must change password" checked... + * Thanks to for this fix. + */ + + if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) { fprintf(stderr, "%s: machine %s rejected the session setup. Error was : %s.\n", prog_name, remote_machine, cli_errstr(&cli) ); cli_shutdown(&cli); -- cgit From 01e04614c7c466fdbdc398c782acaa931965f925 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 3 Nov 1998 02:25:28 +0000 Subject: Makefile.in configure configure.in include/proto.h smbd/noquotas.c smbd/quotas.c: Added quotas patch for autoconf from Dejan Ilic . printing/printing.c: Filenames with spaces patch from Allan Bjorklund utils/nmblookup.c: Fix usage() function. smbd/reply.c: Split out the security=server and security=domain checks into check_server_security() and check_domain_security() to aid the writing of the 'hack' appliance mode invented by John Schimmel. Jeremy. (This used to be commit f09ab9b52251087a58af92ec753537ca34a970fc) --- source3/utils/nmblookup.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 971715f327..23415a0ca6 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -81,6 +81,9 @@ static void usage(void) printf("\t-S lookup node status as well\n"); printf("\t-r Use root port 137 (Win95 only replies to this)\n"); printf("\t-A Do a node status on as an IP Address\n"); + printf("\t-i NetBIOS scope Use the given NetBIOS scope for name queries\n"); + printf("\t-s smb.conf file Use the given path to the smb.conf file\n"); + printf("\t-h Print this help message.\n"); printf("\n"); } -- cgit From 5f4c35ab21a4396f08034497b38ff0820cc007a2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 4 Nov 1998 00:57:00 +0000 Subject: Added scripting option (-s) to smbpasswd. Jeremy. (This used to be commit 4f87a8cf994d7f3287b0fd1720624bf705cfa1da) --- source3/utils/smbpasswd.c | 83 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 883acd0941..2d4ce319e8 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -33,10 +33,10 @@ static char *prog_name; static void usage(char *name, BOOL is_root) { if(is_root) - fprintf(stderr, "Usage is : %s [-D DEBUGLEVEL] [-a] [-d] [-e] [-m] [-n] [username] [password]\n\ + fprintf(stderr, "Usage is : %s [-D DEBUGLEVEL] [-h] [-a] [-d] [-e] [-m] [-n] [-s] [username] [password]\n\ %s: [-R ] [-D DEBUGLEVEL] [-j DOMAINNAME] [-r machine] [-U remote_username] [username] [password]\n%s: [-h]\n", name, name, name); else - fprintf(stderr, "Usage is : %s [-h] [-D DEBUGLEVEL] [-r machine] [-U remote_username] [password]\n", name); + fprintf(stderr, "Usage is : %s [-h] [-s] [-D DEBUGLEVEL] [-r machine] [-U remote_username] [password]\n", name); exit(1); } @@ -113,22 +113,62 @@ unable to join domain.\n", prog_name); return (int)ret; } +/************************************************************* + Utility function to prompt for passwords from stdin. Each + password entered must end with a newline. +*************************************************************/ + +static char *stdin_new_passwd(void) +{ + static fstring new_passwd; + size_t len; + + memset( new_passwd, '\0', sizeof(new_passwd)); + + /* + * if no error is reported from fgets() and string at least contains + * the newline that ends the password, then replace the newline with + * a null terminator. + */ + if ( fgets(new_passwd, sizeof(new_passwd), stdin) != NULL) { + if ((len = strlen(new_passwd)) > 0) { + if(new_passwd[len-1] == '\n') + new_passwd[len - 1] = 0; + } + } + return(new_passwd); +} + +/************************************************************* + Utility function to get passwords via tty or stdin + Used if the '-s' option is set to silently get passwords + to enable scripting. +*************************************************************/ + +static char *get_pass( char *prompt, BOOL stdin_get) +{ + if (stdin_get) + return( stdin_new_passwd()); + else + return( getpass( prompt)); +} + /************************************************************* Utility function to prompt for new password. *************************************************************/ -static void prompt_for_new_password(char *new_passwd) +static void prompt_for_new_password(char *new_passwd, BOOL stdin_get) { char *p; new_passwd[0] = '\0'; - - p = getpass("New SMB password:"); + + p = get_pass("New SMB password:", stdin_get); strncpy(new_passwd, p, sizeof(fstring)); new_passwd[sizeof(fstring)-1] = '\0'; - p = getpass("Retype new SMB password:"); + p = get_pass("Retype new SMB password:", stdin_get); if (strncmp(p, new_passwd, sizeof(fstring)-1)) { @@ -173,6 +213,7 @@ int main(int argc, char **argv) BOOL enable_user = False; BOOL set_no_password = False; BOOL joining_domain = False; + BOOL stdin_passwd_get = False; char *new_domain = NULL; pstring servicesf = CONFIGFILE; void *vp; @@ -235,7 +276,7 @@ int main(int argc, char **argv) is_root = (real_uid == 0); - while ((ch = getopt(argc, argv, "adehmnj:r:R:D:U:")) != EOF) { + while ((ch = getopt(argc, argv, "adehmnj:r:sR:D:U:")) != EOF) { switch(ch) { case 'a': if(is_root) @@ -272,6 +313,28 @@ int main(int argc, char **argv) case 'r': remote_machine = optarg; break; + case 's': + /* + * Ensure stdin/stdout are line buffered. + */ + if (setvbuf( stdin, NULL, _IOLBF, 0) != 0) { + fprintf(stderr, "%s: setvbuf error on stdin. Error was %s\n", prog_name, strerror(errno)); + exit(1); + } + + if (setvbuf( stdout, NULL, _IOLBF, 0) != 0) { + fprintf(stderr, "%s: setvbuf error on stdout. Error was %s\n", prog_name, strerror(errno)); + exit(1); + } + + if (setvbuf( stderr, NULL, _IOLBF, 0) != 0) { + fprintf(stderr, "%s: setvbuf error on stderr. Error was %s\n", prog_name, strerror(errno)); + perror("setvbuf error on stdout"); + exit(1); + } + + stdin_passwd_get = True; + break; case 'R': if(is_root) { lp_set_name_resolve_order(optarg); @@ -439,12 +502,12 @@ int main(int argc, char **argv) */ if (remote_machine != NULL) { - p = getpass("Old SMB password:"); + p = get_pass("Old SMB password:",stdin_passwd_get); fstrcpy(old_passwd, p); } if (!got_new_pass) - prompt_for_new_password(new_passwd); + prompt_for_new_password(new_passwd,stdin_passwd_get); if (new_passwd[0] == '\0') { printf("Password not set\n"); @@ -617,7 +680,7 @@ int main(int argc, char **argv) smb_pwent->acct_ctrl |= ACB_DISABLED; else if (enable_user) { if(smb_pwent->smb_passwd == NULL) { - prompt_for_new_password(new_passwd); + prompt_for_new_password(new_passwd,stdin_passwd_get); nt_lm_owf_gen( new_passwd, new_nt_p16, new_p16); smb_pwent->smb_passwd = new_p16; smb_pwent->smb_nt_passwd = new_nt_p16; -- cgit From fa164d91bdaf0d5aaf2a7093cf450d3c7930e9e3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 5 Nov 1998 12:40:37 +0000 Subject: check return value of locking_init() (This used to be commit 0efac70f756dce4c92744fc59b68b528f6984dee) --- source3/utils/status.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 344d46a9b9..fa1e8b43bf 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -309,17 +309,19 @@ static void print_share_mode(share_mode_entry *e, char *fname) printf("\n"); if (!shares_only) { + if (!locking_init(1)) { + printf("Can't initialise shared memory - exiting\n"); + exit(1); + } - locking_init(1); - - if (share_mode_forall(print_share_mode) <= 0) - printf("No locked files\n"); - - printf("\n"); - - share_status(stdout); - - locking_end(); + if (share_mode_forall(print_share_mode) <= 0) + printf("No locked files\n"); + + printf("\n"); + + share_status(stdout); + + locking_end(); } return (0); -- cgit From 4bd1feb68c4f5134293d87433da932c20cded915 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 6 Nov 1998 18:40:51 +0000 Subject: lib/charcnv.c: Improved debug comment. libsmb/namequery.c: Fix to remove 2 second wait is we are doing a unicast and got a reply. smbd/dfree.c: smbd/noquotas.c: smbd/quotas.c: Fixes from Dejan Ilic for the quota code. utils/smbpasswd.c: Fixes to allow smbpasswd to be called from swat. Jeremy. (This used to be commit b5981c0149ad8c6f13ea87db450080616538b5d5) --- source3/utils/smbpasswd.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 2d4ce319e8..147e3492af 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -191,7 +191,8 @@ int main(int argc, char **argv) extern char *optarg; extern int optind; extern int DEBUGLEVEL; - int real_uid; + uid_t real_uid; + uid_t eff_uid; struct passwd *pwd = NULL; fstring old_passwd; fstring new_passwd; @@ -217,7 +218,7 @@ int main(int argc, char **argv) char *new_domain = NULL; pstring servicesf = CONFIGFILE; void *vp; - struct nmb_name calling, called; + struct nmb_name calling, called; new_passwd[0] = '\0'; @@ -265,16 +266,17 @@ int main(int argc, char **argv) codepage_initialise(lp_client_code_page()); - /* Get the real uid */ + /* Get the real and effective uids */ real_uid = getuid(); - + eff_uid = geteuid(); + /* Check the effective uid */ - if ((geteuid() == 0) && (real_uid != 0)) { + if ((eff_uid == (uid_t)0) && (real_uid != (uid_t)0)) { fprintf(stderr, "%s: Must *NOT* be setuid root.\n", prog_name); exit(1); } - is_root = (real_uid == 0); + is_root = (eff_uid == (uid_t)0); while ((ch = getopt(argc, argv, "adehmnj:r:sR:D:U:")) != EOF) { switch(ch) { @@ -434,7 +436,7 @@ int main(int argc, char **argv) exit(1); } } else { - if((pwd = getpwuid(real_uid)) != NULL) + if((pwd = getpwuid(eff_uid)) != NULL) pstrcpy( user_name, pwd->pw_name); } @@ -463,7 +465,7 @@ int main(int argc, char **argv) got_new_pass = True; } - if(!remote_user_name && ((pwd = getpwuid(real_uid)) != NULL)) + if(!remote_user_name && ((pwd = getpwuid(eff_uid)) != NULL)) pstrcpy( user_name, pwd->pw_name); /* -- cgit From 548b417d404a2653ebb5918b0c169ccdfafe856f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 7 Nov 1998 05:32:37 +0000 Subject: codepages/codepage_def.936: Updated comment. param/loadparm.c: Removed "networkstation user login", "domain controller", and "domain sid" parameters. passdb/passdb.c: Removed "networkstation user login" code and changed bug test code to only check once for a bad password server. This will stop the complaints of many "bad login" audit records in NT PDC logs. utils/smbpasswd.c: Removed check for "domain controller". Jeremy. (This used to be commit d6e6e936b5dd90dd8fc38d9404efbe5c546c15e5) --- source3/utils/smbpasswd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 147e3492af..b27bbbbd3b 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -60,9 +60,9 @@ static int join_domain( char *domain, char *remote) domain if we are locally set up as a domain controller. */ - if(lp_domain_controller() && strequal(lp_workgroup(), domain)) { - fprintf(stderr, "%s: Cannot join domain %s as we already configured as \ -domain controller for that domain.\n", prog_name, domain); + if(strequal(remote, global_myname)) { + fprintf(stderr, "%s: Cannot join domain %s as the domain controller name is our own. \ +We cannot be a domain controller for a domain and also be a domain member.\n", prog_name, domain); return 1; } -- cgit From 8c62b28e0ef1e012ebb0713701916d82ffc7661e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 9 Nov 1998 03:45:49 +0000 Subject: converted smbclient to use clientgen.c rather than clientutil.c I did this when I saw yet another bug report complaining about smbclient intermittently missing files. Rather than applying more patches to smbclient it was better to move to the more robust clientgen.c code. The conversion wasn't perfect, I probably lost some features of smbclient while doing it, but at least smbclient should be consistent now. It if fails it should _always_ fail rather than giving people the false impression of a reliable utility. the tar stuff seems to work, but hasn't had much testing as I never use it myself. I'm sure someone will find bugs in my conversion of smbtar.c. It was quite tricky as it did a lot of its own SMB calls. It now uses clientgen.c exclusively. smbclient is still quite messy, but at least it doesn't build its own SMB packets. I haven't touched smbmount as I never use it. Mike, do you want to convert smbmount to use clientgen.c? (This used to be commit e14ca7765ace1b721dad8eca4a527a4e4a8f1ab8) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index b27bbbbd3b..e1904f9c96 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -476,7 +476,7 @@ int main(int argc, char **argv) if(remote_machine == NULL) remote_machine = "127.0.0.1"; - } + } if (*user_name == '\0') { fprintf(stderr, "%s: Unable to get a user name for password change.\n", prog_name); -- cgit From 375e53826c59c33d52009307f757b71a1fe3d589 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 10 Nov 1998 20:51:25 +0000 Subject: include/local.h: include/smb.h: param/loadparm.c: Made GUEST_SESSSETUP run time selectable. Horror of horrors :-). printing/printing.c: Added J.F.'s latest fix. rpc_parse/parse_misc.c: parse_reg.c: rpcclient/cmd_reg.c: rpcclient/display.c: SGI compiler signed/unsigned issues. smbd/reply.c: Made GUEST_SESSSETUP run time selectable. Horror of horrors :-). utils/testparm.c: Added extra test. Jeremy. (This used to be commit 9668a5ef50be2e6b575f9989e87ee2ff8da5ac1d) --- source3/utils/testparm.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 6697dc7fd9..92bf5cb384 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -52,6 +52,10 @@ static void do_global_checks(void) 'security=share' mode.\n"); } + if (lp_security() == SEC_DOMAIN && !lp_encrypted_passwords()) { + printf("ERROR: in 'security=domain' mode the 'encrypt passwords' parameter must also be set to 'true'.\n"); + } + if (lp_wins_support() && *lp_wins_server()) { printf("ERROR: both 'wins support = true' and 'wins server = ' \ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); -- cgit From d85dcf86d59c14cb624bbb69b658fc6aba842593 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 Nov 1998 06:12:19 +0000 Subject: largely rewrote smbpasswd so that the code is understandable. This should allow us to call a function in swat rather than piping to smbpasswd. while doing this I also fixed quite a few "const char *" versus "char *" issues that cropped up while using const to track down bugs in the code. This led to changes in several generic functions. The smbpasswd changes should be correct but they have not been extensively tested. At least if I have introduced bugs then we should be able to fix them more easily than before. (This used to be commit 713864dd0322ae2ae2d83e333d85be35a7eed4ec) --- source3/utils/smbpasswd.c | 1316 +++++++++++++++++++++++---------------------- 1 file changed, 679 insertions(+), 637 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index e1904f9c96..09aa0be9d6 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -23,697 +23,739 @@ extern pstring scope; extern pstring myhostname; extern pstring global_myname; extern fstring global_myworkgroup; +extern int DEBUGLEVEL; -static char *prog_name; /********************************************************* - Print command usage on stderr and die. +a strdup with exit **********************************************************/ +static char *xstrdup(char *s) +{ + s = strdup(s); + if (!s) { + fprintf(stderr,"out of memory\n"); + exit(1); + } + return s; +} -static void usage(char *name, BOOL is_root) + +/********************************************************* + Print command usage on stderr and die. +**********************************************************/ +static void usage(void) { - if(is_root) - fprintf(stderr, "Usage is : %s [-D DEBUGLEVEL] [-h] [-a] [-d] [-e] [-m] [-n] [-s] [username] [password]\n\ -%s: [-R ] [-D DEBUGLEVEL] [-j DOMAINNAME] [-r machine] [-U remote_username] [username] [password]\n%s: [-h]\n", name, name, name); - else - fprintf(stderr, "Usage is : %s [-h] [-s] [-D DEBUGLEVEL] [-r machine] [-U remote_username] [password]\n", name); + if (getuid() == 0) { + printf("smbpasswd [options] [username] [password]\n"); + } else { + printf("smbpasswd [options] [password]\n"); + } + printf("options:\n"); + printf(" -s use stdin for password prompt\n"); + printf(" -D LEVEL debug level\n"); + printf(" -U USER remote username\n"); + printf(" -r MACHINE remote machine\n"); + + if (getuid() == 0) { + printf(" -R ORDER name resolve order\n"); + printf(" -j DOMAIN join domain name\n"); + printf(" -a add user\n"); + printf(" -d delete user\n"); + printf(" -e enable user\n"); + printf(" -n set no password\n"); + printf(" -m machine trust account\n"); + } exit(1); } /********************************************************* Join a domain. **********************************************************/ +static int join_domain(char *domain, char *remote) +{ + pstring remote_machine; + fstring trust_passwd; + unsigned char orig_trust_passwd_hash[16]; + BOOL ret; + + pstrcpy(remote_machine, remote ? remote : ""); + fstrcpy(trust_passwd, global_myname); + strlower(trust_passwd); + E_md4hash( (uchar *)trust_passwd, orig_trust_passwd_hash); + + /* Ensure that we are not trying to join a + domain if we are locally set up as a domain + controller. */ + + if(strequal(remote, global_myname)) { + fprintf(stderr, "Cannot join domain %s as the domain controller name is our own. We cannot be a domain controller for a domain and also be a domain member.\n", domain); + return 1; + } + + /* + * Create the machine account password file. + */ + if(!trust_password_lock( domain, global_myname, True)) { + fprintf(stderr, "unable to open the machine account password file for \ +machine %s in domain %s.\n", global_myname, domain); + return 1; + } + + /* + * Write the old machine account password. + */ + + if(!set_trust_account_password( orig_trust_passwd_hash)) { + fprintf(stderr, "unable to write the machine account password for \ +machine %s in domain %s.\n", global_myname, domain); + trust_password_unlock(); + return 1; + } + + /* + * If we are given a remote machine assume this is the PDC. + */ + + if(remote == NULL) { + pstrcpy(remote_machine, lp_passwordserver()); + } + + if(!*remote_machine) { + fprintf(stderr, "No password server list given in smb.conf - \ +unable to join domain.\n"); + trust_password_unlock(); + return 1; + } + + ret = change_trust_account_password( domain, remote_machine); + trust_password_unlock(); + + if(!ret) { + trust_password_delete( domain, global_myname); + fprintf(stderr,"Unable to join domain %s.\n",domain); + } else { + printf("Joined domain %s.\n",domain); + } + + return (int)ret; +} + -static int join_domain( char *domain, char *remote) +static void set_line_buffering(FILE *f) { - pstring remote_machine; - fstring trust_passwd; - unsigned char orig_trust_passwd_hash[16]; - BOOL ret; - - pstrcpy(remote_machine, remote ? remote : ""); - fstrcpy(trust_passwd, global_myname); - strlower(trust_passwd); - E_md4hash( (uchar *)trust_passwd, orig_trust_passwd_hash); - - /* Ensure that we are not trying to join a - domain if we are locally set up as a domain - controller. */ - - if(strequal(remote, global_myname)) { - fprintf(stderr, "%s: Cannot join domain %s as the domain controller name is our own. \ -We cannot be a domain controller for a domain and also be a domain member.\n", prog_name, domain); - return 1; - } - - /* - * Create the machine account password file. - */ - if(!trust_password_lock( domain, global_myname, True)) { - fprintf(stderr, "%s: unable to open the machine account password file for \ -machine %s in domain %s.\n", prog_name, global_myname, domain); - return 1; - } - - /* - * Write the old machine account password. - */ - - if(!set_trust_account_password( orig_trust_passwd_hash)) { - fprintf(stderr, "%s: unable to write the machine account password for \ -machine %s in domain %s.\n", prog_name, global_myname, domain); - trust_password_unlock(); - return 1; - } - - /* - * If we are given a remote machine assume this is the PDC. - */ - - if(remote == NULL) - pstrcpy(remote_machine, lp_passwordserver()); - - if(!*remote_machine) { - fprintf(stderr, "%s: No password server list given in smb.conf - \ -unable to join domain.\n", prog_name); - trust_password_unlock(); - return 1; - } - - ret = change_trust_account_password( domain, remote_machine); - trust_password_unlock(); - - if(!ret) { - trust_password_delete( domain, global_myname); - fprintf(stderr,"%s: Unable to join domain %s.\n", prog_name, domain); - } else { - printf("%s: Joined domain %s.\n", prog_name, domain); - } - - return (int)ret; + setvbuf(f, NULL, _IOLBF, 0); } /************************************************************* Utility function to prompt for passwords from stdin. Each password entered must end with a newline. *************************************************************/ - static char *stdin_new_passwd(void) { - static fstring new_passwd; - size_t len; - - memset( new_passwd, '\0', sizeof(new_passwd)); - - /* - * if no error is reported from fgets() and string at least contains - * the newline that ends the password, then replace the newline with - * a null terminator. - */ - if ( fgets(new_passwd, sizeof(new_passwd), stdin) != NULL) { - if ((len = strlen(new_passwd)) > 0) { - if(new_passwd[len-1] == '\n') - new_passwd[len - 1] = 0; - } - } - return(new_passwd); + static fstring new_passwd; + size_t len; + + ZERO_STRUCT(new_passwd); + + /* + * if no error is reported from fgets() and string at least contains + * the newline that ends the password, then replace the newline with + * a null terminator. + */ + if ( fgets(new_passwd, sizeof(new_passwd), stdin) != NULL) { + if ((len = strlen(new_passwd)) > 0) { + if(new_passwd[len-1] == '\n') + new_passwd[len - 1] = 0; + } + } + return(new_passwd); } + /************************************************************* Utility function to get passwords via tty or stdin Used if the '-s' option is set to silently get passwords to enable scripting. *************************************************************/ - static char *get_pass( char *prompt, BOOL stdin_get) { - if (stdin_get) - return( stdin_new_passwd()); - else - return( getpass( prompt)); + char *p; + if (stdin_get) { + p = stdin_new_passwd(); + } else { + p = getpass(prompt); + } + return xstrdup(p); } /************************************************************* Utility function to prompt for new password. *************************************************************/ - -static void prompt_for_new_password(char *new_passwd, BOOL stdin_get) +static char *prompt_for_new_password(BOOL stdin_get) { - char *p; + char *p; + fstring new_passwd; - new_passwd[0] = '\0'; + ZERO_STRUCT(new_passwd); - p = get_pass("New SMB password:", stdin_get); + p = get_pass("New SMB password:", stdin_get); - strncpy(new_passwd, p, sizeof(fstring)); - new_passwd[sizeof(fstring)-1] = '\0'; + fstrcpy(new_passwd, p); - p = get_pass("Retype new SMB password:", stdin_get); + p = get_pass("Retype new SMB password:", stdin_get); - if (strncmp(p, new_passwd, sizeof(fstring)-1)) - { - fprintf(stderr, "%s: Mismatch - password unchanged.\n", prog_name); - exit(1); - } + if (strcmp(p, new_passwd)) { + fprintf(stderr, "Mismatch - password unchanged.\n"); + return NULL; + } - if (new_passwd[0] == '\0') { - printf("Password not set\n"); - exit(0); - } + return xstrdup(p); } -/********************************************************* - Start here. -**********************************************************/ -int main(int argc, char **argv) -{ - extern char *optarg; - extern int optind; - extern int DEBUGLEVEL; - uid_t real_uid; - uid_t eff_uid; - struct passwd *pwd = NULL; - fstring old_passwd; - fstring new_passwd; - uchar new_p16[16]; - uchar new_nt_p16[16]; - char *p; - struct smb_passwd *smb_pwent; - FILE *fp; - int ch; - int err; - BOOL is_root = False; - pstring user_name; - BOOL remote_user_name = False; - char *remote_machine = NULL; - BOOL add_user = False; - BOOL got_new_pass = False; - BOOL trust_account = False; - BOOL disable_user = False; - BOOL enable_user = False; - BOOL set_no_password = False; - BOOL joining_domain = False; - BOOL stdin_passwd_get = False; - char *new_domain = NULL; - pstring servicesf = CONFIGFILE; - void *vp; - struct nmb_name calling, called; - - - new_passwd[0] = '\0'; - user_name[0] = '\0'; - - memset(old_passwd, '\0', sizeof(old_passwd)); - memset(new_passwd, '\0', sizeof(new_passwd)); - prog_name = argv[0]; - TimeInit(); - - setup_logging(prog_name,True); - - charset_initialise(); - - if(!initialize_password_db()) { - fprintf(stderr, "%s: Can't setup password database vectors.\n", prog_name); - exit(1); - } - - if (!lp_load(servicesf,True,False,False)) { - fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n", prog_name, servicesf); - exit(1); - } - - if(!get_myname(myhostname,NULL)) { - fprintf(stderr, "%s: unable to get my hostname.\n", prog_name ); - exit(1); - } - - /* - * Set the machine NETBIOS name if not already - * set from the config file. - */ - - if (!*global_myname) - { - fstrcpy( global_myname, myhostname ); - p = strchr( global_myname, '.' ); - if (p) - *p = 0; - } - strupper( global_myname ); - - codepage_initialise(lp_client_code_page()); - - /* Get the real and effective uids */ - real_uid = getuid(); - eff_uid = geteuid(); - - /* Check the effective uid */ - if ((eff_uid == (uid_t)0) && (real_uid != (uid_t)0)) { - fprintf(stderr, "%s: Must *NOT* be setuid root.\n", prog_name); - exit(1); - } - - is_root = (eff_uid == (uid_t)0); - - while ((ch = getopt(argc, argv, "adehmnj:r:sR:D:U:")) != EOF) { - switch(ch) { - case 'a': - if(is_root) - add_user = True; - else - usage(prog_name, is_root); - break; - case 'd': - if(is_root) { - disable_user = True; - got_new_pass = True; - fstrcpy(new_passwd, "XXXXXX"); - } else - usage(prog_name, is_root); - break; - case 'e': - if(is_root) { - enable_user = True; - got_new_pass = True; - fstrcpy(new_passwd, "XXXXXX"); - } else - usage(prog_name, is_root); - break; - case 'D': - DEBUGLEVEL = atoi(optarg); - break; - case 'n': - if(is_root) { - set_no_password = True; - got_new_pass = True; - fstrcpy(new_passwd, "NO PASSWORD"); - } else - usage(prog_name, is_root); - case 'r': - remote_machine = optarg; - break; - case 's': - /* - * Ensure stdin/stdout are line buffered. - */ - if (setvbuf( stdin, NULL, _IOLBF, 0) != 0) { - fprintf(stderr, "%s: setvbuf error on stdin. Error was %s\n", prog_name, strerror(errno)); - exit(1); - } - - if (setvbuf( stdout, NULL, _IOLBF, 0) != 0) { - fprintf(stderr, "%s: setvbuf error on stdout. Error was %s\n", prog_name, strerror(errno)); - exit(1); - } - - if (setvbuf( stderr, NULL, _IOLBF, 0) != 0) { - fprintf(stderr, "%s: setvbuf error on stderr. Error was %s\n", prog_name, strerror(errno)); - perror("setvbuf error on stdout"); - exit(1); - } - - stdin_passwd_get = True; - break; - case 'R': - if(is_root) { - lp_set_name_resolve_order(optarg); - break; - } else - usage(prog_name, is_root); - case 'm': - if(is_root) { - trust_account = True; - } else - usage(prog_name, is_root); - break; - case 'j': - if(is_root) { - new_domain = optarg; - strupper(new_domain); - joining_domain = True; - } else - usage(prog_name, is_root); - break; - case 'U': - remote_user_name = True; - pstrcpy(user_name, optarg); - break; - case 'h': - default: - usage(prog_name, is_root); - } - } - - argc -= optind; - argv += optind; - - if (!is_root && remote_user_name && !remote_machine) { - fprintf(stderr, "%s: You can only use -U with -r.\n", prog_name); - usage(prog_name, False); - } - - /* - * Ensure add_user and either remote machine or join domain are - * not both set. - */ - - if(add_user && ((remote_machine != NULL) || joining_domain)) - usage(prog_name, True); - - /* - * Deal with joining a domain. - */ - if(joining_domain && argc != 0) - usage(prog_name, True); - - if(joining_domain) { - return join_domain( new_domain, remote_machine); - } - - if(is_root) { - - /* - * Deal with root - can add a user, but only locally. - */ - - switch(argc) { - case 0: - break; - case 1: - /* If we are root we can change another's password. */ - pstrcpy(user_name, argv[0]); - break; - case 2: - pstrcpy(user_name, argv[0]); - fstrcpy(new_passwd, argv[1]); - got_new_pass = True; - break; - default: - usage(prog_name, True); - } - - if(*user_name) { - - if(trust_account) { - int username_len = strlen(user_name); - if(username_len >= sizeof(pstring) - 1) { - fprintf(stderr, "%s: machine account name too long.\n", user_name); - exit(1); - } - - if(user_name[username_len-1] != '$') { - user_name[username_len] = '$'; - user_name[username_len+1] = '\0'; - } - } - - if(!remote_machine && ((pwd = Get_Pwnam(user_name, True)) == NULL)) { - fprintf(stderr, "%s: User \"%s\" was not found in system password file.\n", - prog_name, user_name); - exit(1); - } - } else { - if((pwd = getpwuid(eff_uid)) != NULL) - pstrcpy( user_name, pwd->pw_name); - } - - } else { - - if(add_user) { - fprintf(stderr, "%s: Only root can add a user.\n", prog_name); - usage(prog_name, False); - } - - if(disable_user) { - fprintf(stderr, "%s: Only root can disable a user.\n", prog_name); - usage(prog_name, False); - } - - if(enable_user) { - fprintf(stderr, "%s: Only root can enable a user.\n", prog_name); - usage(prog_name, False); - } - - if(argc > 1) - usage(prog_name, False); - - if(argc == 1) { - fstrcpy(new_passwd, argv[0]); - got_new_pass = True; - } - - if(!remote_user_name && ((pwd = getpwuid(eff_uid)) != NULL)) - pstrcpy( user_name, pwd->pw_name); - - /* - * A non-root user is always setting a password - * via a remote machine (even if that machine is - * localhost). - */ - - if(remote_machine == NULL) - remote_machine = "127.0.0.1"; - } - - if (*user_name == '\0') { - fprintf(stderr, "%s: Unable to get a user name for password change.\n", prog_name); - exit(1); - } - - /* - * If we are adding a machine account then pretend - * we already have the new password, we will be using - * the machinename as the password. - */ - - if(add_user && trust_account) { - got_new_pass = True; - strncpy(new_passwd, user_name, sizeof(fstring)); - new_passwd[sizeof(fstring)-1] = '\0'; - strlower(new_passwd); - if(new_passwd[strlen(new_passwd)-1] == '$') - new_passwd[strlen(new_passwd)-1] = '\0'; - } - - /* - * If we are root we don't ask for the old password (unless it's on a - * remote machine. - */ - - if (remote_machine != NULL) { - p = get_pass("Old SMB password:",stdin_passwd_get); - fstrcpy(old_passwd, p); - } - - if (!got_new_pass) - prompt_for_new_password(new_passwd,stdin_passwd_get); - - if (new_passwd[0] == '\0') { - printf("Password not set\n"); - exit(0); - } - - /* - * Now do things differently depending on if we're changing the - * password on a remote machine. Remember - a normal user is - * always using this code, looping back to the local smbd. - */ - - if(remote_machine != NULL) { - struct cli_state cli; - struct in_addr ip; - - if(!resolve_name( remote_machine, &ip, 0x20)) { - fprintf(stderr, "%s: unable to find an IP address for machine %s.\n", - prog_name, remote_machine ); - exit(1); - } +/************************************************************* +change a password on a remote machine using IPC calls +*************************************************************/ +static BOOL remote_password_change(const char *remote_machine, const char *user_name, + const char *old_passwd, const char *new_passwd) +{ + struct nmb_name calling, called; + struct cli_state cli; + struct in_addr ip; + + if(!resolve_name( remote_machine, &ip, 0x20)) { + fprintf(stderr, "unable to find an IP address for machine %s.\n", + remote_machine ); + return False; + } - ZERO_STRUCT(cli); + ZERO_STRUCT(cli); - if (!cli_initialise(&cli) || !cli_connect(&cli, remote_machine, &ip)) { - fprintf(stderr, "%s: unable to connect to SMB server on machine %s. Error was : %s.\n", - prog_name, remote_machine, cli_errstr(&cli) ); - exit(1); - } + if (!cli_initialise(&cli) || !cli_connect(&cli, remote_machine, &ip)) { + fprintf(stderr, "unable to connect to SMB server on machine %s. Error was : %s.\n", + remote_machine, cli_errstr(&cli) ); + return False; + } make_nmb_name(&calling, global_myname , 0x0 , scope); make_nmb_name(&called , remote_machine, 0x20, scope); - - if (!cli_session_request(&cli, &calling, &called)) - { - fprintf(stderr, "%s: machine %s rejected the session setup. Error was : %s.\n", - prog_name, remote_machine, cli_errstr(&cli) ); - cli_shutdown(&cli); - exit(1); - } + + if (!cli_session_request(&cli, &calling, &called)) { + fprintf(stderr, "machine %s rejected the session setup. Error was : %s.\n", + remote_machine, cli_errstr(&cli) ); + cli_shutdown(&cli); + return False; + } - cli.protocol = PROTOCOL_NT1; - - if (!cli_negprot(&cli)) { - fprintf(stderr, "%s: machine %s rejected the negotiate protocol. Error was : %s.\n", - prog_name, remote_machine, cli_errstr(&cli) ); - cli_shutdown(&cli); - exit(1); - } + cli.protocol = PROTOCOL_NT1; + + if (!cli_negprot(&cli)) { + fprintf(stderr, "machine %s rejected the negotiate protocol. Error was : %s.\n", + remote_machine, cli_errstr(&cli) ); + cli_shutdown(&cli); + return False; + } - /* - * We should connect as the anonymous user here, in case - * the server has "must change password" checked... - * Thanks to for this fix. - */ - - if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) { - fprintf(stderr, "%s: machine %s rejected the session setup. Error was : %s.\n", - prog_name, remote_machine, cli_errstr(&cli) ); - cli_shutdown(&cli); - exit(1); - } - - if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) { - fprintf(stderr, "%s: machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", - prog_name, remote_machine, cli_errstr(&cli) ); - cli_shutdown(&cli); - exit(1); - } - - if(!cli_oem_change_password(&cli, user_name, new_passwd, old_passwd)) { - fprintf(stderr, "%s: machine %s rejected the password change: Error was : %s.\n", - prog_name, remote_machine, cli_errstr(&cli) ); - cli_shutdown(&cli); - exit(1); - } - - cli_shutdown(&cli); - exit(0); - } - - /* - * Check for a machine account. - */ - - if(trust_account && !pwd) { - fprintf(stderr, "%s: User %s does not exist in system password file \ -(usually /etc/passwd). Cannot add machine account without a valid system user.\n", - prog_name, user_name); - exit(1); - } - - /* Calculate the MD4 hash (NT compatible) of the new password. */ - - nt_lm_owf_gen( new_passwd, new_nt_p16, new_p16); - - /* - * Open the smbpaswd file. - */ - vp = startsmbpwent(True); - if (!vp && errno == ENOENT) { - fprintf(stderr,"%s: smbpasswd file did not exist - attempting to create it.\n", prog_name); - fp = fopen(lp_smb_passwd_file(), "w"); - if (fp) { - fprintf(fp, "# Samba SMB password file\n"); - fclose(fp); - vp = startsmbpwent(True); - } - } - if (!vp) { - err = errno; - fprintf(stderr, "%s: Failed to open password file %s.\n", - prog_name, lp_smb_passwd_file()); - errno = err; - perror(prog_name); - exit(err); - } + /* + * We should connect as the anonymous user here, in case + * the server has "must change password" checked... + * Thanks to for this fix. + */ + + if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) { + fprintf(stderr, "machine %s rejected the session setup. Error was : %s.\n", + remote_machine, cli_errstr(&cli) ); + cli_shutdown(&cli); + return False; + } + + if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) { + fprintf(stderr, "machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", + remote_machine, cli_errstr(&cli) ); + cli_shutdown(&cli); + return False; + } + + if(!cli_oem_change_password(&cli, user_name, new_passwd, old_passwd)) { + fprintf(stderr, "machine %s rejected the password change: Error was : %s.\n", + remote_machine, cli_errstr(&cli) ); + cli_shutdown(&cli); + return False; + } + + cli_shutdown(&cli); + return True; +} + + +/************************************************************* +add a new user to the local smbpasswd file +*************************************************************/ +static BOOL add_new_user(char *user_name, uid_t uid, BOOL trust_account, + BOOL disable_user, BOOL set_no_password, + char *new_p16, char *new_nt_p16) +{ + struct smb_passwd new_smb_pwent; + + /* Create a new smb passwd entry and set it to the given password. */ + new_smb_pwent.smb_userid = uid; + new_smb_pwent.smb_name = user_name; + new_smb_pwent.smb_passwd = NULL; + new_smb_pwent.smb_nt_passwd = NULL; + new_smb_pwent.acct_ctrl = (trust_account ? ACB_WSTRUST : ACB_NORMAL); + + if(disable_user) { + new_smb_pwent.acct_ctrl |= ACB_DISABLED; + } else if (set_no_password) { + new_smb_pwent.acct_ctrl |= ACB_PWNOTREQ; + } else { + new_smb_pwent.smb_passwd = new_p16; + new_smb_pwent.smb_nt_passwd = new_nt_p16; + } + + return add_smbpwd_entry(&new_smb_pwent); +} + + +/************************************************************* +change a password entry in the local smbpasswd file +*************************************************************/ +static BOOL local_password_change(char *user_name, BOOL trust_account, BOOL add_user, + BOOL enable_user, BOOL disable_user, BOOL set_no_password, + char *new_passwd) +{ + struct passwd *pwd; + void *vp; + struct smb_passwd *smb_pwent; + uchar new_p16[16]; + uchar new_nt_p16[16]; + + pwd = getpwnam(user_name); + + /* + * Check for a machine account. + */ + + if(trust_account && !pwd) { + fprintf(stderr, "User %s does not exist in system password file (usually /etc/passwd). Cannot add machine account without a valid system user.\n", + user_name); + return False; + } + + /* Calculate the MD4 hash (NT compatible) of the new password. */ + nt_lm_owf_gen(new_passwd, new_nt_p16, new_p16); + + /* + * Open the smbpaswd file. + */ + vp = startsmbpwent(True); + if (!vp && errno == ENOENT) { + FILE *fp; + fprintf(stderr,"smbpasswd file did not exist - attempting to create it.\n"); + fp = fopen(lp_smb_passwd_file(), "w"); + if (fp) { + fprintf(fp, "# Samba SMB password file\n"); + fclose(fp); + vp = startsmbpwent(True); + } + } + + if (!vp) { + perror(lp_smb_passwd_file()); + return False; + } - /* Get the smb passwd entry for this user */ - smb_pwent = getsmbpwnam(user_name); - if (smb_pwent == NULL) { - if(add_user == False) { - fprintf(stderr, "%s: Failed to find entry for user %s.\n", - prog_name, pwd->pw_name); - endsmbpwent(vp); - exit(1); - } - - /* Create a new smb passwd entry and set it to the given password. */ - { - struct smb_passwd new_smb_pwent; - - new_smb_pwent.smb_userid = pwd->pw_uid; - new_smb_pwent.smb_name = pwd->pw_name; - new_smb_pwent.smb_passwd = NULL; - new_smb_pwent.smb_nt_passwd = NULL; - new_smb_pwent.acct_ctrl = (trust_account ? ACB_WSTRUST : ACB_NORMAL); - - if(disable_user) { - new_smb_pwent.acct_ctrl |= ACB_DISABLED; - } else if (set_no_password) { - new_smb_pwent.acct_ctrl |= ACB_PWNOTREQ; - } else { - new_smb_pwent.smb_passwd = new_p16; - new_smb_pwent.smb_nt_passwd = new_nt_p16; - } - - if(add_smbpwd_entry(&new_smb_pwent) == False) { - fprintf(stderr, "%s: Failed to add entry for user %s.\n", - prog_name, pwd->pw_name); - endsmbpwent(vp); - exit(1); - } - - endsmbpwent(vp); - printf("%s: Added user %s.\n", prog_name, user_name); - exit(0); - } - } else { - /* the entry already existed */ - add_user = False; - } - - /* - * We are root - just write the new password - * and the valid last change time. - */ - - if(disable_user) - smb_pwent->acct_ctrl |= ACB_DISABLED; - else if (enable_user) { - if(smb_pwent->smb_passwd == NULL) { - prompt_for_new_password(new_passwd,stdin_passwd_get); - nt_lm_owf_gen( new_passwd, new_nt_p16, new_p16); - smb_pwent->smb_passwd = new_p16; - smb_pwent->smb_nt_passwd = new_nt_p16; - } - smb_pwent->acct_ctrl &= ~ACB_DISABLED; - } else if (set_no_password) { - smb_pwent->acct_ctrl |= ACB_PWNOTREQ; - /* This is needed to preserve ACB_PWNOTREQ in mod_smbfilepwd_entry */ - smb_pwent->smb_passwd = NULL; - smb_pwent->smb_nt_passwd = NULL; - } else { - smb_pwent->acct_ctrl &= ~ACB_PWNOTREQ; - smb_pwent->smb_passwd = new_p16; - smb_pwent->smb_nt_passwd = new_nt_p16; - } - - if(mod_smbpwd_entry(smb_pwent,True) == False) { - fprintf(stderr, "%s: Failed to modify entry for user %s.\n", - prog_name, pwd->pw_name); - endsmbpwent(vp); - exit(1); - } - - endsmbpwent(vp); - if(disable_user) - printf("User %s disabled.\n", user_name); - else if(enable_user) - printf("User %s enabled.\n", user_name); - else if (set_no_password) - printf("User %s - set to no password.\n", user_name); - else - printf("Password changed for user %s.\n", user_name); - return 0; + /* Get the smb passwd entry for this user */ + smb_pwent = getsmbpwnam(user_name); + if (smb_pwent == NULL) { + if(add_user == False) { + fprintf(stderr, "Failed to find entry for user %s.\n", + pwd->pw_name); + endsmbpwent(vp); + return False; + } + + if (add_new_user(user_name, pwd->pw_uid, trust_account, disable_user, + set_no_password, new_p16, new_nt_p16)) { + printf("Added user %s.\n", user_name); + endsmbpwent(vp); + return True; + } else { + fprintf(stderr, "Failed to add entry for user %s.\n", user_name); + endsmbpwent(vp); + return False; + } + } else { + /* the entry already existed */ + add_user = False; + } + + /* + * We are root - just write the new password + * and the valid last change time. + */ + + if(disable_user) { + smb_pwent->acct_ctrl |= ACB_DISABLED; + } else if (enable_user) { + if(smb_pwent->smb_passwd == NULL) { + smb_pwent->smb_passwd = new_p16; + smb_pwent->smb_nt_passwd = new_nt_p16; + } + smb_pwent->acct_ctrl &= ~ACB_DISABLED; + } else if (set_no_password) { + smb_pwent->acct_ctrl |= ACB_PWNOTREQ; + /* This is needed to preserve ACB_PWNOTREQ in mod_smbfilepwd_entry */ + smb_pwent->smb_passwd = NULL; + smb_pwent->smb_nt_passwd = NULL; + } else { + smb_pwent->acct_ctrl &= ~ACB_PWNOTREQ; + smb_pwent->smb_passwd = new_p16; + smb_pwent->smb_nt_passwd = new_nt_p16; + } + + if(mod_smbpwd_entry(smb_pwent,True) == False) { + fprintf(stderr, "Failed to modify entry for user %s.\n", + pwd->pw_name); + endsmbpwent(vp); + return False; + } + + endsmbpwent(vp); + + return True; +} + + +/************************************************************* +change a password either locally or remotely +*************************************************************/ +static BOOL password_change(const char *remote_machine, char *user_name, + char *old_passwd, char *new_passwd, + BOOL add_user, BOOL enable_user, + BOOL disable_user, BOOL set_no_password, + BOOL trust_account) +{ + if (remote_machine != NULL) { + if (add_user || enable_user || disable_user || set_no_password || trust_account) { + /* these things can't be done remotely yet */ + return False; + } + return remote_password_change(remote_machine, user_name, old_passwd, new_passwd); + } + + return local_password_change(user_name, trust_account, add_user, enable_user, + disable_user, set_no_password, new_passwd); +} + + +/************************************************************* +handle password changing for root +*************************************************************/ +static int process_root(int argc, char *argv[]) +{ + struct passwd *pwd; + int ch; + BOOL joining_domain = False; + BOOL trust_account = False; + BOOL add_user = False; + BOOL disable_user = False; + BOOL enable_user = False; + BOOL set_no_password = False; + BOOL stdin_passwd_get = False; + char *user_name = NULL; + char *new_domain = NULL; + char *new_passwd = NULL; + char *old_passwd = NULL; + char *remote_machine = NULL; + + while ((ch = getopt(argc, argv, "adehmnj:r:sR:D:U:")) != EOF) { + switch(ch) { + case 'a': + add_user = True; + break; + case 'd': + disable_user = True; + new_passwd = "XXXXXX"; + break; + case 'e': + enable_user = True; + break; + case 'D': + DEBUGLEVEL = atoi(optarg); + break; + case 'n': + set_no_password = True; + new_passwd = "NO PASSWORD"; + case 'r': + remote_machine = optarg; + break; + case 's': + set_line_buffering(stdin); + set_line_buffering(stdout); + set_line_buffering(stderr); + stdin_passwd_get = True; + break; + case 'R': + lp_set_name_resolve_order(optarg); + break; + case 'm': + trust_account = True; + break; + case 'j': + new_domain = optarg; + strupper(new_domain); + joining_domain = True; + break; + case 'U': + user_name = optarg; + break; + default: + usage(); + } + } + + argc -= optind; + argv += optind; + + + /* + * Ensure add_user and either remote machine or join domain are + * not both set. + */ + if(add_user && ((remote_machine != NULL) || joining_domain)) { + usage(); + } + + if(joining_domain) { + if (argc != 0) usage(); + return join_domain(new_domain, remote_machine); + } + + /* + * Deal with root - can add a user, but only locally. + */ + + switch(argc) { + case 0: + break; + case 1: + user_name = argv[0]; + break; + case 2: + user_name = argv[0]; + new_passwd = argv[1]; + break; + default: + usage(); + } + + if (!user_name && (pwd = getpwuid(0))) { + user_name = xstrdup(pwd->pw_name); + } + + if (!user_name) { + fprintf(stderr,"You must specify a username\n"); + exit(1); + } + + if (!remote_machine && !Get_Pwnam(user_name, True)) { + fprintf(stderr, "User \"%s\" was not found in system password file.\n", + user_name); + exit(1); + } + + if (user_name[strlen(user_name)-1] == '$') { + user_name[strlen(user_name)-1] = 0; + } + + if (trust_account) { + /* add the $ automatically */ + static fstring buf; + + if (add_user) { + new_passwd = xstrdup(user_name); + strlower(new_passwd); + } + + slprintf(buf, sizeof(buf)-1, "%s$", user_name); + user_name = buf; + } + + if (remote_machine != NULL) { + old_passwd = get_pass("Old SMB password:",stdin_passwd_get); + } + + if (!new_passwd) { + new_passwd = prompt_for_new_password(stdin_passwd_get); + } + + if (!password_change(remote_machine, user_name, old_passwd, new_passwd, + add_user, enable_user, disable_user, set_no_password, + trust_account)) { + fprintf(stderr,"Failed to change password entry for %s\n", user_name); + return 1; + } + + if(disable_user) { + printf("User %s disabled.\n", user_name); + } else if(enable_user) { + printf("User %s enabled.\n", user_name); + } else if (set_no_password) { + printf("User %s - set to no password.\n", user_name); + } else { + printf("Password changed for user %s\n", user_name); + } + return 0; +} + + +/************************************************************* +handle password changing for non-root +*************************************************************/ +static int process_nonroot(int argc, char *argv[]) +{ + struct passwd *pwd = NULL; + int ch; + BOOL stdin_passwd_get = False; + char *old_passwd = NULL; + char *remote_machine = NULL; + char *user_name = NULL; + char *new_passwd = NULL; + + while ((ch = getopt(argc, argv, "hD:r:sU:")) != EOF) { + switch(ch) { + case 'D': + DEBUGLEVEL = atoi(optarg); + break; + case 'r': + remote_machine = optarg; + break; + case 's': + set_line_buffering(stdin); + set_line_buffering(stdout); + set_line_buffering(stderr); + stdin_passwd_get = True; + break; + case 'U': + user_name = optarg; + break; + default: + usage(); + } + } + + argc -= optind; + argv += optind; + + if(argc > 1) { + usage(); + } + + if (argc == 1) { + new_passwd = argv[0]; + } + + if (!user_name) { + pwd = getpwuid(getuid()); + if (pwd) { + user_name = xstrdup(pwd->pw_name); + } else { + fprintf(stderr,"you don't exist - go away\n"); + exit(1); + } + } + + /* + * A non-root user is always setting a password + * via a remote machine (even if that machine is + * localhost). + */ + if (remote_machine == NULL) { + remote_machine = "127.0.0.1"; + } + + + if (remote_machine != NULL) { + old_passwd = get_pass("Old SMB password:",stdin_passwd_get); + } + + if (!new_passwd) { + new_passwd = prompt_for_new_password(stdin_passwd_get); + } + + if (!new_passwd) { + printf("unable to get new password\n"); + exit(0); + } + + if (!password_change(remote_machine, user_name, old_passwd, new_passwd, + False, False, False, False, False)) { + fprintf(stderr,"Failed to change password for %s\n", user_name); + return 1; + } + + printf("Password changed for user %s\n", user_name); + return 0; +} + + + +/********************************************************* + Start here. +**********************************************************/ +int main(int argc, char **argv) +{ + static pstring servicesf = CONFIGFILE; + + TimeInit(); + + setup_logging("smbpasswd", True); + + charset_initialise(); + + if(!initialize_password_db()) { + fprintf(stderr, "Can't setup password database vectors.\n"); + exit(1); + } + + if (!lp_load(servicesf,True,False,False)) { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", + servicesf); + exit(1); + } + + if(!get_myname(myhostname,NULL)) { + fprintf(stderr, "unable to get my hostname.\n"); + exit(1); + } + + /* + * Set the machine NETBIOS name if not already + * set from the config file. + */ + + if (!*global_myname) { + char *p; + fstrcpy(global_myname, myhostname); + p = strchr(global_myname, '.' ); + if (p) *p = 0; + } + strupper(global_myname); + + codepage_initialise(lp_client_code_page()); + + /* Check the effective uid - make sure we are not setuid */ + if ((geteuid() == (uid_t)0) && (getuid() != (uid_t)0)) { + fprintf(stderr, "smbpasswd must *NOT* be setuid root.\n"); + exit(1); + } + + if (getuid() == 0) { + return process_root(argc, argv); + } + + return process_nonroot(argc, argv); } -- cgit From 4f368d8b924b76007809e967ac1f37f6a1ebdd68 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 Nov 1998 06:24:18 +0000 Subject: char -> uchar fix (This used to be commit badc0f229a2940560b56aafde9824f1b4bd0f7c7) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 09aa0be9d6..da7caacb11 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -295,7 +295,7 @@ add a new user to the local smbpasswd file *************************************************************/ static BOOL add_new_user(char *user_name, uid_t uid, BOOL trust_account, BOOL disable_user, BOOL set_no_password, - char *new_p16, char *new_nt_p16) + uchar *new_p16, uchar *new_nt_p16) { struct smb_passwd new_smb_pwent; -- cgit From 29e36b713468d7e7de301c483fc340ef42b4a9fb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 Nov 1998 07:06:48 +0000 Subject: extracted the password change code from smbpasswd and used it in swat instead of opening pipes and other horrible stuff. (This used to be commit 49bf19710345a59a2d17cd449be1a132885ed821) --- source3/utils/smbpasswd.c | 218 ---------------------------------------------- 1 file changed, 218 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index da7caacb11..2303bc56df 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -19,10 +19,8 @@ #include "includes.h" -extern pstring scope; extern pstring myhostname; extern pstring global_myname; -extern fstring global_myworkgroup; extern int DEBUGLEVEL; @@ -213,222 +211,6 @@ static char *prompt_for_new_password(BOOL stdin_get) } - - -/************************************************************* -change a password on a remote machine using IPC calls -*************************************************************/ -static BOOL remote_password_change(const char *remote_machine, const char *user_name, - const char *old_passwd, const char *new_passwd) -{ - struct nmb_name calling, called; - struct cli_state cli; - struct in_addr ip; - - if(!resolve_name( remote_machine, &ip, 0x20)) { - fprintf(stderr, "unable to find an IP address for machine %s.\n", - remote_machine ); - return False; - } - - ZERO_STRUCT(cli); - - if (!cli_initialise(&cli) || !cli_connect(&cli, remote_machine, &ip)) { - fprintf(stderr, "unable to connect to SMB server on machine %s. Error was : %s.\n", - remote_machine, cli_errstr(&cli) ); - return False; - } - - make_nmb_name(&calling, global_myname , 0x0 , scope); - make_nmb_name(&called , remote_machine, 0x20, scope); - - if (!cli_session_request(&cli, &calling, &called)) { - fprintf(stderr, "machine %s rejected the session setup. Error was : %s.\n", - remote_machine, cli_errstr(&cli) ); - cli_shutdown(&cli); - return False; - } - - cli.protocol = PROTOCOL_NT1; - - if (!cli_negprot(&cli)) { - fprintf(stderr, "machine %s rejected the negotiate protocol. Error was : %s.\n", - remote_machine, cli_errstr(&cli) ); - cli_shutdown(&cli); - return False; - } - - /* - * We should connect as the anonymous user here, in case - * the server has "must change password" checked... - * Thanks to for this fix. - */ - - if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) { - fprintf(stderr, "machine %s rejected the session setup. Error was : %s.\n", - remote_machine, cli_errstr(&cli) ); - cli_shutdown(&cli); - return False; - } - - if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) { - fprintf(stderr, "machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", - remote_machine, cli_errstr(&cli) ); - cli_shutdown(&cli); - return False; - } - - if(!cli_oem_change_password(&cli, user_name, new_passwd, old_passwd)) { - fprintf(stderr, "machine %s rejected the password change: Error was : %s.\n", - remote_machine, cli_errstr(&cli) ); - cli_shutdown(&cli); - return False; - } - - cli_shutdown(&cli); - return True; -} - - -/************************************************************* -add a new user to the local smbpasswd file -*************************************************************/ -static BOOL add_new_user(char *user_name, uid_t uid, BOOL trust_account, - BOOL disable_user, BOOL set_no_password, - uchar *new_p16, uchar *new_nt_p16) -{ - struct smb_passwd new_smb_pwent; - - /* Create a new smb passwd entry and set it to the given password. */ - new_smb_pwent.smb_userid = uid; - new_smb_pwent.smb_name = user_name; - new_smb_pwent.smb_passwd = NULL; - new_smb_pwent.smb_nt_passwd = NULL; - new_smb_pwent.acct_ctrl = (trust_account ? ACB_WSTRUST : ACB_NORMAL); - - if(disable_user) { - new_smb_pwent.acct_ctrl |= ACB_DISABLED; - } else if (set_no_password) { - new_smb_pwent.acct_ctrl |= ACB_PWNOTREQ; - } else { - new_smb_pwent.smb_passwd = new_p16; - new_smb_pwent.smb_nt_passwd = new_nt_p16; - } - - return add_smbpwd_entry(&new_smb_pwent); -} - - -/************************************************************* -change a password entry in the local smbpasswd file -*************************************************************/ -static BOOL local_password_change(char *user_name, BOOL trust_account, BOOL add_user, - BOOL enable_user, BOOL disable_user, BOOL set_no_password, - char *new_passwd) -{ - struct passwd *pwd; - void *vp; - struct smb_passwd *smb_pwent; - uchar new_p16[16]; - uchar new_nt_p16[16]; - - pwd = getpwnam(user_name); - - /* - * Check for a machine account. - */ - - if(trust_account && !pwd) { - fprintf(stderr, "User %s does not exist in system password file (usually /etc/passwd). Cannot add machine account without a valid system user.\n", - user_name); - return False; - } - - /* Calculate the MD4 hash (NT compatible) of the new password. */ - nt_lm_owf_gen(new_passwd, new_nt_p16, new_p16); - - /* - * Open the smbpaswd file. - */ - vp = startsmbpwent(True); - if (!vp && errno == ENOENT) { - FILE *fp; - fprintf(stderr,"smbpasswd file did not exist - attempting to create it.\n"); - fp = fopen(lp_smb_passwd_file(), "w"); - if (fp) { - fprintf(fp, "# Samba SMB password file\n"); - fclose(fp); - vp = startsmbpwent(True); - } - } - - if (!vp) { - perror(lp_smb_passwd_file()); - return False; - } - - /* Get the smb passwd entry for this user */ - smb_pwent = getsmbpwnam(user_name); - if (smb_pwent == NULL) { - if(add_user == False) { - fprintf(stderr, "Failed to find entry for user %s.\n", - pwd->pw_name); - endsmbpwent(vp); - return False; - } - - if (add_new_user(user_name, pwd->pw_uid, trust_account, disable_user, - set_no_password, new_p16, new_nt_p16)) { - printf("Added user %s.\n", user_name); - endsmbpwent(vp); - return True; - } else { - fprintf(stderr, "Failed to add entry for user %s.\n", user_name); - endsmbpwent(vp); - return False; - } - } else { - /* the entry already existed */ - add_user = False; - } - - /* - * We are root - just write the new password - * and the valid last change time. - */ - - if(disable_user) { - smb_pwent->acct_ctrl |= ACB_DISABLED; - } else if (enable_user) { - if(smb_pwent->smb_passwd == NULL) { - smb_pwent->smb_passwd = new_p16; - smb_pwent->smb_nt_passwd = new_nt_p16; - } - smb_pwent->acct_ctrl &= ~ACB_DISABLED; - } else if (set_no_password) { - smb_pwent->acct_ctrl |= ACB_PWNOTREQ; - /* This is needed to preserve ACB_PWNOTREQ in mod_smbfilepwd_entry */ - smb_pwent->smb_passwd = NULL; - smb_pwent->smb_nt_passwd = NULL; - } else { - smb_pwent->acct_ctrl &= ~ACB_PWNOTREQ; - smb_pwent->smb_passwd = new_p16; - smb_pwent->smb_nt_passwd = new_nt_p16; - } - - if(mod_smbpwd_entry(smb_pwent,True) == False) { - fprintf(stderr, "Failed to modify entry for user %s.\n", - pwd->pw_name); - endsmbpwent(vp); - return False; - } - - endsmbpwent(vp); - - return True; -} - - /************************************************************* change a password either locally or remotely *************************************************************/ -- cgit From 3a334e3e6c52624ab839c150593cdc1471d06768 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 12 Nov 1998 20:22:11 +0000 Subject: Fixed smbpasswd so that enabling a user who already has a password doesn't require a new password entry. Sets the 'enable/disable' code back to being symmetrical. Jeremy. (This used to be commit fa068a6db8da154903fb97a843f261592fcb684a) --- source3/utils/smbpasswd.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 2303bc56df..e9d0e3d313 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -58,7 +58,7 @@ static void usage(void) printf(" -R ORDER name resolve order\n"); printf(" -j DOMAIN join domain name\n"); printf(" -a add user\n"); - printf(" -d delete user\n"); + printf(" -d disable user\n"); printf(" -e enable user\n"); printf(" -n set no password\n"); printf(" -m machine trust account\n"); @@ -371,7 +371,25 @@ static int process_root(int argc, char *argv[]) } if (!new_passwd) { - new_passwd = prompt_for_new_password(stdin_passwd_get); + + /* + * If we are trying to enable a user, first we need to find out + * if they are using a modern version of the smbpasswd file that + * disables a user by just writing a flag into the file. If so + * then we can re-enable a user without prompting for a new + * password. If not (ie. they have a no stored password in the + * smbpasswd file) then we need to prompt for a new password. + */ + + if(enable_user) { + struct smb_passwd *smb_pass = getsmbpwnam(user_name); + if((smb_pass != NULL) && (smb_pass->smb_passwd != NULL)) { + new_passwd = "XXXX"; /* Don't care. */ + } + } + + if(!new_passwd) + new_passwd = prompt_for_new_password(stdin_passwd_get); } if (!password_change(remote_machine, user_name, old_passwd, new_passwd, -- cgit From ea2fa33f6564389240c4b414e27065a4a01dcfbc Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Thu, 12 Nov 1998 23:49:32 +0000 Subject: Removed code that used printf/fprintf in password changin libraries. Now passes strings instead. (This used to be commit 48af29bcc9e8094de6ba057a52dbae3c80ea7a05) --- source3/utils/smbpasswd.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index e9d0e3d313..2adb6d9523 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -220,16 +220,32 @@ static BOOL password_change(const char *remote_machine, char *user_name, BOOL disable_user, BOOL set_no_password, BOOL trust_account) { + BOOL ret; + pstring err_str; + pstring msg_str; + if (remote_machine != NULL) { if (add_user || enable_user || disable_user || set_no_password || trust_account) { /* these things can't be done remotely yet */ return False; } - return remote_password_change(remote_machine, user_name, old_passwd, new_passwd); + ret = remote_password_change(remote_machine, user_name, + old_passwd, new_passwd, err_str, sizeof(err_str)); + if(*err_str) + fprintf(stderr, err_str); + return ret; } - return local_password_change(user_name, trust_account, add_user, enable_user, - disable_user, set_no_password, new_passwd); + ret = local_password_change(user_name, trust_account, add_user, enable_user, + disable_user, set_no_password, new_passwd, + err_str, sizeof(err_str), msg_str, sizeof(msg_str)); + + if(*msg_str) + printf(msg_str); + if(*err_str) + fprintf(stderr, err_str); + + return ret; } -- cgit From 31c4953088c20de1eb292f47c87c70e38ca574ea Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 13 Nov 1998 01:08:28 +0000 Subject: sids in rpctorture changed from fstrings to DOM_SID (This used to be commit bd09e00112fd371aa070b5b47f1d4e27137a7f2e) --- source3/utils/rpctorture.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/rpctorture.c b/source3/utils/rpctorture.c index 50030bcadc..96d1181ca0 100644 --- a/source3/utils/rpctorture.c +++ b/source3/utils/rpctorture.c @@ -294,9 +294,9 @@ enum client_action pstrcpy(cli_info.share, ""); pstrcpy(cli_info.service, ""); - pstrcpy(cli_info.dom.level3_sid, ""); + ZERO_STRUCT(cli_info.dom.level3_sid); pstrcpy(cli_info.dom.level3_dom, ""); - pstrcpy(cli_info.dom.level5_sid, ""); + ZERO_STRUCT(cli_info.dom.level5_sid); pstrcpy(cli_info.dom.level5_dom, ""); smb_cli->nt_pipe_fnum = 0xffff; -- cgit From 2db96e3047400be594e7c5ebf7d6fcedb77f6907 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 13 Nov 1998 03:37:01 +0000 Subject: fixes for OSF1 compilation (This used to be commit 5be3c37f50eac35cad3eadf0d24e7a4ee04c075e) --- source3/utils/debug2html.c | 9 ++++++--- source3/utils/smbpasswd.c | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/debug2html.c b/source3/utils/debug2html.c index 00c6306fcf..fa2be41336 100644 --- a/source3/utils/debug2html.c +++ b/source3/utils/debug2html.c @@ -29,6 +29,9 @@ * -------------------------------------------------------------------------- ** * * $Log: debug2html.c,v $ + * Revision 1.4 1998/11/13 03:37:01 tridge + * fixes for OSF1 compilation + * * Revision 1.3 1998/10/28 20:33:35 crh * I've moved the debugparse module files into the ubiqx directory because I * know that 'make proto' will ignore them there. The debugparse.h header @@ -61,7 +64,7 @@ * The size of the read buffer. */ -#define BSIZE 1024 +#define DBG_BSIZE 1024 /* -------------------------------------------------------------------------- ** * Functions... @@ -219,7 +222,7 @@ int main( int argc, char *argv[] ) { int i; int len; - char bufr[BSIZE]; + char bufr[DBG_BSIZE]; dbg_Token old = dbg_null, new = dbg_null, state = dbg_null, @@ -230,7 +233,7 @@ int main( int argc, char *argv[] ) (void)printf( " Samba Debug Output\n\n\n\n" ); while( (!feof( stdin )) - && ((len = fread( bufr, 1, BSIZE, stdin )) > 0) ) + && ((len = fread( bufr, 1, DBG_BSIZE, stdin )) > 0) ) { for( i = 0; i < len; i++ ) { diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 2adb6d9523..a96a1c0f7b 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -153,7 +153,7 @@ static char *stdin_new_passwd(void) static fstring new_passwd; size_t len; - ZERO_STRUCT(new_passwd); + ZERO_ARRAY(new_passwd); /* * if no error is reported from fgets() and string at least contains @@ -194,7 +194,7 @@ static char *prompt_for_new_password(BOOL stdin_get) char *p; fstring new_passwd; - ZERO_STRUCT(new_passwd); + ZERO_ARRAY(new_passwd); p = get_pass("New SMB password:", stdin_get); -- cgit From f4447df41b59f6939528f517a07078c596d2b8b5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 16 Nov 1998 20:19:57 +0000 Subject: Added fixes for machine accounts. Jeremy. (This used to be commit 7aa644c2f996433f8ec125bfd4221aec49bece2b) --- source3/utils/smbpasswd.c | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index a96a1c0f7b..902f59b245 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -254,6 +254,12 @@ handle password changing for root *************************************************************/ static int process_root(int argc, char *argv[]) { + /* + * Next two lines needed for SunOS and don't + * hurt anything else... + */ + extern char *optarg; + extern int optind; struct passwd *pwd; int ch; BOOL joining_domain = False; @@ -359,29 +365,39 @@ static int process_root(int argc, char *argv[]) exit(1); } - if (!remote_machine && !Get_Pwnam(user_name, True)) { - fprintf(stderr, "User \"%s\" was not found in system password file.\n", - user_name); - exit(1); - } - - if (user_name[strlen(user_name)-1] == '$') { - user_name[strlen(user_name)-1] = 0; - } - if (trust_account) { /* add the $ automatically */ static fstring buf; + /* + * Remove any trailing '$' before we + * generate the initial machine password. + */ + + if (user_name[strlen(user_name)-1] == '$') { + user_name[strlen(user_name)-1] = 0; + } + if (add_user) { new_passwd = xstrdup(user_name); strlower(new_passwd); } + /* + * Now ensure the username ends in '$' for + * the machine add. + */ + slprintf(buf, sizeof(buf)-1, "%s$", user_name); user_name = buf; } + if (!remote_machine && !Get_Pwnam(user_name, True)) { + fprintf(stderr, "User \"%s\" was not found in system password file.\n", + user_name); + exit(1); + } + if (remote_machine != NULL) { old_passwd = get_pass("Old SMB password:",stdin_passwd_get); } @@ -433,6 +449,12 @@ handle password changing for non-root *************************************************************/ static int process_nonroot(int argc, char *argv[]) { + /* + * Next two lines needed for SunOS and don't + * hurt anything else... + */ + extern char *optarg; + extern int optind; struct passwd *pwd = NULL; int ch; BOOL stdin_passwd_get = False; -- cgit From 74d539f5573a3ed3ff1b96c54752a389da4c3e14 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Tue, 17 Nov 1998 16:19:04 +0000 Subject: - group database API. oops and oh dear, the threat has been carried out: the pre-alpha "domain group" etc parameters have disappeared. - interactive debug detection - re-added mem_man (andrew's memory management, detects memory corruption) - american spellings of "initialise" replaced with english spelling of "initialise". - started on "lookup_name()" and "lookup_sid()" functions. proper ones. - moved lots of functions around. created some modules of commonly used code. e.g the password file locking code, which is used in groupfile.c and aliasfile.c and smbpass.c - moved RID_TYPE_MASK up another bit. this is really unfortunate, but there is no other "fast" way to identify users from groups from aliases. i do not believe that this code saves us anything (the multipliers) and puts us at a disadvantage (reduces the useable rid space). the designers of NT aren't silly: if they can get away with a user- interface-speed LsaLookupNames / LsaLookupSids, then so can we. i spoke with isaac at the cifs conference, the only time for example that they do a security context check is on file create. certainly not on individual file reads / writes, which would drastically hit their performance and ours, too. - renamed myworkgroup to global_sam_name, amongst other things, when used in the rpc code. there is also a global_member_name, as we are always responsible for a SAM database, the scope of which is limited by the role of the machine (e.g if a member of a workgroup, your SAM is for _local_ logins only, and its name is the name of your server. you even still have a SID. see LsaQueryInfoPolicy, levels 3 and 5). - updated functionality of groupname.c to be able to cope with names like DOMAIN\group and SERVER\alias. used this code to be able to do aliases as well as groups. this code may actually be better off being used in username mapping, too. - created a connect to serverlist function in clientgen.c and used it in password.c - initialisation in server.c depends on the role of the server. well, it does now. - rpctorture. smbtorture. EXERCISE EXTREME CAUTION. (This used to be commit 0d21e1e6090b933f396c764af535ca3388a562db) --- source3/utils/rpctorture.c | 503 ++++++++++++++++++++++++++++++++++++++++----- source3/utils/smbpasswd.c | 2 +- source3/utils/torture.c | 421 +++++++++++++++++++++++-------------- 3 files changed, 721 insertions(+), 205 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/rpctorture.c b/source3/utils/rpctorture.c index 96d1181ca0..dac64a22e3 100644 --- a/source3/utils/rpctorture.c +++ b/source3/utils/rpctorture.c @@ -49,7 +49,36 @@ struct cli_state *smb_cli = &smbcli; FILE *out_hnd; +static pstring user_name; /* local copy only, if one is entered */ static pstring password; /* local copy only, if one is entered */ +static pstring domain; /* local copy only, if one is entered */ +BOOL got_pass = False; + +static struct nmb_name calling; +static struct nmb_name called; + +static void get_passwd(void) +{ + /* set the password cache info */ + if (got_pass) + { + if (password[0] == 0) + { + pwd_set_nullpwd(&(smb_cli->pwd)); + } + else + { + pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ + } + } + else + { + char *pwd = getpass("Enter Password:"); + safe_strcpy(password, pwd, sizeof(password)); + pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ + got_pass = True; + } +} /**************************************************************************** initialise smb client structure @@ -59,6 +88,23 @@ void rpcclient_init(void) bzero(smb_cli, sizeof(smb_cli)); cli_initialise(smb_cli); smb_cli->capabilities |= CAP_NT_SMBS; + smb_cli->capabilities |= CAP_STATUS32; + + pstrcpy(smb_cli->user_name, user_name); + smb_cli->nt_pipe_fnum = 0xffff; + + get_passwd(); + + if (*domain == 0) + { + pstrcpy(smb_cli->domain,lp_workgroup()); + } + else + { + pstrcpy(smb_cli->domain, domain); + } + + strupper(smb_cli->domain); } /**************************************************************************** @@ -66,11 +112,7 @@ make smb client connection ****************************************************************************/ static BOOL rpcclient_connect(struct client_info *info) { - struct nmb_name calling; - struct nmb_name called; - - make_nmb_name(&called , dns_to_netbios_name(info->dest_host ), info->name_type, scope); - make_nmb_name(&calling, dns_to_netbios_name(info->myhostname), 0x0 , scope); + rpcclient_init(); if (!cli_establish_connection(smb_cli, info->dest_host, &info->dest_ip, @@ -97,7 +139,7 @@ static void rpcclient_stop(void) /**************************************************************************** log in as an nt user, log out again. ****************************************************************************/ -void run_enums_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) +void run_enums_test(int num_ops, struct client_info *cli_info) { pstring cmd; int i; @@ -105,8 +147,8 @@ void run_enums_test(int num_ops, struct client_info *cli_info, struct cli_state /* establish connections. nothing to stop these being re-established. */ rpcclient_connect(cli_info); - DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd)); - if (cli->fd <= 0) + DEBUG(5,("rpcclient_connect: smb_cli->fd:%d\n", smb_cli->fd)); + if (smb_cli->fd <= 0) { fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n", cli_info->dest_host, cli_info->name_type); @@ -141,7 +183,7 @@ void run_enums_test(int num_ops, struct client_info *cli_info, struct cli_state /**************************************************************************** log in as an nt user, log out again. ****************************************************************************/ -void run_ntlogin_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) +void run_ntlogin_test(int num_ops, struct client_info *cli_info) { pstring cmd; int i; @@ -149,8 +191,8 @@ void run_ntlogin_test(int num_ops, struct client_info *cli_info, struct cli_stat /* establish connections. nothing to stop these being re-established. */ rpcclient_connect(cli_info); - DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd)); - if (cli->fd <= 0) + DEBUG(5,("rpcclient_connect: smb_cli->fd:%d\n", smb_cli->fd)); + if (smb_cli->fd <= 0) { fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n", cli_info->dest_host, cli_info->name_type); @@ -159,7 +201,7 @@ void run_ntlogin_test(int num_ops, struct client_info *cli_info, struct cli_stat for (i = 0; i < num_ops; i++) { - slprintf(cmd, sizeof(cmd)-1, "%s %s", cli->user_name, password); + slprintf(cmd, sizeof(cmd)-1, "%s %s", smb_cli->user_name, password); set_first_token(cmd); cmd_netlogon_login_test(cli_info); @@ -169,12 +211,387 @@ void run_ntlogin_test(int num_ops, struct client_info *cli_info, struct cli_stat } +/* generate a random buffer */ +static void rand_buf(char *buf, int len) +{ + while (len--) { + *buf = sys_random(); + buf++; + } +} + +/**************************************************************************** +do a random rpc command +****************************************************************************/ +BOOL do_random_rpc(struct cli_state *cli, int max_len) +{ + prs_struct rbuf; + prs_struct buf; + uint8 opcode; + int param_len; + BOOL response = False; + + if ((sys_random() % 20) == 0) + { + param_len = (sys_random() % 256) + 4; + } + else + { + param_len = (sys_random() % max_len) + 4; + } + + prs_init(&buf , param_len, 4, SAFETY_MARGIN, False); + prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True ); + + opcode = sys_random() % 256; + + /* turn parameters into data stream */ + rand_buf(mem_data(&buf.data, 0), param_len); + buf.offset = param_len; + + /* send the data on \PIPE\ */ + if (rpc_api_pipe_req(cli, opcode, &buf, &rbuf)) + { + response = rbuf.offset != 0; + + if (response) + { + DEBUG(0,("response! opcode: 0x%x\n", opcode)); + DEBUG(0,("request: length %d\n", param_len)); + dump_data(0, mem_data(&buf.data , 0), MIN(param_len, 128)); + DEBUG(0,("response: length %d\n", rbuf.data->offset.end)); + dump_data(0, mem_data(&rbuf.data, 0), rbuf.data->offset.end); + } + } + + prs_mem_free(&rbuf); + prs_mem_free(&buf ); + + return response; +} + + +/* send random IPC commands */ +static void random_rpc_pipe_enc(char *pipe_name, struct client_info *cli_info, + int numops) +{ + int i; + + DEBUG(0,("starting random rpc test on %s (encryped)\n", pipe_name)); + + /* establish connections. nothing to stop these being re-established. */ + if (!rpcclient_connect(cli_info)) + { + DEBUG(0,("random rpc test: connection failed\n")); + return; + } + + cli_nt_set_ntlmssp_flgs(smb_cli, + NTLMSSP_NEGOTIATE_UNICODE | + NTLMSSP_NEGOTIATE_OEM | + NTLMSSP_NEGOTIATE_SIGN | + NTLMSSP_NEGOTIATE_SEAL | + NTLMSSP_NEGOTIATE_LM_KEY | + NTLMSSP_NEGOTIATE_NTLM | + NTLMSSP_NEGOTIATE_ALWAYS_SIGN | + NTLMSSP_NEGOTIATE_00001000 | + NTLMSSP_NEGOTIATE_00002000); + + for (i = 1; i <= numops * 100; i++) + { + /* open session. */ + cli_nt_session_open(smb_cli, pipe_name); + + do_random_rpc(smb_cli, 1024); + if (i % 500 == 0) + { + DEBUG(0,("calls: %i\n", i)); + } + + /* close the session */ + cli_nt_session_close(smb_cli); + } + + /* close the rpc pipe */ + rpcclient_stop(); + + DEBUG(0,("finished random rpc test on %s\n", pipe_name)); +} + +/* send random IPC commands */ +static void random_rpc_pipe(char *pipe_name, struct client_info *cli_info, + int numops) +{ + int i; + + DEBUG(0,("starting random rpc test on %s\n", pipe_name)); + + /* establish connections. nothing to stop these being re-established. */ + if (!rpcclient_connect(cli_info)) + { + DEBUG(0,("random rpc test: connection failed\n")); + return; + } + + /* open session. */ + if (!cli_nt_session_open(smb_cli, pipe_name)) + { + DEBUG(0,("random rpc test: session open failed\n")); + return; + } + + for (i = 1; i <= numops * 100; i++) + { + do_random_rpc(smb_cli, 8192); + if (i % 500 == 0) + { + DEBUG(0,("calls: %i\n", i)); + } + } + + /* close the session */ + cli_nt_session_close(smb_cli); + + /* close the rpc pipe */ + rpcclient_stop(); + + DEBUG(0,("finished random rpc test on %s\n", pipe_name)); +} + +static void run_randomrpc(int numops, struct client_info *cli_info) +{ + char *pipes[] = + { + PIPE_SAMR , + PIPE_WINREG , + PIPE_SRVSVC , + PIPE_WKSSVC , + PIPE_NETLOGON , + PIPE_NTSVCS , + PIPE_LSARPC , + NULL + }; + + int i = 0; + + while (pipes[i] != NULL) + { + random_rpc_pipe(pipes[i], cli_info, numops); +#if 0 + random_rpc_pipe_enc(pipes[i], cli_info, numops); +#endif + + i++; + } +} + + +static void run_samhandles(int numops, struct client_info *cli_info) +{ + int i; + int count = 0; + int failed = 0; + int retry = 500; + fstring srv_name; + fstrcpy(srv_name, "\\\\"); + fstrcat(srv_name, cli_info->dest_host); + strupper(srv_name); + + DEBUG(0,("starting sam handle test\n")); + + /* establish connections. nothing to stop these being re-established. */ + while (retry > 0 && !rpcclient_connect(cli_info)) + { + retry--; + } + + if (retry == 0) + { + DEBUG(0,("samhandle test: connection failed\n")); + return; + } + + /* open session. */ + if (!cli_nt_session_open(smb_cli, PIPE_SAMR)) + { + DEBUG(0,("samhandle test: session open failed\n")); + return; + } + + for (i = 1; i <= numops * 100; i++) + { + POLICY_HND pol; + POLICY_HND dom; + if (!do_samr_connect(smb_cli, srv_name, 0x20, &pol)) + { + failed++; + } +/* + if (!do_samr_open_domain(smb_cli, srv_name, 0x00000020, &pol)) + { + DEBUG(0,("samhandle domain open test (%i): failed\n", i)); + } + */ + if (i % 500 == 0) + { + DEBUG(0,("calls: %i\n", i)); + } + count++; + } + + /* close the session */ + cli_nt_session_close(smb_cli); + + /* close the rpc pipe */ + rpcclient_stop(); + + DEBUG(0,("finished samhandle test. count: %d failed: %d\n", count, failed)); +} + + +static void run_lsahandles(int numops, struct client_info *cli_info) +{ + int i; + int count = 0; + int failed = 0; + int retry = 500; + fstring srv_name; + fstrcpy(srv_name, "\\\\"); + fstrcat(srv_name, cli_info->myhostname); + strupper(srv_name); + + DEBUG(0,("starting lsa handle test\n")); + + /* establish connections. nothing to stop these being re-established. */ + while (retry > 0 && !rpcclient_connect(cli_info)) + { + retry--; + } + + if (retry == 0) + { + DEBUG(0,("lsahandle test: connection failed\n")); + return; + } + /* open session. */ + if (!cli_nt_session_open(smb_cli, PIPE_LSARPC)) + { + DEBUG(0,("lsahandle test: session open failed\n")); + return; + } + + for (i = 1; i <= numops * 100; i++) + { + POLICY_HND pol; + if (!do_lsa_open_policy(smb_cli, srv_name, &pol, False)) + { + failed++; + } + if (i % 500 == 0) + { + DEBUG(0,("calls: %i\n", i)); + } + count++; + } + + /* close the session */ + cli_nt_session_close(smb_cli); + + /* close the rpc pipe */ + rpcclient_stop(); + + DEBUG(0,("finished lsahandle test. count: %d failed: %d\n", count, failed)); +} + + +static void run_pipegobble(int numops, struct client_info *cli_info, char *pipe_name) +{ + int i; + int count = 0; + int failed = 0; + int retry = 500; + fstring srv_name; + fstrcpy(srv_name, "\\\\"); + fstrcat(srv_name, cli_info->myhostname); + strupper(srv_name); + + DEBUG(0,("starting pipe gobble test (%s)\n", pipe_name)); + + /* establish connections. nothing to stop these being re-established. */ + while (retry > 0 && !rpcclient_connect(cli_info)) + { + retry--; + } + + if (retry == 0) + { + DEBUG(0,("pipe gobble test: connection failed\n")); + return; + } + for (i = 1; i <= numops * 100; i++) + { + /* open session. */ + if (!cli_nt_session_open(smb_cli, pipe_name)) + { + DEBUG(0,("pipe gobble test: session open failed\n")); + } + + if (i % 500 == 0) + { + DEBUG(0,("calls: %i\n", i)); + } + count++; + } + + rpcclient_stop(); + + DEBUG(0,("finished pipe gobble test (%s). count: %d failed: %d\n", + pipe_name, count, failed)); +} + + +static void run_handles(int numops, struct client_info *cli_info) +{ + run_samhandles(numops, cli_info); + run_lsahandles(numops, cli_info); +} + +static void run_pipegobbler(int numops, struct client_info *cli_info) +{ +/* + run_pipegobble(numops, cli_info, PIPE_SAMR); +*/ + run_pipegobble(numops, cli_info, PIPE_LSARPC); +} + +/**************************************************************************** +make tcp connection +****************************************************************************/ +static void run_tcpconnect(int numops, struct client_info *info) +{ + int i; + int failed = 0; + + for (i = 0; i < numops; i++) + { + rpcclient_init(); + + if (!cli_connect(smb_cli, info->dest_host, &info->dest_ip)) + { + failed++; + } + cli_shutdown(smb_cli); + } + + DEBUG(0,("tcp connections: count: %d failed: %d\n", numops, failed)); +} + /**************************************************************************** runs n simultaneous functions. ****************************************************************************/ static void create_procs(int nprocs, int numops, - struct client_info *cli_info, struct cli_state *cli, - void (*fn)(int, struct client_info *, struct cli_state *)) + struct client_info *cli_info, + void (*fn)(int, struct client_info *)) { int i, status; @@ -184,8 +601,8 @@ static void create_procs(int nprocs, int numops, { int mypid = getpid(); sys_srandom(mypid ^ time(NULL)); - fn(numops, cli_info, cli); - fflush(out_hnd); + fn(numops, cli_info); + dbgflush(); _exit(0); } } @@ -195,6 +612,8 @@ static void create_procs(int nprocs, int numops, waitpid(0, &status, 0); } } + + /**************************************************************************** usage on the program - OUT OF DATE! ****************************************************************************/ @@ -235,7 +654,6 @@ enum client_action extern int optind; static pstring servicesf = CONFIGFILE; pstring term_code; - BOOL got_pass = False; char *cmd_str=""; mode_t myumask = 0755; enum client_action cli_action = CLIENT_NONE; @@ -246,8 +664,6 @@ enum client_action out_hnd = stdout; - rpcclient_init(); - #ifdef KANJI pstrcpy(term_code, KANJI); #else /* KANJI */ @@ -285,8 +701,6 @@ enum client_action pstrcpy(cli_info.cur_dir , "\\"); pstrcpy(cli_info.file_sel, ""); pstrcpy(cli_info.base_dir, ""); - pstrcpy(smb_cli->domain, ""); - pstrcpy(smb_cli->user_name, ""); pstrcpy(cli_info.myhostname, ""); pstrcpy(cli_info.dest_host, ""); @@ -299,7 +713,6 @@ enum client_action ZERO_STRUCT(cli_info.dom.level5_sid); pstrcpy(cli_info.dom.level5_dom, ""); - smb_cli->nt_pipe_fnum = 0xffff; setup_logging(pname, True); @@ -403,8 +816,8 @@ enum client_action case 'U': { char *lp; - pstrcpy(smb_cli->user_name,optarg); - if ((lp=strchr(smb_cli->user_name,'%'))) + pstrcpy(user_name,optarg); + if ((lp=strchr(user_name,'%'))) { *lp = 0; pstrcpy(password,lp+1); @@ -416,7 +829,7 @@ enum client_action case 'W': { - pstrcpy(smb_cli->domain,optarg); + pstrcpy(domain,optarg); break; } @@ -516,12 +929,6 @@ enum client_action DEBUG(3,("%s client started (version %s)\n",timestring(),VERSION)); - if (*smb_cli->domain == 0) - { - pstrcpy(smb_cli->domain,lp_workgroup()); - } - strupper(smb_cli->domain); - load_interfaces(); if (cli_action == CLIENT_IPC) @@ -534,31 +941,25 @@ enum client_action strupper(cli_info.mach_acct); fstrcat(cli_info.mach_acct, "$"); - /* set the password cache info */ - if (got_pass) - { - if (password[0] == 0) - { - pwd_set_nullpwd(&(smb_cli->pwd)); - } - else - { - pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ - } - } - else - { - char *pwd = getpass("Enter Password:"); - safe_strcpy(password, pwd, sizeof(password)); - pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ - } + make_nmb_name(&called , dns_to_netbios_name(cli_info.dest_host ), cli_info.name_type, scope); + make_nmb_name(&calling, dns_to_netbios_name(cli_info.myhostname), 0x0 , scope); - create_procs(nprocs, numops, &cli_info, smb_cli, run_enums_test); + get_passwd(); +/* + create_procs(nprocs, numops, &cli_info, run_enums_test); if (password[0] != 0) { - create_procs(nprocs, numops, &cli_info, smb_cli, run_ntlogin_test); + create_procs(nprocs, numops, &cli_info, run_ntlogin_test); } +*/ + + create_procs(nprocs, numops, &cli_info, run_tcpconnect); +/* + create_procs(nprocs, numops, &cli_info, run_pipegobbler); + create_procs(nprocs, numops, &cli_info, run_handles); + create_procs(nprocs, numops, &cli_info, run_randomrpc); +*/ fflush(out_hnd); diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 902f59b245..3249103a27 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -554,7 +554,7 @@ int main(int argc, char **argv) charset_initialise(); - if(!initialize_password_db()) { + if(!initialise_password_db()) { fprintf(stderr, "Can't setup password database vectors.\n"); exit(1); } diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 81fa33fc75..fb09f515cf 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -23,6 +23,9 @@ #include "includes.h" +extern int DEBUGLEVEL; +extern pstring debugf; + static fstring host, workgroup, share, password, username, myname; static int max_protocol = PROTOCOL_NT1; static char *sockops=""; @@ -42,8 +45,27 @@ static double end_timer(void) (tp2.tv_usec - tp1.tv_usec)*1.0e-6); } +#define FAILED_NO_ERROR 0 +#define FAILED_TCP_CONNECT 1 +#define FAILED_SESSION_REQ 2 +#define FAILED_SMB_SESS_SETUP 3 +#define FAILED_SMB_TCON 4 +#define FAILED_SMB_NEGPROT 5 +#define FAILED_CLI_STATE_INIT 6 +#define NUM_ERR_STATES 7 -static BOOL open_connection(struct cli_state *c) +static char *smb_messages[] = +{ + "No errors in connection", + "TCP connection ", + "NetBIOS Session Request", + "SMB Session Setup ", + "SMB Tcon ", + "SMB Negprot ", + "Client initialisation " +}; + +static int open_connection(struct cli_state *c) { struct nmb_name called, calling; @@ -52,48 +74,53 @@ static BOOL open_connection(struct cli_state *c) make_nmb_name(&calling, myname, 0x0, ""); make_nmb_name(&called , host, 0x20, ""); - if (!cli_initialise(c) || !cli_connect(c, host, NULL)) { - printf("Failed to connect with %s\n", host); - return False; + if (!cli_initialise(c)) + { + DEBUG(0,("Failed to connect with %s\n", host)); + return FAILED_CLI_STATE_INIT; + } + + if (!cli_connect(c, host, NULL)) { + DEBUG(0,("Failed to connect with %s\n", host)); + return FAILED_TCP_CONNECT; } if (!cli_session_request(c, &calling, &called)) { cli_shutdown(c); - printf("%s rejected the session\n",host); - return False; + DEBUG(0,("%s rejected the session\n",host)); + return FAILED_SESSION_REQ; } if (!cli_negprot(c)) { - printf("%s rejected the negprot (%s)\n",host, cli_errstr(c)); + DEBUG(0,("%s rejected the negprot (%s)\n",host, cli_errstr(c))); cli_shutdown(c); - return False; + return FAILED_SMB_NEGPROT; } if (!cli_session_setup(c, username, password, strlen(password), password, strlen(password), workgroup)) { + DEBUG(0,("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c))); cli_shutdown(c); - printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c)); - return False; + return FAILED_SMB_SESS_SETUP; } if (!cli_send_tconX(c, share, "?????", password, strlen(password)+1)) { - printf("%s refused tree connect (%s)\n", host, cli_errstr(c)); + DEBUG(0,("%s refused tree connect (%s)\n", host, cli_errstr(c))); cli_shutdown(c); - return False; + return FAILED_SMB_TCON; } - return True; + return FAILED_NO_ERROR; } - static void close_connection(struct cli_state *c) { if (!cli_tdis(c)) { - printf("tdis failed (%s)\n", cli_errstr(c)); + DEBUG(0,("tdis failed (%s)\n", cli_errstr(c))); } cli_shutdown(c); @@ -110,10 +137,10 @@ static BOOL check_error(struct cli_state *c, eno = cli_error(c, &class, &num); if ((eclass != class || ecode != num) && num != (nterr&0xFFFFFF)) { - printf("unexpected error code class=%d code=%d\n", - (int)class, (int)num); - printf(" expected %d/%d %d\n", - (int)eclass, (int)ecode, (int)nterr); + DEBUG(0,("unexpected error code class=%d code=%d\n", + (int)class, (int)num)); + DEBUG(0,(" expected %d/%d %d\n", + (int)eclass, (int)ecode, (int)nterr)); return False; } return True; @@ -144,7 +171,7 @@ static BOOL rw_torture(struct cli_state *c, int numops) if (fnum2 == -1) fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - printf("open of %s failed (%s)\n", lockfname, cli_errstr(c)); + DEBUG(0,("open of %s failed (%s)\n", lockfname, cli_errstr(c))); return False; } @@ -152,7 +179,7 @@ static BOOL rw_torture(struct cli_state *c, int numops) for (i=0;i n) { fnum--; slprintf(fname,sizeof(fname)-1,template, fnum,getpid()); if (cli_unlink(&cli, fname)) { - printf("unlink of %s failed (%s)\n", - fname, cli_errstr(&cli)); + DEBUG(0,("unlink of %s failed (%s)\n", + fname, cli_errstr(&cli))); } } - printf("maxfid test finished\n"); + DEBUG(0,("maxfid test finished\n")); close_connection(&cli); } @@ -713,24 +746,41 @@ static void rand_buf(char *buf, int len) } /* send random IPC commands */ -static void run_randomipc(void) +static void run_randomipc(int numops) { char *rparam = NULL; char *rdata = NULL; int rdrcnt,rprcnt; - pstring param; + char param[BUFFER_SIZE]; int api, param_len, i; + int reconnect_count = 50; static struct cli_state cli; - printf("starting random ipc test\n"); + DEBUG(0,("starting random ipc test\n")); + + while (reconnect_count > 0 && open_connection(&cli) != 0) + { + DEBUG(0,("connection failed: retrying %d\n", reconnect_count)); + msleep(sys_random() % 1000); + reconnect_count--; + } - if (!open_connection(&cli)) { + if (reconnect_count == 0) + { return; } - for (i=0;i<50000;i++) { + for (i=0;i 2) { - printf("ERROR: SMBgetatr bug. time is %s", - ctime(&t)); + DEBUG(0,("ERROR: SMBgetatr bug. time is %s", + ctime(&t))); t = time(NULL); } t2 = t-60*60*24; /* 1 day ago */ if (!cli_setatr(&cli, fname, 0, t2)) { - printf("setatr failed (%s)\n", cli_errstr(&cli)); + DEBUG(0,("setatr failed (%s)\n", cli_errstr(&cli))); } if (!cli_getatr(&cli, fname, NULL, NULL, &t)) { - printf("getatr failed (%s)\n", cli_errstr(&cli)); + DEBUG(0,("getatr failed (%s)\n", cli_errstr(&cli))); } if (t != t2) { - printf("ERROR: getatr/setatr bug. times are\n%s", - ctime(&t)); - printf("%s", ctime(&t2)); + DEBUG(0,("ERROR: getatr/setatr bug. times are\n%s", + ctime(&t))); + DEBUG(0,("%s", ctime(&t2))); } cli_unlink(&cli, fname); close_connection(&cli); - printf("attrib test finished\n"); + DEBUG(0,("attrib test finished\n")); } @@ -855,9 +905,9 @@ static void run_trans2test(void) char *dname = "\\trans2"; char *fname2 = "\\trans2\\trans2.tst"; - printf("starting trans2 test\n"); + DEBUG(0,("starting trans2 test\n")); - if (!open_connection(&cli)) { + if (open_connection(&cli) != 0) { return; } @@ -866,7 +916,7 @@ static void run_trans2test(void) O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time, NULL, NULL)) { - printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli)); + DEBUG(0,("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli))); } cli_close(&cli, fnum); @@ -878,20 +928,20 @@ static void run_trans2test(void) cli_close(&cli, fnum); if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) { - printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli)); + DEBUG(0,("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli))); } else { if (c_time != m_time) { - printf("create time=%s", ctime(&c_time)); - printf("modify time=%s", ctime(&m_time)); - printf("This system appears to have sticky create times\n"); + DEBUG(0,("create time=%s", ctime(&c_time))); + DEBUG(0,("modify time=%s", ctime(&m_time))); + DEBUG(0,("This system appears to have sticky create times\n")); } if (a_time % (60*60) == 0) { - printf("access time=%s", ctime(&a_time)); - printf("This system appears to set a midnight access time\n"); + DEBUG(0,("access time=%s", ctime(&a_time))); + DEBUG(0,("This system appears to set a midnight access time\n")); } if (abs(m_time - time(NULL)) > 60*60*24*7) { - printf("ERROR: totally incorrect times - maybe word reversed?\n"); + DEBUG(0,("ERROR: totally incorrect times - maybe word reversed?\n")); } } @@ -902,11 +952,11 @@ static void run_trans2test(void) cli_close(&cli, fnum); if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL)) { - printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); + DEBUG(0,("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli))); } else { if (w_time < 60*60*24*2) { - printf("write time=%s", ctime(&w_time)); - printf("This system appears to set a initial 0 write time\n"); + DEBUG(0,("write time=%s", ctime(&w_time))); + DEBUG(0,("This system appears to set a initial 0 write time\n")); } } @@ -916,12 +966,12 @@ static void run_trans2test(void) /* check if the server updates the directory modification time when creating a new file */ if (!cli_mkdir(&cli, dname)) { - printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli)); + DEBUG(0,("ERROR: mkdir failed (%s)\n", cli_errstr(&cli))); } sleep(3); if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL)) { - printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); + DEBUG(0,("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli))); } fnum = cli_open(&cli, fname2, @@ -930,10 +980,10 @@ static void run_trans2test(void) cli_close(&cli, fnum); if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL, NULL)) { - printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); + DEBUG(0,("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli))); } else { if (m_time2 == m_time) - printf("This system does not update directory modification times\n"); + DEBUG(0,("This system does not update directory modification times\n")); } cli_unlink(&cli, fname2); cli_rmdir(&cli, dname); @@ -941,29 +991,83 @@ static void run_trans2test(void) close_connection(&cli); - printf("trans2 test finished\n"); + DEBUG(0,("trans2 test finished\n")); } +static void run_connection(int numops) +{ + struct cli_state c; + int count = 0; + int failed[NUM_ERR_STATES]; + int i; + + DEBUG(0,("Connection test starts:\n")); + + for (i = 0; i < NUM_ERR_STATES; i++) + { + failed[i] = 0; + } + + for (i = 0; i < numops; i++) + { + int err; + DEBUG(0,("Connection test %d %d\n", i, numops)); + if ((err = open_connection(&c))) + { + failed[err]++; + } + count++; + } + + { + int failtotal = 0; + + for (i = 0, failtotal = 0; i < NUM_ERR_STATES; i++) + { + failtotal += failed[i]; + } + DEBUG(0,("Connection test results: count %d success %d\n", count, count-failtotal)); + } + for (i = 0; i < NUM_ERR_STATES; i++) + { + DEBUG(0,("%s: failed: %d\n", smb_messages[i], failed[i])); + } +} + static void create_procs(int nprocs, int numops, void (*fn)(int )) { int i, status; - for (i=0;i Date: Tue, 17 Nov 1998 20:50:07 +0000 Subject: Added the same open()/fopen()/creat()/mmap() -> sys_XXX calls. Tidied up some of the mess (no other word for it). Still doesn't compile cleanly. There are calls with incorrect parameters that don't seem to be doing the right thing. This code still needs surgery :-(. Jeremy. (This used to be commit 18ff93a9abbf68ee8c59c0af3e57c63e4a015dac) --- source3/utils/make_printerdef.c | 2 +- source3/utils/make_smbcodepage.c | 8 ++++---- source3/utils/status.c | 2 +- source3/utils/testprns.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index c64ce64bbf..68b603bf1f 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -471,7 +471,7 @@ int main(int argc, char *argv[]) return(-1); } - inf_file=fopen(argv[1],"r"); + inf_file=sys_fopen(argv[1],"r"); if (!inf_file) { fprintf(stderr,"Description file not found, bye\n"); diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c index 0653fd31f1..a57af2fc44 100644 --- a/source3/utils/make_smbcodepage.c +++ b/source3/utils/make_smbcodepage.c @@ -190,7 +190,7 @@ The maximum size I will believe is 100k.\n", prog_name, size); exit(1); } - if((fp = fopen(input_file, "r")) == NULL) + if((fp = sys_fopen(input_file, "r")) == NULL) { fprintf(stderr, "%s: cannot open file %s for input.\n", prog_name, input_file); exit(1); @@ -283,7 +283,7 @@ definition file. File %s has %d.\n", prog_name, MAXCODEPAGELINES, input_file, nu } /* Now write out the output_buf. */ - if((fp = fopen(output_file, "w"))==NULL) + 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)); @@ -339,7 +339,7 @@ code page file.\n", prog_name, input_file); is held in little endian format. */ - if((fp = fopen( input_file, "r")) == NULL) + if((fp = sys_fopen( input_file, "r")) == NULL) { fprintf(stderr, "%s: cannot open file %s. Error was %s\n", prog_name, input_file, strerror(errno)); @@ -411,7 +411,7 @@ multiple of 4.\n", prog_name, input_file); fclose(fp); /* Now dump the codepage into an ascii file. */ - if((fp = fopen(output_file, "w")) == NULL) + if((fp = sys_fopen(output_file, "w")) == NULL) { fprintf(stderr, "%s: cannot open file %s. Error was %s\n", prog_name, output_file, strerror(errno)); diff --git a/source3/utils/status.c b/source3/utils/status.c index fa1e8b43bf..96df087858 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -211,7 +211,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) trim_string(fname,"","/"); pstrcat(fname,"/STATUS..LCK"); - f = fopen(fname,"r"); + f = sys_fopen(fname,"r"); if (!f) { printf("Couldn't open status file %s\n",fname); if (!lp_status(-1)) diff --git a/source3/utils/testprns.c b/source3/utils/testprns.c index caa9e2740a..c03fa0436a 100644 --- a/source3/utils/testprns.c +++ b/source3/utils/testprns.c @@ -52,7 +52,7 @@ int main(int argc, char *argv[]) printf("Usage: testprns printername [printcapfile]\n"); else { - dbf = fopen("test.log", "w"); + dbf = sys_fopen("test.log", "w"); if (dbf == NULL) { printf("Unable to open logfile.\n"); } else { -- cgit From 9579b9823707b9acadfd7bf24d1c540eacf53fc0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 18 Nov 1998 22:04:24 +0000 Subject: Added OSF1 changes to HEAD (-lsecurity etc.) groupdb/groupdb.c: Fixed compile error caught by IRIX compiler. utils/smbpasswd.c: Fixed SunOS optind, optarg problem. Jeremy. (This used to be commit 30af39ae1edf51d5d06a1764982e5df431c142ac) --- source3/utils/smbpasswd.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 3249103a27..519ca5a33d 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -23,6 +23,12 @@ extern pstring myhostname; extern pstring global_myname; extern int DEBUGLEVEL; +/* + * Next two lines needed for SunOS and don't + * hurt anything else... + */ +extern char *optarg; +extern int optind; /********************************************************* a strdup with exit @@ -254,12 +260,6 @@ handle password changing for root *************************************************************/ static int process_root(int argc, char *argv[]) { - /* - * Next two lines needed for SunOS and don't - * hurt anything else... - */ - extern char *optarg; - extern int optind; struct passwd *pwd; int ch; BOOL joining_domain = False; @@ -449,12 +449,6 @@ handle password changing for non-root *************************************************************/ static int process_nonroot(int argc, char *argv[]) { - /* - * Next two lines needed for SunOS and don't - * hurt anything else... - */ - extern char *optarg; - extern int optind; struct passwd *pwd = NULL; int ch; BOOL stdin_passwd_get = False; -- cgit From 735631539ca8ab74056894b653a8fee785262854 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Thu, 19 Nov 1998 21:17:58 +0000 Subject: update testparm with -s option so it doesn't require a carriage return also allow specifying [host hostip] without [configfile] updated man page (This used to be commit 85fbd401026e7f1464c9a125cbaa505b768f8a10) --- source3/utils/testparm.c | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 92bf5cb384..9bf741e24f 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -72,8 +72,12 @@ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); int main(int argc, char *argv[]) { + extern char *optarg; + extern int optind; pstring configfile; + int opt; int s; + BOOL silent_mode = False; TimeInit(); @@ -81,10 +85,20 @@ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); charset_initialise(); - if (argc < 2) + while ((opt = getopt(argc, argv,"s")) != EOF) { + switch (opt) { + case 's': + silent_mode = True; + break; + } + } + + argc += (1 - optind); + + if ((argc == 1) || (argc == 3)) pstrcpy(configfile,CONFIGFILE); - else - pstrcpy(configfile,argv[1]); + else if ((argc == 2) || (argc == 4)) + pstrcpy(configfile,argv[optind]); dbf = stdout; DEBUGLEVEL = 2; @@ -116,19 +130,29 @@ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); break; } - if (argc < 4) + if (argc < 3) { - printf("Press enter to see a dump of your service definitions\n"); - fflush(stdout); - getc(stdin); + if (!silent_mode) { + printf("Press enter to see a dump of your service definitions\n"); + fflush(stdout); + getc(stdin); + } lp_dump(stdout,True); } - if (argc == 4) + if (argc >= 3) { - char *cname = argv[2]; - char *caddr = argv[3]; + char *cname; + char *caddr; + if (argc == 3) { + cname = argv[optind]; + caddr = argv[optind+1]; + } else if (argc == 4) { + cname = argv[optind+1]; + caddr = argv[optind+2]; + } + /* this is totally ugly, a real `quick' hack */ for (s=0;s<1000;s++) if (VALID_SNUM(s)) -- cgit From c9b2f20efcb9cd2e93f29928442e9a61360fa5a0 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 25 Nov 1998 14:54:23 +0000 Subject: fixing domain join and domain login problems (This used to be commit 90a24664318da97a6e8cfe4622a8573c0e3cbe5e) --- source3/utils/rpctorture.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/rpctorture.c b/source3/utils/rpctorture.c index dac64a22e3..3b2a497ad4 100644 --- a/source3/utils/rpctorture.c +++ b/source3/utils/rpctorture.c @@ -558,9 +558,7 @@ static void run_handles(int numops, struct client_info *cli_info) static void run_pipegobbler(int numops, struct client_info *cli_info) { -/* run_pipegobble(numops, cli_info, PIPE_SAMR); -*/ run_pipegobble(numops, cli_info, PIPE_LSARPC); } @@ -954,9 +952,9 @@ enum client_action } */ - create_procs(nprocs, numops, &cli_info, run_tcpconnect); -/* create_procs(nprocs, numops, &cli_info, run_pipegobbler); +/* + create_procs(nprocs, numops, &cli_info, run_tcpconnect); create_procs(nprocs, numops, &cli_info, run_handles); create_procs(nprocs, numops, &cli_info, run_randomrpc); */ -- cgit From 30038de4623bc827ee8019c569faf00583d1fe58 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sun, 29 Nov 1998 20:03:33 +0000 Subject: weekend work. user / group database API. - split sam_passwd and smb_passwd into separate higher-order function tables - renamed struct smb_passwd's "smb_user" to "unix_user". added "nt_user" plus user_rid, and added a "wrap" function in both sam_passwd and smb_passwd password databases to fill in the blank entries that are not obtained from whatever password database API instance is being used. NOTE: whenever a struct smb_passwd or struct sam_passwd is used, it MUST be initialised with pwdb_sam_init() or pwd_smb_init(), see chgpasswd.c for the only example outside of the password database APIs i could find. - added query_useraliases code to rpcclient. - dealt with some nasty interdependencies involving non-smbd programs and the password database API. this is still not satisfactorily resolved completelely, but it's the best i can do for now. - #ifdef'd out some password database options so that people don't mistakenly set them unless they recompile to _use_ those options. lots of debugging done, it's still not finished. the unix/NT uid/gid and user-rid/group-rid issues are better, but not perfect. the "BUILTIN" domain is still missing: users cannot be added to "BUILTIN" groups yet, as we only have an "alias" db API and a "group" db API but not "builtin-alias" db API... (This used to be commit 5d5d7e4de7d1514ab87b07ede629de8aa00519a1) --- source3/utils/smbpasswd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 519ca5a33d..92ec9ae5a8 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -548,7 +548,8 @@ int main(int argc, char **argv) charset_initialise(); - if(!initialise_password_db()) { + if(!pwdb_initialise()) + { fprintf(stderr, "Can't setup password database vectors.\n"); exit(1); } -- cgit From dc879e9ca7382cf981123ed35cdd3cace0abf5be Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Mon, 30 Nov 1998 19:29:32 +0000 Subject: pwdb_initialise() in the wrong place: must load smb.conf first. thanks phil. (This used to be commit 4b5bd4e18cee72aeb76909cf85b1f932393fcfc8) --- source3/utils/smbpasswd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 92ec9ae5a8..a5756dd797 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -548,12 +548,6 @@ int main(int argc, char **argv) charset_initialise(); - if(!pwdb_initialise()) - { - fprintf(stderr, "Can't setup password database vectors.\n"); - exit(1); - } - if (!lp_load(servicesf,True,False,False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); @@ -580,6 +574,12 @@ int main(int argc, char **argv) codepage_initialise(lp_client_code_page()); + if(!pwdb_initialise()) + { + fprintf(stderr, "Can't setup password database vectors.\n"); + exit(1); + } + /* Check the effective uid - make sure we are not setuid */ if ((geteuid() == (uid_t)0) && (getuid() != (uid_t)0)) { fprintf(stderr, "smbpasswd must *NOT* be setuid root.\n"); -- cgit From 04e382fb166a64de193dc3c7b21187d8382eaeea Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Tue, 1 Dec 1998 19:10:44 +0000 Subject: rpc_samr.h parse_samr.c srv_samr.c : samr_query_aliasmembers (cool!) util_pwdb.c sids.c nmbd.c server.c smbpasswd.c swat.c : pwdb_initialise(BOOL is_server) now creates / reads DOMAIN_NAME.SID if is_server is True, and does LsaQueryInfoPolicy(levels 3 and 5) to obtain member and pdc sids. (This used to be commit 3e1eb4f26b67e484b05e1dde94fd4e4dae982631) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index a5756dd797..722ff6f8b2 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -574,7 +574,7 @@ int main(int argc, char **argv) codepage_initialise(lp_client_code_page()); - if(!pwdb_initialise()) + if(!pwdb_initialise(False)) { fprintf(stderr, "Can't setup password database vectors.\n"); exit(1); -- cgit From 9c848ec329a6ce86cffb2304746590116d9292f0 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Mon, 7 Dec 1998 20:23:41 +0000 Subject: removed nt_pipe_fnum from struct cli_state. need to be able to call LsaLookupSids etc from within SamrQueryAliasMembers, for example. fnum is now a parameter to client functions. thanks to mike black for starting the ball rolling. (This used to be commit bee8f7fa6b0f7f995f71303f4e14a4aaed0c2437) --- source3/utils/rpctorture.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/rpctorture.c b/source3/utils/rpctorture.c index 3b2a497ad4..c08db239b7 100644 --- a/source3/utils/rpctorture.c +++ b/source3/utils/rpctorture.c @@ -275,6 +275,7 @@ BOOL do_random_rpc(struct cli_state *cli, int max_len) static void random_rpc_pipe_enc(char *pipe_name, struct client_info *cli_info, int numops) { + uint16 nt_pipe_fnum; int i; DEBUG(0,("starting random rpc test on %s (encryped)\n", pipe_name)); @@ -300,7 +301,7 @@ static void random_rpc_pipe_enc(char *pipe_name, struct client_info *cli_info, for (i = 1; i <= numops * 100; i++) { /* open session. */ - cli_nt_session_open(smb_cli, pipe_name); + cli_nt_session_open(smb_cli, pipe_name, &nt_pipe_fnum); do_random_rpc(smb_cli, 1024); if (i % 500 == 0) @@ -309,7 +310,7 @@ static void random_rpc_pipe_enc(char *pipe_name, struct client_info *cli_info, } /* close the session */ - cli_nt_session_close(smb_cli); + cli_nt_session_close(smb_cli, nt_pipe_fnum); } /* close the rpc pipe */ @@ -322,6 +323,7 @@ static void random_rpc_pipe_enc(char *pipe_name, struct client_info *cli_info, static void random_rpc_pipe(char *pipe_name, struct client_info *cli_info, int numops) { + uint16 nt_pipe_fnum; int i; DEBUG(0,("starting random rpc test on %s\n", pipe_name)); @@ -334,7 +336,7 @@ static void random_rpc_pipe(char *pipe_name, struct client_info *cli_info, } /* open session. */ - if (!cli_nt_session_open(smb_cli, pipe_name)) + if (!cli_nt_session_open(smb_cli, pipe_name, &nt_pipe_fnum)) { DEBUG(0,("random rpc test: session open failed\n")); return; @@ -350,7 +352,7 @@ static void random_rpc_pipe(char *pipe_name, struct client_info *cli_info, } /* close the session */ - cli_nt_session_close(smb_cli); + cli_nt_session_close(smb_cli, nt_pipe_fnum); /* close the rpc pipe */ rpcclient_stop(); @@ -388,6 +390,7 @@ static void run_randomrpc(int numops, struct client_info *cli_info) static void run_samhandles(int numops, struct client_info *cli_info) { + uint16 nt_pipe_fnum; int i; int count = 0; int failed = 0; @@ -412,7 +415,7 @@ static void run_samhandles(int numops, struct client_info *cli_info) } /* open session. */ - if (!cli_nt_session_open(smb_cli, PIPE_SAMR)) + if (!cli_nt_session_open(smb_cli, PIPE_SAMR, &nt_pipe_fnum)) { DEBUG(0,("samhandle test: session open failed\n")); return; @@ -440,7 +443,7 @@ static void run_samhandles(int numops, struct client_info *cli_info) } /* close the session */ - cli_nt_session_close(smb_cli); + cli_nt_session_close(smb_cli, nt_pipe_fnum); /* close the rpc pipe */ rpcclient_stop(); @@ -451,6 +454,7 @@ static void run_samhandles(int numops, struct client_info *cli_info) static void run_lsahandles(int numops, struct client_info *cli_info) { + uint16 nt_pipe_fnum; int i; int count = 0; int failed = 0; @@ -474,7 +478,7 @@ static void run_lsahandles(int numops, struct client_info *cli_info) return; } /* open session. */ - if (!cli_nt_session_open(smb_cli, PIPE_LSARPC)) + if (!cli_nt_session_open(smb_cli, PIPE_LSARPC, &nt_pipe_fnum)) { DEBUG(0,("lsahandle test: session open failed\n")); return; @@ -495,7 +499,7 @@ static void run_lsahandles(int numops, struct client_info *cli_info) } /* close the session */ - cli_nt_session_close(smb_cli); + cli_nt_session_close(smb_cli, nt_pipe_fnum); /* close the rpc pipe */ rpcclient_stop(); @@ -506,6 +510,7 @@ static void run_lsahandles(int numops, struct client_info *cli_info) static void run_pipegobble(int numops, struct client_info *cli_info, char *pipe_name) { + uint16 nt_pipe_fnum; int i; int count = 0; int failed = 0; @@ -531,7 +536,7 @@ static void run_pipegobble(int numops, struct client_info *cli_info, char *pipe_ for (i = 1; i <= numops * 100; i++) { /* open session. */ - if (!cli_nt_session_open(smb_cli, pipe_name)) + if (!cli_nt_session_open(smb_cli, pipe_name, &nt_pipe_fnum)) { DEBUG(0,("pipe gobble test: session open failed\n")); } -- cgit From dc003d8d408b87eecba9044d2d8732a3604827bf Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 16 Dec 1998 18:50:54 +0000 Subject: A while back, Andrew and I talked about making the debug parsing code a better "fit" with other Samba code. This is a small first step toward doing what (I think) we agreed to do. I've moved the key function from ubiqx/debugparse.c into lib/debug.c. I have also moved the enum from ubiqx/debugparse.h into the debug section in smb.h. The next thing to do is to get debug2html added into the Makefile.in so that it is always produced when compiling the suite. Chris -)----- (This used to be commit 782474f41e0c2bc0b1f098758a3e5cb44e87d8b1) --- source3/utils/debug2html.c | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/debug2html.c b/source3/utils/debug2html.c index fa2be41336..d5d8fb872c 100644 --- a/source3/utils/debug2html.c +++ b/source3/utils/debug2html.c @@ -28,37 +28,12 @@ * does a decent job of converting Samba logs into HTML. * -------------------------------------------------------------------------- ** * - * $Log: debug2html.c,v $ - * Revision 1.4 1998/11/13 03:37:01 tridge - * fixes for OSF1 compilation - * - * Revision 1.3 1998/10/28 20:33:35 crh - * I've moved the debugparse module files into the ubiqx directory because I - * know that 'make proto' will ignore them there. The debugparse.h header - * file is included in includes.h, and includes.h is included in debugparse.c, - * so all of the pieces "see" each other. I've compiled and tested this, - * and it does seem to work. It's the same compromise model I used when - * adding the ubiqx modules into the system, which is why I put it all into - * the same directory. - * - * Chris -)----- - * - * Revision 1.1 1998/10/26 23:21:37 crh - * Here is the simple debug parser and the debug2html converter. Still to do: - * - * * Debug message filtering. - * * I need to add all this to Makefile.in - * (If it looks at all strange I'll ask for help.) - * - * If you want to compile debug2html, you'll need to do it by hand until I - * make the changes to Makefile.in. Sorry. - * - * Chris -)----- + * $Revision: 1.5 $ * * ========================================================================== ** */ -#include "debugparse.h" +#include "include.h" /* -------------------------------------------------------------------------- ** * The size of the read buffer. -- cgit From 7bf6e4d6a0e479a0f2fbe0ccee11522d7a19b7b9 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Mon, 28 Dec 1998 22:34:08 +0000 Subject: Sorry that this is going so slowly. I've added debug2html to Makefile.in so that it compiles as part of the normal build. Fixed a typo in debug2html.c as well. One problem: I found it necessary to link with both $(PARAM_OBJ) and $(LIB_OBJ). The result is an executable that is much larger than it really needs to be. (This used to be commit d2d6f0bf362d376f39d0ec7e4b6651ca2b8c8819) --- source3/utils/debug2html.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/debug2html.c b/source3/utils/debug2html.c index d5d8fb872c..1349da5b28 100644 --- a/source3/utils/debug2html.c +++ b/source3/utils/debug2html.c @@ -28,12 +28,12 @@ * does a decent job of converting Samba logs into HTML. * -------------------------------------------------------------------------- ** * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * * ========================================================================== ** */ -#include "include.h" +#include "includes.h" /* -------------------------------------------------------------------------- ** * The size of the read buffer. -- cgit From 8cb794707b4e25fdf008b57dd2f87b70e26f69c2 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Tue, 29 Dec 1998 20:43:01 +0000 Subject: While writing the man page, I realized that it was a bit silly not to accept command-line parameters. I've added that capability. Of course, the man page is now wrong. Sigh. Chris -)----- (This used to be commit 300a8c9e5077206b706c522c0b4288b00b7afda7) --- source3/utils/debug2html.c | 149 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 117 insertions(+), 32 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/debug2html.c b/source3/utils/debug2html.c index 1349da5b28..c7f36da0c0 100644 --- a/source3/utils/debug2html.c +++ b/source3/utils/debug2html.c @@ -28,13 +28,20 @@ * does a decent job of converting Samba logs into HTML. * -------------------------------------------------------------------------- ** * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * * ========================================================================== ** */ #include "includes.h" +/* -------------------------------------------------------------------------- ** + * Global values. + */ + +FILE *infile = stdin; +FILE *outfile = stdout; + /* -------------------------------------------------------------------------- ** * The size of the read buffer. */ @@ -74,7 +81,7 @@ static dbg_Token modechange( dbg_Token new, dbg_Token mode ) if( dbg_message != mode ) { /* Switching to message mode. */ - (void)printf( "
\n" );
+        (void)fprintf( outfile, "
\n" );
         return( dbg_message );
         }
       break;
@@ -82,7 +89,7 @@ static dbg_Token modechange( dbg_Token new, dbg_Token mode )
       if( dbg_message == mode )
         {
         /* Switching out of message mode. */
-        (void)printf( "
\n\n" ); + (void)fprintf( outfile, "
\n\n" ); return( dbg_null ); } } @@ -110,29 +117,29 @@ static void newblock( dbg_Token old, dbg_Token new ) switch( old ) { case dbg_timestamp: - (void)printf( ",
" ); + (void)fprintf( outfile, ",
" ); break; case dbg_level: - (void)printf( "]\n " ); + (void)fprintf( outfile, "]\n " ); break; case dbg_sourcefile: - (void)printf( ":" ); + (void)fprintf( outfile, ":" ); break; case dbg_lineno: - (void)printf( ")" ); + (void)fprintf( outfile, ")" ); break; } switch( new ) { case dbg_timestamp: - (void)printf( "[" ); + (void)fprintf( outfile, "[" ); break; case dbg_level: - (void)printf( " " ); + (void)fprintf( outfile, " " ); break; case dbg_lineno: - (void)printf( "(" ); + (void)fprintf( outfile, "(" ); break; } } /* newblock */ @@ -156,41 +163,38 @@ static void charprint( dbg_Token tok, int c ) break; case dbg_null: case dbg_eof: - (void)putchar( '\n' ); + (void)putc( '\n', outfile ); break; default: switch( c ) { case '<': - (void)printf( "<" ); + (void)fprintf( outfile, "<" ); break; case '>': - (void)printf( ">" ); + (void)fprintf( outfile, ">" ); break; case '&': - (void)printf( "&" ); + (void)fprintf( outfile, "&" ); break; case '\"': - (void)printf( """ ); + (void)fprintf( outfile, """ ); break; default: - (void)putchar( c ); + (void)putc( c, outfile ); break; } } } /* charprint */ -int main( int argc, char *argv[] ) +static void convert( void ) /* ------------------------------------------------------------------------ ** - * This simple program scans and parses Samba debug logs, and produces HTML - * output. + * Read the input logfile, converting the entries to HTML. * - * Input: argc - Currently ignored. - * argv - Currently ignored. - * - * Output: Always zero. - * - * Notes: The HTML output is sent to stdout. + * Input: none. + * output: none. + * Notes: Reads from the global infile, writes to the global outfile. + * These default to stdin and stdout, respectively. * * ------------------------------------------------------------------------ ** */ @@ -203,12 +207,8 @@ int main( int argc, char *argv[] ) state = dbg_null, mode = dbg_null; - (void)printf( "\n" ); - (void)printf( "\n\n" ); - (void)printf( " Samba Debug Output\n\n\n\n" ); - - while( (!feof( stdin )) - && ((len = fread( bufr, 1, DBG_BSIZE, stdin )) > 0) ) + while( (!feof( infile )) + && ((len = fread( bufr, 1, DBG_BSIZE, infile )) > 0) ) { for( i = 0; i < len; i++ ) { @@ -224,6 +224,91 @@ int main( int argc, char *argv[] ) } (void)modechange( dbg_eof, mode ); - (void)printf( "\n\n" ); + } /* convert */ + +static void usage( void ) + /* ------------------------------------------------------------------------ ** + * Prints a usage message on stderr, then gently exits. + * + * Input: none. + * Output: none. Exits with return code of 0. + * + * ------------------------------------------------------------------------ ** + */ + { + fprintf( stderr, "This utility converts Samba log files " ); + fprintf( stderr, "into HTML documents.\n" ); + fprintf( stderr, "Usage:\n" ); + fprintf( stderr, " debug2html \n" ); + exit( 0 ); + } /* usage */ + +static FILE *carefull_fopen( const char *path, const char *type ) + /* ------------------------------------------------------------------------ ** + * Checks for leading '-' characters, which are generically regarded as + * flags. Also exits the program gracefully should the file fail to open. + * + * Input: path - pathname of the file to open. + * type - open mode. See fopen(3S). + * + * Output: Pointer to open file. + * + * ------------------------------------------------------------------------ ** + */ + { + FILE *tmp; + + if( '-' == path[0] || '\0' == path[0] ) + usage(); + + tmp = sys_fopen( path, type ); + if( NULL == tmp ) + { + fprintf( stderr, "Error opening file %s: %s\n", path, strerror(errno) ); + exit( 1 ); + } + return( tmp ); + } /* carefull_fopen */ + +int main( int argc, char *argv[] ) + /* ------------------------------------------------------------------------ ** + * This simple program scans and parses Samba debug logs, and produces HTML + * output. + * + * Input: argc - Argument count. + * argv[1] - Input file name. + * argv[2] - Output file name. + * A '-' character by itself means use defaults (i.e., + * or depending upon the argument. + * A string beginning with '-' and containing more than + * that one character will generate a usage message. + * + * Output: An exit value of 1 is returned if an error was encountered + * while opening a file, else 0. + * + * Notes: The HTML output is sent to stdout. + * + * ------------------------------------------------------------------------ ** + */ + { + if( argc > 3 ) + usage(); + + if( argc > 1 && 0 != strcmp( argv[1], "-" ) ) + infile = carefull_fopen( argv[1], "r" ); + + if( argc > 2 && 0 != strcmp( argv[2], "-" ) ) + infile = carefull_fopen( argv[2], "w" ); + + (void)fprintf( outfile, + "\n" ); + (void)fprintf( outfile, "\n\n" ); + (void)fprintf( outfile, + " Samba Log\n\n\n\n" ); + + convert(); + + (void)fprintf( outfile, "\n\n" ); + return( 0 ); } /* main */ -- cgit From e10503d1a2053b0a4d5e86ffcf9b36e6cccc9497 Mon Sep 17 00:00:00 2001 From: Matthew Chapman Date: Mon, 18 Jan 1999 01:32:45 +0000 Subject: Added load_interfaces in smbpasswd to allow name resolution by broadcast and multiple interfaces. (Jeremy already committed this in SAMBA_2_0). (This used to be commit f530e289c6f69961c51511e0220fdd886fbd2c78) --- source3/utils/smbpasswd.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 722ff6f8b2..157583925b 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -574,6 +574,8 @@ int main(int argc, char **argv) codepage_initialise(lp_client_code_page()); + load_interfaces(); + if(!pwdb_initialise(False)) { fprintf(stderr, "Can't setup password database vectors.\n"); -- cgit From 0637d46d6083fb2969fadf3211e0d91298b7ca28 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 27 Jan 1999 00:03:31 +0000 Subject: compilation errors due to addition of smb file handle parameter. (This used to be commit 03967986ec6a92785b92fefce9e27b8bb088ea85) --- source3/utils/rpctorture.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/rpctorture.c b/source3/utils/rpctorture.c index c08db239b7..831af55e0f 100644 --- a/source3/utils/rpctorture.c +++ b/source3/utils/rpctorture.c @@ -91,7 +91,6 @@ void rpcclient_init(void) smb_cli->capabilities |= CAP_STATUS32; pstrcpy(smb_cli->user_name, user_name); - smb_cli->nt_pipe_fnum = 0xffff; get_passwd(); @@ -223,7 +222,7 @@ static void rand_buf(char *buf, int len) /**************************************************************************** do a random rpc command ****************************************************************************/ -BOOL do_random_rpc(struct cli_state *cli, int max_len) +BOOL do_random_rpc(struct cli_state *cli, uint16 nt_pipe_fnum, int max_len) { prs_struct rbuf; prs_struct buf; @@ -250,7 +249,7 @@ BOOL do_random_rpc(struct cli_state *cli, int max_len) buf.offset = param_len; /* send the data on \PIPE\ */ - if (rpc_api_pipe_req(cli, opcode, &buf, &rbuf)) + if (rpc_api_pipe_req(cli, nt_pipe_fnum, opcode, &buf, &rbuf)) { response = rbuf.offset != 0; @@ -303,7 +302,7 @@ static void random_rpc_pipe_enc(char *pipe_name, struct client_info *cli_info, /* open session. */ cli_nt_session_open(smb_cli, pipe_name, &nt_pipe_fnum); - do_random_rpc(smb_cli, 1024); + do_random_rpc(smb_cli, nt_pipe_fnum, 1024); if (i % 500 == 0) { DEBUG(0,("calls: %i\n", i)); @@ -344,7 +343,7 @@ static void random_rpc_pipe(char *pipe_name, struct client_info *cli_info, for (i = 1; i <= numops * 100; i++) { - do_random_rpc(smb_cli, 8192); + do_random_rpc(smb_cli, nt_pipe_fnum, 8192); if (i % 500 == 0) { DEBUG(0,("calls: %i\n", i)); @@ -425,12 +424,12 @@ static void run_samhandles(int numops, struct client_info *cli_info) { POLICY_HND pol; POLICY_HND dom; - if (!do_samr_connect(smb_cli, srv_name, 0x20, &pol)) + if (!samr_connect(smb_cli, nt_pipe_fnum, srv_name, 0x20, &pol)) { failed++; } /* - if (!do_samr_open_domain(smb_cli, srv_name, 0x00000020, &pol)) + if (!samr_open_domain(smb_cli, nt_pipe_fnum, srv_name, 0x00000020, &pol)) { DEBUG(0,("samhandle domain open test (%i): failed\n", i)); } @@ -487,7 +486,7 @@ static void run_lsahandles(int numops, struct client_info *cli_info) for (i = 1; i <= numops * 100; i++) { POLICY_HND pol; - if (!do_lsa_open_policy(smb_cli, srv_name, &pol, False)) + if (!lsa_open_policy(smb_cli, nt_pipe_fnum, srv_name, &pol, False)) { failed++; } @@ -957,11 +956,11 @@ enum client_action } */ - create_procs(nprocs, numops, &cli_info, run_pipegobbler); + create_procs(nprocs, numops, &cli_info, run_randomrpc); /* + create_procs(nprocs, numops, &cli_info, run_pipegobbler); create_procs(nprocs, numops, &cli_info, run_tcpconnect); create_procs(nprocs, numops, &cli_info, run_handles); - create_procs(nprocs, numops, &cli_info, run_randomrpc); */ fflush(out_hnd); -- cgit From 4423c27fe5ff58580add16b28f08ca693144107b Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 27 Jan 1999 18:22:48 +0000 Subject: Fuss fuss fuss. Added missing default: statements to two switch blocks. Chris -)----- (This used to be commit 0681f6946be2f7b528a1efb6adcc2366a2951644) --- source3/utils/debug2html.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/debug2html.c b/source3/utils/debug2html.c index c7f36da0c0..62ecacf7e8 100644 --- a/source3/utils/debug2html.c +++ b/source3/utils/debug2html.c @@ -28,7 +28,7 @@ * does a decent job of converting Samba logs into HTML. * -------------------------------------------------------------------------- ** * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * * ========================================================================== ** */ @@ -128,6 +128,8 @@ static void newblock( dbg_Token old, dbg_Token new ) case dbg_lineno: (void)fprintf( outfile, ")" ); break; + default: + break; } switch( new ) @@ -141,6 +143,8 @@ static void newblock( dbg_Token old, dbg_Token new ) case dbg_lineno: (void)fprintf( outfile, "(" ); break; + default: + break; } } /* newblock */ -- cgit From 8b6b6b57b54aeafb915cf99e5610941ee1d464b8 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 10 Feb 1999 22:30:47 +0000 Subject: use jeremy's versions of the UNICODE routines. (This used to be commit c5109ff782be8774db47a92b48ca6335ec8d6065) --- source3/utils/torture.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index fb09f515cf..be77c48cfe 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -1167,9 +1167,9 @@ static void create_procs(int nprocs, int numops, void (*fn)(int )) printf("host=%s share=%s user=%s myname=%s procs=%d ops=%d\n", host, share, username, myname, nprocs, numops); - create_procs(nprocs, numops, run_connection); -/* create_procs(nprocs, numops, run_randomipc); +/* + create_procs(nprocs, numops, run_connection); run_fdpasstest(); run_locktest1(); -- cgit From f02321a9987555d616d36b0c151e408d7140c023 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Thu, 11 Feb 1999 18:35:26 +0000 Subject: refinement of random ipc$ SMBtrans torture test. send requests, and don't wait for responses :-) (This used to be commit c1d65e906054297e42d6d177194d3b9ab16c7e35) --- source3/utils/torture.c | 62 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index be77c48cfe..0e1b0b6fcd 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -786,10 +786,10 @@ static void run_randomipc(int numops) SSVAL(param,0,api); - cli_api(&cli, + cli_api(&cli, param, param_len, 8, NULL, 0, BUFFER_SIZE, - &rparam, &rprcnt, + &rparam, &rprcnt, &rdata, &rdrcnt); } @@ -798,6 +798,58 @@ static void run_randomipc(int numops) DEBUG(0,("finished random ipc test\n")); } +/* send random IPC commands */ +static void run_randomipc_nowait(int numops) +{ + char param[BUFFER_SIZE]; + int api, param_len, i; + int reconnect_count = 50; + static struct cli_state cli; + + DEBUG(0,("start random ipc test no waiting for SMBtrans response\n")); + + while (reconnect_count > 0 && open_connection(&cli) != 0) + { + DEBUG(0,("connection failed: retrying %d\n", reconnect_count)); + msleep(sys_random() % 1000); + reconnect_count--; + } + + if (reconnect_count == 0) + { + return; + } + + for (i=0;i Date: Tue, 9 Mar 1999 01:21:57 +0000 Subject: mods to allow inter-domain trust accounts to be added to SAM database using smbpasswd command. (This used to be commit 62d499f83256c6e8b3308dc4bd8e9f5df873b14b) --- source3/utils/smbpasswd.c | 254 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 177 insertions(+), 77 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 157583925b..83b9b0bdc9 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -1,6 +1,7 @@ /* - * Unix SMB/Netbios implementation. Version 1.9. smbpasswd module. Copyright - * (C) Jeremy Allison 1995-1998 + * Unix SMB/Netbios implementation. Version 1.9. smbpasswd module. + * Copyright (C) Jeremy Allison 1995-1999 + * Copyright (C) Luke Kenneth Casson Leighton 1996-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 @@ -67,7 +68,8 @@ static void usage(void) printf(" -d disable user\n"); printf(" -e enable user\n"); printf(" -n set no password\n"); - printf(" -m machine trust account\n"); + printf(" -m workstation trust account\n"); + printf(" -i inter-domain trust account\n"); } exit(1); } @@ -221,35 +223,47 @@ static char *prompt_for_new_password(BOOL stdin_get) change a password either locally or remotely *************************************************************/ static BOOL password_change(const char *remote_machine, char *user_name, - char *old_passwd, char *new_passwd, - BOOL add_user, BOOL enable_user, - BOOL disable_user, BOOL set_no_password, - BOOL trust_account) + char *old_passwd, char *new_passwd, + BOOL add_user, + uint16 acb_info, uint16 acb_mask) { BOOL ret; pstring err_str; pstring msg_str; - if (remote_machine != NULL) { - if (add_user || enable_user || disable_user || set_no_password || trust_account) { + if (remote_machine != NULL) + { + if (add_user || + IS_BITS_SET_SOME(acb_info, ACB_PWNOTREQ | ACB_WSTRUST | ACB_DOMTRUST | ACB_SVRTRUST) || + (IS_BITS_SET_SOME(acb_mask, ACB_DISABLED) && + IS_BITS_CLR_ALL(acb_info, ACB_DISABLED))) + { /* these things can't be done remotely yet */ return False; } ret = remote_password_change(remote_machine, user_name, - old_passwd, new_passwd, err_str, sizeof(err_str)); - if(*err_str) + old_passwd, new_passwd, + err_str, sizeof(err_str)); + if (*err_str != 0) + { fprintf(stderr, err_str); + } return ret; } - ret = local_password_change(user_name, trust_account, add_user, enable_user, - disable_user, set_no_password, new_passwd, - err_str, sizeof(err_str), msg_str, sizeof(msg_str)); + ret = local_password_change(user_name, add_user, acb_info, acb_mask, + new_passwd, + err_str, sizeof(err_str), + msg_str, sizeof(msg_str)); - if(*msg_str) + if (*msg_str != 0) + { printf(msg_str); - if(*err_str) + } + if (*err_str != 0) + { fprintf(stderr, err_str); + } return ret; } @@ -262,8 +276,11 @@ static int process_root(int argc, char *argv[]) { struct passwd *pwd; int ch; + uint16 acb_info = 0; + uint16 acb_mask = 0; BOOL joining_domain = False; - BOOL trust_account = False; + BOOL wks_trust_account = False; + BOOL dom_trust_account = False; BOOL add_user = False; BOOL disable_user = False; BOOL enable_user = False; @@ -275,65 +292,97 @@ static int process_root(int argc, char *argv[]) char *old_passwd = NULL; char *remote_machine = NULL; - while ((ch = getopt(argc, argv, "adehmnj:r:sR:D:U:")) != EOF) { - switch(ch) { - case 'a': - add_user = True; - break; - case 'd': - disable_user = True; - new_passwd = "XXXXXX"; - break; - case 'e': - enable_user = True; - break; - case 'D': - DEBUGLEVEL = atoi(optarg); - break; - case 'n': - set_no_password = True; - new_passwd = "NO PASSWORD"; - case 'r': - remote_machine = optarg; - break; - case 's': - set_line_buffering(stdin); - set_line_buffering(stdout); - set_line_buffering(stderr); - stdin_passwd_get = True; - break; - case 'R': - lp_set_name_resolve_order(optarg); - break; - case 'm': - trust_account = True; - break; - case 'j': - new_domain = optarg; - strupper(new_domain); - joining_domain = True; - break; - case 'U': - user_name = optarg; - break; - default: - usage(); + while ((ch = getopt(argc, argv, "adehimnj:r:sR:D:U:")) != EOF) + { + switch(ch) + { + case 'a': + { + add_user = True; + break; + } + case 'd': + { + disable_user = True; + new_passwd = "XXXXXX"; + break; + } + case 'e': + { + enable_user = True; + break; + } + case 'D': + { + DEBUGLEVEL = atoi(optarg); + break; + } + case 'n': + { + set_no_password = True; + new_passwd = "NO PASSWORD"; + } + case 'r': + { + remote_machine = optarg; + break; + } + case 's': + { + set_line_buffering(stdin); + set_line_buffering(stdout); + set_line_buffering(stderr); + stdin_passwd_get = True; + break; + } + case 'R': + { + lp_set_name_resolve_order(optarg); + break; + } + case 'i': + { + dom_trust_account = True; + break; + } + case 'm': + { + wks_trust_account = True; + break; + } + case 'j': + { + new_domain = optarg; + strupper(new_domain); + joining_domain = True; + break; + } + case 'U': + { + user_name = optarg; + break; + } + default: + { + usage(); + } } } argc -= optind; argv += optind; - /* * Ensure add_user and either remote machine or join domain are * not both set. */ - if(add_user && ((remote_machine != NULL) || joining_domain)) { + if (add_user && ((remote_machine != NULL) || joining_domain)) + { usage(); } - if(joining_domain) { + if (joining_domain) + { if (argc != 0) usage(); return join_domain(new_domain, remote_machine); } @@ -365,7 +414,8 @@ static int process_root(int argc, char *argv[]) exit(1); } - if (trust_account) { + if (wks_trust_account || dom_trust_account) + { /* add the $ automatically */ static fstring buf; @@ -402,7 +452,8 @@ static int process_root(int argc, char *argv[]) old_passwd = get_pass("Old SMB password:",stdin_passwd_get); } - if (!new_passwd) { + if (!new_passwd) + { /* * If we are trying to enable a user, first we need to find out @@ -413,31 +464,76 @@ static int process_root(int argc, char *argv[]) * smbpasswd file) then we need to prompt for a new password. */ - if(enable_user) { + if (enable_user) + { struct smb_passwd *smb_pass = getsmbpwnam(user_name); - if((smb_pass != NULL) && (smb_pass->smb_passwd != NULL)) { + if((smb_pass != NULL) && (smb_pass->smb_passwd != NULL)) + { new_passwd = "XXXX"; /* Don't care. */ } } if(!new_passwd) + { new_passwd = prompt_for_new_password(stdin_passwd_get); + } } + if (enable_user) + { + acb_mask |= ACB_DISABLED; + acb_info &= ~ACB_DISABLED; + } + + if (disable_user) + { + acb_mask |= ACB_DISABLED; + acb_info |= ACB_DISABLED; + } + + if (set_no_password) + { + acb_mask |= ACB_PWNOTREQ; + acb_info |= ACB_PWNOTREQ; + } + + if (wks_trust_account) + { + acb_mask |= ACB_WSTRUST; + acb_info |= ACB_WSTRUST; + } + else if (dom_trust_account) + { + acb_mask |= ACB_DOMTRUST; + acb_info |= ACB_DOMTRUST; + } + else + { + acb_mask |= ACB_NORMAL; + acb_info |= ACB_NORMAL; + } + if (!password_change(remote_machine, user_name, old_passwd, new_passwd, - add_user, enable_user, disable_user, set_no_password, - trust_account)) { + add_user, acb_info, acb_mask)) + { fprintf(stderr,"Failed to change password entry for %s\n", user_name); return 1; } - if(disable_user) { + if (disable_user) + { printf("User %s disabled.\n", user_name); - } else if(enable_user) { + } + if (enable_user) + { printf("User %s enabled.\n", user_name); - } else if (set_no_password) { + } + if (set_no_password) + { printf("User %s - set to no password.\n", user_name); - } else { + } + if (!disable_user && !enable_user && !set_no_password) + { printf("Password changed for user %s\n", user_name); } return 0; @@ -457,8 +553,10 @@ static int process_nonroot(int argc, char *argv[]) char *user_name = NULL; char *new_passwd = NULL; - while ((ch = getopt(argc, argv, "hD:r:sU:")) != EOF) { - switch(ch) { + while ((ch = getopt(argc, argv, "hD:r:sU:")) != EOF) + { + switch(ch) + { case 'D': DEBUGLEVEL = atoi(optarg); break; @@ -523,8 +621,10 @@ static int process_nonroot(int argc, char *argv[]) exit(0); } - if (!password_change(remote_machine, user_name, old_passwd, new_passwd, - False, False, False, False, False)) { + if (!password_change(remote_machine, user_name, + old_passwd, new_passwd, + False, 0x0, 0x0)) + { fprintf(stderr,"Failed to change password for %s\n", user_name); return 1; } -- cgit From fda194255c156ce373d5f195e960bf8712fe4d67 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 19 Mar 1999 05:00:39 +0000 Subject: Beau Kuiper: provided patch so that passwords could only be changed by root if the ACB_PWLOCK bit is set (on a per-user basis). he also added an extra smbpasswd option so that this bit can be modified from command-line. (This used to be commit 534fe319d9de8da2ed7e911dbba3c7df08193efa) --- source3/utils/smbpasswd.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 83b9b0bdc9..e1c6666820 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -70,7 +70,10 @@ static void usage(void) printf(" -n set no password\n"); printf(" -m workstation trust account\n"); printf(" -i inter-domain trust account\n"); + printf(" -p user cannot change password\n"); + printf(" -x user can change password\n"); } + exit(1); } @@ -286,13 +289,15 @@ static int process_root(int argc, char *argv[]) BOOL enable_user = False; BOOL set_no_password = False; BOOL stdin_passwd_get = False; + BOOL lock_password = False; + BOOL unlock_password = False; char *user_name = NULL; char *new_domain = NULL; char *new_passwd = NULL; char *old_passwd = NULL; char *remote_machine = NULL; - while ((ch = getopt(argc, argv, "adehimnj:r:sR:D:U:")) != EOF) + while ((ch = getopt(argc, argv, "adehimnpxj:r:sR:D:U:")) != EOF) { switch(ch) { @@ -362,6 +367,16 @@ static int process_root(int argc, char *argv[]) user_name = optarg; break; } + case 'p': + { + lock_password = True; + break; + } + case 'x': + { + unlock_password = True; + break; + } default: { usage(); @@ -497,6 +512,18 @@ static int process_root(int argc, char *argv[]) acb_info |= ACB_PWNOTREQ; } + if (lock_password) + { + acb_mask |= ACB_PWLOCK; + acb_info |= ACB_PWLOCK; + } + + if (unlock_password) + { + acb_mask |= ACB_PWLOCK; + acb_info &= ~ACB_PWLOCK; + } + if (wks_trust_account) { acb_mask |= ACB_WSTRUST; @@ -552,7 +579,7 @@ static int process_nonroot(int argc, char *argv[]) char *remote_machine = NULL; char *user_name = NULL; char *new_passwd = NULL; - + while ((ch = getopt(argc, argv, "hD:r:sU:")) != EOF) { switch(ch) @@ -607,7 +634,6 @@ static int process_nonroot(int argc, char *argv[]) remote_machine = "127.0.0.1"; } - if (remote_machine != NULL) { old_passwd = get_pass("Old SMB password:",stdin_passwd_get); } -- cgit From d330c907bdc5d8e3c242cea76dfafaae84041270 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 1 Apr 1999 05:22:58 +0000 Subject: Ken McDonell from SGI was interested in adding some profiling capabilities to Samba so that Samba could talk to the SGI PCP (Performance Co-Pilot) apps. This change adds a profiling shared memory area and uses it to count two fairly trivial things, the number of uid switches and the number of SMB packets processes. To add more just edit include/profile.h and then increment it at the right place. I've also added a -P switch to smbstatus to dump the profile area. (This used to be commit ef3d61a80ad0b87c196a63ef2bd4fe8fc3863bd0) --- source3/utils/status.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 96df087858..e20af8444c 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -138,6 +138,27 @@ static void print_share_mode(share_mode_entry *e, char *fname) } +/******************************************************************* + dump the elements of the profile structure + ******************************************************************/ +static int profile_dump(void) +{ +#ifndef WITH_PROFILE + fprintf(stderr,"ERROR: not compiled with profile support\n"); + return -1; +#else + if (!profile_setup(True)) { + fprintf(stderr,"Failed to initialise profile memory\n"); + return -1; + } + + printf("smb_count:\t%u\n", profile_p->smb_count); + printf("uid_changes:\t%u\n", profile_p->uid_changes); + return 0; +#endif +} + + int main(int argc, char *argv[]) { @@ -150,7 +171,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) BOOL processes_only=False; int last_pid=0; struct session_record *ptr; - + int profile_only = 0; TimeInit(); setup_logging(argv[0],True); @@ -165,7 +186,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) return(1); } - while ((c = getopt(argc, argv, "pdLSs:u:b")) != EOF) { + while ((c = getopt(argc, argv, "pdLSs:u:bP")) != EOF) { switch (c) { case 'b': brief = 1; @@ -179,6 +200,9 @@ static void print_share_mode(share_mode_entry *e, char *fname) case 'p': processes_only = 1; break; + case 'P': + profile_only = 1; + break; case 'S': shares_only = 1; break; @@ -189,7 +213,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) Ucrit_addUsername(optarg); /* added by OH */ break; default: - fprintf(stderr, "Usage: %s [-d] [-L] [-p] [-S] [-s configfile] [-u username]\n", *argv); /* changed by OH */ + fprintf(stderr, "Usage: %s [-P] [-d] [-L] [-p] [-S] [-s configfile] [-u username]\n", *argv); return (-1); } } @@ -206,6 +230,10 @@ static void print_share_mode(share_mode_entry *e, char *fname) printf("lockdir = %s\n", *lp_lockdir() ? lp_lockdir() : "NULL"); } + if (profile_only) { + return profile_dump(); + } + pstrcpy(fname,lp_lockdir()); standard_sub_basic(fname); trim_string(fname,"","/"); -- cgit From a1d6f07e54b9f7cd8718e6eae98385886dddec1f Mon Sep 17 00:00:00 2001 From: Matthew Chapman Date: Thu, 8 Apr 1999 05:37:15 +0000 Subject: Mainly BDC-related changes. * Added SEC_CHAN_BDC * Added -b switch to smbpasswd (for a BDC (server) trust account). * Propagate sec_chan into the various functions which change trust account passwords, so they can be used for domain control and inter-domain trusts. (This used to be commit 6f2b37bfc5fc8d56b275883d0ed2c5179aa60ccd) --- source3/utils/smbpasswd.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index e1c6666820..29f2d364e5 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -69,6 +69,7 @@ static void usage(void) printf(" -e enable user\n"); printf(" -n set no password\n"); printf(" -m workstation trust account\n"); + printf(" -b backup domain controller account\n"); printf(" -i inter-domain trust account\n"); printf(" -p user cannot change password\n"); printf(" -x user can change password\n"); @@ -86,19 +87,23 @@ static int join_domain(char *domain, char *remote) fstring trust_passwd; unsigned char orig_trust_passwd_hash[16]; BOOL ret; + uint16 sec_chan; pstrcpy(remote_machine, remote ? remote : ""); fstrcpy(trust_passwd, global_myname); strlower(trust_passwd); E_md4hash( (uchar *)trust_passwd, orig_trust_passwd_hash); - /* Ensure that we are not trying to join a - domain if we are locally set up as a domain - controller. */ - - if(strequal(remote, global_myname)) { - fprintf(stderr, "Cannot join domain %s as the domain controller name is our own. We cannot be a domain controller for a domain and also be a domain member.\n", domain); - return 1; + switch (lp_server_role()) + { + case ROLE_DOMAIN_PDC: + DEBUG(0, ("Cannot join domain - we are PDC!\n")); + return; + case ROLE_DOMAIN_BDC: + sec_chan = SEC_CHAN_BDC; + break; + default: + sec_chan = SEC_CHAN_WKSTA; } /* @@ -136,7 +141,7 @@ unable to join domain.\n"); return 1; } - ret = change_trust_account_password( domain, remote_machine); + ret = change_trust_account_password(domain, remote_machine, sec_chan); trust_password_unlock(); if(!ret) { @@ -283,6 +288,7 @@ static int process_root(int argc, char *argv[]) uint16 acb_mask = 0; BOOL joining_domain = False; BOOL wks_trust_account = False; + BOOL srv_trust_account = False; BOOL dom_trust_account = False; BOOL add_user = False; BOOL disable_user = False; @@ -297,7 +303,7 @@ static int process_root(int argc, char *argv[]) char *old_passwd = NULL; char *remote_machine = NULL; - while ((ch = getopt(argc, argv, "adehimnpxj:r:sR:D:U:")) != EOF) + while ((ch = getopt(argc, argv, "abdehimnpxj:r:sR:D:U:")) != EOF) { switch(ch) { @@ -350,6 +356,11 @@ static int process_root(int argc, char *argv[]) dom_trust_account = True; break; } + case 'b': + { + srv_trust_account = True; + break; + } case 'm': { wks_trust_account = True; @@ -429,7 +440,7 @@ static int process_root(int argc, char *argv[]) exit(1); } - if (wks_trust_account || dom_trust_account) + if (wks_trust_account || srv_trust_account || dom_trust_account) { /* add the $ automatically */ static fstring buf; @@ -529,6 +540,11 @@ static int process_root(int argc, char *argv[]) acb_mask |= ACB_WSTRUST; acb_info |= ACB_WSTRUST; } + else if (srv_trust_account) + { + acb_mask |= ACB_SVRTRUST; + acb_info |= ACB_SVRTRUST; + } else if (dom_trust_account) { acb_mask |= ACB_DOMTRUST; -- cgit From 94928d4de7881cdf3655bcd4cb9b01608e7452aa Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 11 Apr 1999 00:27:43 +0000 Subject: Modification to compile under egcs 2.91.63. (This used to be commit d04c530836202ca2277176341261b3ac78f4956a) --- source3/utils/debug2html.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/debug2html.c b/source3/utils/debug2html.c index 62ecacf7e8..ef7201168f 100644 --- a/source3/utils/debug2html.c +++ b/source3/utils/debug2html.c @@ -28,7 +28,7 @@ * does a decent job of converting Samba logs into HTML. * -------------------------------------------------------------------------- ** * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * * ========================================================================== ** */ @@ -39,8 +39,8 @@ * Global values. */ -FILE *infile = stdin; -FILE *outfile = stdout; +FILE *infile; +FILE *outfile; /* -------------------------------------------------------------------------- ** * The size of the read buffer. @@ -298,6 +298,9 @@ int main( int argc, char *argv[] ) if( argc > 3 ) usage(); + infile = stdin; + outfile = stdout; + if( argc > 1 && 0 != strcmp( argv[1], "-" ) ) infile = carefull_fopen( argv[1], "r" ); -- cgit From a32c9262894f73b91d10db30bb6e7085d6bacd87 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 17 Apr 1999 14:06:57 +0000 Subject: damn, new files need to be added to the head branch first, I've told other people this before then forgot myself :) (This used to be commit a116228d37fdd18979caec6765394e79be49fa99) --- source3/utils/smbfilter.c | 233 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 233 insertions(+) create mode 100644 source3/utils/smbfilter.c (limited to 'source3/utils') diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c new file mode 100644 index 0000000000..81b10e4519 --- /dev/null +++ b/source3/utils/smbfilter.c @@ -0,0 +1,233 @@ +/* + Unix SMB/Netbios implementation. + Version 2 + SMB filter/socket plugin + 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. +*/ + +#include "includes.h" +#include "smb.h" + +#define SECURITY_MASK 0 +#define SECURITY_SET 0 + +/* this forces non-unicode */ +#define CAPABILITY_MASK CAP_UNICODE +#define CAPABILITY_SET 0 + +/* and non-unicode for the client too */ +#define CLI_CAPABILITY_MASK CAP_UNICODE +#define CLI_CAPABILITY_SET 0 + +static char *netbiosname; +static char packet[BUFFER_SIZE]; + +extern int DEBUGLEVEL; + +static void filter_reply(char *buf) +{ + int msg_type = CVAL(buf,0); + int type = CVAL(buf,smb_com); + unsigned x; + + if (msg_type) return; + + switch (type) { + + case SMBnegprot: + /* force the security bits */ + x = CVAL(buf, smb_vwv1); + x = (x | SECURITY_SET) & ~SECURITY_MASK; + SCVAL(buf, smb_vwv1, x); + + /* force the capabilities */ + x = IVAL(buf,smb_vwv9+1); + x = (x | CAPABILITY_SET) & ~CAPABILITY_MASK; + SIVAL(buf, smb_vwv9+1, x); + break; + + } +} + +static void filter_request(char *buf) +{ + int msg_type = CVAL(buf,0); + int type = CVAL(buf,smb_com); + pstring name1,name2; + unsigned x; + + if (msg_type) { + /* it's a netbios special */ + switch (msg_type) { + case 0x81: + /* session request */ + name_extract(buf,4,name1); + name_extract(buf,4 + name_len(buf + 4),name2); + DEBUG(0,("sesion_request: %s -> %s\n", + name1, name2)); + if (netbiosname) { + /* replace the destination netbios name */ + name_mangle(netbiosname, buf+4, 0x20); + } + } + return; + } + + /* it's an ordinary SMB request */ + switch (type) { + case SMBsesssetupX: + /* force the client capabilities */ + x = IVAL(buf,smb_vwv11); + x = (x | CLI_CAPABILITY_SET) & ~CLI_CAPABILITY_MASK; + SIVAL(buf, smb_vwv11, x); + break; + } + +} + + +static void filter_child(int c, struct in_addr dest_ip) +{ + int s; + + /* we have a connection from a new client, now connect to the server */ + s = open_socket_out(SOCK_STREAM, &dest_ip, 139, LONG_CONNECT_TIMEOUT); + + if (s == -1) { + DEBUG(0,("Unable to connect to %s\n", inet_ntoa(dest_ip))); + exit(1); + } + + while (c != -1 || s != -1) { + fd_set fds; + int num; + + FD_ZERO(&fds); + if (s != -1) FD_SET(s, &fds); + if (c != -1) FD_SET(c, &fds); + + num = sys_select(MAX(s+1, c+1),&fds,NULL); + if (num <= 0) continue; + + if (c != -1 && FD_ISSET(c, &fds)) { + if (!receive_smb(c, packet, 0)) { + DEBUG(0,("client closed connection\n")); + exit(0); + } + filter_request(packet); + if (!send_smb(s, packet)) { + DEBUG(0,("server is dead\n")); + exit(1); + } + } + if (s != -1 && FD_ISSET(s, &fds)) { + if (!receive_smb(s, packet, 0)) { + DEBUG(0,("server closed connection\n")); + exit(0); + } + filter_reply(packet); + if (!send_smb(c, packet)) { + DEBUG(0,("client is dead\n")); + exit(1); + } + } + } + DEBUG(0,("Connection closed\n")); + exit(0); +} + + +static void start_filter(char *desthost) +{ + int s, c; + struct in_addr dest_ip; + + CatchChild(); + + /* start listening on port 139 locally */ + s = open_socket_in(SOCK_STREAM, 139, 0, 0, True); + + if (s == -1) { + DEBUG(0,("bind failed\n")); + exit(1); + } + + if (listen(s, 5) == -1) { + DEBUG(0,("listen failed\n")); + } + + if (!resolve_name(desthost, &dest_ip, 0x20)) { + DEBUG(0,("Unable to resolve host %s\n", desthost)); + exit(1); + } + + while (1) { + fd_set fds; + int num; + struct sockaddr addr; + int in_addrlen = sizeof(addr); + + FD_ZERO(&fds); + FD_SET(s, &fds); + + num = sys_select(s+1,&fds,NULL); + if (num > 0) { + c = accept(s, &addr, &in_addrlen); + if (c != -1) { + if (fork() == 0) { + close(s); + filter_child(c, dest_ip); + exit(0); + } else { + close(c); + } + } + } + } +} + + +int main(int argc, char *argv[]) +{ + char *desthost; + pstring configfile; + + TimeInit(); + + setup_logging(argv[0],True); + + charset_initialise(); + + pstrcpy(configfile,CONFIGFILE); + + if (argc < 2) { + fprintf(stderr,"smbfilter \n"); + exit(1); + } + + desthost = argv[1]; + if (argc > 2) { + netbiosname = argv[2]; + } + + if (!lp_load(configfile,True,False,False)) { + DEBUG(0,("Unable to load config file\n")); + } + + start_filter(desthost); + return 0; +} -- cgit From 4c5c9d6734786c7cc3ed2d03e66f7ae586e8f610 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 17 Apr 1999 14:13:06 +0000 Subject: open_socket_in() takes a different number of parameters in the head branch. We need that merge soon! (This used to be commit 5fb06c603efe08ea64da602de848b79fea6505c0) --- source3/utils/smbfilter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c index 81b10e4519..4f6420c767 100644 --- a/source3/utils/smbfilter.c +++ b/source3/utils/smbfilter.c @@ -159,7 +159,7 @@ static void start_filter(char *desthost) CatchChild(); /* start listening on port 139 locally */ - s = open_socket_in(SOCK_STREAM, 139, 0, 0, True); + s = open_socket_in(SOCK_STREAM, 139, 0, 0); if (s == -1) { DEBUG(0,("bind failed\n")); -- cgit From 94a4094f444ba7433dbf812b1252d964adfa6916 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 7 May 1999 18:20:59 +0000 Subject: had to move day display names into lib/util, to get rpctorture to compile. (This used to be commit 8c80742e4e5604bc667314e51c47924efd65df49) --- source3/utils/rpctorture.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/rpctorture.c b/source3/utils/rpctorture.c index 831af55e0f..86729c3d10 100644 --- a/source3/utils/rpctorture.c +++ b/source3/utils/rpctorture.c @@ -556,8 +556,8 @@ static void run_pipegobble(int numops, struct client_info *cli_info, char *pipe_ static void run_handles(int numops, struct client_info *cli_info) { - run_samhandles(numops, cli_info); run_lsahandles(numops, cli_info); + run_samhandles(numops, cli_info); } static void run_pipegobbler(int numops, struct client_info *cli_info) @@ -634,6 +634,8 @@ static void usage(char *pname) fprintf(out_hnd, "\t-U username set the network username\n"); fprintf(out_hnd, "\t-W workgroup set the workgroup name\n"); fprintf(out_hnd, "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n"); + fprintf(out_hnd, "\t-N processes number of processes\n"); + fprintf(out_hnd, "\t-o operations number of operations\n"); fprintf(out_hnd, "\n"); } @@ -956,12 +958,12 @@ enum client_action } */ - create_procs(nprocs, numops, &cli_info, run_randomrpc); /* + create_procs(nprocs, numops, &cli_info, run_randomrpc); create_procs(nprocs, numops, &cli_info, run_pipegobbler); create_procs(nprocs, numops, &cli_info, run_tcpconnect); - create_procs(nprocs, numops, &cli_info, run_handles); */ + create_procs(nprocs, numops, &cli_info, run_handles); fflush(out_hnd); -- cgit From 810d9a1627980042daa7b5c2f8ceeb225a2c5275 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 7 May 1999 20:21:30 +0000 Subject: variation of random SMBtrans2. random delays in between reconnections increased. size of large random buffer decreased. number of reconnection attempts increased. (This used to be commit 980a7b11f3dabce561a0ed02041695451bfeb391) --- source3/utils/torture.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 0e1b0b6fcd..2de9681031 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -745,15 +745,17 @@ static void rand_buf(char *buf, int len) } } +#define TORT_BUFFER_SIZE 1024 + /* send random IPC commands */ static void run_randomipc(int numops) { char *rparam = NULL; char *rdata = NULL; int rdrcnt,rprcnt; - char param[BUFFER_SIZE]; + char param[TORT_BUFFER_SIZE]; int api, param_len, i; - int reconnect_count = 50; + int reconnect_count = 500; static struct cli_state cli; DEBUG(0,("starting random ipc test\n")); @@ -761,7 +763,7 @@ static void run_randomipc(int numops) while (reconnect_count > 0 && open_connection(&cli) != 0) { DEBUG(0,("connection failed: retrying %d\n", reconnect_count)); - msleep(sys_random() % 1000); + msleep(sys_random() % 5000); reconnect_count--; } @@ -775,7 +777,7 @@ static void run_randomipc(int numops) api = sys_random() % 500; if ((sys_random() % 10) == 0) { - param_len = (sys_random() % BUFFER_SIZE); + param_len = (sys_random() % TORT_BUFFER_SIZE); } else { @@ -801,9 +803,9 @@ static void run_randomipc(int numops) /* send random IPC commands */ static void run_randomipc_nowait(int numops) { - char param[BUFFER_SIZE]; + char param[TORT_BUFFER_SIZE]; int api, param_len, i; - int reconnect_count = 50; + int reconnect_count = 500; static struct cli_state cli; DEBUG(0,("start random ipc test no waiting for SMBtrans response\n")); @@ -811,7 +813,7 @@ static void run_randomipc_nowait(int numops) while (reconnect_count > 0 && open_connection(&cli) != 0) { DEBUG(0,("connection failed: retrying %d\n", reconnect_count)); - msleep(sys_random() % 1000); + msleep(sys_random() % 5000); reconnect_count--; } @@ -825,7 +827,7 @@ static void run_randomipc_nowait(int numops) api = sys_random() % 500; if ((sys_random() % 10) == 0) { - param_len = (sys_random() % BUFFER_SIZE); + param_len = (sys_random() % TORT_BUFFER_SIZE); } else { @@ -1219,11 +1221,11 @@ static void create_procs(int nprocs, int numops, void (*fn)(int )) printf("host=%s share=%s user=%s myname=%s procs=%d ops=%d\n", host, share, username, myname, nprocs, numops); - create_procs(nprocs, numops, run_connection); + create_procs(nprocs, numops, run_randomipc_nowait); /* + create_procs(nprocs, numops, run_connection); create_procs(nprocs, numops, run_randomipc); - create_procs(nprocs, numops, run_randomipc_nowait); run_fdpasstest(); run_locktest1(); -- cgit From cae3620b2e8abbe35f0369a82d5461cb596475a3 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Thu, 24 Jun 1999 18:58:08 +0000 Subject: safe string error reporting functions (found a potential buffer overflow of a pstrcpy into an fstring). (This used to be commit ac0060443de800fec9042b69b299ff2e9128a31c) --- source3/utils/torture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 2de9681031..3c872ea672 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -1223,9 +1223,9 @@ static void create_procs(int nprocs, int numops, void (*fn)(int )) create_procs(nprocs, numops, run_randomipc_nowait); /* + create_procs(nprocs, numops, run_randomipc); create_procs(nprocs, numops, run_connection); - create_procs(nprocs, numops, run_randomipc); run_fdpasstest(); run_locktest1(); -- cgit From 73891ca8e4f6cca6aa8bb0ae043f660a64baa056 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Tue, 29 Jun 1999 18:47:06 +0000 Subject: improving authentication code (tidyup). (This used to be commit ab1a6aa42db5217f025941fb5107436556bc23b7) --- source3/utils/rpctorture.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/rpctorture.c b/source3/utils/rpctorture.c index 86729c3d10..ff98c0a837 100644 --- a/source3/utils/rpctorture.c +++ b/source3/utils/rpctorture.c @@ -113,6 +113,8 @@ static BOOL rpcclient_connect(struct client_info *info) { rpcclient_init(); + smb_cli->use_ntlmv2 = lp_client_ntlmv2(); + if (!cli_establish_connection(smb_cli, info->dest_host, &info->dest_ip, &calling, &called, -- cgit From 6a5a4e818684a616306d2954d1a2612113b314a6 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 21 Jul 1999 00:32:09 +0000 Subject: BDC support. (This used to be commit 2331aa32ab36c3ee5fd8cfbe972e57299939e33d) --- source3/utils/smbpasswd.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 29f2d364e5..e9360651da 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -89,6 +89,8 @@ static int join_domain(char *domain, char *remote) BOOL ret; uint16 sec_chan; + DEBUG(5,("join_domain: domain %s remote %s\n", domain, remote)); + pstrcpy(remote_machine, remote ? remote : ""); fstrcpy(trust_passwd, global_myname); strlower(trust_passwd); @@ -97,19 +99,28 @@ static int join_domain(char *domain, char *remote) switch (lp_server_role()) { case ROLE_DOMAIN_PDC: + { DEBUG(0, ("Cannot join domain - we are PDC!\n")); - return; + return 1; + } case ROLE_DOMAIN_BDC: + { + DEBUG(0, ("Joining Domain as BDC\n")); sec_chan = SEC_CHAN_BDC; break; + } default: + { + DEBUG(0, ("Joining Domain as Workstation\n")); sec_chan = SEC_CHAN_WKSTA; + } } /* * Create the machine account password file. */ - if(!trust_password_lock( domain, global_myname, True)) { + if(!trust_password_lock( domain, global_myname, True)) + { fprintf(stderr, "unable to open the machine account password file for \ machine %s in domain %s.\n", global_myname, domain); return 1; @@ -119,7 +130,8 @@ machine %s in domain %s.\n", global_myname, domain); * Write the old machine account password. */ - if(!set_trust_account_password( orig_trust_passwd_hash)) { + if(!set_trust_account_password( orig_trust_passwd_hash)) + { fprintf(stderr, "unable to write the machine account password for \ machine %s in domain %s.\n", global_myname, domain); trust_password_unlock(); @@ -130,7 +142,8 @@ machine %s in domain %s.\n", global_myname, domain); * If we are given a remote machine assume this is the PDC. */ - if(remote == NULL) { + if(remote == NULL) + { pstrcpy(remote_machine, lp_passwordserver()); } @@ -145,12 +158,15 @@ unable to join domain.\n"); trust_password_unlock(); if(!ret) { - trust_password_delete( domain, global_myname); fprintf(stderr,"Unable to join domain %s.\n",domain); } else { printf("Joined domain %s.\n",domain); } +#if 0 + trust_password_delete( domain, global_myname); +#endif + return (int)ret; } -- cgit From 8f54fdb01a3aed5bdcfc9dc69e1c77c0d13b4e98 Mon Sep 17 00:00:00 2001 From: Matthew Chapman Date: Thu, 22 Jul 1999 10:55:41 +0000 Subject: BDC support. Added -S (Synchronise) option to smbpasswd, which calls synchronise_passdb. (This used to be commit 21c92d24977015f0368480f44f67366f7c412343) --- source3/utils/smbpasswd.c | 70 +++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 32 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index e9360651da..d9a5dc4bbd 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -64,6 +64,7 @@ static void usage(void) if (getuid() == 0) { printf(" -R ORDER name resolve order\n"); printf(" -j DOMAIN join domain name\n"); + printf(" -S synchronise with PDC (if we are BDC)\n"); printf(" -a add user\n"); printf(" -d disable user\n"); printf(" -e enable user\n"); @@ -89,13 +90,6 @@ static int join_domain(char *domain, char *remote) BOOL ret; uint16 sec_chan; - DEBUG(5,("join_domain: domain %s remote %s\n", domain, remote)); - - pstrcpy(remote_machine, remote ? remote : ""); - fstrcpy(trust_passwd, global_myname); - strlower(trust_passwd); - E_md4hash( (uchar *)trust_passwd, orig_trust_passwd_hash); - switch (lp_server_role()) { case ROLE_DOMAIN_PDC: @@ -116,6 +110,18 @@ static int join_domain(char *domain, char *remote) } } + pstrcpy(remote_machine, remote ? remote : lp_passwordserver()); + + if (!remote_machine[0]) + { + fprintf(stderr, "You must specify the PDC via 'password server' or -r."); + return 1; + } + + fstrcpy(trust_passwd, global_myname); + strlower(trust_passwd); + E_md4hash( (uchar *)trust_passwd, orig_trust_passwd_hash); + /* * Create the machine account password file. */ @@ -138,36 +144,16 @@ machine %s in domain %s.\n", global_myname, domain); return 1; } - /* - * If we are given a remote machine assume this is the PDC. - */ - - if(remote == NULL) - { - pstrcpy(remote_machine, lp_passwordserver()); - } - - if(!*remote_machine) { - fprintf(stderr, "No password server list given in smb.conf - \ -unable to join domain.\n"); - trust_password_unlock(); - return 1; - } - ret = change_trust_account_password(domain, remote_machine, sec_chan); trust_password_unlock(); if(!ret) { fprintf(stderr,"Unable to join domain %s.\n",domain); - } else { - printf("Joined domain %s.\n",domain); + return 1; } - -#if 0 - trust_password_delete( domain, global_myname); -#endif - return (int)ret; + printf("Joined domain %s.\n",domain); + return 0; } @@ -303,6 +289,7 @@ static int process_root(int argc, char *argv[]) uint16 acb_info = 0; uint16 acb_mask = 0; BOOL joining_domain = False; + BOOL sam_sync = False; BOOL wks_trust_account = False; BOOL srv_trust_account = False; BOOL dom_trust_account = False; @@ -318,8 +305,9 @@ static int process_root(int argc, char *argv[]) char *new_passwd = NULL; char *old_passwd = NULL; char *remote_machine = NULL; + int ret; - while ((ch = getopt(argc, argv, "abdehimnpxj:r:sR:D:U:")) != EOF) + while ((ch = getopt(argc, argv, "abdehimnpxj:Sr:sR:D:U:")) != EOF) { switch(ch) { @@ -389,6 +377,11 @@ static int process_root(int argc, char *argv[]) joining_domain = True; break; } + case 'S': + { + sam_sync = True; + break; + } case 'U': { user_name = optarg; @@ -422,11 +415,24 @@ static int process_root(int argc, char *argv[]) { usage(); } + + if (sam_sync && lp_server_role() != ROLE_DOMAIN_BDC) { + fprintf(stderr, "The -S option can only be used on a Backup Domain Controller.\n"); + return 1; + } if (joining_domain) { if (argc != 0) usage(); - return join_domain(new_domain, remote_machine); + ret = join_domain(new_domain, remote_machine); + + if ((ret != 0) || (!sam_sync)) + return ret; + } + + if (sam_sync) + { + return synchronise_passdb(); } /* -- cgit From 06b4627df0b75d91f3f7198f1cad1098e3431820 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 18 Aug 1999 00:12:19 +0000 Subject: patch from Michael Glauche to call get_status_connections() instead of reading STATUS..LCK direct. (This used to be commit d794e2eb51b94a334ddb1d1b0775ebf4cef048db) --- source3/utils/status.c | 104 ++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index e20af8444c..320a54cc7d 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -36,8 +36,6 @@ #include "includes.h" -struct connect_record crec; - struct session_record{ int pid; int uid; @@ -172,6 +170,9 @@ static int profile_dump(void) int last_pid=0; struct session_record *ptr; int profile_only = 0; + struct connect_record *crec = NULL; + uint32 connection_count; + uint32 conn; TimeInit(); setup_logging(argv[0],True); @@ -266,60 +267,59 @@ static int profile_dump(void) printf("----------------------------------------------\n"); } } - - while (!feof(f)) - { - if (fread(&crec,sizeof(crec),1,f) != 1) - break; - if (crec.cnum == -1) continue; - if ( crec.magic == 0x280267 && process_exists(crec.pid) - && Ucrit_checkUsername(uidtoname(crec.uid)) /* added by OH */ - ) + + if (get_connection_status(&crec, &connection_count)) + { + for (conn=0;connpid==crec.pid)&&(strncmp(ptr->machine,crec.machine,30)==0)) + if (Ucrit_checkUsername(uidtoname(crec[conn].uid))) + { + if (brief) { - if (ptr->start > crec.start) - ptr->start=crec.start; - break; + ptr=srecs; + while (ptr!=NULL) + { + if ((ptr->pid==crec[conn].pid)&&(strncmp(ptr->machine,crec[conn].machine,30)==0)) + { + if (ptr->start > crec[conn].start) + ptr->start=crec[conn].start; + break; + } + ptr=ptr->next; + } + if (ptr==NULL) + { + ptr=(struct session_record *) malloc(sizeof(struct session_record)); + ptr->uid=crec[conn].uid; + ptr->pid=crec[conn].pid; + ptr->start=crec[conn].start; + strncpy(ptr->machine,crec[conn].machine,30); + ptr->machine[30]='\0'; + ptr->next=srecs; + srecs=ptr; + } } - ptr=ptr->next; - } - if (ptr==NULL) - { - ptr=(struct session_record *) malloc(sizeof(struct session_record)); - ptr->uid=crec.uid; - ptr->pid=crec.pid; - ptr->start=crec.start; - strncpy(ptr->machine,crec.machine,30); - ptr->machine[30]='\0'; - ptr->next=srecs; - srecs=ptr; - } - } - else - { - Ucrit_addPid(crec.pid); /* added by OH */ - if (processes_only) { - if (last_pid != crec.pid) - printf("%d\n",crec.pid); - last_pid = crec.pid; /* XXXX we can still get repeats, have to - add a sort at some time */ - } - else - printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", - crec.name,uidtoname(crec.uid),gidtoname(crec.gid),crec.pid, - crec.machine,crec.addr, - asctime(LocalTime(&crec.start))); - } - } - } - fclose(f); + else + { + Ucrit_addPid(crec[conn].pid); /* added by OH */ + if (processes_only) { + if (last_pid != crec[conn].pid) + printf("%d\n",crec[conn].pid); + last_pid = crec[conn].pid; /* XXXX we can still get repeats, have to + add a sort at some time */ + } + else + printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", + crec[conn].name,uidtoname(crec[conn].uid),gidtoname(crec[conn].gid),crec[conn].pid, + crec[conn].machine,crec[conn].addr, + asctime(LocalTime(&crec[conn].start))); + } + } + } + free(crec); + } } + if (processes_only) exit(0); if (brief) -- cgit From d2d6144253da533fb2f47cae9e0ed008a167585b Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 18 Aug 1999 20:33:49 +0000 Subject: event log update, netsessenum, netconnenum update. (This used to be commit 819af560745b0bec7bfb9067dd9d9d6cfabb1555) --- source3/utils/torture.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 3c872ea672..6dea2f2d22 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -1221,9 +1221,9 @@ static void create_procs(int nprocs, int numops, void (*fn)(int )) printf("host=%s share=%s user=%s myname=%s procs=%d ops=%d\n", host, share, username, myname, nprocs, numops); - create_procs(nprocs, numops, run_randomipc_nowait); -/* create_procs(nprocs, numops, run_randomipc); +/* + create_procs(nprocs, numops, run_randomipc_nowait); create_procs(nprocs, numops, run_connection); -- cgit From 27b8df4d9bc31fc73f7db6ceed24a6fca1271d3f Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sat, 20 Nov 1999 21:59:16 +0000 Subject: attempting to establish inter-domain trust relationships. modified smbpasswd so it can be used to set up inter-domain trust account. (This used to be commit 99ec0620c3bf4af96440c684f880d414659de2e9) --- source3/utils/smbpasswd.c | 143 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 115 insertions(+), 28 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index d9a5dc4bbd..7411d07a9b 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -22,6 +22,7 @@ extern pstring myhostname; extern pstring global_myname; +extern pstring global_myworkgroup; extern int DEBUGLEVEL; /* @@ -79,6 +80,98 @@ static void usage(void) exit(1); } +/********************************************************* +record Trust Account password. +**********************************************************/ +static BOOL create_trust_account_file(char *domain, char *name, uchar pass[16]) +{ + /* + * Create the machine account password file. + */ + + if(!trust_password_lock( domain, name, True)) + { + fprintf(stderr, "unable to open the trust account password file for \ +machine %s in domain %s.\n", global_myname, domain); + return False; + } + + /* + * Write the old machine account password. + */ + + if(!set_trust_account_password( pass)) + { + fprintf(stderr, "unable to write the trust account password for \ +%s in domain %s.\n", name, domain); + trust_password_unlock(); + return False; + } + + trust_password_unlock(); + + return True; +} + +/********************************************************* +Join a domain. +**********************************************************/ +static int create_interdomain_trust_acct(char *domain, char *name) +{ + fstring trust_passwd; + unsigned char hash[16]; + uint16 sec_chan; + + switch (lp_server_role()) + { + case ROLE_DOMAIN_PDC: + { + DEBUG(0, ("Joining domain - we are PDC\n")); + sec_chan = SEC_CHAN_DOMAIN; + break; + } + case ROLE_DOMAIN_BDC: + { + DEBUG(0, ("Cannot set up inter-domain trust as BDC!\n")); + return 1; + } + default: + { + DEBUG(0, ("Cannot set up inter-domain trust as workstation!\n")); + return 1; + } + } + +#if 0 + pstrcpy(remote_machine, remote ? remote : lp_passwordserver()); + + if (!remote_machine[0]) + { + fprintf(stderr, "You must specify the PDC via 'password server' or -r."); + return 1; + } +#endif + + fstrcpy(trust_passwd, name); + strlower(trust_passwd); + E_md4hash( (uchar *)trust_passwd, hash); + + if (!create_trust_account_file(domain, name, hash)) + { + return 1; + } + +#if 0 + if(!change_trust_account_password(domain, remote_machine, sec_chan)) + { + fprintf(stderr,"Unable to join domain %s.\n",domain); + return 1; + } +#endif + printf("Created Inter-Domain Trust Account for %s.\n",domain); + return 0; +} + /********************************************************* Join a domain. **********************************************************/ @@ -87,7 +180,6 @@ static int join_domain(char *domain, char *remote) pstring remote_machine; fstring trust_passwd; unsigned char orig_trust_passwd_hash[16]; - BOOL ret; uint16 sec_chan; switch (lp_server_role()) @@ -122,32 +214,13 @@ static int join_domain(char *domain, char *remote) strlower(trust_passwd); E_md4hash( (uchar *)trust_passwd, orig_trust_passwd_hash); - /* - * Create the machine account password file. - */ - if(!trust_password_lock( domain, global_myname, True)) + if (!create_trust_account_file(domain, global_myname, trust_passwd)) { - fprintf(stderr, "unable to open the machine account password file for \ -machine %s in domain %s.\n", global_myname, domain); - return 1; - } - - /* - * Write the old machine account password. - */ - - if(!set_trust_account_password( orig_trust_passwd_hash)) - { - fprintf(stderr, "unable to write the machine account password for \ -machine %s in domain %s.\n", global_myname, domain); - trust_password_unlock(); return 1; } - ret = change_trust_account_password(domain, remote_machine, sec_chan); - trust_password_unlock(); - - if(!ret) { + if(!change_trust_account_password(domain, remote_machine, sec_chan)) + { fprintf(stderr,"Unable to join domain %s.\n",domain); return 1; } @@ -423,11 +496,14 @@ static int process_root(int argc, char *argv[]) if (joining_domain) { - if (argc != 0) usage(); - ret = join_domain(new_domain, remote_machine); + if (!dom_trust_account) + { + if (argc != 0) usage(); + ret = join_domain(new_domain, remote_machine); - if ((ret != 0) || (!sam_sync)) - return ret; + if ((ret != 0) || (!sam_sync)) + return ret; + } } if (sam_sync) @@ -496,13 +572,24 @@ static int process_root(int argc, char *argv[]) exit(1); } + if (joining_domain) + { + if (dom_trust_account) + { + ret = create_interdomain_trust_acct(new_domain, + global_myworkgroup); + + if ((ret != 0) || (!sam_sync)) + return ret; + } + } + if (remote_machine != NULL) { old_passwd = get_pass("Old SMB password:",stdin_passwd_get); } if (!new_passwd) { - /* * If we are trying to enable a user, first we need to find out * if they are using a modern version of the smbpasswd file that -- cgit From f8b82a7b9507e11595bc924def179dc1d7d79a54 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 24 Nov 1999 20:24:33 +0000 Subject: first stages of removing struct cli_state* and uint16 fnum from all msrpc client code. the intent is to hide / abstract / associate connection info behind policy handles. this makes the msrpc functions look more and more like their nt equivalents. who-hou! (This used to be commit c01b18e632aede6fce7264ef6971d7ddba945cfb) --- source3/utils/rpctorture.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/rpctorture.c b/source3/utils/rpctorture.c index ff98c0a837..0933cf38c1 100644 --- a/source3/utils/rpctorture.c +++ b/source3/utils/rpctorture.c @@ -478,17 +478,12 @@ static void run_lsahandles(int numops, struct client_info *cli_info) DEBUG(0,("lsahandle test: connection failed\n")); return; } - /* open session. */ - if (!cli_nt_session_open(smb_cli, PIPE_LSARPC, &nt_pipe_fnum)) - { - DEBUG(0,("lsahandle test: session open failed\n")); - return; - } - for (i = 1; i <= numops * 100; i++) { + extern struct cli_state *rpc_smb_cli; + rpc_smb_cli = smb_cli; POLICY_HND pol; - if (!lsa_open_policy(smb_cli, nt_pipe_fnum, srv_name, &pol, False)) + if (!lsa_open_policy(srv_name, &pol, False)) { failed++; } @@ -499,9 +494,6 @@ static void run_lsahandles(int numops, struct client_info *cli_info) count++; } - /* close the session */ - cli_nt_session_close(smb_cli, nt_pipe_fnum); - /* close the rpc pipe */ rpcclient_stop(); -- cgit From 6ddfc68e0496dc41f8c9a022a0b04a2066b43c9d Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 1 Dec 1999 02:15:14 +0000 Subject: sys_select added one more argument (read, write selectors). (This used to be commit e4d92ff9dfc51735e6932748f66a7c20b2c1cb6a) --- source3/utils/smbfilter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c index 4f6420c767..643a3ed2ce 100644 --- a/source3/utils/smbfilter.c +++ b/source3/utils/smbfilter.c @@ -120,7 +120,7 @@ static void filter_child(int c, struct in_addr dest_ip) if (s != -1) FD_SET(s, &fds); if (c != -1) FD_SET(c, &fds); - num = sys_select(MAX(s+1, c+1),&fds,NULL); + num = sys_select(MAX(s+1, c+1),&fds,NULL, NULL); if (num <= 0) continue; if (c != -1 && FD_ISSET(c, &fds)) { @@ -184,7 +184,7 @@ static void start_filter(char *desthost) FD_ZERO(&fds); FD_SET(s, &fds); - num = sys_select(s+1,&fds,NULL); + num = sys_select(s+1,&fds,NULL, NULL); if (num > 0) { c = accept(s, &addr, &in_addrlen); if (c != -1) { -- cgit From 86ac6fa9389532bc0e39b4da2fb73766cf29aeb9 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 1 Dec 1999 19:25:51 +0000 Subject: fixing joining to domain plus something weird going down with nt logins... (This used to be commit cef258f1c931ecb7c2dda9d5c9977153e4c1dc73) --- source3/utils/smbpasswd.c | 33 --------------------------------- 1 file changed, 33 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 7411d07a9b..3b87687c26 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -80,39 +80,6 @@ static void usage(void) exit(1); } -/********************************************************* -record Trust Account password. -**********************************************************/ -static BOOL create_trust_account_file(char *domain, char *name, uchar pass[16]) -{ - /* - * Create the machine account password file. - */ - - if(!trust_password_lock( domain, name, True)) - { - fprintf(stderr, "unable to open the trust account password file for \ -machine %s in domain %s.\n", global_myname, domain); - return False; - } - - /* - * Write the old machine account password. - */ - - if(!set_trust_account_password( pass)) - { - fprintf(stderr, "unable to write the trust account password for \ -%s in domain %s.\n", name, domain); - trust_password_unlock(); - return False; - } - - trust_password_unlock(); - - return True; -} - /********************************************************* Join a domain. **********************************************************/ -- cgit From 7d01f964ff3c1a11bd72d987312f9826fee1c124 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 3 Dec 1999 18:16:08 +0000 Subject: cool! a unix socket smb redirector. code based on smbfilter and ideas from ssh-agent. the intent is to be able to share smb sessions using cli_net_use_add() across multiple processes, where one process knows the target server name, user name and domain, but not the smb password. (This used to be commit 294b653f2e9cdc1864ec638ae8b4300df25723cf) --- source3/utils/smb-agent.c | 347 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 347 insertions(+) create mode 100644 source3/utils/smb-agent.c (limited to 'source3/utils') diff --git a/source3/utils/smb-agent.c b/source3/utils/smb-agent.c new file mode 100644 index 0000000000..52feda2bea --- /dev/null +++ b/source3/utils/smb-agent.c @@ -0,0 +1,347 @@ +/* + Unix SMB/Netbios implementation. + Version 2 + SMB agent/socket plugin + 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. +*/ + +#include "includes.h" +#include "smb.h" + +#define SECURITY_MASK 0 +#define SECURITY_SET 0 + +/* this forces non-unicode */ +#define CAPABILITY_MASK CAP_UNICODE +#define CAPABILITY_SET 0 + +/* and non-unicode for the client too */ +#define CLI_CAPABILITY_MASK CAP_UNICODE +#define CLI_CAPABILITY_SET 0 + +static char *netbiosname; +static char packet[BUFFER_SIZE]; + +extern int DEBUGLEVEL; + +static void agent_reply(char *buf) +{ + int msg_type = CVAL(buf,0); + int type = CVAL(buf,smb_com); + unsigned x; + + if (msg_type) return; + + switch (type) { + + case SMBnegprot: + /* force the security bits */ + x = CVAL(buf, smb_vwv1); + x = (x | SECURITY_SET) & ~SECURITY_MASK; + SCVAL(buf, smb_vwv1, x); + + /* force the capabilities */ + x = IVAL(buf,smb_vwv9+1); + x = (x | CAPABILITY_SET) & ~CAPABILITY_MASK; + SIVAL(buf, smb_vwv9+1, x); + break; + + } +} + +static void agent_request(char *buf) +{ + int msg_type = CVAL(buf,0); + int type = CVAL(buf,smb_com); + pstring name1,name2; + unsigned x; + + if (msg_type) { + /* it's a netbios special */ + switch (msg_type) { + case 0x81: + /* session request */ + name_extract(buf,4,name1); + name_extract(buf,4 + name_len(buf + 4),name2); + DEBUG(0,("sesion_request: %s -> %s\n", + name1, name2)); + if (netbiosname) { + /* replace the destination netbios name */ + name_mangle(netbiosname, buf+4, 0x20); + } + } + return; + } + + /* it's an ordinary SMB request */ + switch (type) { + case SMBsesssetupX: + /* force the client capabilities */ + x = IVAL(buf,smb_vwv11); + x = (x | CLI_CAPABILITY_SET) & ~CLI_CAPABILITY_MASK; + SIVAL(buf, smb_vwv11, x); + break; + } + +} + + +static void agent_child(int c) +{ + struct cli_state *s = NULL; + + DEBUG(10,("agent_child: %d\n", c)); + + while (c != -1) + { + fd_set fds; + int num; + int maxfd = 0; + + FD_ZERO(&fds); + if (s != NULL) + { + FD_SET(s->fd, &fds); + maxfd = MAX(s->fd, maxfd); + } + + if (c != -1) + { + FD_SET(c, &fds); + maxfd = MAX(c, maxfd); + } + + num = sys_select(maxfd+1,&fds,NULL, NULL); + if (num <= 0) continue; + + if (c != -1 && FD_ISSET(c, &fds)) + { + if (s == NULL) + { + pstring buf; + uchar ntpw[16]; + uchar lmpw[16]; + fstring srv_name; + struct user_credentials usr; + char *p = buf; + int rl; + uint32 len; + + DEBUG(10,("first request\n")); + + rl = read(c, &buf, sizeof(len)); + + if (rl != sizeof(len)) + { + DEBUG(0,("Unable to read length\n")); + dump_data(0, buf, sizeof(len)); + exit(1); + } + + len = IVAL(buf, 0); + + if (len > sizeof(buf)) + { + DEBUG(0,("length %d too long\n", len)); + exit(1); + } + + rl = read(c, buf, len); + + if (rl < 0) + { + DEBUG(0,("Unable to read from connection\n")); + exit(1); + } + +#ifdef DEBUG_PASSWORD + dump_data(100, buf, rl); +#endif + fstrcpy(srv_name, p); + p = skip_string(p, 1); + fstrcpy(usr.user_name, p); + p = skip_string(p, 1); + fstrcpy(usr.domain, p); + p = skip_string(p, 1); + + if (PTR_DIFF(p, buf) < rl) + { + memcpy(ntpw, p, 16); + p += 16; + memcpy(lmpw, p, 16); + p += 16; + pwd_set_lm_nt_16(&usr.pwd, lmpw, ntpw); + } + else + { + pwd_set_nullpwd(&usr.pwd); + } + + if (PTR_DIFF(p, buf) != rl) + { + DEBUG(0,("Buffer size %d %d!\n", + PTR_DIFF(p, buf), rl)); + exit(1); + } + + s = cli_net_use_add(srv_name, &usr, False); + + if (s == NULL) + { + DEBUG(0,("Unable to connect to %s\n", srv_name)); + exit(1); + } + if (write(c, s, sizeof(*s)) < 0) + { + DEBUG(0,("Could not write ack\n")); + exit(1); + } + } + else + { + if (!receive_smb(c, packet, 0)) + { + DEBUG(0,("client closed connection\n")); + exit(0); + } + if (!send_smb(s->fd, packet)) + { + DEBUG(0,("server is dead\n")); + exit(1); + } + } + } + if (s != NULL && FD_ISSET(s->fd, &fds)) + { + if (!receive_smb(s->fd, packet, 0)) + { + DEBUG(0,("server closed connection\n")); + exit(0); + } +#if 0 + agent_reply(packet); +#endif + if (!send_smb(c, packet)) + { + DEBUG(0,("client is dead\n")); + cli_shutdown(s); + free(s); + exit(1); + } + } + } + DEBUG(0,("Connection closed\n")); + if (s != NULL) + { + cli_shutdown(s); + free(s); + } + exit(0); +} + + +static void start_agent(void) +{ + int s, c; + struct sockaddr_un sa; + + CatchChild(); + + /* start listening on unix socket */ + + mkdir("/tmp/smb-agent", 700); + s = socket(AF_UNIX, SOCK_STREAM, 0); + + if (s < 0) + { + fprintf(stderr, "socket open failed\n"); + exit(1); + } + + ZERO_STRUCT(sa); + sa.sun_family = AF_UNIX; + safe_strcpy(sa.sun_path, "/tmp/smb-agent/smb.sock", + sizeof(sa.sun_path)-1); + + if (bind(s, (struct sockaddr*) &sa, sizeof(sa)) < 0) + { + fprintf(stderr, "socket bind to %s failed\n", sa.sun_path); + close(s); + remove("/tmp/smb-agent/smb.sock"); + exit(1); + } + + if (s == -1) { + DEBUG(0,("bind failed\n")); + remove("/tmp/smb-agent/smb.sock"); + exit(1); + } + + if (listen(s, 5) == -1) + { + DEBUG(0,("listen failed\n")); + remove("/tmp/smb-agent/smb.sock"); + } + + while (1) + { + fd_set fds; + int num; + struct sockaddr_un addr; + int in_addrlen = sizeof(addr); + + FD_ZERO(&fds); + FD_SET(s, &fds); + + num = sys_select(s+1,&fds,NULL, NULL); + if (num > 0) + { + c = accept(s, (struct sockaddr*)&addr, &in_addrlen); + if (c != -1) { + if (fork() == 0) + { + close(s); + agent_child(c); + exit(0); + } else { + close(c); + } + } + } + } +} + + +int main(int argc, char *argv[]) +{ + pstring configfile; + + TimeInit(); + + setup_logging(argv[0],True); + + charset_initialise(); + + pstrcpy(configfile,CONFIGFILE); + + if (!lp_load(configfile,True,False,False)) { + DEBUG(0,("Unable to load config file\n")); + } + + start_agent(); + return 0; +} -- cgit From 6eebe18fa9682f570127b08fb116ab561223de22 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 3 Dec 1999 19:55:34 +0000 Subject: smb-agent improvements. added -D (daemon) option. smb agent is restricted to connections from the current user (socket is created with current user uid). (This used to be commit 5af076e4b7ee13eebe0b89748e3f5a1ef21f8c73) --- source3/utils/smb-agent.c | 88 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 16 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smb-agent.c b/source3/utils/smb-agent.c index 52feda2bea..8c039dfc86 100644 --- a/source3/utils/smb-agent.c +++ b/source3/utils/smb-agent.c @@ -218,11 +218,15 @@ static void agent_child(int c) DEBUG(0,("client closed connection\n")); exit(0); } - if (!send_smb(s->fd, packet)) + /* ignore keep-alives */ + if (CVAL(packet, 0) != 0x85) { - DEBUG(0,("server is dead\n")); - exit(1); - } + if (!send_smb(s->fd, packet)) + { + DEBUG(0,("server is dead\n")); + exit(1); + } + } } } if (s != NULL && FD_ISSET(s->fd, &fds)) @@ -258,12 +262,14 @@ static void start_agent(void) { int s, c; struct sockaddr_un sa; + fstring path; + slprintf(path, sizeof(path)-1, "/tmp/smb-agent/smb.%d", getuid()); CatchChild(); /* start listening on unix socket */ - - mkdir("/tmp/smb-agent", 700); + mkdir("/tmp/smb-agent", 777); + s = socket(AF_UNIX, SOCK_STREAM, 0); if (s < 0) @@ -274,27 +280,35 @@ static void start_agent(void) ZERO_STRUCT(sa); sa.sun_family = AF_UNIX; - safe_strcpy(sa.sun_path, "/tmp/smb-agent/smb.sock", - sizeof(sa.sun_path)-1); + safe_strcpy(sa.sun_path, path, sizeof(sa.sun_path)-1); if (bind(s, (struct sockaddr*) &sa, sizeof(sa)) < 0) { fprintf(stderr, "socket bind to %s failed\n", sa.sun_path); close(s); - remove("/tmp/smb-agent/smb.sock"); + remove(path); + exit(1); + } + + if (chmod(path, S_IRUSR|S_IWUSR|S_ISVTX) < 0) + { + fprintf(stderr, "chmod on %s failed\n", sa.sun_path); + close(s); + remove(path); exit(1); } - if (s == -1) { + if (s == -1) + { DEBUG(0,("bind failed\n")); - remove("/tmp/smb-agent/smb.sock"); + remove(path); exit(1); } if (listen(s, 5) == -1) { DEBUG(0,("listen failed\n")); - remove("/tmp/smb-agent/smb.sock"); + remove(path); } while (1) @@ -325,23 +339,65 @@ static void start_agent(void) } } +/**************************************************************************** +usage on the program +****************************************************************************/ +static void usage(char *pname) +{ + printf("Usage: %s [-D]", pname); + + printf("\nVersion %s\n",VERSION); + printf("\t-D run as a daemon\n"); + printf("\t-h usage\n"); + printf("\n"); +} int main(int argc, char *argv[]) { pstring configfile; + BOOL is_daemon = False; + int opt; + extern pstring debugf; TimeInit(); - setup_logging(argv[0],True); + pstrcpy(configfile,CONFIGFILE); + + while ((opt = getopt(argc, argv, "Dh")) != EOF) + { + switch (opt) + { + case 'D': + { + is_daemon = True; + break; + } + case 'h': + default: + { + usage(argv[0]); + break; + } + } + } + + slprintf(debugf, sizeof(debugf)-1, "log.%s", argv[0]); + setup_logging(argv[0], !is_daemon); charset_initialise(); - pstrcpy(configfile,CONFIGFILE); - - if (!lp_load(configfile,True,False,False)) { + if (!lp_load(configfile,True,False,False)) + { DEBUG(0,("Unable to load config file\n")); } + if (is_daemon) + { + DEBUG(0,("%s: becoming daemon\n", argv[0])); + become_daemon(); + } + start_agent(); + return 0; } -- cgit From c2a3b11b0738f57accafe19c84b682f761fa9631 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 3 Dec 1999 22:02:03 +0000 Subject: starting "connection reuse" system in smb-agent. added version number which isn't actually used right now :-) (This used to be commit d54a64ae3ab7cdc1ac67fb49f7255e6a106d624e) --- source3/utils/smb-agent.c | 196 +++++++++++++++++++++++++++++----------------- 1 file changed, 122 insertions(+), 74 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smb-agent.c b/source3/utils/smb-agent.c index 8c039dfc86..bcc5eebd75 100644 --- a/source3/utils/smb-agent.c +++ b/source3/utils/smb-agent.c @@ -99,6 +99,127 @@ static void agent_request(char *buf) } +#define AGENT_CMD_CON 0 +#define AGENT_CMD_CON_REUSE 1 + +static struct cli_state *init_client_connection(int c) +{ + pstring buf; + uchar ntpw[16]; + uchar lmpw[16]; + fstring srv_name; + struct user_credentials usr; + char *p = buf; + int rl; + uint32 len; + uint16 version; + uint16 command; + BOOL new_con = False; + + ZERO_STRUCT(usr); + + DEBUG(10,("first request\n")); + + rl = read(c, &buf, sizeof(len)); + + if (rl != sizeof(len)) + { + DEBUG(0,("Unable to read length\n")); + dump_data(0, buf, sizeof(len)); + return NULL; + } + + len = IVAL(buf, 0); + + if (len > sizeof(buf)) + { + DEBUG(0,("length %d too long\n", len)); + return NULL; + } + + rl = read(c, buf, len); + + if (rl < 0) + { + DEBUG(0,("Unable to read from connection\n")); + exit(1); + } + +#ifdef DEBUG_PASSWORD + dump_data(100, buf, rl); +#endif + version = SVAL(p, 0); + p += 2; + command = SVAL(p, 0); + p += 2; + + fstrcpy(srv_name, p); + p = skip_string(p, 1); + fstrcpy(usr.user_name, p); + p = skip_string(p, 1); + fstrcpy(usr.domain, p); + p = skip_string(p, 1); + + if (PTR_DIFF(p, buf) < rl) + { + memcpy(ntpw, p, 16); + p += 16; + memcpy(lmpw, p, 16); + p += 16; + pwd_set_lm_nt_16(&usr.pwd, lmpw, ntpw); + } + else + { + pwd_set_nullpwd(&usr.pwd); + } + + if (PTR_DIFF(p, buf) != rl) + { + DEBUG(0,("Buffer size %d %d!\n", + PTR_DIFF(p, buf), rl)); + exit(1); + } + + switch (command) + { + case AGENT_CMD_CON: + { + new_con = True; + break; + } + case AGENT_CMD_CON_REUSE: + { + new_con = True; + usr.reuse = True; + break; + } + default: + { + DEBUG(0,("unknown command %d\n", command)); + return NULL; + } + } + + if (new_con) + { + struct cli_state *s; + s = cli_net_use_add(srv_name, &usr, False); + + if (s == NULL) + { + DEBUG(0,("Unable to connect to %s\n", srv_name)); + return NULL; + } + if (write(c, s, sizeof(*s)) < 0) + { + DEBUG(0,("Could not write connection down pipe.\n")); + cli_net_use_del(srv_name, &usr, False, NULL); + return NULL; + } + return s; + } + return NULL; +} static void agent_child(int c) { @@ -132,82 +253,9 @@ static void agent_child(int c) { if (s == NULL) { - pstring buf; - uchar ntpw[16]; - uchar lmpw[16]; - fstring srv_name; - struct user_credentials usr; - char *p = buf; - int rl; - uint32 len; - - DEBUG(10,("first request\n")); - - rl = read(c, &buf, sizeof(len)); - - if (rl != sizeof(len)) - { - DEBUG(0,("Unable to read length\n")); - dump_data(0, buf, sizeof(len)); - exit(1); - } - - len = IVAL(buf, 0); - - if (len > sizeof(buf)) - { - DEBUG(0,("length %d too long\n", len)); - exit(1); - } - - rl = read(c, buf, len); - - if (rl < 0) - { - DEBUG(0,("Unable to read from connection\n")); - exit(1); - } - -#ifdef DEBUG_PASSWORD - dump_data(100, buf, rl); -#endif - fstrcpy(srv_name, p); - p = skip_string(p, 1); - fstrcpy(usr.user_name, p); - p = skip_string(p, 1); - fstrcpy(usr.domain, p); - p = skip_string(p, 1); - - if (PTR_DIFF(p, buf) < rl) - { - memcpy(ntpw, p, 16); - p += 16; - memcpy(lmpw, p, 16); - p += 16; - pwd_set_lm_nt_16(&usr.pwd, lmpw, ntpw); - } - else - { - pwd_set_nullpwd(&usr.pwd); - } - - if (PTR_DIFF(p, buf) != rl) - { - DEBUG(0,("Buffer size %d %d!\n", - PTR_DIFF(p, buf), rl)); - exit(1); - } - - s = cli_net_use_add(srv_name, &usr, False); - + s = init_client_connection(c); if (s == NULL) { - DEBUG(0,("Unable to connect to %s\n", srv_name)); - exit(1); - } - if (write(c, s, sizeof(*s)) < 0) - { - DEBUG(0,("Could not write ack\n")); exit(1); } } -- cgit From 0ca1f87930a57dfd2510b98443423d8a67cfa70b Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 3 Dec 1999 23:36:53 +0000 Subject: argh! smb-agent redirection client reusage is a nightmare! moved smb-agent over to a single-process model instead of fork() in order to reuse client connections. except, of course, you can't do a select() on the same socket connections! argh! (This used to be commit e9e5a34de8e8f9a69e817aceb8c16284334d4642) --- source3/utils/smb-agent.c | 368 ++++++++++++++++++++++++++++------------------ 1 file changed, 225 insertions(+), 143 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smb-agent.c b/source3/utils/smb-agent.c index bcc5eebd75..a52d696615 100644 --- a/source3/utils/smb-agent.c +++ b/source3/utils/smb-agent.c @@ -33,74 +33,139 @@ #define CLI_CAPABILITY_MASK CAP_UNICODE #define CLI_CAPABILITY_SET 0 -static char *netbiosname; static char packet[BUFFER_SIZE]; extern int DEBUGLEVEL; -static void agent_reply(char *buf) -{ - int msg_type = CVAL(buf,0); - int type = CVAL(buf,smb_com); - unsigned x; - - if (msg_type) return; - switch (type) { +struct sock_redir +{ + int c; + struct cli_state *s; - case SMBnegprot: - /* force the security bits */ - x = CVAL(buf, smb_vwv1); - x = (x | SECURITY_SET) & ~SECURITY_MASK; - SCVAL(buf, smb_vwv1, x); +}; - /* force the capabilities */ - x = IVAL(buf,smb_vwv9+1); - x = (x | CAPABILITY_SET) & ~CAPABILITY_MASK; - SIVAL(buf, smb_vwv9+1, x); - break; +static uint32 num_socks = 0; +static struct sock_redir **socks = NULL; +/**************************************************************************** +terminate sockent connection +****************************************************************************/ +static void sock_redir_free(struct sock_redir *sock) +{ + close(sock->c); + sock->c = -1; + if (sock->s != NULL) + { + cli_net_use_del(sock->s->desthost, &sock->s->usr, + False, NULL); + sock->s = NULL; } + free(sock); +} + +/**************************************************************************** +free a sockent array +****************************************************************************/ +static void free_sock_array(uint32 num_entries, struct sock_redir **entries) +{ + void(*fn)(void*) = (void(*)(void*))&sock_redir_free; + free_void_array(num_entries, (void**)entries, *fn); } -static void agent_request(char *buf) +/**************************************************************************** +add a sockent state to the array +****************************************************************************/ +static struct sock_redir* add_sock_to_array(uint32 *len, + struct sock_redir ***array, + struct sock_redir *sock) { - int msg_type = CVAL(buf,0); - int type = CVAL(buf,smb_com); - pstring name1,name2; - unsigned x; - - if (msg_type) { - /* it's a netbios special */ - switch (msg_type) { - case 0x81: - /* session request */ - name_extract(buf,4,name1); - name_extract(buf,4 + name_len(buf + 4),name2); - DEBUG(0,("sesion_request: %s -> %s\n", - name1, name2)); - if (netbiosname) { - /* replace the destination netbios name */ - name_mangle(netbiosname, buf+4, 0x20); - } + int i; + for (i = 0; i < num_socks; i++) + { + if (socks[i] == NULL) + { + socks[i] = sock; + return sock; } - return; } - /* it's an ordinary SMB request */ - switch (type) { - case SMBsesssetupX: - /* force the client capabilities */ - x = IVAL(buf,smb_vwv11); - x = (x | CLI_CAPABILITY_SET) & ~CLI_CAPABILITY_MASK; - SIVAL(buf, smb_vwv11, x); - break; + return (struct sock_redir*)add_item_to_array(len, + (void***)array, (void*)sock); + +} + +/**************************************************************************** +initiate sockent array +****************************************************************************/ +void init_sock_redir(void) +{ + socks = NULL; + num_socks = 0; +} + +/**************************************************************************** +terminate sockent array +****************************************************************************/ +void free_sock_redir(void) +{ + free_sock_array(num_socks, socks); + init_sock_redir(); +} + +/**************************************************************************** +create a new sockent state from user credentials +****************************************************************************/ +static struct sock_redir *sock_redir_get(int fd, struct cli_state *cli) +{ + struct sock_redir *sock = (struct sock_redir*)malloc(sizeof(*sock)); + + if (sock == NULL) + { + return NULL; } + ZERO_STRUCTP(sock); + + sock->c = fd; + sock->s = cli; + + return sock; +} + +/**************************************************************************** +init sock state +****************************************************************************/ +static void sock_add(int fd, struct cli_state *cli) +{ + struct sock_redir *sock; + sock = sock_redir_get(fd, cli); + if (sock != NULL) + { + add_sock_to_array(&num_socks, &socks, sock); + } } -#define AGENT_CMD_CON 0 -#define AGENT_CMD_CON_REUSE 1 +/**************************************************************************** +delete a sockent state +****************************************************************************/ +static BOOL sock_del(int fd) +{ + int i; + + for (i = 0; i < num_socks; i++) + { + if (socks[i] == NULL) continue; + if (socks[i]->c == fd) + { + sock_redir_free(socks[i]); + socks[i] = NULL; + return True; + } + } + + return False; +} static struct cli_state *init_client_connection(int c) { @@ -142,7 +207,7 @@ static struct cli_state *init_client_connection(int c) if (rl < 0) { DEBUG(0,("Unable to read from connection\n")); - exit(1); + return NULL; } #ifdef DEBUG_PASSWORD @@ -162,10 +227,10 @@ static struct cli_state *init_client_connection(int c) if (PTR_DIFF(p, buf) < rl) { - memcpy(ntpw, p, 16); - p += 16; memcpy(lmpw, p, 16); p += 16; + memcpy(ntpw, p, 16); + p += 16; pwd_set_lm_nt_16(&usr.pwd, lmpw, ntpw); } else @@ -177,7 +242,7 @@ static struct cli_state *init_client_connection(int c) { DEBUG(0,("Buffer size %d %d!\n", PTR_DIFF(p, buf), rl)); - exit(1); + return NULL; } switch (command) @@ -221,88 +286,60 @@ static struct cli_state *init_client_connection(int c) return NULL; } -static void agent_child(int c) +void process_cli_sock(struct sock_redir **sock) { - struct cli_state *s = NULL; - - DEBUG(10,("agent_child: %d\n", c)); - - while (c != -1) + struct cli_state *s = (*sock)->s; + if (s == NULL) { - fd_set fds; - int num; - int maxfd = 0; - - FD_ZERO(&fds); - if (s != NULL) - { - FD_SET(s->fd, &fds); - maxfd = MAX(s->fd, maxfd); - } - - if (c != -1) + s = init_client_connection((*sock)->c); + if (s == NULL) { - FD_SET(c, &fds); - maxfd = MAX(c, maxfd); + sock_redir_free(*sock); + *sock = NULL; + return ; } - - num = sys_select(maxfd+1,&fds,NULL, NULL); - if (num <= 0) continue; - - if (c != -1 && FD_ISSET(c, &fds)) + (*sock)->s = s; + } + else + { + if (!receive_smb((*sock)->c, packet, 0)) { - if (s == NULL) - { - s = init_client_connection(c); - if (s == NULL) - { - exit(1); - } - } - else - { - if (!receive_smb(c, packet, 0)) - { - DEBUG(0,("client closed connection\n")); - exit(0); - } - /* ignore keep-alives */ - if (CVAL(packet, 0) != 0x85) - { - if (!send_smb(s->fd, packet)) - { - DEBUG(0,("server is dead\n")); - exit(1); - } - } - } + DEBUG(0,("client closed connection\n")); + sock_redir_free(*sock); + *sock = NULL; + return; } - if (s != NULL && FD_ISSET(s->fd, &fds)) + /* ignore keep-alives */ + if (CVAL(packet, 0) != 0x85) { - if (!receive_smb(s->fd, packet, 0)) + if (!send_smb(s->fd, packet)) { - DEBUG(0,("server closed connection\n")); - exit(0); - } -#if 0 - agent_reply(packet); -#endif - if (!send_smb(c, packet)) - { - DEBUG(0,("client is dead\n")); - cli_shutdown(s); - free(s); - exit(1); + DEBUG(0,("server is dead\n")); + sock_redir_free(*sock); + *sock = NULL; + return; } } } - DEBUG(0,("Connection closed\n")); - if (s != NULL) +} + +void process_srv_sock(struct sock_redir **sock) +{ + struct cli_state *s = (*sock)->s; + if (!receive_smb(s->fd, packet, 0)) { - cli_shutdown(s); - free(s); + DEBUG(0,("server closed connection\n")); + sock_redir_free(*sock); + (*sock) = NULL; + return; } - exit(0); + if (!send_smb((*sock)->c, packet)) + { + DEBUG(0,("client is dead\n")); + sock_redir_free(*sock); + (*sock) = NULL; + return; + } } @@ -311,13 +348,22 @@ static void start_agent(void) int s, c; struct sockaddr_un sa; fstring path; - slprintf(path, sizeof(path)-1, "/tmp/smb-agent/smb.%d", getuid()); + fstring dir; CatchChild(); - /* start listening on unix socket */ - mkdir("/tmp/smb-agent", 777); + slprintf(dir, sizeof(dir)-1, "/tmp/.smb.%d", getuid()); + mkdir(dir, S_IRUSR|S_IWUSR|S_IXUSR); + + slprintf(path, sizeof(path)-1, "%s/agent", dir); + if (chmod(dir, S_IRUSR|S_IWUSR|S_IXUSR) < 0) + { + fprintf(stderr, "chmod on %s failed\n", sa.sun_path); + exit(1); + } + + /* start listening on unix socket */ s = socket(AF_UNIX, SOCK_STREAM, 0); if (s < 0) @@ -338,14 +384,6 @@ static void start_agent(void) exit(1); } - if (chmod(path, S_IRUSR|S_IWUSR|S_ISVTX) < 0) - { - fprintf(stderr, "chmod on %s failed\n", sa.sun_path); - close(s); - remove(path); - exit(1); - } - if (s == -1) { DEBUG(0,("bind failed\n")); @@ -361,29 +399,73 @@ static void start_agent(void) while (1) { + int i; fd_set fds; int num; struct sockaddr_un addr; int in_addrlen = sizeof(addr); + int maxfd = s; FD_ZERO(&fds); FD_SET(s, &fds); - num = sys_select(s+1,&fds,NULL, NULL); - if (num > 0) + for (i = 0; i < num_socks; i++) { - c = accept(s, (struct sockaddr*)&addr, &in_addrlen); - if (c != -1) { - if (fork() == 0) + if (socks[i] != NULL) + { + int fd = socks[i]->c; + FD_SET(fd, &fds); + maxfd = MAX(maxfd, fd); + + if (socks[i]->s != NULL) { - close(s); - agent_child(c); - exit(0); - } else { - close(c); + fd = socks[i]->s->fd; + FD_SET(fd, &fds); + maxfd = MAX(fd, maxfd); } } } + + dbgflush(); + num = sys_select(maxfd+1,&fds,NULL, NULL); + + if (num <= 0) + { + continue; + } + + if (FD_ISSET(s, &fds)) + { + c = accept(s, (struct sockaddr*)&addr, &in_addrlen); + if (c != -1) + { + sock_add(c, NULL); + } + } + + for (i = 0; i < num_socks; i++) + { + if (socks[i] == NULL) + { + continue; + } + if (FD_ISSET(socks[i]->c, &fds)) + { + process_cli_sock(&socks[i]); + } + if (socks[i] == NULL) + { + continue; + } + if (socks[i]->s == NULL) + { + continue; + } + if (FD_ISSET(socks[i]->s->fd, &fds)) + { + process_srv_sock(&socks[i]); + } + } } } -- cgit From 8a8a7da5186596ee86b0b188156bca7d5e664784 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sat, 4 Dec 1999 00:49:13 +0000 Subject: argh! you wouldn't believe what i had to do: use the mid (multiplex id) to redirect multiple socket-based connnections onto a single client state. argh! (This used to be commit 06390e792cd8aa57a91c3a3d1d267fd1bcdc17a1) --- source3/utils/smb-agent.c | 110 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 96 insertions(+), 14 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smb-agent.c b/source3/utils/smb-agent.c index a52d696615..fd8697771d 100644 --- a/source3/utils/smb-agent.c +++ b/source3/utils/smb-agent.c @@ -41,12 +41,14 @@ extern int DEBUGLEVEL; struct sock_redir { int c; + int mid_offset; struct cli_state *s; }; static uint32 num_socks = 0; static struct sock_redir **socks = NULL; +static uint16 mid_offset = 0x0; /**************************************************************************** terminate sockent connection @@ -129,6 +131,9 @@ static struct sock_redir *sock_redir_get(int fd, struct cli_state *cli) sock->c = fd; sock->s = cli; + sock->mid_offset = mid_offset; + + DEBUG(10,("sock_redir_get:\tfd:\t%d\tmidoff:\t%d\n", fd, mid_offset)); return sock; } @@ -275,6 +280,15 @@ static struct cli_state *init_client_connection(int c) DEBUG(0,("Unable to connect to %s\n", srv_name)); return NULL; } + + mid_offset += MIN(MAX(s->max_mux, 1), MAX_MAX_MUX_LIMIT); + + if (mid_offset > 0xffff) + { + mid_offset = 0x0; + } + DEBUG(10,("new mid offset: %d\n", mid_offset)); + if (write(c, s, sizeof(*s)) < 0) { DEBUG(0,("Could not write connection down pipe.\n")); @@ -286,6 +300,29 @@ static struct cli_state *init_client_connection(int c) return NULL; } +static void filter_reply(char *buf, int moff) +{ + int msg_type = CVAL(buf,0); + int x; + + if (msg_type != 0x0) return; + + /* alter the mid */ + x = SVAL(buf, smb_mid); + x += moff; + + if (x < 0) + { + x += 0x10000; + } + if (x > 0xffff) + { + x -= 0x10000; + } + + SCVAL(buf, smb_mid, x); + +} void process_cli_sock(struct sock_redir **sock) { struct cli_state *s = (*sock)->s; @@ -309,6 +346,8 @@ void process_cli_sock(struct sock_redir **sock) *sock = NULL; return; } + + filter_reply(packet, (*sock)->mid_offset); /* ignore keep-alives */ if (CVAL(packet, 0) != 0x85) { @@ -323,25 +362,63 @@ void process_cli_sock(struct sock_redir **sock) } } -void process_srv_sock(struct sock_redir **sock) +static int get_smbmid(char *buf) { - struct cli_state *s = (*sock)->s; - if (!receive_smb(s->fd, packet, 0)) + int msg_type = CVAL(buf,0); + + if (msg_type != 0x0) + { + return -1; + } + + return SVAL(buf,smb_mid); +} + +static BOOL process_srv_sock(int fd) +{ + int smbmid; + int i; + if (!receive_smb(fd, packet, 0)) { DEBUG(0,("server closed connection\n")); - sock_redir_free(*sock); - (*sock) = NULL; - return; + return False; } - if (!send_smb((*sock)->c, packet)) + + smbmid = get_smbmid(packet); + + DEBUG(10,("process_srv_sock:\tfd:\t%d\tmid:\t%d\n", fd, smbmid)); + + if (smbmid == -1) { - DEBUG(0,("client is dead\n")); - sock_redir_free(*sock); - (*sock) = NULL; - return; - } -} + return True; + } + for (i = 0; i < num_socks; i++) + { + int moff; + if (socks[i] == NULL || socks[i]->s == NULL) + { + continue; + } + moff = socks[i]->mid_offset; + DEBUG(10,("list:\tfd:\t%d\tmid:\t%d\tmoff:\t%d\n", + socks[i]->s->fd, + socks[i]->s->mid, + moff)); + if (smbmid != socks[i]->s->mid + moff) + { + continue; + } + filter_reply(packet, -moff); + if (!send_smb(socks[i]->c, packet)) + { + DEBUG(0,("client is dead\n")); + return False; + } + return True; + } + return False; +} static void start_agent(void) { @@ -463,7 +540,12 @@ static void start_agent(void) } if (FD_ISSET(socks[i]->s->fd, &fds)) { - process_srv_sock(&socks[i]); + FD_CLR(socks[i]->s->fd, &fds); + if (!process_srv_sock(socks[i]->s->fd)) + { + sock_redir_free(socks[i]); + socks[i] = NULL; + } } } } -- cgit From f521205cb3d188fdcadcbd205dcfda4a7dcb89a0 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sat, 4 Dec 1999 19:14:37 +0000 Subject: jeremy is going to hate me for this. created an "nmb-agent" utility that, yes: it connects to the 137 socket and accepts unix socket connections which it redirects onto port 137. it uses the name_trn_id field to filter requests to the correct location. name_query() and name_status() are the first victims to use this feature (by specifying a file descriptor of -1). (This used to be commit d923bc8da2cf996408194d98381409191dd81a16) --- source3/utils/nmb-agent.c | 515 ++++++++++++++++++++++++++++++++++++++++++++++ source3/utils/nmblookup.c | 26 ++- 2 files changed, 530 insertions(+), 11 deletions(-) create mode 100644 source3/utils/nmb-agent.c (limited to 'source3/utils') diff --git a/source3/utils/nmb-agent.c b/source3/utils/nmb-agent.c new file mode 100644 index 0000000000..12795e5bdd --- /dev/null +++ b/source3/utils/nmb-agent.c @@ -0,0 +1,515 @@ +/* + Unix SMB/Netbios implementation. + Version 2 + SMB agent/socket plugin + 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. +*/ + +#include "includes.h" +#include "smb.h" + +#define SECURITY_MASK 0 +#define SECURITY_SET 0 + +/* this forces non-unicode */ +#define CAPABILITY_MASK CAP_UNICODE +#define CAPABILITY_SET 0 + +/* and non-unicode for the client too */ +#define CLI_CAPABILITY_MASK CAP_UNICODE +#define CLI_CAPABILITY_SET 0 + +extern int DEBUGLEVEL; + +static int ClientNMB = -1; + +struct sock_redir +{ + int c; + int c_trn_id; + int s_trn_id; + struct nmb_state *n; + time_t time; + +}; + +static uint32 num_socks = 0; +static struct sock_redir **socks = NULL; + +/**************************************************************************** +terminate sockent connection +****************************************************************************/ +static void sock_redir_free(struct sock_redir *sock) +{ + close(sock->c); + sock->c = -1; + if (sock->n != NULL) + { +#if 0 + free(sock->n); +#endif + sock->n = NULL; + } +#if 0 + free(sock); +#endif + ZERO_STRUCTP(sock); +} + +/**************************************************************************** +free a sockent array +****************************************************************************/ +static void free_sock_array(uint32 num_entries, struct sock_redir **entries) +{ + void(*fn)(void*) = (void(*)(void*))&sock_redir_free; + free_void_array(num_entries, (void**)entries, *fn); +} + +/**************************************************************************** +add a sockent state to the array +****************************************************************************/ +static struct sock_redir* add_sock_to_array(uint32 *len, + struct sock_redir ***array, + struct sock_redir *sock) +{ + int i; + for (i = 0; i < num_socks; i++) + { + if (socks[i] == NULL) + { + socks[i] = sock; + return sock; + } + } + + return (struct sock_redir*)add_item_to_array(len, + (void***)array, (void*)sock); + +} + +/**************************************************************************** +initiate sockent array +****************************************************************************/ +void init_sock_redir(void) +{ + socks = NULL; + num_socks = 0; +} + +/**************************************************************************** +terminate sockent array +****************************************************************************/ +void free_sock_redir(void) +{ + free_sock_array(num_socks, socks); + init_sock_redir(); +} + +/**************************************************************************** +create a new sockent state from user credentials +****************************************************************************/ +static struct sock_redir *sock_redir_get(int fd) +{ + struct sock_redir *sock; + + sock = (struct sock_redir*)malloc(sizeof(*sock)); + + if (sock == NULL) + { + return NULL; + } + + ZERO_STRUCTP(sock); + + sock->c = fd; + sock->n = NULL; + sock->time = time(NULL); + + DEBUG(10,("sock_redir_get:\tfd:\t%d\t\n", fd)); + + return sock; +} + +/**************************************************************************** +init sock state +****************************************************************************/ +static void sock_add(int fd) +{ + struct sock_redir *sock; + sock = sock_redir_get(fd); + if (sock != NULL) + { + add_sock_to_array(&num_socks, &socks, sock); + } +} + +/**************************************************************************** +delete a sockent state +****************************************************************************/ +static BOOL sock_del(int fd) +{ + int i; + + for (i = 0; i < num_socks; i++) + { + if (socks[i] == NULL) continue; + if (socks[i]->c == fd) + { + sock_redir_free(socks[i]); + socks[i] = NULL; + return True; + } + } + + return False; +} + +static void filter_reply(struct packet_struct *p, int tr_id) +{ + p->packet.nmb.header.name_trn_id = tr_id; +} + +static BOOL process_cli_sock(struct sock_redir **sock) +{ + struct packet_struct *p; + struct nmb_state *nmb; + static uint16 trn_id = 0x0; + + p = receive_packet((*sock)->c, NMB_SOCK_PACKET, 0); + if (p == NULL) + { + DEBUG(0,("client closed connection\n")); + return False; + } + + nmb = (struct nmb_state*)malloc(sizeof(struct nmb_state)); + if (nmb == NULL) + { + return False; + } + + (*sock)->n = nmb; + (*sock)->c_trn_id = p->packet.nmb.header.name_trn_id; + (*sock)->s_trn_id = trn_id; + trn_id++; + if (trn_id > 0xffff) + { + trn_id = 0x0; + } + + DEBUG(10,("new trn_id: %d\n", trn_id)); + + filter_reply(p, (*sock)->s_trn_id); + + nmb->ip = p->ip; + nmb->port = p->port; + + p->fd = ClientNMB; + p->packet_type = NMB_PACKET; + + if (!send_packet(p)) + { + DEBUG(0,("server is dead\n")); + return False; + } + return True; +} + +static BOOL process_srv_sock(struct sock_redir *sock, struct packet_struct *p) +{ + int nmb_id; + int tr_id; + if (p == NULL) + { + return False; + } + + nmb_id = p->packet.nmb.header.name_trn_id; + tr_id = sock->s_trn_id; + + DEBUG(10,("process_srv_sock:\tnmb_id:\t%d\n", nmb_id)); + + DEBUG(10,("list:\tfd:\t%d\tnmb_id:\t%d\ttr_id:\t%d\n", + sock->c, + nmb_id, + tr_id)); + + if (nmb_id != tr_id) + { + return False; + } + + filter_reply(p, sock->c_trn_id); + p->fd = sock->c; + p->packet_type = NMB_SOCK_PACKET; + + if (!send_packet(p)) + { + DEBUG(0,("client is dead\n")); + } + return True; +} + +static void start_agent(void) +{ + int s, c; + struct sockaddr_un sa; + fstring path; + fstring dir; + + CatchChild(); + + slprintf(dir, sizeof(dir)-1, "/tmp/.nmb"); + mkdir(dir, 0777); + + slprintf(path, sizeof(path)-1, "%s/agent", dir); + if (chmod(dir, 0777) < 0) + { + fprintf(stderr, "chmod on %s failed\n", sa.sun_path); + exit(1); + } + + + /* start listening on unix socket */ + s = socket(AF_UNIX, SOCK_STREAM, 0); + + if (s < 0) + { + fprintf(stderr, "socket open failed\n"); + exit(1); + } + + ZERO_STRUCT(sa); + sa.sun_family = AF_UNIX; + safe_strcpy(sa.sun_path, path, sizeof(sa.sun_path)-1); + + if (bind(s, (struct sockaddr*) &sa, sizeof(sa)) < 0) + { + fprintf(stderr, "socket bind to %s failed\n", sa.sun_path); + close(s); + remove(path); + exit(1); + } + + if (s == -1) + { + DEBUG(0,("bind failed\n")); + remove(path); + exit(1); + } + + if (listen(s, 5) == -1) + { + DEBUG(0,("listen failed\n")); + remove(path); + } + + while (1) + { + int i; + fd_set fds; + int num; + struct sockaddr_un addr; + int in_addrlen = sizeof(addr); + int maxfd = s; + struct packet_struct *p = NULL; + time_t current_time = time(NULL); + + FD_ZERO(&fds); + FD_SET(s, &fds); + FD_SET(ClientNMB, &fds); + maxfd = MAX(ClientNMB, maxfd); + + for (i = 0; i < num_socks; i++) + { + if (socks[i] != NULL) + { + int fd = socks[i]->c; + FD_SET(fd, &fds); + maxfd = MAX(maxfd, fd); + + } + } + + dbgflush(); + num = sys_select(maxfd+1,&fds,NULL, NULL); + + if (num <= 0) + { + continue; + } + + if (FD_ISSET(s, &fds)) + { + c = accept(s, (struct sockaddr*)&addr, &in_addrlen); + if (c != -1) + { + sock_add(c); + } + } + + if (FD_ISSET(ClientNMB, &fds)) + { + p = receive_packet(ClientNMB, NMB_PACKET, 0); + if (p && !p->packet.nmb.header.response) + { + free(p); + p = NULL; + } + } + else + { + p = NULL; + } + for (i = 0; i < num_socks; i++) + { + if (socks[i] == NULL) + { + continue; + } + if (FD_ISSET(socks[i]->c, &fds)) + { + if (!process_cli_sock(&socks[i])) + { + sock_redir_free(socks[i]); + socks[i] = NULL; + } + } + + if (p == NULL) + { + continue; + } + + if (socks[i] == NULL) + { + continue; + } + + if (process_srv_sock(socks[i], p) || + current_time > socks[i]->time + 5) + { + sock_redir_free(socks[i]); + socks[i] = NULL; + } + } + + if (p != NULL) + { + free(p); + p = NULL; + } + } +} + +/**************************************************************************** ** + open the socket communication + **************************************************************************** */ +static BOOL open_sockets(BOOL isdaemon, int port) +{ + /* The sockets opened here will be used to receive broadcast + packets *only*. Interface specific sockets are opened in + make_subnet() in namedbsubnet.c. Thus we bind to the + address "0.0.0.0". The parameter 'socket address' is + now deprecated. + */ + + if ( isdaemon ) + ClientNMB = open_socket_in(SOCK_DGRAM, port,0,0); + else + ClientNMB = 0; + + if ( ClientNMB == -1 ) + return( False ); + + /* we are never interested in SIGPIPE */ + BlockSignals(True,SIGPIPE); + + set_socket_options( ClientNMB, "SO_BROADCAST" ); + + DEBUG( 3, ( "open_sockets: Broadcast sockets opened.\n" ) ); + return( True ); +} /* open_sockets */ + +/**************************************************************************** +usage on the program +****************************************************************************/ +static void usage(char *pname) +{ + printf("Usage: %s [-D]", pname); + + printf("\nVersion %s\n",VERSION); + printf("\t-D run as a daemon\n"); + printf("\t-h usage\n"); + printf("\n"); +} + +int main(int argc, char *argv[]) +{ + pstring configfile; + BOOL is_daemon = False; + int opt; + extern pstring debugf; + int global_nmb_port = NMB_PORT; + + TimeInit(); + + pstrcpy(configfile,CONFIGFILE); + + while ((opt = getopt(argc, argv, "Dh")) != EOF) + { + switch (opt) + { + case 'D': + { + is_daemon = True; + break; + } + case 'h': + default: + { + usage(argv[0]); + break; + } + } + } + + slprintf(debugf, sizeof(debugf)-1, "log.%s", argv[0]); + setup_logging(argv[0], !is_daemon); + + charset_initialise(); + + if (!lp_load(configfile,True,False,False)) + { + DEBUG(0,("Unable to load config file\n")); + } + + if (is_daemon) + { + DEBUG(0,("%s: becoming daemon\n", argv[0])); + become_daemon(); + } + + if (!open_sockets(True, global_nmb_port)) + { + return 1; + } + + start_agent(); + + return 0; +} diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 23415a0ca6..f920106f75 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -33,24 +33,28 @@ extern struct in_addr ipzero; int ServerFD= -1; -int RootPort = 0; +BOOL RootPort = False; /**************************************************************************** open the socket communication **************************************************************************/ static BOOL open_sockets(void) { - ServerFD = open_socket_in( SOCK_DGRAM, - (RootPort ? 137 :0), - 3, - interpret_addr(lp_socket_address()) ); - - if (ServerFD == -1) - return(False); - - set_socket_options(ServerFD,"SO_BROADCAST"); + if (RootPort) + { + ServerFD = open_socket_in( SOCK_DGRAM, + 137, + 3, + interpret_addr(lp_socket_address()) ); + + if (ServerFD == -1) + { + return(False); + } + set_socket_options(ServerFD,"SO_BROADCAST"); DEBUG(3, ("Socket opened.\n")); + } return True; } @@ -152,7 +156,7 @@ int main(int argc,char *argv[]) pstrcpy(servicesf, optarg); break; case 'r': - RootPort = -1; + RootPort = True; break; case 'h': usage(); -- cgit From 409798953d16ea254ca1b1615648b7e12818fa64 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sat, 4 Dec 1999 20:11:31 +0000 Subject: trying to make redirector agent code same base. (This used to be commit 9ba9df453abab1085b5537580b1da87d1dcdb7de) --- source3/utils/nmb-agent.c | 116 ++++++++++++++++++++++++++-------------------- source3/utils/smb-agent.c | 24 +++++----- 2 files changed, 78 insertions(+), 62 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmb-agent.c b/source3/utils/nmb-agent.c index 12795e5bdd..61959ba680 100644 --- a/source3/utils/nmb-agent.c +++ b/source3/utils/nmb-agent.c @@ -40,6 +40,7 @@ static int ClientNMB = -1; struct sock_redir { int c; + int s; int c_trn_id; int s_trn_id; struct nmb_state *n; @@ -136,6 +137,7 @@ static struct sock_redir *sock_redir_get(int fd) ZERO_STRUCTP(sock); sock->c = fd; + sock->s = -1; sock->n = NULL; sock->time = time(NULL); @@ -199,9 +201,11 @@ static BOOL process_cli_sock(struct sock_redir **sock) nmb = (struct nmb_state*)malloc(sizeof(struct nmb_state)); if (nmb == NULL) { + free(p); return False; } + (*sock)->s = ClientNMB; (*sock)->n = nmb; (*sock)->c_trn_id = p->packet.nmb.header.name_trn_id; (*sock)->s_trn_id = trn_id; @@ -224,44 +228,67 @@ static BOOL process_cli_sock(struct sock_redir **sock) if (!send_packet(p)) { DEBUG(0,("server is dead\n")); + free(p); return False; } + free(p); return True; } -static BOOL process_srv_sock(struct sock_redir *sock, struct packet_struct *p) +static BOOL process_srv_sock(struct sock_redir *sock) { int nmb_id; int tr_id; + int i; + + struct packet_struct *p; + + p = receive_packet(sock->s, NMB_PACKET, 0); if (p == NULL) { return False; } - nmb_id = p->packet.nmb.header.name_trn_id; - tr_id = sock->s_trn_id; + if (!p->packet.nmb.header.response) + { + free(p); + return True; + } + nmb_id = p->packet.nmb.header.name_trn_id; DEBUG(10,("process_srv_sock:\tnmb_id:\t%d\n", nmb_id)); - DEBUG(10,("list:\tfd:\t%d\tnmb_id:\t%d\ttr_id:\t%d\n", - sock->c, - nmb_id, - tr_id)); - - if (nmb_id != tr_id) + for (i = 0; i < num_socks; i++) { - return False; - } + if (socks[i] == NULL) + { + continue; + } - filter_reply(p, sock->c_trn_id); - p->fd = sock->c; - p->packet_type = NMB_SOCK_PACKET; + tr_id = socks[i]->s_trn_id; - if (!send_packet(p)) - { - DEBUG(0,("client is dead\n")); - } - return True; + DEBUG(10,("list:\tfd:\t%d\tc_trn_id:\t%d\ttr_id:\t%d\n", + socks[i]->c, + socks[i]->c_trn_id, + tr_id)); + + if (nmb_id != tr_id) + { + continue; + } + + filter_reply(p, socks[i]->c_trn_id); + p->fd = socks[i]->c; + p->packet_type = NMB_SOCK_PACKET; + + if (!send_packet(p)) + { + DEBUG(0,("client is dead\n")); + return False; + } + return True; + } + return False; } static void start_agent(void) @@ -326,13 +353,9 @@ static void start_agent(void) struct sockaddr_un addr; int in_addrlen = sizeof(addr); int maxfd = s; - struct packet_struct *p = NULL; - time_t current_time = time(NULL); FD_ZERO(&fds); FD_SET(s, &fds); - FD_SET(ClientNMB, &fds); - maxfd = MAX(ClientNMB, maxfd); for (i = 0; i < num_socks; i++) { @@ -342,6 +365,12 @@ static void start_agent(void) FD_SET(fd, &fds); maxfd = MAX(maxfd, fd); + fd = socks[i]->s; + if (fd != -1) + { + FD_SET(fd, &fds); + maxfd = MAX(maxfd, fd); + } } } @@ -353,8 +382,11 @@ static void start_agent(void) continue; } + DEBUG(10,("select received\n")); + if (FD_ISSET(s, &fds)) { + FD_CLR(s, &fds); c = accept(s, (struct sockaddr*)&addr, &in_addrlen); if (c != -1) { @@ -362,19 +394,6 @@ static void start_agent(void) } } - if (FD_ISSET(ClientNMB, &fds)) - { - p = receive_packet(ClientNMB, NMB_PACKET, 0); - if (p && !p->packet.nmb.header.response) - { - free(p); - p = NULL; - } - } - else - { - p = NULL; - } for (i = 0; i < num_socks; i++) { if (socks[i] == NULL) @@ -383,36 +402,31 @@ static void start_agent(void) } if (FD_ISSET(socks[i]->c, &fds)) { + FD_CLR(socks[i]->c, &fds); if (!process_cli_sock(&socks[i])) { sock_redir_free(socks[i]); socks[i] = NULL; } } - - if (p == NULL) + if (socks[i] == NULL) { continue; } - - if (socks[i] == NULL) + if (socks[i]->s == -1) { continue; } - - if (process_srv_sock(socks[i], p) || - current_time > socks[i]->time + 5) + if (FD_ISSET(socks[i]->s, &fds)) { - sock_redir_free(socks[i]); - socks[i] = NULL; + FD_CLR(socks[i]->s, &fds); + if (!process_srv_sock(socks[i])) + { + sock_redir_free(socks[i]); + socks[i] = NULL; + } } } - - if (p != NULL) - { - free(p); - p = NULL; - } } } diff --git a/source3/utils/smb-agent.c b/source3/utils/smb-agent.c index fd8697771d..dc110fb1da 100644 --- a/source3/utils/smb-agent.c +++ b/source3/utils/smb-agent.c @@ -323,7 +323,8 @@ static void filter_reply(char *buf, int moff) SCVAL(buf, smb_mid, x); } -void process_cli_sock(struct sock_redir **sock) + +static BOOL process_cli_sock(struct sock_redir **sock) { struct cli_state *s = (*sock)->s; if (s == NULL) @@ -331,9 +332,7 @@ void process_cli_sock(struct sock_redir **sock) s = init_client_connection((*sock)->c); if (s == NULL) { - sock_redir_free(*sock); - *sock = NULL; - return ; + return False; } (*sock)->s = s; } @@ -342,9 +341,7 @@ void process_cli_sock(struct sock_redir **sock) if (!receive_smb((*sock)->c, packet, 0)) { DEBUG(0,("client closed connection\n")); - sock_redir_free(*sock); - *sock = NULL; - return; + return False; } filter_reply(packet, (*sock)->mid_offset); @@ -354,12 +351,11 @@ void process_cli_sock(struct sock_redir **sock) if (!send_smb(s->fd, packet)) { DEBUG(0,("server is dead\n")); - sock_redir_free(*sock); - *sock = NULL; - return; + return False; } } } + return True; } static int get_smbmid(char *buf) @@ -513,6 +509,7 @@ static void start_agent(void) if (FD_ISSET(s, &fds)) { + FD_CLR(s, &fds); c = accept(s, (struct sockaddr*)&addr, &in_addrlen); if (c != -1) { @@ -528,7 +525,12 @@ static void start_agent(void) } if (FD_ISSET(socks[i]->c, &fds)) { - process_cli_sock(&socks[i]); + FD_CLR(socks[i]->c, &fds); + if (!process_cli_sock(&socks[i])) + { + sock_redir_free(socks[i]); + socks[i] = NULL; + } } if (socks[i] == NULL) { -- cgit From 45032218520e2cc8763a84e900b9738417b9cdd5 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sat, 4 Dec 1999 20:29:03 +0000 Subject: nmb agent memory free problems (This used to be commit b4306cbf06f70dd9d2760bb005e15059d6f904f0) --- source3/utils/nmb-agent.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmb-agent.c b/source3/utils/nmb-agent.c index 61959ba680..8a202d04fa 100644 --- a/source3/utils/nmb-agent.c +++ b/source3/utils/nmb-agent.c @@ -56,19 +56,18 @@ terminate sockent connection ****************************************************************************/ static void sock_redir_free(struct sock_redir *sock) { - close(sock->c); - sock->c = -1; + DEBUG(10,("sock_redir_free: %d\n", sock->c)); + if (sock->c != -1) + { + close(sock->c); + sock->c = -1; + } if (sock->n != NULL) { -#if 0 free(sock->n); -#endif sock->n = NULL; } -#if 0 free(sock); -#endif - ZERO_STRUCTP(sock); } /**************************************************************************** -- cgit From 9b44e117f955872ae42dcd5eee128394ca4d9ccd Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sat, 4 Dec 1999 20:43:45 +0000 Subject: more similar agent code (This used to be commit 2c778313b8c2b4535f16e11aea81a61edb3b2d45) --- source3/utils/nmb-agent.c | 17 ++++------- source3/utils/smb-agent.c | 73 ++++++++++++++++++++++++----------------------- 2 files changed, 43 insertions(+), 47 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmb-agent.c b/source3/utils/nmb-agent.c index 8a202d04fa..7e7b1642cb 100644 --- a/source3/utils/nmb-agent.c +++ b/source3/utils/nmb-agent.c @@ -44,8 +44,6 @@ struct sock_redir int c_trn_id; int s_trn_id; struct nmb_state *n; - time_t time; - }; static uint32 num_socks = 0; @@ -138,7 +136,6 @@ static struct sock_redir *sock_redir_get(int fd) sock->c = fd; sock->s = -1; sock->n = NULL; - sock->time = time(NULL); DEBUG(10,("sock_redir_get:\tfd:\t%d\t\n", fd)); @@ -234,7 +231,7 @@ static BOOL process_cli_sock(struct sock_redir **sock) return True; } -static BOOL process_srv_sock(struct sock_redir *sock) +static BOOL process_srv_sock(int fd) { int nmb_id; int tr_id; @@ -242,7 +239,7 @@ static BOOL process_srv_sock(struct sock_redir *sock) struct packet_struct *p; - p = receive_packet(sock->s, NMB_PACKET, 0); + p = receive_packet(fd, NMB_PACKET, 0); if (p == NULL) { return False; @@ -381,8 +378,6 @@ static void start_agent(void) continue; } - DEBUG(10,("select received\n")); - if (FD_ISSET(s, &fds)) { FD_CLR(s, &fds); @@ -412,14 +407,14 @@ static void start_agent(void) { continue; } - if (socks[i]->s == -1) + if (socks[i]->n == NULL) { continue; } if (FD_ISSET(socks[i]->s, &fds)) { FD_CLR(socks[i]->s, &fds); - if (!process_srv_sock(socks[i])) + if (!process_srv_sock(socks[i]->s)) { sock_redir_free(socks[i]); socks[i] = NULL; @@ -429,9 +424,9 @@ static void start_agent(void) } } -/**************************************************************************** ** +/****************************************************************************** open the socket communication - **************************************************************************** */ + *****************************************************************************/ static BOOL open_sockets(BOOL isdaemon, int port) { /* The sockets opened here will be used to receive broadcast diff --git a/source3/utils/smb-agent.c b/source3/utils/smb-agent.c index dc110fb1da..457631c307 100644 --- a/source3/utils/smb-agent.c +++ b/source3/utils/smb-agent.c @@ -41,9 +41,9 @@ extern int DEBUGLEVEL; struct sock_redir { int c; + int s; int mid_offset; - struct cli_state *s; - + struct cli_state *n; }; static uint32 num_socks = 0; @@ -57,11 +57,12 @@ static void sock_redir_free(struct sock_redir *sock) { close(sock->c); sock->c = -1; - if (sock->s != NULL) + if (sock->n != NULL) { - cli_net_use_del(sock->s->desthost, &sock->s->usr, + sock->n->fd = sock->s; + cli_net_use_del(sock->n->desthost, &sock->n->usr, False, NULL); - sock->s = NULL; + sock->n = NULL; } free(sock); } @@ -118,7 +119,7 @@ void free_sock_redir(void) /**************************************************************************** create a new sockent state from user credentials ****************************************************************************/ -static struct sock_redir *sock_redir_get(int fd, struct cli_state *cli) +static struct sock_redir *sock_redir_get(int fd) { struct sock_redir *sock = (struct sock_redir*)malloc(sizeof(*sock)); @@ -130,7 +131,7 @@ static struct sock_redir *sock_redir_get(int fd, struct cli_state *cli) ZERO_STRUCTP(sock); sock->c = fd; - sock->s = cli; + sock->n = NULL; sock->mid_offset = mid_offset; DEBUG(10,("sock_redir_get:\tfd:\t%d\tmidoff:\t%d\n", fd, mid_offset)); @@ -141,10 +142,10 @@ static struct sock_redir *sock_redir_get(int fd, struct cli_state *cli) /**************************************************************************** init sock state ****************************************************************************/ -static void sock_add(int fd, struct cli_state *cli) +static void sock_add(int fd) { struct sock_redir *sock; - sock = sock_redir_get(fd, cli); + sock = sock_redir_get(fd); if (sock != NULL) { add_sock_to_array(&num_socks, &socks, sock); @@ -272,16 +273,16 @@ static struct cli_state *init_client_connection(int c) if (new_con) { - struct cli_state *s; - s = cli_net_use_add(srv_name, &usr, False); + struct cli_state *n; + n = cli_net_use_add(srv_name, &usr, False); - if (s == NULL) + if (n == NULL) { DEBUG(0,("Unable to connect to %s\n", srv_name)); return NULL; } - mid_offset += MIN(MAX(s->max_mux, 1), MAX_MAX_MUX_LIMIT); + mid_offset += MIN(MAX(n->max_mux, 1), MAX_MAX_MUX_LIMIT); if (mid_offset > 0xffff) { @@ -289,13 +290,13 @@ static struct cli_state *init_client_connection(int c) } DEBUG(10,("new mid offset: %d\n", mid_offset)); - if (write(c, s, sizeof(*s)) < 0) + if (write(c, n, sizeof(*n)) < 0) { DEBUG(0,("Could not write connection down pipe.\n")); cli_net_use_del(srv_name, &usr, False, NULL); return NULL; } - return s; + return n; } return NULL; } @@ -324,31 +325,31 @@ static void filter_reply(char *buf, int moff) } -static BOOL process_cli_sock(struct sock_redir **sock) +static BOOL process_cli_sock(struct sock_redir *sock) { - struct cli_state *s = (*sock)->s; - if (s == NULL) + struct cli_state *n = sock->n; + if (n == NULL) { - s = init_client_connection((*sock)->c); - if (s == NULL) + n = init_client_connection(sock->c); + if (n == NULL) { return False; } - (*sock)->s = s; + sock->n = n; } else { - if (!receive_smb((*sock)->c, packet, 0)) + if (!receive_smb(sock->c, packet, 0)) { DEBUG(0,("client closed connection\n")); return False; } - filter_reply(packet, (*sock)->mid_offset); + filter_reply(packet, sock->mid_offset); /* ignore keep-alives */ if (CVAL(packet, 0) != 0x85) { - if (!send_smb(s->fd, packet)) + if (!send_smb(sock->s, packet)) { DEBUG(0,("server is dead\n")); return False; @@ -392,16 +393,16 @@ static BOOL process_srv_sock(int fd) for (i = 0; i < num_socks; i++) { int moff; - if (socks[i] == NULL || socks[i]->s == NULL) + if (socks[i] == NULL || socks[i]->n == NULL) { continue; } moff = socks[i]->mid_offset; DEBUG(10,("list:\tfd:\t%d\tmid:\t%d\tmoff:\t%d\n", - socks[i]->s->fd, - socks[i]->s->mid, + socks[i]->s, + socks[i]->n->mid, moff)); - if (smbmid != socks[i]->s->mid + moff) + if (smbmid != socks[i]->n->mid + moff) { continue; } @@ -490,9 +491,9 @@ static void start_agent(void) FD_SET(fd, &fds); maxfd = MAX(maxfd, fd); - if (socks[i]->s != NULL) + if (socks[i]->n != NULL) { - fd = socks[i]->s->fd; + fd = socks[i]->s; FD_SET(fd, &fds); maxfd = MAX(fd, maxfd); } @@ -513,7 +514,7 @@ static void start_agent(void) c = accept(s, (struct sockaddr*)&addr, &in_addrlen); if (c != -1) { - sock_add(c, NULL); + sock_add(c); } } @@ -526,7 +527,7 @@ static void start_agent(void) if (FD_ISSET(socks[i]->c, &fds)) { FD_CLR(socks[i]->c, &fds); - if (!process_cli_sock(&socks[i])) + if (!process_cli_sock(socks[i])) { sock_redir_free(socks[i]); socks[i] = NULL; @@ -536,14 +537,14 @@ static void start_agent(void) { continue; } - if (socks[i]->s == NULL) + if (socks[i]->n == NULL) { continue; } - if (FD_ISSET(socks[i]->s->fd, &fds)) + if (FD_ISSET(socks[i]->s, &fds)) { - FD_CLR(socks[i]->s->fd, &fds); - if (!process_srv_sock(socks[i]->s->fd)) + FD_CLR(socks[i]->s, &fds); + if (!process_srv_sock(socks[i]->s)) { sock_redir_free(socks[i]); socks[i] = NULL; -- cgit From f6077db3173c7b6520d5735f78d06138ac273174 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sat, 4 Dec 1999 21:55:39 +0000 Subject: cool! created higher-order function table for agent redirection. (This used to be commit 7bb2e55d0d3a00a97bba99ebed722a4adf84093c) --- source3/utils/smb-agent.c | 253 +++++++--------------------------------------- 1 file changed, 37 insertions(+), 216 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smb-agent.c b/source3/utils/smb-agent.c index 457631c307..5d1aa4db04 100644 --- a/source3/utils/smb-agent.c +++ b/source3/utils/smb-agent.c @@ -38,139 +38,19 @@ static char packet[BUFFER_SIZE]; extern int DEBUGLEVEL; -struct sock_redir -{ - int c; - int s; - int mid_offset; - struct cli_state *n; -}; - -static uint32 num_socks = 0; -static struct sock_redir **socks = NULL; static uint16 mid_offset = 0x0; /**************************************************************************** terminate sockent connection ****************************************************************************/ -static void sock_redir_free(struct sock_redir *sock) -{ - close(sock->c); - sock->c = -1; - if (sock->n != NULL) - { - sock->n->fd = sock->s; - cli_net_use_del(sock->n->desthost, &sock->n->usr, - False, NULL); - sock->n = NULL; - } - free(sock); -} - -/**************************************************************************** -free a sockent array -****************************************************************************/ -static void free_sock_array(uint32 num_entries, struct sock_redir **entries) +static void free_sock(void *sock) { - void(*fn)(void*) = (void(*)(void*))&sock_redir_free; - free_void_array(num_entries, (void**)entries, *fn); -} - -/**************************************************************************** -add a sockent state to the array -****************************************************************************/ -static struct sock_redir* add_sock_to_array(uint32 *len, - struct sock_redir ***array, - struct sock_redir *sock) -{ - int i; - for (i = 0; i < num_socks; i++) - { - if (socks[i] == NULL) - { - socks[i] = sock; - return sock; - } - } - - return (struct sock_redir*)add_item_to_array(len, - (void***)array, (void*)sock); - -} - -/**************************************************************************** -initiate sockent array -****************************************************************************/ -void init_sock_redir(void) -{ - socks = NULL; - num_socks = 0; -} - -/**************************************************************************** -terminate sockent array -****************************************************************************/ -void free_sock_redir(void) -{ - free_sock_array(num_socks, socks); - init_sock_redir(); -} - -/**************************************************************************** -create a new sockent state from user credentials -****************************************************************************/ -static struct sock_redir *sock_redir_get(int fd) -{ - struct sock_redir *sock = (struct sock_redir*)malloc(sizeof(*sock)); - - if (sock == NULL) - { - return NULL; - } - - ZERO_STRUCTP(sock); - - sock->c = fd; - sock->n = NULL; - sock->mid_offset = mid_offset; - - DEBUG(10,("sock_redir_get:\tfd:\t%d\tmidoff:\t%d\n", fd, mid_offset)); - - return sock; -} - -/**************************************************************************** -init sock state -****************************************************************************/ -static void sock_add(int fd) -{ - struct sock_redir *sock; - sock = sock_redir_get(fd); if (sock != NULL) { - add_sock_to_array(&num_socks, &socks, sock); - } -} - -/**************************************************************************** -delete a sockent state -****************************************************************************/ -static BOOL sock_del(int fd) -{ - int i; - - for (i = 0; i < num_socks; i++) - { - if (socks[i] == NULL) continue; - if (socks[i]->c == fd) - { - sock_redir_free(socks[i]); - socks[i] = NULL; - return True; - } + struct cli_state *n = (struct cli_state*)sock; + cli_net_use_del(n->desthost, &n->usr, + False, NULL); } - - return False; } static struct cli_state *init_client_connection(int c) @@ -325,9 +205,10 @@ static void filter_reply(char *buf, int moff) } -static BOOL process_cli_sock(struct sock_redir *sock) +static BOOL process_cli_sock(struct sock_redir **socks, uint32 num_socks, + struct sock_redir *sock) { - struct cli_state *n = sock->n; + struct cli_state *n = (struct cli_state*)sock->n; if (n == NULL) { n = init_client_connection(sock->c); @@ -335,7 +216,9 @@ static BOOL process_cli_sock(struct sock_redir *sock) { return False; } - sock->n = n; + sock->n = (void*)n; + sock->s_id = mid_offset; + sock->s = n->fd; } else { @@ -345,7 +228,7 @@ static BOOL process_cli_sock(struct sock_redir *sock) return False; } - filter_reply(packet, sock->mid_offset); + filter_reply(packet, sock->s_id); /* ignore keep-alives */ if (CVAL(packet, 0) != 0x85) { @@ -371,7 +254,8 @@ static int get_smbmid(char *buf) return SVAL(buf,smb_mid); } -static BOOL process_srv_sock(int fd) +static BOOL process_srv_sock(struct sock_redir **socks, uint32 num_socks, + int fd) { int smbmid; int i; @@ -393,16 +277,18 @@ static BOOL process_srv_sock(int fd) for (i = 0; i < num_socks; i++) { int moff; + struct cli_state *n; if (socks[i] == NULL || socks[i]->n == NULL) { continue; } - moff = socks[i]->mid_offset; + moff = socks[i]->s_id; + n = (struct cli_state*)socks[i]->n; DEBUG(10,("list:\tfd:\t%d\tmid:\t%d\tmoff:\t%d\n", socks[i]->s, - socks[i]->n->mid, + n->mid, moff)); - if (smbmid != socks[i]->n->mid + moff) + if (smbmid != n->mid + moff) { continue; } @@ -417,15 +303,13 @@ static BOOL process_srv_sock(int fd) return False; } -static void start_agent(void) +static int get_agent_sock(void *id) { - int s, c; + int s; struct sockaddr_un sa; fstring path; fstring dir; - CatchChild(); - slprintf(dir, sizeof(dir)-1, "/tmp/.smb.%d", getuid()); mkdir(dir, S_IRUSR|S_IWUSR|S_IXUSR); @@ -470,88 +354,25 @@ static void start_agent(void) DEBUG(0,("listen failed\n")); remove(path); } + return s; +} - while (1) +static void start_smb_agent(void) +{ + struct vagent_ops va = { - int i; - fd_set fds; - int num; - struct sockaddr_un addr; - int in_addrlen = sizeof(addr); - int maxfd = s; - - FD_ZERO(&fds); - FD_SET(s, &fds); - - for (i = 0; i < num_socks; i++) - { - if (socks[i] != NULL) - { - int fd = socks[i]->c; - FD_SET(fd, &fds); - maxfd = MAX(maxfd, fd); - - if (socks[i]->n != NULL) - { - fd = socks[i]->s; - FD_SET(fd, &fds); - maxfd = MAX(fd, maxfd); - } - } - } - - dbgflush(); - num = sys_select(maxfd+1,&fds,NULL, NULL); - - if (num <= 0) - { - continue; - } - - if (FD_ISSET(s, &fds)) - { - FD_CLR(s, &fds); - c = accept(s, (struct sockaddr*)&addr, &in_addrlen); - if (c != -1) - { - sock_add(c); - } - } + free_sock, + get_agent_sock, + process_cli_sock, + process_srv_sock, + NULL, + NULL, + 0 + }; + + CatchChild(); - for (i = 0; i < num_socks; i++) - { - if (socks[i] == NULL) - { - continue; - } - if (FD_ISSET(socks[i]->c, &fds)) - { - FD_CLR(socks[i]->c, &fds); - if (!process_cli_sock(socks[i])) - { - sock_redir_free(socks[i]); - socks[i] = NULL; - } - } - if (socks[i] == NULL) - { - continue; - } - if (socks[i]->n == NULL) - { - continue; - } - if (FD_ISSET(socks[i]->s, &fds)) - { - FD_CLR(socks[i]->s, &fds); - if (!process_srv_sock(socks[i]->s)) - { - sock_redir_free(socks[i]); - socks[i] = NULL; - } - } - } - } + start_agent(&va); } /**************************************************************************** @@ -612,7 +433,7 @@ int main(int argc, char *argv[]) become_daemon(); } - start_agent(); + start_smb_agent(); return 0; } -- cgit From c41205e28f39feb090ea6fe4357d0fa714d38bef Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sat, 4 Dec 1999 22:05:59 +0000 Subject: even more cool! nmb-agent moved over to new vagent style, too! (This used to be commit 49c157eae4bb24164f0f976d1bf6cf0cfc068863) --- source3/utils/nmb-agent.c | 275 ++++++++-------------------------------------- 1 file changed, 46 insertions(+), 229 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmb-agent.c b/source3/utils/nmb-agent.c index 7e7b1642cb..fb0e72d461 100644 --- a/source3/utils/nmb-agent.c +++ b/source3/utils/nmb-agent.c @@ -37,143 +37,15 @@ extern int DEBUGLEVEL; static int ClientNMB = -1; -struct sock_redir -{ - int c; - int s; - int c_trn_id; - int s_trn_id; - struct nmb_state *n; -}; - -static uint32 num_socks = 0; -static struct sock_redir **socks = NULL; - /**************************************************************************** terminate sockent connection ****************************************************************************/ -static void sock_redir_free(struct sock_redir *sock) -{ - DEBUG(10,("sock_redir_free: %d\n", sock->c)); - if (sock->c != -1) - { - close(sock->c); - sock->c = -1; - } - if (sock->n != NULL) - { - free(sock->n); - sock->n = NULL; - } - free(sock); -} - -/**************************************************************************** -free a sockent array -****************************************************************************/ -static void free_sock_array(uint32 num_entries, struct sock_redir **entries) +static void free_sock(void *sock) { - void(*fn)(void*) = (void(*)(void*))&sock_redir_free; - free_void_array(num_entries, (void**)entries, *fn); -} - -/**************************************************************************** -add a sockent state to the array -****************************************************************************/ -static struct sock_redir* add_sock_to_array(uint32 *len, - struct sock_redir ***array, - struct sock_redir *sock) -{ - int i; - for (i = 0; i < num_socks; i++) - { - if (socks[i] == NULL) - { - socks[i] = sock; - return sock; - } - } - - return (struct sock_redir*)add_item_to_array(len, - (void***)array, (void*)sock); - -} - -/**************************************************************************** -initiate sockent array -****************************************************************************/ -void init_sock_redir(void) -{ - socks = NULL; - num_socks = 0; -} - -/**************************************************************************** -terminate sockent array -****************************************************************************/ -void free_sock_redir(void) -{ - free_sock_array(num_socks, socks); - init_sock_redir(); -} - -/**************************************************************************** -create a new sockent state from user credentials -****************************************************************************/ -static struct sock_redir *sock_redir_get(int fd) -{ - struct sock_redir *sock; - - sock = (struct sock_redir*)malloc(sizeof(*sock)); - - if (sock == NULL) - { - return NULL; - } - - ZERO_STRUCTP(sock); - - sock->c = fd; - sock->s = -1; - sock->n = NULL; - - DEBUG(10,("sock_redir_get:\tfd:\t%d\t\n", fd)); - - return sock; -} - -/**************************************************************************** -init sock state -****************************************************************************/ -static void sock_add(int fd) -{ - struct sock_redir *sock; - sock = sock_redir_get(fd); if (sock != NULL) { - add_sock_to_array(&num_socks, &socks, sock); - } -} - -/**************************************************************************** -delete a sockent state -****************************************************************************/ -static BOOL sock_del(int fd) -{ - int i; - - for (i = 0; i < num_socks; i++) - { - if (socks[i] == NULL) continue; - if (socks[i]->c == fd) - { - sock_redir_free(socks[i]); - socks[i] = NULL; - return True; - } + free(sock); } - - return False; } static void filter_reply(struct packet_struct *p, int tr_id) @@ -181,13 +53,15 @@ static void filter_reply(struct packet_struct *p, int tr_id) p->packet.nmb.header.name_trn_id = tr_id; } -static BOOL process_cli_sock(struct sock_redir **sock) +static BOOL process_cli_sock(struct sock_redir **socks, + uint32 num_socks, + struct sock_redir *sock) { struct packet_struct *p; struct nmb_state *nmb; static uint16 trn_id = 0x0; - p = receive_packet((*sock)->c, NMB_SOCK_PACKET, 0); + p = receive_packet(sock->c, NMB_SOCK_PACKET, 0); if (p == NULL) { DEBUG(0,("client closed connection\n")); @@ -201,10 +75,11 @@ static BOOL process_cli_sock(struct sock_redir **sock) return False; } - (*sock)->s = ClientNMB; - (*sock)->n = nmb; - (*sock)->c_trn_id = p->packet.nmb.header.name_trn_id; - (*sock)->s_trn_id = trn_id; + sock->s = ClientNMB; + sock->n = nmb; + sock->c_id = p->packet.nmb.header.name_trn_id; + sock->s_id = trn_id; + trn_id++; if (trn_id > 0xffff) { @@ -213,7 +88,7 @@ static BOOL process_cli_sock(struct sock_redir **sock) DEBUG(10,("new trn_id: %d\n", trn_id)); - filter_reply(p, (*sock)->s_trn_id); + filter_reply(p, sock->s_id); nmb->ip = p->ip; nmb->port = p->port; @@ -231,7 +106,9 @@ static BOOL process_cli_sock(struct sock_redir **sock) return True; } -static BOOL process_srv_sock(int fd) +static BOOL process_srv_sock(struct sock_redir **socks, + uint32 num_socks, + int fd) { int nmb_id; int tr_id; @@ -261,11 +138,11 @@ static BOOL process_srv_sock(int fd) continue; } - tr_id = socks[i]->s_trn_id; + tr_id = socks[i]->s_id; - DEBUG(10,("list:\tfd:\t%d\tc_trn_id:\t%d\ttr_id:\t%d\n", + DEBUG(10,("list:\tfd:\t%d\tc_id:\t%d\ttr_id:\t%d\n", socks[i]->c, - socks[i]->c_trn_id, + socks[i]->c_id, tr_id)); if (nmb_id != tr_id) @@ -273,7 +150,7 @@ static BOOL process_srv_sock(int fd) continue; } - filter_reply(p, socks[i]->c_trn_id); + filter_reply(p, socks[i]->c_id); p->fd = socks[i]->c; p->packet_type = NMB_SOCK_PACKET; @@ -287,9 +164,9 @@ static BOOL process_srv_sock(int fd) return False; } -static void start_agent(void) +static int get_agent_sock(void*id) { - int s, c; + int s; struct sockaddr_un sa; fstring path; fstring dir; @@ -303,7 +180,7 @@ static void start_agent(void) if (chmod(dir, 0777) < 0) { fprintf(stderr, "chmod on %s failed\n", sa.sun_path); - exit(1); + return -1; } @@ -313,7 +190,7 @@ static void start_agent(void) if (s < 0) { fprintf(stderr, "socket open failed\n"); - exit(1); + return -1; } ZERO_STRUCT(sa); @@ -325,103 +202,43 @@ static void start_agent(void) fprintf(stderr, "socket bind to %s failed\n", sa.sun_path); close(s); remove(path); - exit(1); + return -1; } if (s == -1) { DEBUG(0,("bind failed\n")); remove(path); - exit(1); + return -1; } + chmod(path, 0666); + if (listen(s, 5) == -1) { DEBUG(0,("listen failed\n")); - remove(path); + return -1; } - while (1) - { - int i; - fd_set fds; - int num; - struct sockaddr_un addr; - int in_addrlen = sizeof(addr); - int maxfd = s; - - FD_ZERO(&fds); - FD_SET(s, &fds); - - for (i = 0; i < num_socks; i++) - { - if (socks[i] != NULL) - { - int fd = socks[i]->c; - FD_SET(fd, &fds); - maxfd = MAX(maxfd, fd); - - fd = socks[i]->s; - if (fd != -1) - { - FD_SET(fd, &fds); - maxfd = MAX(maxfd, fd); - } - } - } - - dbgflush(); - num = sys_select(maxfd+1,&fds,NULL, NULL); - - if (num <= 0) - { - continue; - } + return s; +} - if (FD_ISSET(s, &fds)) - { - FD_CLR(s, &fds); - c = accept(s, (struct sockaddr*)&addr, &in_addrlen); - if (c != -1) - { - sock_add(c); - } - } +static void start_nmb_agent(void) +{ + struct vagent_ops va = + { + free_sock, + get_agent_sock, + process_cli_sock, + process_srv_sock, + NULL, + NULL, + 0 + }; + + CatchChild(); - for (i = 0; i < num_socks; i++) - { - if (socks[i] == NULL) - { - continue; - } - if (FD_ISSET(socks[i]->c, &fds)) - { - FD_CLR(socks[i]->c, &fds); - if (!process_cli_sock(&socks[i])) - { - sock_redir_free(socks[i]); - socks[i] = NULL; - } - } - if (socks[i] == NULL) - { - continue; - } - if (socks[i]->n == NULL) - { - continue; - } - if (FD_ISSET(socks[i]->s, &fds)) - { - FD_CLR(socks[i]->s, &fds); - if (!process_srv_sock(socks[i]->s)) - { - sock_redir_free(socks[i]); - socks[i] = NULL; - } - } - } - } + start_agent(&va); } /****************************************************************************** @@ -517,7 +334,7 @@ int main(int argc, char *argv[]) return 1; } - start_agent(); + start_nmb_agent(); return 0; } -- cgit From ddda7722a673cefc89a55133f99c07dd153b1f19 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sat, 4 Dec 1999 23:40:21 +0000 Subject: argh! how horrible! spent ages working out why packets weren't being received properly when a UDP "retry" occurs. it's because reads and writes must be interleaved / matched. scenario: nmblookup connects to agent, sends request. agent receives request, broadcasts it on 137. agent RECEIVES 137 broadcast, sends it to nmblookup agent receives RESPONSE to 137 broadcast, sends it to nmblookup. if reads are not equally interspersed with writes, then second send will fail. if you think this is odd behaviour and that the agent should be filtering its own UDP traffic, think again. agent will be, potentially, redirecting nmbd traffic (including WINS server) not just client programs. (This used to be commit 43e158c4261e51678d6e7f77ceb4a1c7281a2525) --- source3/utils/nmb-agent.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmb-agent.c b/source3/utils/nmb-agent.c index fb0e72d461..ad9c958350 100644 --- a/source3/utils/nmb-agent.c +++ b/source3/utils/nmb-agent.c @@ -71,7 +71,7 @@ static BOOL process_cli_sock(struct sock_redir **socks, nmb = (struct nmb_state*)malloc(sizeof(struct nmb_state)); if (nmb == NULL) { - free(p); + free_packet(p); return False; } @@ -99,10 +99,10 @@ static BOOL process_cli_sock(struct sock_redir **socks, if (!send_packet(p)) { DEBUG(0,("server is dead\n")); - free(p); + free_packet(p); return False; } - free(p); + free_packet(p); return True; } @@ -119,14 +119,17 @@ static BOOL process_srv_sock(struct sock_redir **socks, p = receive_packet(fd, NMB_PACKET, 0); if (p == NULL) { - return False; + return True; } +#if 0 if (!p->packet.nmb.header.response) { - free(p); + DEBUG(10,("skipping response packet\n")); + free_packet(p); return True; } +#endif nmb_id = p->packet.nmb.header.name_trn_id; DEBUG(10,("process_srv_sock:\tnmb_id:\t%d\n", nmb_id)); @@ -161,7 +164,7 @@ static BOOL process_srv_sock(struct sock_redir **socks, } return True; } - return False; + return True; } static int get_agent_sock(void*id) @@ -212,7 +215,7 @@ static int get_agent_sock(void*id) return -1; } - chmod(path, 0666); + chmod(path, 0777); if (listen(s, 5) == -1) { -- cgit From 854f35e20fa4748312e4b0fbae6bb38342ab0389 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sun, 5 Dec 1999 00:13:17 +0000 Subject: created create_pipe_socket() function. (This used to be commit a3af3b4312144943413894b18b5845b56474ebb5) --- source3/utils/nmb-agent.c | 54 +++-------------------------------------------- source3/utils/smb-agent.c | 45 ++------------------------------------- 2 files changed, 5 insertions(+), 94 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmb-agent.c b/source3/utils/nmb-agent.c index ad9c958350..f49983db79 100644 --- a/source3/utils/nmb-agent.c +++ b/source3/utils/nmb-agent.c @@ -167,63 +167,15 @@ static BOOL process_srv_sock(struct sock_redir **socks, return True; } -static int get_agent_sock(void*id) +static int get_agent_sock(char *id) { - int s; - struct sockaddr_un sa; - fstring path; fstring dir; - - CatchChild(); + fstring path; slprintf(dir, sizeof(dir)-1, "/tmp/.nmb"); - mkdir(dir, 0777); - slprintf(path, sizeof(path)-1, "%s/agent", dir); - if (chmod(dir, 0777) < 0) - { - fprintf(stderr, "chmod on %s failed\n", sa.sun_path); - return -1; - } - - - /* start listening on unix socket */ - s = socket(AF_UNIX, SOCK_STREAM, 0); - - if (s < 0) - { - fprintf(stderr, "socket open failed\n"); - return -1; - } - - ZERO_STRUCT(sa); - sa.sun_family = AF_UNIX; - safe_strcpy(sa.sun_path, path, sizeof(sa.sun_path)-1); - - if (bind(s, (struct sockaddr*) &sa, sizeof(sa)) < 0) - { - fprintf(stderr, "socket bind to %s failed\n", sa.sun_path); - close(s); - remove(path); - return -1; - } - - if (s == -1) - { - DEBUG(0,("bind failed\n")); - remove(path); - return -1; - } - - chmod(path, 0777); - - if (listen(s, 5) == -1) - { - DEBUG(0,("listen failed\n")); - return -1; - } - return s; + return create_pipe_socket(dir, 0777, path, 0777); } static void start_nmb_agent(void) diff --git a/source3/utils/smb-agent.c b/source3/utils/smb-agent.c index 5d1aa4db04..96c43cadaf 100644 --- a/source3/utils/smb-agent.c +++ b/source3/utils/smb-agent.c @@ -303,7 +303,7 @@ static BOOL process_srv_sock(struct sock_redir **socks, uint32 num_socks, return False; } -static int get_agent_sock(void *id) +static int get_agent_sock(char *id) { int s; struct sockaddr_un sa; @@ -311,50 +311,9 @@ static int get_agent_sock(void *id) fstring dir; slprintf(dir, sizeof(dir)-1, "/tmp/.smb.%d", getuid()); - mkdir(dir, S_IRUSR|S_IWUSR|S_IXUSR); - slprintf(path, sizeof(path)-1, "%s/agent", dir); - if (chmod(dir, S_IRUSR|S_IWUSR|S_IXUSR) < 0) - { - fprintf(stderr, "chmod on %s failed\n", sa.sun_path); - exit(1); - } - - - /* start listening on unix socket */ - s = socket(AF_UNIX, SOCK_STREAM, 0); - - if (s < 0) - { - fprintf(stderr, "socket open failed\n"); - exit(1); - } - - ZERO_STRUCT(sa); - sa.sun_family = AF_UNIX; - safe_strcpy(sa.sun_path, path, sizeof(sa.sun_path)-1); - if (bind(s, (struct sockaddr*) &sa, sizeof(sa)) < 0) - { - fprintf(stderr, "socket bind to %s failed\n", sa.sun_path); - close(s); - remove(path); - exit(1); - } - - if (s == -1) - { - DEBUG(0,("bind failed\n")); - remove(path); - exit(1); - } - - if (listen(s, 5) == -1) - { - DEBUG(0,("listen failed\n")); - remove(path); - } - return s; + return create_pipe_socket(dir, S_IRUSR|S_IWUSR|S_IXUSR, path, 0); } static void start_smb_agent(void) -- cgit From 4ab9d91428b66bd2fe407b0dba94f4130160b576 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 8 Dec 1999 21:43:03 +0000 Subject: ABOUT TIME!!!!!!!! damn, this one is bad. started, at least two days ago, to add an authentication mechanism to the smbd<->msrpc redirector/relay, such that sufficient unix / nt information could be transferred across the unix socket to do a become_user() on the other side of the socket. it is necessary that the msrpc daemon inherit the same unix and nt credentials as the smbd process from which it was spawned, until such time as the msrpc daemon receives an authentication request of its own, whereupon the msrpc daemon is responsible for authenticating the new credentials and doing yet another become_user() etc sequence. (This used to be commit 30c7fdd6ef10ecd35594311c1b250b95ff895489) --- source3/utils/smb-agent.c | 69 +++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 41 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smb-agent.c b/source3/utils/smb-agent.c index 96c43cadaf..2ecfdba7e2 100644 --- a/source3/utils/smb-agent.c +++ b/source3/utils/smb-agent.c @@ -53,23 +53,25 @@ static void free_sock(void *sock) } } + static struct cli_state *init_client_connection(int c) { pstring buf; - uchar ntpw[16]; - uchar lmpw[16]; - fstring srv_name; - struct user_credentials usr; - char *p = buf; + struct user_creds usr; int rl; uint32 len; - uint16 version; - uint16 command; BOOL new_con = False; + CREDS_CMD cmd; + prs_struct ps; + BOOL reuse = False; + + ZERO_STRUCT(usr); + ZERO_STRUCT(cmd); + cmd.cred = &usr; ZERO_STRUCT(usr); - DEBUG(10,("first request\n")); + DEBUG(10,("init_client_connection: first request\n")); rl = read(c, &buf, sizeof(len)); @@ -99,39 +101,26 @@ static struct cli_state *init_client_connection(int c) #ifdef DEBUG_PASSWORD dump_data(100, buf, rl); #endif - version = SVAL(p, 0); - p += 2; - command = SVAL(p, 0); - p += 2; - - fstrcpy(srv_name, p); - p = skip_string(p, 1); - fstrcpy(usr.user_name, p); - p = skip_string(p, 1); - fstrcpy(usr.domain, p); - p = skip_string(p, 1); - - if (PTR_DIFF(p, buf) < rl) - { - memcpy(lmpw, p, 16); - p += 16; - memcpy(ntpw, p, 16); - p += 16; - pwd_set_lm_nt_16(&usr.pwd, lmpw, ntpw); - } - else + /* make a static data parsing structure from the api_fd_reply data */ + prs_init(&ps, 0, 4, 0, True); + mem_create(ps.data, buf, 0, len, 0, False); + + if (!creds_io_cmd("creds", &cmd, &ps, 0)) { - pwd_set_nullpwd(&usr.pwd); + DEBUG(0,("Unable to parse credentials\n")); + mem_free_data(ps.data); + return NULL; } - if (PTR_DIFF(p, buf) != rl) + mem_free_data(ps.data); + + if (ps.offset != rl) { - DEBUG(0,("Buffer size %d %d!\n", - PTR_DIFF(p, buf), rl)); + DEBUG(0,("Buffer size %d %d!\n", ps.offset, rl)); return NULL; } - switch (command) + switch (cmd.command) { case AGENT_CMD_CON: { @@ -141,12 +130,12 @@ static struct cli_state *init_client_connection(int c) case AGENT_CMD_CON_REUSE: { new_con = True; - usr.reuse = True; + reuse = True; break; } default: { - DEBUG(0,("unknown command %d\n", command)); + DEBUG(0,("unknown command %d\n", cmd.command)); return NULL; } } @@ -154,11 +143,11 @@ static struct cli_state *init_client_connection(int c) if (new_con) { struct cli_state *n; - n = cli_net_use_add(srv_name, &usr, False); + n = cli_net_use_add(cmd.name, &usr.ntc, False, reuse); if (n == NULL) { - DEBUG(0,("Unable to connect to %s\n", srv_name)); + DEBUG(0,("Unable to connect to %s\n", cmd.name)); return NULL; } @@ -173,7 +162,7 @@ static struct cli_state *init_client_connection(int c) if (write(c, n, sizeof(*n)) < 0) { DEBUG(0,("Could not write connection down pipe.\n")); - cli_net_use_del(srv_name, &usr, False, NULL); + cli_net_use_del(cmd.name, &usr.ntc, False, NULL); return NULL; } return n; @@ -305,8 +294,6 @@ static BOOL process_srv_sock(struct sock_redir **socks, uint32 num_socks, static int get_agent_sock(char *id) { - int s; - struct sockaddr_un sa; fstring path; fstring dir; -- cgit From 12ca139d5cb79f7e61a84d7dfe8a4c64ed56d82b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 9 Dec 1999 07:06:12 +0000 Subject: OK. This code works on a RedHat 6.0 system. However smbpasswd time out of sending the session setup on Solaris 2.6. No idea. I'll work on it some tomorrow. This is to fix the "Unable to setup password vectors" thingy. Also changed an inet_aton() to inet_addr() as the former is not very portable :-) Luke, I set the redir flag to false because the connection to the smb-agent was failing and smbpasswd bombed. Double check me on this one. -jc (This used to be commit e1d2b174caf5f0c48a8fac25778f72a868ec6eb7) --- source3/utils/smbpasswd.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 3b87687c26..a1a870a674 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -794,6 +794,8 @@ int main(int argc, char **argv) load_interfaces(); + init_policy_hnd(64); + if(!pwdb_initialise(False)) { fprintf(stderr, "Can't setup password database vectors.\n"); -- cgit From 4f8a24522c683761c6f2ee23dba56f6c7913377b Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sun, 12 Dec 1999 20:03:42 +0000 Subject: final part of "first" phase converting over to msrpc daemon architecture. done a minimal amout of clean-up in the Makefile, removing unnecessary modules from the link stage. this is not complete, yet, and will involve some changes, for example to smbd, to remove dependencies on the password database API that shouldn't be there. for example, smbd should not ever call getsmbpwXXX() it should call the Samr or Lsa API. this first implementation has minor problems with not reinstantiating the same services as the caller. the "homes" service is a good example. (This used to be commit caa50525220b0d0250fa139367593c2de2c12135) --- source3/utils/smbpasswd.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index a1a870a674..3b87687c26 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -794,8 +794,6 @@ int main(int argc, char **argv) load_interfaces(); - init_policy_hnd(64); - if(!pwdb_initialise(False)) { fprintf(stderr, "Can't setup password database vectors.\n"); -- cgit From 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 1999 13:27:58 +0000 Subject: first pass at updating head branch to be to be the same as the SAMBA_2_0 branch (This used to be commit 453a822a76780063dff23526c35408866d0c0154) --- source3/utils/debug2html.c | 182 +++----- source3/utils/make_printerdef.c | 7 + source3/utils/make_smbcodepage.c | 10 +- source3/utils/nmblookup.c | 151 +++--- source3/utils/rpctorture.c | 515 +++------------------ source3/utils/smbfilter.c | 6 +- source3/utils/smbpasswd.c | 521 +++++++-------------- source3/utils/smbrun.c | 28 +- source3/utils/status.c | 132 +++--- source3/utils/testparm.c | 247 +++++++--- source3/utils/torture.c | 959 ++++++++++++++++++++++++--------------- 11 files changed, 1224 insertions(+), 1534 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/debug2html.c b/source3/utils/debug2html.c index ef7201168f..f9a1f43f46 100644 --- a/source3/utils/debug2html.c +++ b/source3/utils/debug2html.c @@ -28,19 +28,36 @@ * does a decent job of converting Samba logs into HTML. * -------------------------------------------------------------------------- ** * - * $Revision: 1.9 $ + * Revision 1.4 1998/11/13 03:37:01 tridge + * fixes for OSF1 compilation + * + * Revision 1.3 1998/10/28 20:33:35 crh + * I've moved the debugparse module files into the ubiqx directory because I + * know that 'make proto' will ignore them there. The debugparse.h header + * file is included in includes.h, and includes.h is included in debugparse.c, + * so all of the pieces "see" each other. I've compiled and tested this, + * and it does seem to work. It's the same compromise model I used when + * adding the ubiqx modules into the system, which is why I put it all into + * the same directory. + * + * Chris -)----- + * + * Revision 1.1 1998/10/26 23:21:37 crh + * Here is the simple debug parser and the debug2html converter. Still to do: + * + * * Debug message filtering. + * * I need to add all this to Makefile.in + * (If it looks at all strange I'll ask for help.) + * + * If you want to compile debug2html, you'll need to do it by hand until I + * make the changes to Makefile.in. Sorry. + * + * Chris -)----- * * ========================================================================== ** */ -#include "includes.h" - -/* -------------------------------------------------------------------------- ** - * Global values. - */ - -FILE *infile; -FILE *outfile; +#include "debugparse.h" /* -------------------------------------------------------------------------- ** * The size of the read buffer. @@ -81,7 +98,7 @@ static dbg_Token modechange( dbg_Token new, dbg_Token mode ) if( dbg_message != mode ) { /* Switching to message mode. */ - (void)fprintf( outfile, "
\n" );
+        (void)printf( "
\n" );
         return( dbg_message );
         }
       break;
@@ -89,7 +106,7 @@ static dbg_Token modechange( dbg_Token new, dbg_Token mode )
       if( dbg_message == mode )
         {
         /* Switching out of message mode. */
-        (void)fprintf( outfile, "
\n\n" ); + (void)printf( "
\n\n" ); return( dbg_null ); } } @@ -117,33 +134,29 @@ static void newblock( dbg_Token old, dbg_Token new ) switch( old ) { case dbg_timestamp: - (void)fprintf( outfile, ",
" ); + (void)printf( ",
" ); break; case dbg_level: - (void)fprintf( outfile, "]
\n " ); + (void)printf( "]
\n " ); break; case dbg_sourcefile: - (void)fprintf( outfile, ":" ); + (void)printf( ":" ); break; case dbg_lineno: - (void)fprintf( outfile, ")" ); - break; - default: + (void)printf( ")" ); break; } switch( new ) { case dbg_timestamp: - (void)fprintf( outfile, "[" ); + (void)printf( "[" ); break; case dbg_level: - (void)fprintf( outfile, " " ); + (void)printf( " " ); break; case dbg_lineno: - (void)fprintf( outfile, "(" ); - break; - default: + (void)printf( "(" ); break; } } /* newblock */ @@ -167,38 +180,41 @@ static void charprint( dbg_Token tok, int c ) break; case dbg_null: case dbg_eof: - (void)putc( '\n', outfile ); + (void)putchar( '\n' ); break; default: switch( c ) { case '<': - (void)fprintf( outfile, "<" ); + (void)printf( "<" ); break; case '>': - (void)fprintf( outfile, ">" ); + (void)printf( ">" ); break; case '&': - (void)fprintf( outfile, "&" ); + (void)printf( "&" ); break; case '\"': - (void)fprintf( outfile, """ ); + (void)printf( """ ); break; default: - (void)putc( c, outfile ); + (void)putchar( c ); break; } } } /* charprint */ -static void convert( void ) +int main( int argc, char *argv[] ) /* ------------------------------------------------------------------------ ** - * Read the input logfile, converting the entries to HTML. + * This simple program scans and parses Samba debug logs, and produces HTML + * output. + * + * Input: argc - Currently ignored. + * argv - Currently ignored. + * + * Output: Always zero. * - * Input: none. - * output: none. - * Notes: Reads from the global infile, writes to the global outfile. - * These default to stdin and stdout, respectively. + * Notes: The HTML output is sent to stdout. * * ------------------------------------------------------------------------ ** */ @@ -211,8 +227,12 @@ static void convert( void ) state = dbg_null, mode = dbg_null; - while( (!feof( infile )) - && ((len = fread( bufr, 1, DBG_BSIZE, infile )) > 0) ) + (void)printf( "\n" ); + (void)printf( "\n\n" ); + (void)printf( " Samba Debug Output\n\n\n\n" ); + + while( (!feof( stdin )) + && ((len = fread( bufr, 1, DBG_BSIZE, stdin )) > 0) ) { for( i = 0; i < len; i++ ) { @@ -228,94 +248,6 @@ static void convert( void ) } (void)modechange( dbg_eof, mode ); - } /* convert */ - -static void usage( void ) - /* ------------------------------------------------------------------------ ** - * Prints a usage message on stderr, then gently exits. - * - * Input: none. - * Output: none. Exits with return code of 0. - * - * ------------------------------------------------------------------------ ** - */ - { - fprintf( stderr, "This utility converts Samba log files " ); - fprintf( stderr, "into HTML documents.\n" ); - fprintf( stderr, "Usage:\n" ); - fprintf( stderr, " debug2html \n" ); - exit( 0 ); - } /* usage */ - -static FILE *carefull_fopen( const char *path, const char *type ) - /* ------------------------------------------------------------------------ ** - * Checks for leading '-' characters, which are generically regarded as - * flags. Also exits the program gracefully should the file fail to open. - * - * Input: path - pathname of the file to open. - * type - open mode. See fopen(3S). - * - * Output: Pointer to open file. - * - * ------------------------------------------------------------------------ ** - */ - { - FILE *tmp; - - if( '-' == path[0] || '\0' == path[0] ) - usage(); - - tmp = sys_fopen( path, type ); - if( NULL == tmp ) - { - fprintf( stderr, "Error opening file %s: %s\n", path, strerror(errno) ); - exit( 1 ); - } - return( tmp ); - } /* carefull_fopen */ - -int main( int argc, char *argv[] ) - /* ------------------------------------------------------------------------ ** - * This simple program scans and parses Samba debug logs, and produces HTML - * output. - * - * Input: argc - Argument count. - * argv[1] - Input file name. - * argv[2] - Output file name. - * A '-' character by itself means use defaults (i.e., - * or depending upon the argument. - * A string beginning with '-' and containing more than - * that one character will generate a usage message. - * - * Output: An exit value of 1 is returned if an error was encountered - * while opening a file, else 0. - * - * Notes: The HTML output is sent to stdout. - * - * ------------------------------------------------------------------------ ** - */ - { - if( argc > 3 ) - usage(); - - infile = stdin; - outfile = stdout; - - if( argc > 1 && 0 != strcmp( argv[1], "-" ) ) - infile = carefull_fopen( argv[1], "r" ); - - if( argc > 2 && 0 != strcmp( argv[2], "-" ) ) - infile = carefull_fopen( argv[2], "w" ); - - (void)fprintf( outfile, - "\n" ); - (void)fprintf( outfile, "\n\n" ); - (void)fprintf( outfile, - " Samba Log\n\n\n\n" ); - - convert(); - - (void)fprintf( outfile, "\n\n" ); - + (void)printf( "\n\n" ); return( 0 ); } /* main */ diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index 68b603bf1f..fc1f8ad781 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -176,6 +176,13 @@ static void lookup_strings(FILE *fichier) pointeur++; } } + + /* CCMRCF Mod, seg fault or worse if not found */ + if (pointeur == 0) { + fprintf(stderr,"Printer not found\tNo [Strings] block in inf file\n"); + exit(2); + } + #ifdef DEBUGIT fprintf(stderr,"\t\tFound %d entries\n",pointeur-1); #endif diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c index a57af2fc44..f0b68a7bae 100644 --- a/source3/utils/make_smbcodepage.c +++ b/source3/utils/make_smbcodepage.c @@ -3,7 +3,7 @@ Version 1.9. Create codepage files from codepage_def.XXX files. - Copyright (C) Jeremy Allison 1997-1998. + 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 @@ -62,7 +62,7 @@ static void read_line( char **buf, char *line_buf, int size) * Returns the number of lines copied. */ -static int clean_data( char **buf, uint32 *size) +static int clean_data( char **buf, size_t *size) { pstring linebuf; char *p = *buf; @@ -165,7 +165,7 @@ static void parse_error(char *buf, char *msg) static int do_compile(int codepage, char *input_file, char *output_file) { FILE *fp = NULL; - uint32 size = 0; + size_t size = 0; char *buf = NULL; char output_buf[CODEPAGE_HEADER_SIZE + 4 * MAXCODEPAGELINES]; int num_lines = 0; @@ -309,7 +309,7 @@ definition file. File %s has %d.\n", prog_name, MAXCODEPAGELINES, input_file, nu static int do_decompile( int codepage, char *input_file, char *output_file) { - uint32 size = 0; + size_t size = 0; SMB_STRUCT_STAT st; char header_buf[CODEPAGE_HEADER_SIZE]; char *buf = NULL; @@ -325,7 +325,7 @@ static int do_decompile( int codepage, char *input_file, char *output_file) exit(1); } - size = (uint32)st.st_size; + size = (size_t)st.st_size; if( size < CODEPAGE_HEADER_SIZE || size > (CODEPAGE_HEADER_SIZE + 256)) { diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index f920106f75..2f9bbc6c53 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -28,48 +28,37 @@ extern int DEBUGLEVEL; extern pstring scope; -extern pstring myhostname; extern struct in_addr ipzero; -int ServerFD= -1; - -BOOL RootPort = False; +static BOOL use_bcast = True; +static BOOL got_bcast = False; +static struct in_addr bcast_addr; +static BOOL recursion_desired = False; +static BOOL translate_addresses = False; +static int ServerFD= -1; +static int RootPort = 0; +static BOOL find_status=False; /**************************************************************************** open the socket communication **************************************************************************/ static BOOL open_sockets(void) { - if (RootPort) - { - ServerFD = open_socket_in( SOCK_DGRAM, - 137, - 3, - interpret_addr(lp_socket_address()) ); - - if (ServerFD == -1) - { - return(False); - } + ServerFD = open_socket_in( SOCK_DGRAM, + (RootPort ? 137 :0), + 3, + interpret_addr(lp_socket_address()), True ); - set_socket_options(ServerFD,"SO_BROADCAST"); - DEBUG(3, ("Socket opened.\n")); - } - return True; -} - - -/**************************************************************************** - initialise connect, service and file structs -****************************************************************************/ -static BOOL init_structs(void ) -{ - if (!get_myname(myhostname,NULL)) + if (ServerFD == -1) return(False); + set_socket_options(ServerFD,"SO_BROADCAST"); + + DEBUG(3, ("Socket opened.\n")); return True; } + /**************************************************************************** usage on the program ****************************************************************************/ @@ -83,15 +72,70 @@ static void usage(void) printf("\t-M searches for a master browser\n"); printf("\t-R set recursion desired in packet\n"); printf("\t-S lookup node status as well\n"); + printf("\t-T translate IP addresses into names\n"); printf("\t-r Use root port 137 (Win95 only replies to this)\n"); printf("\t-A Do a node status on as an IP Address\n"); printf("\t-i NetBIOS scope Use the given NetBIOS scope for name queries\n"); printf("\t-s smb.conf file Use the given path to the smb.conf file\n"); printf("\t-h Print this help message.\n"); + printf("\n If you specify -M and name is \"-\", nmblookup looks up __MSBROWSE__<01>\n"); printf("\n"); } +/**************************************************************************** +send out one query +****************************************************************************/ +static BOOL query_one(char *lookup, unsigned int lookup_type) +{ + int j, count; + struct in_addr *ip_list=NULL; + + if (got_bcast) { + printf("querying %s on %s\n", lookup, inet_ntoa(bcast_addr)); + ip_list = name_query(ServerFD,lookup,lookup_type,use_bcast, + use_bcast?True:recursion_desired, + bcast_addr,&count,NULL); + } else { + struct in_addr *bcast; + for (j=iface_count() - 1; + !ip_list && j >= 0; + j--) { + bcast = iface_n_bcast(j); + printf("querying %s on %s\n", + lookup, inet_ntoa(*bcast)); + ip_list = name_query(ServerFD,lookup,lookup_type, + use_bcast, + use_bcast?True:recursion_desired, + *bcast,&count,NULL); + } + } + + if (!ip_list) return False; + + for (j=0;j h_name); + } + } + printf("%s %s<%02x>\n",inet_ntoa(ip_list[j]),lookup, lookup_type); + } + + /* We can only do find_status if the ip address returned + was valid - ie. name_query returned true. + */ + if (find_status) { + printf("Looking up status of %s\n",inet_ntoa(ip_list[0])); + name_status(ServerFD,lookup,lookup_type,True,ip_list[0],NULL,NULL,NULL); + printf("\n"); + } + + return (ip_list != NULL); +} + + /**************************************************************************** main program ****************************************************************************/ @@ -103,14 +147,10 @@ int main(int argc,char *argv[]) extern int optind; extern char *optarg; BOOL find_master=False; - BOOL find_status=False; int i; static pstring servicesf = CONFIGFILE; - struct in_addr bcast_addr; - BOOL use_bcast = True; - BOOL got_bcast = False; BOOL lookup_by_ip = False; - BOOL recursion_desired = False; + int commandline_debuglevel = -2; DEBUGLEVEL = 1; *lookup = 0; @@ -121,21 +161,22 @@ int main(int argc,char *argv[]) charset_initialise(); - while ((opt = getopt(argc, argv, "d:B:U:i:s:SMrhAR")) != EOF) + while ((opt = getopt(argc, argv, "d:B:U:i:s:SMrhART")) != EOF) switch (opt) { case 'B': - iface_set_default(NULL,optarg,NULL); bcast_addr = *interpret_addr2(optarg); got_bcast = True; use_bcast = True; break; case 'U': - iface_set_default(NULL,optarg,NULL); bcast_addr = *interpret_addr2(optarg); got_bcast = True; use_bcast = False; break; + case 'T': + translate_addresses = !translate_addresses; + break; case 'i': fstrcpy(scope,optarg); strupper(scope); @@ -150,13 +191,13 @@ int main(int argc,char *argv[]) recursion_desired = True; break; case 'd': - DEBUGLEVEL = atoi(optarg); + commandline_debuglevel = DEBUGLEVEL = atoi(optarg); break; case 's': pstrcpy(servicesf, optarg); break; case 'r': - RootPort = True; + RootPort = -1; break; case 'h': usage(); @@ -175,27 +216,25 @@ int main(int argc,char *argv[]) exit(1); } - init_structs(); - if (!lp_load(servicesf,True,False,False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); } - load_interfaces(); - if (!open_sockets()) return(1); - - if (!got_bcast) - bcast_addr = *iface_bcast(ipzero); + /* + * Ensure we reset DEBUGLEVEL if someone specified it + * on the command line. + */ - DEBUG(1,("Sending queries to %s\n",inet_ntoa(bcast_addr))); + if(commandline_debuglevel != -2) + DEBUGLEVEL = commandline_debuglevel; + load_interfaces(); + if (!open_sockets()) return(1); for (i=optind;i\n",inet_ntoa(ip_list[j]),lookup, lookup_type); - - /* We can only do find_status if the ip address returned - was valid - ie. name_query returned true. - */ - if (find_status) { - printf("Looking up status of %s\n",inet_ntoa(ip_list[0])); - name_status(ServerFD,lookup,lookup_type,True,ip_list[0],NULL,NULL,NULL); - printf("\n"); - } - } else { + if (!query_one(lookup, lookup_type)) { printf("name_query failed to find name %s\n", lookup); } } diff --git a/source3/utils/rpctorture.c b/source3/utils/rpctorture.c index 0933cf38c1..fb08d70011 100644 --- a/source3/utils/rpctorture.c +++ b/source3/utils/rpctorture.c @@ -49,61 +49,16 @@ struct cli_state *smb_cli = &smbcli; FILE *out_hnd; -static pstring user_name; /* local copy only, if one is entered */ static pstring password; /* local copy only, if one is entered */ -static pstring domain; /* local copy only, if one is entered */ -BOOL got_pass = False; - -static struct nmb_name calling; -static struct nmb_name called; - -static void get_passwd(void) -{ - /* set the password cache info */ - if (got_pass) - { - if (password[0] == 0) - { - pwd_set_nullpwd(&(smb_cli->pwd)); - } - else - { - pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ - } - } - else - { - char *pwd = getpass("Enter Password:"); - safe_strcpy(password, pwd, sizeof(password)); - pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ - got_pass = True; - } -} /**************************************************************************** initialise smb client structure ****************************************************************************/ void rpcclient_init(void) { - bzero(smb_cli, sizeof(smb_cli)); + memset((char *)smb_cli, '\0', sizeof(smb_cli)); cli_initialise(smb_cli); smb_cli->capabilities |= CAP_NT_SMBS; - smb_cli->capabilities |= CAP_STATUS32; - - pstrcpy(smb_cli->user_name, user_name); - - get_passwd(); - - if (*domain == 0) - { - pstrcpy(smb_cli->domain,lp_workgroup()); - } - else - { - pstrcpy(smb_cli->domain, domain); - } - - strupper(smb_cli->domain); } /**************************************************************************** @@ -111,9 +66,11 @@ make smb client connection ****************************************************************************/ static BOOL rpcclient_connect(struct client_info *info) { - rpcclient_init(); + struct nmb_name calling; + struct nmb_name called; - smb_cli->use_ntlmv2 = lp_client_ntlmv2(); + make_nmb_name(&called , dns_to_netbios_name(info->dest_host ), info->name_type, scope); + make_nmb_name(&calling, dns_to_netbios_name(info->myhostname), 0x0 , scope); if (!cli_establish_connection(smb_cli, info->dest_host, &info->dest_ip, @@ -140,7 +97,7 @@ static void rpcclient_stop(void) /**************************************************************************** log in as an nt user, log out again. ****************************************************************************/ -void run_enums_test(int num_ops, struct client_info *cli_info) +void run_enums_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) { pstring cmd; int i; @@ -148,8 +105,8 @@ void run_enums_test(int num_ops, struct client_info *cli_info) /* establish connections. nothing to stop these being re-established. */ rpcclient_connect(cli_info); - DEBUG(5,("rpcclient_connect: smb_cli->fd:%d\n", smb_cli->fd)); - if (smb_cli->fd <= 0) + DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd)); + if (cli->fd <= 0) { fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n", cli_info->dest_host, cli_info->name_type); @@ -184,7 +141,7 @@ void run_enums_test(int num_ops, struct client_info *cli_info) /**************************************************************************** log in as an nt user, log out again. ****************************************************************************/ -void run_ntlogin_test(int num_ops, struct client_info *cli_info) +void run_ntlogin_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) { pstring cmd; int i; @@ -192,8 +149,8 @@ void run_ntlogin_test(int num_ops, struct client_info *cli_info) /* establish connections. nothing to stop these being re-established. */ rpcclient_connect(cli_info); - DEBUG(5,("rpcclient_connect: smb_cli->fd:%d\n", smb_cli->fd)); - if (smb_cli->fd <= 0) + DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd)); + if (cli->fd <= 0) { fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n", cli_info->dest_host, cli_info->name_type); @@ -202,7 +159,7 @@ void run_ntlogin_test(int num_ops, struct client_info *cli_info) for (i = 0; i < num_ops; i++) { - slprintf(cmd, sizeof(cmd)-1, "%s %s", smb_cli->user_name, password); + slprintf(cmd, sizeof(cmd)-1, "%s %s", cli->user_name, password); set_first_token(cmd); cmd_netlogon_login_test(cli_info); @@ -212,382 +169,12 @@ void run_ntlogin_test(int num_ops, struct client_info *cli_info) } -/* generate a random buffer */ -static void rand_buf(char *buf, int len) -{ - while (len--) { - *buf = sys_random(); - buf++; - } -} - -/**************************************************************************** -do a random rpc command -****************************************************************************/ -BOOL do_random_rpc(struct cli_state *cli, uint16 nt_pipe_fnum, int max_len) -{ - prs_struct rbuf; - prs_struct buf; - uint8 opcode; - int param_len; - BOOL response = False; - - if ((sys_random() % 20) == 0) - { - param_len = (sys_random() % 256) + 4; - } - else - { - param_len = (sys_random() % max_len) + 4; - } - - prs_init(&buf , param_len, 4, SAFETY_MARGIN, False); - prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True ); - - opcode = sys_random() % 256; - - /* turn parameters into data stream */ - rand_buf(mem_data(&buf.data, 0), param_len); - buf.offset = param_len; - - /* send the data on \PIPE\ */ - if (rpc_api_pipe_req(cli, nt_pipe_fnum, opcode, &buf, &rbuf)) - { - response = rbuf.offset != 0; - - if (response) - { - DEBUG(0,("response! opcode: 0x%x\n", opcode)); - DEBUG(0,("request: length %d\n", param_len)); - dump_data(0, mem_data(&buf.data , 0), MIN(param_len, 128)); - DEBUG(0,("response: length %d\n", rbuf.data->offset.end)); - dump_data(0, mem_data(&rbuf.data, 0), rbuf.data->offset.end); - } - } - - prs_mem_free(&rbuf); - prs_mem_free(&buf ); - - return response; -} - - -/* send random IPC commands */ -static void random_rpc_pipe_enc(char *pipe_name, struct client_info *cli_info, - int numops) -{ - uint16 nt_pipe_fnum; - int i; - - DEBUG(0,("starting random rpc test on %s (encryped)\n", pipe_name)); - - /* establish connections. nothing to stop these being re-established. */ - if (!rpcclient_connect(cli_info)) - { - DEBUG(0,("random rpc test: connection failed\n")); - return; - } - - cli_nt_set_ntlmssp_flgs(smb_cli, - NTLMSSP_NEGOTIATE_UNICODE | - NTLMSSP_NEGOTIATE_OEM | - NTLMSSP_NEGOTIATE_SIGN | - NTLMSSP_NEGOTIATE_SEAL | - NTLMSSP_NEGOTIATE_LM_KEY | - NTLMSSP_NEGOTIATE_NTLM | - NTLMSSP_NEGOTIATE_ALWAYS_SIGN | - NTLMSSP_NEGOTIATE_00001000 | - NTLMSSP_NEGOTIATE_00002000); - - for (i = 1; i <= numops * 100; i++) - { - /* open session. */ - cli_nt_session_open(smb_cli, pipe_name, &nt_pipe_fnum); - - do_random_rpc(smb_cli, nt_pipe_fnum, 1024); - if (i % 500 == 0) - { - DEBUG(0,("calls: %i\n", i)); - } - - /* close the session */ - cli_nt_session_close(smb_cli, nt_pipe_fnum); - } - - /* close the rpc pipe */ - rpcclient_stop(); - - DEBUG(0,("finished random rpc test on %s\n", pipe_name)); -} - -/* send random IPC commands */ -static void random_rpc_pipe(char *pipe_name, struct client_info *cli_info, - int numops) -{ - uint16 nt_pipe_fnum; - int i; - - DEBUG(0,("starting random rpc test on %s\n", pipe_name)); - - /* establish connections. nothing to stop these being re-established. */ - if (!rpcclient_connect(cli_info)) - { - DEBUG(0,("random rpc test: connection failed\n")); - return; - } - - /* open session. */ - if (!cli_nt_session_open(smb_cli, pipe_name, &nt_pipe_fnum)) - { - DEBUG(0,("random rpc test: session open failed\n")); - return; - } - - for (i = 1; i <= numops * 100; i++) - { - do_random_rpc(smb_cli, nt_pipe_fnum, 8192); - if (i % 500 == 0) - { - DEBUG(0,("calls: %i\n", i)); - } - } - - /* close the session */ - cli_nt_session_close(smb_cli, nt_pipe_fnum); - - /* close the rpc pipe */ - rpcclient_stop(); - - DEBUG(0,("finished random rpc test on %s\n", pipe_name)); -} - -static void run_randomrpc(int numops, struct client_info *cli_info) -{ - char *pipes[] = - { - PIPE_SAMR , - PIPE_WINREG , - PIPE_SRVSVC , - PIPE_WKSSVC , - PIPE_NETLOGON , - PIPE_NTSVCS , - PIPE_LSARPC , - NULL - }; - - int i = 0; - - while (pipes[i] != NULL) - { - random_rpc_pipe(pipes[i], cli_info, numops); -#if 0 - random_rpc_pipe_enc(pipes[i], cli_info, numops); -#endif - - i++; - } -} - - -static void run_samhandles(int numops, struct client_info *cli_info) -{ - uint16 nt_pipe_fnum; - int i; - int count = 0; - int failed = 0; - int retry = 500; - fstring srv_name; - fstrcpy(srv_name, "\\\\"); - fstrcat(srv_name, cli_info->dest_host); - strupper(srv_name); - - DEBUG(0,("starting sam handle test\n")); - - /* establish connections. nothing to stop these being re-established. */ - while (retry > 0 && !rpcclient_connect(cli_info)) - { - retry--; - } - - if (retry == 0) - { - DEBUG(0,("samhandle test: connection failed\n")); - return; - } - - /* open session. */ - if (!cli_nt_session_open(smb_cli, PIPE_SAMR, &nt_pipe_fnum)) - { - DEBUG(0,("samhandle test: session open failed\n")); - return; - } - - for (i = 1; i <= numops * 100; i++) - { - POLICY_HND pol; - POLICY_HND dom; - if (!samr_connect(smb_cli, nt_pipe_fnum, srv_name, 0x20, &pol)) - { - failed++; - } -/* - if (!samr_open_domain(smb_cli, nt_pipe_fnum, srv_name, 0x00000020, &pol)) - { - DEBUG(0,("samhandle domain open test (%i): failed\n", i)); - } - */ - if (i % 500 == 0) - { - DEBUG(0,("calls: %i\n", i)); - } - count++; - } - - /* close the session */ - cli_nt_session_close(smb_cli, nt_pipe_fnum); - - /* close the rpc pipe */ - rpcclient_stop(); - - DEBUG(0,("finished samhandle test. count: %d failed: %d\n", count, failed)); -} - - -static void run_lsahandles(int numops, struct client_info *cli_info) -{ - uint16 nt_pipe_fnum; - int i; - int count = 0; - int failed = 0; - int retry = 500; - fstring srv_name; - fstrcpy(srv_name, "\\\\"); - fstrcat(srv_name, cli_info->myhostname); - strupper(srv_name); - - DEBUG(0,("starting lsa handle test\n")); - - /* establish connections. nothing to stop these being re-established. */ - while (retry > 0 && !rpcclient_connect(cli_info)) - { - retry--; - } - - if (retry == 0) - { - DEBUG(0,("lsahandle test: connection failed\n")); - return; - } - for (i = 1; i <= numops * 100; i++) - { - extern struct cli_state *rpc_smb_cli; - rpc_smb_cli = smb_cli; - POLICY_HND pol; - if (!lsa_open_policy(srv_name, &pol, False)) - { - failed++; - } - if (i % 500 == 0) - { - DEBUG(0,("calls: %i\n", i)); - } - count++; - } - - /* close the rpc pipe */ - rpcclient_stop(); - - DEBUG(0,("finished lsahandle test. count: %d failed: %d\n", count, failed)); -} - - -static void run_pipegobble(int numops, struct client_info *cli_info, char *pipe_name) -{ - uint16 nt_pipe_fnum; - int i; - int count = 0; - int failed = 0; - int retry = 500; - fstring srv_name; - fstrcpy(srv_name, "\\\\"); - fstrcat(srv_name, cli_info->myhostname); - strupper(srv_name); - - DEBUG(0,("starting pipe gobble test (%s)\n", pipe_name)); - - /* establish connections. nothing to stop these being re-established. */ - while (retry > 0 && !rpcclient_connect(cli_info)) - { - retry--; - } - - if (retry == 0) - { - DEBUG(0,("pipe gobble test: connection failed\n")); - return; - } - for (i = 1; i <= numops * 100; i++) - { - /* open session. */ - if (!cli_nt_session_open(smb_cli, pipe_name, &nt_pipe_fnum)) - { - DEBUG(0,("pipe gobble test: session open failed\n")); - } - - if (i % 500 == 0) - { - DEBUG(0,("calls: %i\n", i)); - } - count++; - } - - rpcclient_stop(); - - DEBUG(0,("finished pipe gobble test (%s). count: %d failed: %d\n", - pipe_name, count, failed)); -} - - -static void run_handles(int numops, struct client_info *cli_info) -{ - run_lsahandles(numops, cli_info); - run_samhandles(numops, cli_info); -} - -static void run_pipegobbler(int numops, struct client_info *cli_info) -{ - run_pipegobble(numops, cli_info, PIPE_SAMR); - run_pipegobble(numops, cli_info, PIPE_LSARPC); -} - -/**************************************************************************** -make tcp connection -****************************************************************************/ -static void run_tcpconnect(int numops, struct client_info *info) -{ - int i; - int failed = 0; - - for (i = 0; i < numops; i++) - { - rpcclient_init(); - - if (!cli_connect(smb_cli, info->dest_host, &info->dest_ip)) - { - failed++; - } - cli_shutdown(smb_cli); - } - - DEBUG(0,("tcp connections: count: %d failed: %d\n", numops, failed)); -} - /**************************************************************************** runs n simultaneous functions. ****************************************************************************/ static void create_procs(int nprocs, int numops, - struct client_info *cli_info, - void (*fn)(int, struct client_info *)) + struct client_info *cli_info, struct cli_state *cli, + void (*fn)(int, struct client_info *, struct cli_state *)) { int i, status; @@ -595,10 +182,10 @@ static void create_procs(int nprocs, int numops, { if (fork() == 0) { - int mypid = getpid(); + pid_t mypid = getpid(); sys_srandom(mypid ^ time(NULL)); - fn(numops, cli_info); - dbgflush(); + fn(numops, cli_info, cli); + fflush(out_hnd); _exit(0); } } @@ -608,8 +195,6 @@ static void create_procs(int nprocs, int numops, waitpid(0, &status, 0); } } - - /**************************************************************************** usage on the program - OUT OF DATE! ****************************************************************************/ @@ -628,8 +213,6 @@ static void usage(char *pname) fprintf(out_hnd, "\t-U username set the network username\n"); fprintf(out_hnd, "\t-W workgroup set the workgroup name\n"); fprintf(out_hnd, "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n"); - fprintf(out_hnd, "\t-N processes number of processes\n"); - fprintf(out_hnd, "\t-o operations number of operations\n"); fprintf(out_hnd, "\n"); } @@ -652,6 +235,7 @@ enum client_action extern int optind; static pstring servicesf = CONFIGFILE; pstring term_code; + BOOL got_pass = False; char *cmd_str=""; mode_t myumask = 0755; enum client_action cli_action = CLIENT_NONE; @@ -662,6 +246,8 @@ enum client_action out_hnd = stdout; + rpcclient_init(); + #ifdef KANJI pstrcpy(term_code, KANJI); #else /* KANJI */ @@ -699,6 +285,8 @@ enum client_action pstrcpy(cli_info.cur_dir , "\\"); pstrcpy(cli_info.file_sel, ""); pstrcpy(cli_info.base_dir, ""); + pstrcpy(smb_cli->domain, ""); + pstrcpy(smb_cli->user_name, ""); pstrcpy(cli_info.myhostname, ""); pstrcpy(cli_info.dest_host, ""); @@ -711,6 +299,7 @@ enum client_action ZERO_STRUCT(cli_info.dom.level5_sid); pstrcpy(cli_info.dom.level5_dom, ""); + smb_cli->nt_pipe_fnum = 0xffff; setup_logging(pname, True); @@ -720,7 +309,7 @@ enum client_action myumask = umask(0); umask(myumask); - if (!get_myname(global_myname, NULL)) + if (!get_myname(global_myname)) { fprintf(stderr, "Failed to get my hostname.\n"); } @@ -771,7 +360,7 @@ enum client_action cli_action = CLIENT_SVC; } - while ((opt = getopt(argc, argv,"s:B:O:M:S:i:N:o:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF) + while ((opt = getopt(argc, argv,"s:O:M:S:i:N:o:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF) { switch (opt) { @@ -799,12 +388,6 @@ enum client_action break; } - case 'B': - { - iface_set_default(NULL,optarg,NULL); - break; - } - case 'i': { pstrcpy(scope, optarg); @@ -814,8 +397,8 @@ enum client_action case 'U': { char *lp; - pstrcpy(user_name,optarg); - if ((lp=strchr(user_name,'%'))) + pstrcpy(smb_cli->user_name,optarg); + if ((lp=strchr(smb_cli->user_name,'%'))) { *lp = 0; pstrcpy(password,lp+1); @@ -827,7 +410,7 @@ enum client_action case 'W': { - pstrcpy(domain,optarg); + pstrcpy(smb_cli->domain,optarg); break; } @@ -925,7 +508,13 @@ enum client_action strupper(global_myname); fstrcpy(cli_info.myhostname, global_myname); - DEBUG(3,("%s client started (version %s)\n",timestring(),VERSION)); + DEBUG(3,("%s client started (version %s)\n",timestring(False),VERSION)); + + if (*smb_cli->domain == 0) + { + pstrcpy(smb_cli->domain,lp_workgroup()); + } + strupper(smb_cli->domain); load_interfaces(); @@ -939,25 +528,31 @@ enum client_action strupper(cli_info.mach_acct); fstrcat(cli_info.mach_acct, "$"); - make_nmb_name(&called , dns_to_netbios_name(cli_info.dest_host ), cli_info.name_type, scope); - make_nmb_name(&calling, dns_to_netbios_name(cli_info.myhostname), 0x0 , scope); + /* set the password cache info */ + if (got_pass) + { + if (password[0] == 0) + { + pwd_set_nullpwd(&(smb_cli->pwd)); + } + else + { + pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ + } + } + else + { + char *pwd = getpass("Enter Password:"); + safe_strcpy(password, pwd, sizeof(password)); + pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ + } - get_passwd(); -/* - create_procs(nprocs, numops, &cli_info, run_enums_test); + create_procs(nprocs, numops, &cli_info, smb_cli, run_enums_test); if (password[0] != 0) { - create_procs(nprocs, numops, &cli_info, run_ntlogin_test); + create_procs(nprocs, numops, &cli_info, smb_cli, run_ntlogin_test); } -*/ - -/* - create_procs(nprocs, numops, &cli_info, run_randomrpc); - create_procs(nprocs, numops, &cli_info, run_pipegobbler); - create_procs(nprocs, numops, &cli_info, run_tcpconnect); -*/ - create_procs(nprocs, numops, &cli_info, run_handles); fflush(out_hnd); diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c index 643a3ed2ce..81b10e4519 100644 --- a/source3/utils/smbfilter.c +++ b/source3/utils/smbfilter.c @@ -120,7 +120,7 @@ static void filter_child(int c, struct in_addr dest_ip) if (s != -1) FD_SET(s, &fds); if (c != -1) FD_SET(c, &fds); - num = sys_select(MAX(s+1, c+1),&fds,NULL, NULL); + num = sys_select(MAX(s+1, c+1),&fds,NULL); if (num <= 0) continue; if (c != -1 && FD_ISSET(c, &fds)) { @@ -159,7 +159,7 @@ static void start_filter(char *desthost) CatchChild(); /* start listening on port 139 locally */ - s = open_socket_in(SOCK_STREAM, 139, 0, 0); + s = open_socket_in(SOCK_STREAM, 139, 0, 0, True); if (s == -1) { DEBUG(0,("bind failed\n")); @@ -184,7 +184,7 @@ static void start_filter(char *desthost) FD_ZERO(&fds); FD_SET(s, &fds); - num = sys_select(s+1,&fds,NULL, NULL); + num = sys_select(s+1,&fds,NULL); if (num > 0) { c = accept(s, &addr, &in_addrlen); if (c != -1) { diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 3b87687c26..ec6ce15f07 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -1,7 +1,6 @@ /* - * Unix SMB/Netbios implementation. Version 1.9. smbpasswd module. - * Copyright (C) Jeremy Allison 1995-1999 - * Copyright (C) Luke Kenneth Casson Leighton 1996-1999 + * Unix SMB/Netbios implementation. Version 1.9. smbpasswd module. Copyright + * (C) Jeremy Allison 1995-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 @@ -20,9 +19,7 @@ #include "includes.h" -extern pstring myhostname; extern pstring global_myname; -extern pstring global_myworkgroup; extern int DEBUGLEVEL; /* @@ -65,135 +62,85 @@ static void usage(void) if (getuid() == 0) { printf(" -R ORDER name resolve order\n"); printf(" -j DOMAIN join domain name\n"); - printf(" -S synchronise with PDC (if we are BDC)\n"); printf(" -a add user\n"); printf(" -d disable user\n"); printf(" -e enable user\n"); printf(" -n set no password\n"); - printf(" -m workstation trust account\n"); - printf(" -b backup domain controller account\n"); - printf(" -i inter-domain trust account\n"); - printf(" -p user cannot change password\n"); - printf(" -x user can change password\n"); + printf(" -m machine trust account\n"); } - exit(1); } /********************************************************* Join a domain. **********************************************************/ -static int create_interdomain_trust_acct(char *domain, char *name) +static int join_domain(char *domain, char *remote) { + pstring remote_machine; fstring trust_passwd; - unsigned char hash[16]; - uint16 sec_chan; - - switch (lp_server_role()) - { - case ROLE_DOMAIN_PDC: - { - DEBUG(0, ("Joining domain - we are PDC\n")); - sec_chan = SEC_CHAN_DOMAIN; - break; - } - case ROLE_DOMAIN_BDC: - { - DEBUG(0, ("Cannot set up inter-domain trust as BDC!\n")); - return 1; - } - default: - { - DEBUG(0, ("Cannot set up inter-domain trust as workstation!\n")); - return 1; - } - } + unsigned char orig_trust_passwd_hash[16]; + BOOL ret; + + pstrcpy(remote_machine, remote ? remote : ""); + fstrcpy(trust_passwd, global_myname); + strlower(trust_passwd); + E_md4hash( (uchar *)trust_passwd, orig_trust_passwd_hash); -#if 0 - pstrcpy(remote_machine, remote ? remote : lp_passwordserver()); + /* Ensure that we are not trying to join a + domain if we are locally set up as a domain + controller. */ - if (!remote_machine[0]) - { - fprintf(stderr, "You must specify the PDC via 'password server' or -r."); + if(strequal(remote, global_myname)) { + fprintf(stderr, "Cannot join domain %s as the domain controller name is our own. We cannot be a domain controller for a domain and also be a domain member.\n", domain); return 1; } -#endif - fstrcpy(trust_passwd, name); - strlower(trust_passwd); - E_md4hash( (uchar *)trust_passwd, hash); - - if (!create_trust_account_file(domain, name, hash)) - { + /* + * Create the machine account password file. + */ + if(!trust_password_lock( domain, global_myname, True)) { + fprintf(stderr, "Unable to open the machine account password file for \ +machine %s in domain %s.\n", global_myname, domain); return 1; } + + /* + * Write the old machine account password. + */ -#if 0 - if(!change_trust_account_password(domain, remote_machine, sec_chan)) - { - fprintf(stderr,"Unable to join domain %s.\n",domain); + if(!set_trust_account_password( orig_trust_passwd_hash)) { + fprintf(stderr, "Unable to write the machine account password for \ +machine %s in domain %s.\n", global_myname, domain); + trust_password_unlock(); return 1; } -#endif - printf("Created Inter-Domain Trust Account for %s.\n",domain); - return 0; -} - -/********************************************************* -Join a domain. -**********************************************************/ -static int join_domain(char *domain, char *remote) -{ - pstring remote_machine; - fstring trust_passwd; - unsigned char orig_trust_passwd_hash[16]; - uint16 sec_chan; - - switch (lp_server_role()) - { - case ROLE_DOMAIN_PDC: - { - DEBUG(0, ("Cannot join domain - we are PDC!\n")); - return 1; - } - case ROLE_DOMAIN_BDC: - { - DEBUG(0, ("Joining Domain as BDC\n")); - sec_chan = SEC_CHAN_BDC; - break; - } - default: - { - DEBUG(0, ("Joining Domain as Workstation\n")); - sec_chan = SEC_CHAN_WKSTA; - } + + /* + * If we are given a remote machine assume this is the PDC. + */ + + if(remote == NULL) { + pstrcpy(remote_machine, lp_passwordserver()); } - pstrcpy(remote_machine, remote ? remote : lp_passwordserver()); - - if (!remote_machine[0]) - { - fprintf(stderr, "You must specify the PDC via 'password server' or -r."); + if(!*remote_machine) { + fprintf(stderr, "No password server list given in smb.conf - \ +unable to join domain.\n"); + trust_password_unlock(); return 1; } - fstrcpy(trust_passwd, global_myname); - strlower(trust_passwd); - E_md4hash( (uchar *)trust_passwd, orig_trust_passwd_hash); - - if (!create_trust_account_file(domain, global_myname, trust_passwd)) - { - return 1; - } + ret = change_trust_account_password( domain, remote_machine); + trust_password_unlock(); - if(!change_trust_account_password(domain, remote_machine, sec_chan)) - { + if(!ret) { + trust_password_delete( domain, global_myname); fprintf(stderr,"Unable to join domain %s.\n",domain); - return 1; + } else { + printf("Joined domain %s.\n",domain); } - - printf("Joined domain %s.\n",domain); - return 0; + + return (int)ret; } @@ -262,6 +209,7 @@ static char *prompt_for_new_password(BOOL stdin_get) if (strcmp(p, new_passwd)) { fprintf(stderr, "Mismatch - password unchanged.\n"); + ZERO_ARRAY(new_passwd); return NULL; } @@ -273,47 +221,35 @@ static char *prompt_for_new_password(BOOL stdin_get) change a password either locally or remotely *************************************************************/ static BOOL password_change(const char *remote_machine, char *user_name, - char *old_passwd, char *new_passwd, - BOOL add_user, - uint16 acb_info, uint16 acb_mask) + char *old_passwd, char *new_passwd, + BOOL add_user, BOOL enable_user, + BOOL disable_user, BOOL set_no_password, + BOOL trust_account) { BOOL ret; pstring err_str; pstring msg_str; - if (remote_machine != NULL) - { - if (add_user || - IS_BITS_SET_SOME(acb_info, ACB_PWNOTREQ | ACB_WSTRUST | ACB_DOMTRUST | ACB_SVRTRUST) || - (IS_BITS_SET_SOME(acb_mask, ACB_DISABLED) && - IS_BITS_CLR_ALL(acb_info, ACB_DISABLED))) - { + if (remote_machine != NULL) { + if (add_user || enable_user || disable_user || set_no_password || trust_account) { /* these things can't be done remotely yet */ return False; } ret = remote_password_change(remote_machine, user_name, - old_passwd, new_passwd, - err_str, sizeof(err_str)); - if (*err_str != 0) - { + old_passwd, new_passwd, err_str, sizeof(err_str)); + if(*err_str) fprintf(stderr, err_str); - } return ret; } - ret = local_password_change(user_name, add_user, acb_info, acb_mask, - new_passwd, - err_str, sizeof(err_str), - msg_str, sizeof(msg_str)); + ret = local_password_change(user_name, trust_account, add_user, enable_user, + disable_user, set_no_password, new_passwd, + err_str, sizeof(err_str), msg_str, sizeof(msg_str)); - if (*msg_str != 0) - { + if(*msg_str) printf(msg_str); - } - if (*err_str != 0) - { + if(*err_str) fprintf(stderr, err_str); - } return ret; } @@ -326,156 +262,80 @@ static int process_root(int argc, char *argv[]) { struct passwd *pwd; int ch; - uint16 acb_info = 0; - uint16 acb_mask = 0; BOOL joining_domain = False; - BOOL sam_sync = False; - BOOL wks_trust_account = False; - BOOL srv_trust_account = False; - BOOL dom_trust_account = False; + BOOL trust_account = False; BOOL add_user = False; BOOL disable_user = False; BOOL enable_user = False; BOOL set_no_password = False; BOOL stdin_passwd_get = False; - BOOL lock_password = False; - BOOL unlock_password = False; char *user_name = NULL; char *new_domain = NULL; char *new_passwd = NULL; char *old_passwd = NULL; char *remote_machine = NULL; - int ret; - - while ((ch = getopt(argc, argv, "abdehimnpxj:Sr:sR:D:U:")) != EOF) - { - switch(ch) - { - case 'a': - { - add_user = True; - break; - } - case 'd': - { - disable_user = True; - new_passwd = "XXXXXX"; - break; - } - case 'e': - { - enable_user = True; - break; - } - case 'D': - { - DEBUGLEVEL = atoi(optarg); - break; - } - case 'n': - { - set_no_password = True; - new_passwd = "NO PASSWORD"; - } - case 'r': - { - remote_machine = optarg; - break; - } - case 's': - { - set_line_buffering(stdin); - set_line_buffering(stdout); - set_line_buffering(stderr); - stdin_passwd_get = True; - break; - } - case 'R': - { - lp_set_name_resolve_order(optarg); - break; - } - case 'i': - { - dom_trust_account = True; - break; - } - case 'b': - { - srv_trust_account = True; - break; - } - case 'm': - { - wks_trust_account = True; - break; - } - case 'j': - { - new_domain = optarg; - strupper(new_domain); - joining_domain = True; - break; - } - case 'S': - { - sam_sync = True; - break; - } - case 'U': - { - user_name = optarg; - break; - } - case 'p': - { - lock_password = True; - break; - } - case 'x': - { - unlock_password = True; - break; - } - default: - { - usage(); - } + + while ((ch = getopt(argc, argv, "adehmnj:r:sR:D:U:")) != EOF) { + switch(ch) { + case 'a': + add_user = True; + break; + case 'd': + disable_user = True; + new_passwd = "XXXXXX"; + break; + case 'e': + enable_user = True; + break; + case 'D': + DEBUGLEVEL = atoi(optarg); + break; + case 'n': + set_no_password = True; + new_passwd = "NO PASSWORD"; + case 'r': + remote_machine = optarg; + break; + case 's': + set_line_buffering(stdin); + set_line_buffering(stdout); + set_line_buffering(stderr); + stdin_passwd_get = True; + break; + case 'R': + lp_set_name_resolve_order(optarg); + break; + case 'm': + trust_account = True; + break; + case 'j': + new_domain = optarg; + strupper(new_domain); + joining_domain = True; + break; + case 'U': + user_name = optarg; + break; + default: + usage(); } } argc -= optind; argv += optind; + /* * Ensure add_user and either remote machine or join domain are * not both set. */ - if (add_user && ((remote_machine != NULL) || joining_domain)) - { + if(add_user && ((remote_machine != NULL) || joining_domain)) { usage(); } - - if (sam_sync && lp_server_role() != ROLE_DOMAIN_BDC) { - fprintf(stderr, "The -S option can only be used on a Backup Domain Controller.\n"); - return 1; - } - if (joining_domain) - { - if (!dom_trust_account) - { - if (argc != 0) usage(); - ret = join_domain(new_domain, remote_machine); - - if ((ret != 0) || (!sam_sync)) - return ret; - } - } - - if (sam_sync) - { - return synchronise_passdb(); + if(joining_domain) { + if (argc != 0) usage(); + return join_domain(new_domain, remote_machine); } /* @@ -496,7 +356,7 @@ static int process_root(int argc, char *argv[]) usage(); } - if (!user_name && (pwd = getpwuid(0))) { + if (!user_name && (pwd = sys_getpwuid(0))) { user_name = xstrdup(pwd->pw_name); } @@ -505,8 +365,7 @@ static int process_root(int argc, char *argv[]) exit(1); } - if (wks_trust_account || srv_trust_account || dom_trust_account) - { + if (trust_account) { /* add the $ automatically */ static fstring buf; @@ -539,24 +398,12 @@ static int process_root(int argc, char *argv[]) exit(1); } - if (joining_domain) - { - if (dom_trust_account) - { - ret = create_interdomain_trust_acct(new_domain, - global_myworkgroup); - - if ((ret != 0) || (!sam_sync)) - return ret; - } - } - if (remote_machine != NULL) { old_passwd = get_pass("Old SMB password:",stdin_passwd_get); } - if (!new_passwd) - { + if (!new_passwd) { + /* * If we are trying to enable a user, first we need to find out * if they are using a modern version of the smbpasswd file that @@ -566,94 +413,43 @@ static int process_root(int argc, char *argv[]) * smbpasswd file) then we need to prompt for a new password. */ - if (enable_user) - { + if(enable_user) { struct smb_passwd *smb_pass = getsmbpwnam(user_name); - if((smb_pass != NULL) && (smb_pass->smb_passwd != NULL)) - { + if((smb_pass != NULL) && (smb_pass->smb_passwd != NULL)) { new_passwd = "XXXX"; /* Don't care. */ } } if(!new_passwd) - { new_passwd = prompt_for_new_password(stdin_passwd_get); - } - } - - if (enable_user) - { - acb_mask |= ACB_DISABLED; - acb_info &= ~ACB_DISABLED; - } - - if (disable_user) - { - acb_mask |= ACB_DISABLED; - acb_info |= ACB_DISABLED; - } - if (set_no_password) - { - acb_mask |= ACB_PWNOTREQ; - acb_info |= ACB_PWNOTREQ; - } - - if (lock_password) - { - acb_mask |= ACB_PWLOCK; - acb_info |= ACB_PWLOCK; - } - - if (unlock_password) - { - acb_mask |= ACB_PWLOCK; - acb_info &= ~ACB_PWLOCK; + if(!new_passwd) { + fprintf(stderr, "Unable to get new password.\n"); + exit(1); + } } - if (wks_trust_account) - { - acb_mask |= ACB_WSTRUST; - acb_info |= ACB_WSTRUST; - } - else if (srv_trust_account) - { - acb_mask |= ACB_SVRTRUST; - acb_info |= ACB_SVRTRUST; - } - else if (dom_trust_account) - { - acb_mask |= ACB_DOMTRUST; - acb_info |= ACB_DOMTRUST; - } - else - { - acb_mask |= ACB_NORMAL; - acb_info |= ACB_NORMAL; - } - if (!password_change(remote_machine, user_name, old_passwd, new_passwd, - add_user, acb_info, acb_mask)) - { + add_user, enable_user, disable_user, set_no_password, + trust_account)) { fprintf(stderr,"Failed to change password entry for %s\n", user_name); return 1; } - if (disable_user) - { + if(disable_user) { printf("User %s disabled.\n", user_name); - } - if (enable_user) - { + } else if(enable_user) { printf("User %s enabled.\n", user_name); - } - if (set_no_password) - { + } else if (set_no_password) { printf("User %s - set to no password.\n", user_name); - } - if (!disable_user && !enable_user && !set_no_password) - { - printf("Password changed for user %s\n", user_name); + } else { + struct smb_passwd *smb_pass = getsmbpwnam(user_name); + printf("Password changed for user %s.", user_name ); + if((smb_pass != NULL) && (smb_pass->acct_ctrl & ACB_DISABLED )) + printf(" User has disabled flag set."); + if((smb_pass != NULL) && (smb_pass->acct_ctrl & ACB_PWNOTREQ)) + printf(" User has no password flag set."); + printf("\n"); } return 0; } @@ -671,11 +467,9 @@ static int process_nonroot(int argc, char *argv[]) char *remote_machine = NULL; char *user_name = NULL; char *new_passwd = NULL; - - while ((ch = getopt(argc, argv, "hD:r:sU:")) != EOF) - { - switch(ch) - { + + while ((ch = getopt(argc, argv, "hD:r:sU:")) != EOF) { + switch(ch) { case 'D': DEBUGLEVEL = atoi(optarg); break; @@ -708,7 +502,7 @@ static int process_nonroot(int argc, char *argv[]) } if (!user_name) { - pwd = getpwuid(getuid()); + pwd = sys_getpwuid(getuid()); if (pwd) { user_name = xstrdup(pwd->pw_name); } else { @@ -726,6 +520,7 @@ static int process_nonroot(int argc, char *argv[]) remote_machine = "127.0.0.1"; } + if (remote_machine != NULL) { old_passwd = get_pass("Old SMB password:",stdin_passwd_get); } @@ -735,14 +530,12 @@ static int process_nonroot(int argc, char *argv[]) } if (!new_passwd) { - printf("unable to get new password\n"); - exit(0); + fprintf(stderr, "Unable to get new password.\n"); + exit(1); } - if (!password_change(remote_machine, user_name, - old_passwd, new_passwd, - False, 0x0, 0x0)) - { + if (!password_change(remote_machine, user_name, old_passwd, new_passwd, + False, False, False, False, False)) { fprintf(stderr,"Failed to change password for %s\n", user_name); return 1; } @@ -760,20 +553,24 @@ int main(int argc, char **argv) { static pstring servicesf = CONFIGFILE; +#if defined(HAVE_SET_AUTH_PARAMETERS) + set_auth_parameters(argc, argv); +#endif /* HAVE_SET_AUTH_PARAMETERS */ + TimeInit(); setup_logging("smbpasswd", True); charset_initialise(); - if (!lp_load(servicesf,True,False,False)) { - fprintf(stderr, "Can't load %s - run testparm to debug it\n", - servicesf); + if(!initialize_password_db()) { + fprintf(stderr, "Can't setup password database vectors.\n"); exit(1); } - if(!get_myname(myhostname,NULL)) { - fprintf(stderr, "unable to get my hostname.\n"); + if (!lp_load(servicesf,True,False,False)) { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", + servicesf); exit(1); } @@ -784,7 +581,7 @@ int main(int argc, char **argv) if (!*global_myname) { char *p; - fstrcpy(global_myname, myhostname); + fstrcpy(global_myname, myhostname()); p = strchr(global_myname, '.' ); if (p) *p = 0; } @@ -794,12 +591,6 @@ int main(int argc, char **argv) load_interfaces(); - if(!pwdb_initialise(False)) - { - fprintf(stderr, "Can't setup password database vectors.\n"); - exit(1); - } - /* Check the effective uid - make sure we are not setuid */ if ((geteuid() == (uid_t)0) && (getuid() != (uid_t)0)) { fprintf(stderr, "smbpasswd must *NOT* be setuid root.\n"); diff --git a/source3/utils/smbrun.c b/source3/utils/smbrun.c index 2a94ac3235..b7c678411c 100644 --- a/source3/utils/smbrun.c +++ b/source3/utils/smbrun.c @@ -48,35 +48,17 @@ It takes 3 arguments as uid,gid,command and runs command after becoming a non-root user */ int main(int argc,char *argv[]) { - int uid,gid; + uid_t uid; + gid_t gid; close_fds(); if (argc != 4) exit(2); - uid = atoi(argv[1]); - gid = atoi(argv[2]); - - /* first become root - we may need to do this in order to lose - our privilages! */ -#ifdef HAVE_SETRESUID - setresgid(0,0,0); - setresuid(0,0,0); -#else - setuid(0); - seteuid(0); -#endif - -#ifdef HAVE_SETRESUID - setresgid(gid,gid,gid); - setresuid(uid,uid,uid); -#else - setgid(gid); - setegid(gid); - setuid(uid); - seteuid(uid); -#endif + uid = (uid_t)atoi(argv[1]); + gid = (gid_t)atoi(argv[2]); + become_user_permanently( uid, gid); /* paranoia :-) */ if (getuid() != uid) diff --git a/source3/utils/status.c b/source3/utils/status.c index 320a54cc7d..2cbfbfdaf5 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -36,9 +36,11 @@ #include "includes.h" +struct connect_record crec; + struct session_record{ - int pid; - int uid; + pid_t pid; + uid_t uid; char machine[31]; time_t start; struct session_record *next; @@ -46,10 +48,9 @@ struct session_record{ extern int DEBUGLEVEL; extern FILE *dbf; -extern pstring myhostname; static pstring Ucrit_username = ""; /* added by OH */ -int Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ +pid_t Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ int Ucrit_MaxPid=0; /* added by OH */ unsigned int Ucrit_IsActive = 0; /* added by OH */ @@ -76,7 +77,7 @@ static unsigned int Ucrit_checkUsername(char *username) return 0; } -static void Ucrit_addPid(int pid) +static void Ucrit_addPid(pid_t pid) { int i; if ( !Ucrit_IsActive) return; @@ -85,7 +86,7 @@ static void Ucrit_addPid(int pid) Ucrit_pid[Ucrit_MaxPid++] = pid; } -static unsigned int Ucrit_checkPid(int pid) +static unsigned int Ucrit_checkPid(pid_t pid) { int i; if ( !Ucrit_IsActive) return 1; @@ -106,7 +107,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) count++; if (Ucrit_checkPid(e->pid)) { - printf("%-5d ",e->pid); + printf("%-5d ",(int)e->pid); switch ((e->share_mode>>4)&0xF) { case DENY_NONE: printf("DENY_NONE "); break; case DENY_ALL: printf("DENY_ALL "); break; @@ -128,10 +129,13 @@ static void print_share_mode(share_mode_entry *e, char *fname) printf("EXCLUSIVE "); else if (e->op_type & BATCH_OPLOCK) printf("BATCH "); + else if (e->op_type & LEVEL_II_OPLOCK) + printf("LEVEL_II "); else printf("NONE "); - printf(" %s %s",fname,asctime(LocalTime((time_t *)&e->time.tv_sec))); + printf(" %s %s",dos_to_unix(fname,False), + asctime(LocalTime((time_t *)&e->time.tv_sec))); } } @@ -167,12 +171,9 @@ static int profile_dump(void) extern char *optarg; int verbose = 0, brief =0; BOOL processes_only=False; - int last_pid=0; + pid_t last_pid=(pid_t)0; struct session_record *ptr; int profile_only = 0; - struct connect_record *crec = NULL; - uint32 connection_count; - uint32 conn; TimeInit(); setup_logging(argv[0],True); @@ -214,13 +215,11 @@ static int profile_dump(void) Ucrit_addUsername(optarg); /* added by OH */ break; default: - fprintf(stderr, "Usage: %s [-P] [-d] [-L] [-p] [-S] [-s configfile] [-u username]\n", *argv); + fprintf(stderr, "Usage: %s [-P] [-d] [-L] [-p] [-S] [-s configfile] [-u username]\n", *argv); /* changed by OH */ return (-1); } } - get_myname(myhostname, NULL); - if (!lp_load(servicesf,False,False,False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); return (-1); @@ -232,7 +231,7 @@ static int profile_dump(void) } if (profile_only) { - return profile_dump(); + return profile_dump(); } pstrcpy(fname,lp_lockdir()); @@ -267,59 +266,60 @@ static int profile_dump(void) printf("----------------------------------------------\n"); } } - - if (get_connection_status(&crec, &connection_count)) - { - for (conn=0;connpid==crec.pid)&&(strncmp(ptr->machine,crec.machine,30)==0)) { - ptr=srecs; - while (ptr!=NULL) - { - if ((ptr->pid==crec[conn].pid)&&(strncmp(ptr->machine,crec[conn].machine,30)==0)) - { - if (ptr->start > crec[conn].start) - ptr->start=crec[conn].start; - break; - } - ptr=ptr->next; - } - if (ptr==NULL) - { - ptr=(struct session_record *) malloc(sizeof(struct session_record)); - ptr->uid=crec[conn].uid; - ptr->pid=crec[conn].pid; - ptr->start=crec[conn].start; - strncpy(ptr->machine,crec[conn].machine,30); - ptr->machine[30]='\0'; - ptr->next=srecs; - srecs=ptr; - } + if (ptr->start > crec.start) + ptr->start=crec.start; + break; } - else - { - Ucrit_addPid(crec[conn].pid); /* added by OH */ - if (processes_only) { - if (last_pid != crec[conn].pid) - printf("%d\n",crec[conn].pid); - last_pid = crec[conn].pid; /* XXXX we can still get repeats, have to - add a sort at some time */ - } - else - printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", - crec[conn].name,uidtoname(crec[conn].uid),gidtoname(crec[conn].gid),crec[conn].pid, - crec[conn].machine,crec[conn].addr, - asctime(LocalTime(&crec[conn].start))); - } - } - } - free(crec); - } + ptr=ptr->next; + } + if (ptr==NULL) + { + ptr=(struct session_record *) malloc(sizeof(struct session_record)); + ptr->uid=crec.uid; + ptr->pid=crec.pid; + ptr->start=crec.start; + strncpy(ptr->machine,crec.machine,30); + ptr->machine[30]='\0'; + ptr->next=srecs; + srecs=ptr; + } + } + else + { + Ucrit_addPid(crec.pid); /* added by OH */ + if (processes_only) { + if (last_pid != crec.pid) + printf("%d\n",(int)crec.pid); + last_pid = crec.pid; /* XXXX we can still get repeats, have to + add a sort at some time */ + } + else + printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", + crec.name,uidtoname(crec.uid),gidtoname(crec.gid),(int)crec.pid, + crec.machine,crec.addr, + asctime(LocalTime(&crec.start))); + } + } + } + fclose(f); } - if (processes_only) exit(0); if (brief) @@ -327,7 +327,7 @@ static int profile_dump(void) ptr=srecs; while (ptr!=NULL) { - printf("%-8d%-10.10s%-30.30s%s",ptr->pid,uidtoname(ptr->uid),ptr->machine,asctime(LocalTime(&(ptr->start)))); + printf("%-8d%-10.10s%-30.30s%s",(int)ptr->pid,uidtoname(ptr->uid),ptr->machine,asctime(LocalTime(&(ptr->start)))); ptr=ptr->next; } printf("\n"); diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 9bf741e24f..e4f603e0ce 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -38,46 +38,153 @@ /* these live in util.c */ extern FILE *dbf; extern int DEBUGLEVEL; -extern pstring myhostname; /*********************************************** Here we do a set of 'hard coded' checks for bad configuration settings. ************************************************/ -static void do_global_checks(void) + +static int do_global_checks(void) { + int ret = 0; SMB_STRUCT_STAT st; + if (lp_security() > SEC_SHARE && lp_revalidate(-1)) { printf("WARNING: the 'revalidate' parameter is ignored in all but \ 'security=share' mode.\n"); } - if (lp_security() == SEC_DOMAIN && !lp_encrypted_passwords()) { + if (lp_security() == SEC_DOMAIN && !lp_encrypted_passwords()) { printf("ERROR: in 'security=domain' mode the 'encrypt passwords' parameter must also be set to 'true'.\n"); + ret = 1; } if (lp_wins_support() && *lp_wins_server()) { printf("ERROR: both 'wins support = true' and 'wins server = ' \ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); + ret = 1; } if (!directory_exist(lp_lockdir(), &st)) { printf("ERROR: lock directory %s does not exist\n", lp_lockdir()); + ret = 1; } else if ((st.st_mode & 0777) != 0755) { printf("WARNING: lock directory %s should have permissions 0755 for browsing to work\n", lp_lockdir()); + ret = 1; + } + + /* + * Password server sanity checks. + */ + + if((lp_security() == SEC_SERVER || lp_security() == SEC_DOMAIN) && !lp_passwordserver()) { + pstring sec_setting; + if(lp_security() == SEC_SERVER) + pstrcpy(sec_setting, "server"); + else if(lp_security() == SEC_DOMAIN) + pstrcpy(sec_setting, "domain"); + + printf("ERROR: The setting 'security=%s' requires the 'password server' parameter be set \ +to a valid password server.\n", sec_setting ); + ret = 1; + } + + /* + * Password chat sanity checks. + */ + + if(lp_security() == SEC_USER && lp_unix_password_sync()) { + + /* + * Check that we have a valid lp_passwd_program(). + */ + + if(lp_passwd_program() == NULL) { + printf("ERROR: the 'unix password sync' parameter is set and there is no valid 'passwd program' \ +parameter.\n" ); + ret = 1; + } else { + pstring passwd_prog; + pstring truncated_prog; + char *p; + + pstrcpy( passwd_prog, lp_passwd_program()); + p = passwd_prog; + *truncated_prog = '\0'; + next_token(&p, truncated_prog, NULL, sizeof(pstring)); + + if(access(truncated_prog, F_OK) == -1) { + printf("ERROR: the 'unix password sync' parameter is set and the 'passwd program' (%s) \ +cannot be executed (error was %s).\n", truncated_prog, strerror(errno) ); + ret = 1; + } + } + + if(lp_passwd_chat() == NULL) { + printf("ERROR: the 'unix password sync' parameter is set and there is no valid 'passwd chat' \ +parameter.\n"); + ret = 1; + } + + /* + * Check that we have a valid script and that it hasn't + * been written to expect the old password. + */ + + if(lp_encrypted_passwords()) { + if(strstr( lp_passwd_chat(), "%o")!=NULL) { + printf("ERROR: the 'passwd chat' script [%s] expects to use the old plaintext password \ +via the %%o substitution. With encrypted passwords this is not possible.\n", lp_passwd_chat() ); + ret = 1; + } + } + } + + /* + * WINS server line sanity checks. + */ + + if(*lp_wins_server()) { + fstring server; + int count = 0; + char *p = lp_wins_server(); + + while(next_token(&p,server,LIST_SEP,sizeof(server))) + count++; + if(count > 1) { + printf("ERROR: the 'wins server' parameter must only contain one WINS server.\n"); + ret = -1; + } } + + return ret; } - int main(int argc, char *argv[]) +static void usage(char *pname) +{ + printf("Usage: %s [-sh] [-L servername] [configfilename] [hostname hostIP]\n", pname); + printf("\t-s Suppress prompt for enter\n"); + printf("\t-h Print usage\n"); + printf("\t-L servername Set %%L macro to servername\n"); + printf("\tconfigfilename Configuration file to test\n"); + printf("\thostname hostIP. Hostname and Host IP address to test\n"); + printf("\t against \"host allow\" and \"host deny\"\n"); + printf("\n"); +} + + +int main(int argc, char *argv[]) { extern char *optarg; extern int optind; + extern fstring local_machine; pstring configfile; int opt; int s; BOOL silent_mode = False; + int ret = 0; TimeInit(); @@ -85,11 +192,23 @@ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); charset_initialise(); - while ((opt = getopt(argc, argv,"s")) != EOF) { + while ((opt = getopt(argc, argv,"shL:")) != EOF) { switch (opt) { case 's': silent_mode = True; break; + case 'L': + fstrcpy(local_machine,optarg); + break; + case 'h': + usage(argv[0]); + exit(0); + break; + default: + printf("Incorrect program usage\n"); + usage(argv[0]); + exit(1); + break; } } @@ -105,71 +224,87 @@ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); printf("Load smb config files from %s\n",configfile); - if(!get_myname(myhostname,NULL)) - { - printf("Failed to get my hostname.\n"); - return(1); - } - - if (!lp_load(configfile,False,True,False)) - { + if (!lp_load(configfile,False,True,False)) { printf("Error loading services.\n"); return(1); - } - + } printf("Loaded services file OK.\n"); - do_global_checks(); + ret = do_global_checks(); - for (s=0;s<1000;s++) + for (s=0;s<1000;s++) { if (VALID_SNUM(s)) if (strlen(lp_servicename(s)) > 8) { - printf("WARNING: You have some share names that are longer than 8 chars\n"); - printf("These may give errors while browsing or may not be accessible\nto some older clients\n"); - break; + printf("WARNING: You have some share names that are longer than 8 chars\n"); + printf("These may give errors while browsing or may not be accessible\nto some older clients\n"); + break; + } + } + + for (s=0;s<1000;s++) { + if (VALID_SNUM(s)) { + char *deny_list = lp_hostsdeny(s); + char *allow_list = lp_hostsallow(s); + if(deny_list) { + char *hasstar = strchr(deny_list, '*'); + char *hasquery = strchr(deny_list, '?'); + if(hasstar || hasquery) { + printf("Invalid character %c in hosts deny list %s for service %s.\n", + hasstar ? *hasstar : *hasquery, deny_list, lp_servicename(s) ); + } } - if (argc < 3) - { - if (!silent_mode) { - printf("Press enter to see a dump of your service definitions\n"); - fflush(stdout); - getc(stdin); + if(allow_list) { + char *hasstar = strchr(allow_list, '*'); + char *hasquery = strchr(allow_list, '?'); + if(hasstar || hasquery) { + printf("Invalid character %c in hosts allow list %s for service %s.\n", + hasstar ? *hasstar : *hasquery, allow_list, lp_servicename(s) ); + } } - lp_dump(stdout,True); + + if(lp_level2_oplocks(s) && !lp_oplocks(s)) { + printf("Invalid combination of parameters for service %s. \ +Level II oplocks can only be set if oplocks are also set.\n", + lp_servicename(s) ); + } + } + } + + if (argc < 3) { + if (!silent_mode) { + printf("Press enter to see a dump of your service definitions\n"); + fflush(stdout); + getc(stdin); } + lp_dump(stdout,True, lp_numservices()); + } - if (argc >= 3) - { - char *cname; - char *caddr; + if (argc >= 3) { + char *cname; + char *caddr; - if (argc == 3) { - cname = argv[optind]; - caddr = argv[optind+1]; - } else if (argc == 4) { - cname = argv[optind+1]; - caddr = argv[optind+2]; - } + if (argc == 3) { + cname = argv[optind]; + caddr = argv[optind+1]; + } else { + cname = argv[optind+1]; + caddr = argv[optind+2]; + } - /* this is totally ugly, a real `quick' hack */ - for (s=0;s<1000;s++) - if (VALID_SNUM(s)) - { - if (allow_access(lp_hostsdeny(s),lp_hostsallow(s),cname,caddr)) - { - printf("Allow connection from %s (%s) to %s\n", - cname,caddr,lp_servicename(s)); - } - else - { - printf("Deny connection from %s (%s) to %s\n", - cname,caddr,lp_servicename(s)); - } - } + /* this is totally ugly, a real `quick' hack */ + for (s=0;s<1000;s++) { + if (VALID_SNUM(s)) { + if (allow_access(lp_hostsdeny(s),lp_hostsallow(s),cname,caddr)) { + printf("Allow connection from %s (%s) to %s\n", + cname,caddr,lp_servicename(s)); + } else { + printf("Deny connection from %s (%s) to %s\n", + cname,caddr,lp_servicename(s)); + } + } } - return(0); + } + return(ret); } - - diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 6dea2f2d22..9dc9d664b2 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -23,12 +23,13 @@ #include "includes.h" -extern int DEBUGLEVEL; -extern pstring debugf; - static fstring host, workgroup, share, password, username, myname; static int max_protocol = PROTOCOL_NT1; -static char *sockops=""; +static char *sockops="TCP_NODELAY"; +static int nprocs=1, numops=100; +static struct cli_state current_cli; + +static double create_procs(void (*fn)(int)); static struct timeval tp1,tp2; @@ -45,82 +46,101 @@ static double end_timer(void) (tp2.tv_usec - tp1.tv_usec)*1.0e-6); } -#define FAILED_NO_ERROR 0 -#define FAILED_TCP_CONNECT 1 -#define FAILED_SESSION_REQ 2 -#define FAILED_SMB_SESS_SETUP 3 -#define FAILED_SMB_TCON 4 -#define FAILED_SMB_NEGPROT 5 -#define FAILED_CLI_STATE_INIT 6 -#define NUM_ERR_STATES 7 -static char *smb_messages[] = +/* return a pointer to a anonymous shared memory segment of size "size" + which will persist across fork() but will disappear when all processes + exit + + The memory is not zeroed + + This function uses system5 shared memory. It takes advantage of a property + that the memory is not destroyed if it is attached when the id is removed + */ +static void *shm_setup(int size) { - "No errors in connection", - "TCP connection ", - "NetBIOS Session Request", - "SMB Session Setup ", - "SMB Tcon ", - "SMB Negprot ", - "Client initialisation " -}; - -static int open_connection(struct cli_state *c) + int shmid; + void *ret; + + shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W); + if (shmid == -1) { + printf("can't get shared memory\n"); + exit(1); + } + ret = (void *)shmat(shmid, 0, 0); + if (!ret || ret == (void *)-1) { + printf("can't attach to shared memory\n"); + return NULL; + } + /* the following releases the ipc, but note that this process + and all its children will still have access to the memory, its + just that the shmid is no longer valid for other shm calls. This + means we don't leave behind lots of shm segments after we exit + + See Stevens "advanced programming in unix env" for details + */ + shmctl(shmid, IPC_RMID, 0); + + return ret; +} + + +static BOOL open_connection(struct cli_state *c) { struct nmb_name called, calling; + struct in_addr ip; + extern struct in_addr ipzero; ZERO_STRUCTP(c); make_nmb_name(&calling, myname, 0x0, ""); make_nmb_name(&called , host, 0x20, ""); - if (!cli_initialise(c)) - { - DEBUG(0,("Failed to connect with %s\n", host)); - return FAILED_CLI_STATE_INIT; - } + ip = ipzero; - if (!cli_connect(c, host, NULL)) { - DEBUG(0,("Failed to connect with %s\n", host)); - return FAILED_TCP_CONNECT; + if (!cli_initialise(c) || !cli_connect(c, host, &ip)) { + printf("Failed to connect with %s\n", host); + return False; } + c->timeout = 120000; /* set a really long timeout (2 minutes) */ + if (!cli_session_request(c, &calling, &called)) { + printf("%s rejected the session\n",host); cli_shutdown(c); - DEBUG(0,("%s rejected the session\n",host)); - return FAILED_SESSION_REQ; + return False; } if (!cli_negprot(c)) { - DEBUG(0,("%s rejected the negprot (%s)\n",host, cli_errstr(c))); + printf("%s rejected the negprot (%s)\n",host, cli_errstr(c)); cli_shutdown(c); - return FAILED_SMB_NEGPROT; + return False; } if (!cli_session_setup(c, username, password, strlen(password), password, strlen(password), workgroup)) { - DEBUG(0,("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c))); + printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c)); cli_shutdown(c); - return FAILED_SMB_SESS_SETUP; + return False; } if (!cli_send_tconX(c, share, "?????", password, strlen(password)+1)) { - DEBUG(0,("%s refused tree connect (%s)\n", host, cli_errstr(c))); + printf("%s refused tree connect (%s)\n", host, cli_errstr(c)); cli_shutdown(c); - return FAILED_SMB_TCON; + return False; } - return FAILED_NO_ERROR; + return True; } + static void close_connection(struct cli_state *c) { if (!cli_tdis(c)) { - DEBUG(0,("tdis failed (%s)\n", cli_errstr(c))); + printf("tdis failed (%s)\n", cli_errstr(c)); } cli_shutdown(c); @@ -133,14 +153,13 @@ static BOOL check_error(struct cli_state *c, { uint8 class; uint32 num; - int eno; - eno = cli_error(c, &class, &num); + (void)cli_error(c, &class, &num, NULL); if ((eclass != class || ecode != num) && num != (nterr&0xFFFFFF)) { - DEBUG(0,("unexpected error code class=%d code=%d\n", - (int)class, (int)num)); - DEBUG(0,(" expected %d/%d %d\n", - (int)eclass, (int)ecode, (int)nterr)); + printf("unexpected error code class=%d code=%d\n", + (int)class, (int)num); + printf(" expected %d/%d %d\n", + (int)eclass, (int)ecode, (int)nterr); return False; } return True; @@ -156,13 +175,13 @@ static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len) } -static BOOL rw_torture(struct cli_state *c, int numops) +static BOOL rw_torture(struct cli_state *c) { char *lockfname = "\\torture.lck"; fstring fname; int fnum; int fnum2; - int pid2, pid = getpid(); + pid_t pid2, pid = getpid(); int i, j; char buf[1024]; @@ -171,7 +190,7 @@ static BOOL rw_torture(struct cli_state *c, int numops) if (fnum2 == -1) fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - DEBUG(0,("open of %s failed (%s)\n", lockfname, cli_errstr(c))); + printf("open of %s failed (%s)\n", lockfname, cli_errstr(c)); return False; } @@ -179,7 +198,7 @@ static BOOL rw_torture(struct cli_state *c, int numops) for (i=0;i\n"); + struct cli_state cli; - printf("\t-U user%%pass\n"); - printf("\t-N numprocs\n"); - printf("\t-n my_netbios_name\n"); - printf("\t-W workgroup\n"); - printf("\t-o num_operations\n"); - printf("\t-O socket_options\n"); - printf("\t-m maximum protocol\n"); - printf("\n"); + cli = current_cli; - exit(1); -} + cli_sockopt(&cli, sockops); + rw_torture(&cli); + + close_connection(&cli); +} +int line_count = 0; -static void run_torture(int numops) +/* run a test that simulates an approximate netbench client load */ +static void run_netbench(int client) { - static struct cli_state cli; + struct cli_state cli; + int i; + fstring fname; + pstring line; + char cname[20]; + FILE *f; + char *params[20]; + + cli = current_cli; + + cli_sockopt(&cli, sockops); - if (open_connection(&cli) == 0) - { - cli_sockopt(&cli, sockops); + nb_setup(&cli); - DEBUG(0,("pid %d OK\n", getpid())); + slprintf(cname,sizeof(fname), "CLIENT%d", client); - rw_torture(&cli, numops); + f = fopen("client.txt", "r"); - close_connection(&cli); + if (!f) { + perror("client.txt"); + return; } - else - { - DEBUG(0,("pid %d failed\n", getpid())); + + while (fgets(line, sizeof(line)-1, f)) { + line_count++; + + line[strlen(line)-1] = 0; + + /* printf("[%d] %s\n", line_count, line); */ + + all_string_sub(line,"CLIENT1", cname, sizeof(line)); + + for (i=0;i<20;i++) params[i] = ""; + + /* parse the command parameters */ + params[0] = strtok(line," "); + i = 0; + while (params[i]) params[++i] = strtok(NULL," "); + + params[i] = ""; + + if (i < 2) continue; + + if (strcmp(params[1],"REQUEST") == 0) { + if (!strcmp(params[0],"SMBopenX")) { + fstrcpy(fname, params[5]); + } else if (!strcmp(params[0],"SMBclose")) { + nb_close(atoi(params[3])); + } else if (!strcmp(params[0],"SMBmkdir")) { + nb_mkdir(params[3]); + } else if (!strcmp(params[0],"CREATE")) { + nb_create(params[3], atoi(params[5])); + } else if (!strcmp(params[0],"SMBrmdir")) { + nb_rmdir(params[3]); + } else if (!strcmp(params[0],"SMBunlink")) { + fstrcpy(fname, params[3]); + } else if (!strcmp(params[0],"SMBmv")) { + nb_rename(params[3], params[5]); + } else if (!strcmp(params[0],"SMBgetatr")) { + fstrcpy(fname, params[3]); + } else if (!strcmp(params[0],"SMBwrite")) { + nb_write(atoi(params[3]), + atoi(params[5]), atoi(params[7])); + } else if (!strcmp(params[0],"SMBwritebraw")) { + nb_write(atoi(params[3]), + atoi(params[7]), atoi(params[5])); + } else if (!strcmp(params[0],"SMBreadbraw")) { + nb_read(atoi(params[3]), + atoi(params[7]), atoi(params[5])); + } else if (!strcmp(params[0],"SMBread")) { + nb_read(atoi(params[3]), + atoi(params[5]), atoi(params[7])); + } + } else { + if (!strcmp(params[0],"SMBopenX")) { + if (!strncmp(params[2], "ERR", 3)) continue; + nb_open(fname, atoi(params[3]), atoi(params[5])); + } else if (!strcmp(params[0],"SMBgetatr")) { + if (!strncmp(params[2], "ERR", 3)) continue; + nb_stat(fname, atoi(params[3])); + } else if (!strcmp(params[0],"SMBunlink")) { + if (!strncmp(params[2], "ERR", 3)) continue; + nb_unlink(fname); + } + } } + fclose(f); + + slprintf(fname,sizeof(fname), "CLIENTS/CLIENT%d", client); + rmdir(fname); + rmdir("CLIENTS"); + printf("+"); + + close_connection(&cli); } + +/* run a test that simulates an approximate netbench w9X client load */ +static void run_nbw95(int dummy) +{ + double t; + t = create_procs(run_netbench); + /* to produce a netbench result we scale accoding to the + netbench measured throughput for the run that produced the + sniff that was used to produce client.txt. That run used 2 + clients and ran for 660 seconds to produce a result of + 4MBit/sec. */ + printf("Throughput %g MB/sec (NB=%g MB/sec %g MBit/sec)\n", + 132*nprocs/t, 0.5*0.5*nprocs*660/t, 2*nprocs*660/t); +} + +/* run a test that simulates an approximate netbench wNT client load */ +static void run_nbwnt(int dummy) +{ + double t; + t = create_procs(run_netbench); + printf("Throughput %g MB/sec (NB=%g MB/sec %g MBit/sec)\n", + 132*nprocs/t, 0.5*0.5*nprocs*660/t, 2*nprocs*660/t); +} + + + /* This test checks for two things: @@ -282,57 +403,57 @@ static void run_torture(int numops) must not use posix semantics) 2) support for lock timeouts */ -static void run_locktest1(void) +static void run_locktest1(int dummy) { static struct cli_state cli1, cli2; char *fname = "\\lockt1.lck"; int fnum1, fnum2, fnum3; time_t t1, t2; - if (open_connection(&cli1) != 0 || open_connection(&cli2) != 0) { + if (!open_connection(&cli1) || !open_connection(&cli2)) { return; } cli_sockopt(&cli1, sockops); cli_sockopt(&cli2, sockops); - DEBUG(0,("starting locktest1\n")); + printf("starting locktest1\n"); cli_unlink(&cli1, fname); fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); if (fnum1 == -1) { - DEBUG(0,("open of %s failed (%s)\n", fname, cli_errstr(&cli1))); + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); return; } fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - DEBUG(0,("open2 of %s failed (%s)\n", fname, cli_errstr(&cli1))); + printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli1)); return; } fnum3 = cli_open(&cli2, fname, O_RDWR, DENY_NONE); if (fnum3 == -1) { - DEBUG(0,("open3 of %s failed (%s)\n", fname, cli_errstr(&cli2))); + printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli2)); return; } if (!cli_lock(&cli1, fnum1, 0, 4, 0)) { - DEBUG(0,("lock1 failed (%s)\n", cli_errstr(&cli1))); + printf("lock1 failed (%s)\n", cli_errstr(&cli1)); return; } if (cli_lock(&cli2, fnum3, 0, 4, 0)) { - DEBUG(0,("lock2 succeeded! This is a locking bug\n")); + printf("lock2 succeeded! This is a locking bug\n"); return; } else { if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return; } - DEBUG(0,("Testing lock timeouts\n")); + printf("Testing lock timeouts\n"); t1 = time(NULL); if (cli_lock(&cli2, fnum3, 0, 4, 10*1000)) { - DEBUG(0,("lock3 succeeded! This is a locking bug\n")); + printf("lock3 succeeded! This is a locking bug\n"); return; } else { if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return; @@ -340,33 +461,33 @@ static void run_locktest1(void) t2 = time(NULL); if (t2 - t1 < 5) { - DEBUG(0,("error: This server appears not to support timed lock requests\n")); + printf("error: This server appears not to support timed lock requests\n"); } if (!cli_close(&cli1, fnum2)) { - DEBUG(0,("close1 failed (%s)\n", cli_errstr(&cli1))); + printf("close1 failed (%s)\n", cli_errstr(&cli1)); return; } if (cli_lock(&cli2, fnum3, 0, 4, 0)) { - DEBUG(0,("lock4 succeeded! This is a locking bug\n")); + printf("lock4 succeeded! This is a locking bug\n"); return; } else { if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return; } if (!cli_close(&cli1, fnum1)) { - DEBUG(0,("close2 failed (%s)\n", cli_errstr(&cli1))); + printf("close2 failed (%s)\n", cli_errstr(&cli1)); return; } if (!cli_close(&cli2, fnum3)) { - DEBUG(0,("close3 failed (%s)\n", cli_errstr(&cli2))); + printf("close3 failed (%s)\n", cli_errstr(&cli2)); return; } if (!cli_unlink(&cli1, fname)) { - DEBUG(0,("unlink failed (%s)\n", cli_errstr(&cli1))); + printf("unlink failed (%s)\n", cli_errstr(&cli1)); return; } @@ -374,7 +495,7 @@ static void run_locktest1(void) close_connection(&cli1); close_connection(&cli2); - DEBUG(0,("Passed locktest1\n")); + printf("Passed locktest1\n"); } @@ -389,19 +510,19 @@ static void run_locktest1(void) 3) the server denies unlock requests by an incorrect client PID */ -static void run_locktest2(void) +static void run_locktest2(int dummy) { static struct cli_state cli; char *fname = "\\lockt2.lck"; int fnum1, fnum2, fnum3; - if (open_connection(&cli) != 0) { + if (!open_connection(&cli)) { return; } cli_sockopt(&cli, sockops); - DEBUG(0,("starting locktest2\n")); + printf("starting locktest2\n"); cli_unlink(&cli, fname); @@ -409,13 +530,13 @@ static void run_locktest2(void) fnum1 = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); if (fnum1 == -1) { - DEBUG(0,("open of %s failed (%s)\n", fname, cli_errstr(&cli))); + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli)); return; } fnum2 = cli_open(&cli, fname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - DEBUG(0,("open2 of %s failed (%s)\n", fname, cli_errstr(&cli))); + printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli)); return; } @@ -423,19 +544,19 @@ static void run_locktest2(void) fnum3 = cli_open(&cli, fname, O_RDWR, DENY_NONE); if (fnum3 == -1) { - DEBUG(0,("open3 of %s failed (%s)\n", fname, cli_errstr(&cli))); + printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli)); return; } cli_setpid(&cli, 1); if (!cli_lock(&cli, fnum1, 0, 4, 0)) { - DEBUG(0,("lock1 failed (%s)\n", cli_errstr(&cli))); + printf("lock1 failed (%s)\n", cli_errstr(&cli)); return; } if (cli_lock(&cli, fnum2, 0, 4, 0)) { - DEBUG(0,("lock2 succeeded! This is a locking bug\n")); + printf("lock2 succeeded! This is a locking bug\n"); } else { if (!check_error(&cli, ERRDOS, ERRlock, 0)) return; } @@ -443,11 +564,11 @@ static void run_locktest2(void) cli_setpid(&cli, 2); if (cli_unlock(&cli, fnum1, 0, 4, 0)) { - DEBUG(0,("unlock1 succeeded! This is a locking bug\n")); + printf("unlock1 succeeded! This is a locking bug\n"); } if (cli_lock(&cli, fnum3, 0, 4, 0)) { - DEBUG(0,("lock3 succeeded! This is a locking bug\n")); + printf("lock3 succeeded! This is a locking bug\n"); } else { if (!check_error(&cli, ERRDOS, ERRlock, 0)) return; } @@ -455,23 +576,23 @@ static void run_locktest2(void) cli_setpid(&cli, 1); if (!cli_close(&cli, fnum1)) { - DEBUG(0,("close1 failed (%s)\n", cli_errstr(&cli))); + printf("close1 failed (%s)\n", cli_errstr(&cli)); return; } if (!cli_close(&cli, fnum2)) { - DEBUG(0,("close2 failed (%s)\n", cli_errstr(&cli))); + printf("close2 failed (%s)\n", cli_errstr(&cli)); return; } if (!cli_close(&cli, fnum3)) { - DEBUG(0,("close3 failed (%s)\n", cli_errstr(&cli))); + printf("close3 failed (%s)\n", cli_errstr(&cli)); return; } close_connection(&cli); - DEBUG(0,("locktest2 finished\n")); + printf("locktest2 finished\n"); } @@ -480,7 +601,7 @@ static void run_locktest2(void) 1) the server supports the full offset range in lock requests */ -static void run_locktest3(int numops) +static void run_locktest3(int dummy) { static struct cli_state cli1, cli2; char *fname = "\\lockt3.lck"; @@ -489,40 +610,40 @@ static void run_locktest3(int numops) #define NEXT_OFFSET offset += (~(uint32)0) / numops - if (open_connection(&cli1) != 0 || open_connection(&cli2) != 0) { + if (!open_connection(&cli1) || !open_connection(&cli2)) { return; } cli_sockopt(&cli1, sockops); cli_sockopt(&cli2, sockops); - DEBUG(0,("starting locktest3\n")); + printf("starting locktest3\n"); cli_unlink(&cli1, fname); fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); if (fnum1 == -1) { - DEBUG(0,("open of %s failed (%s)\n", fname, cli_errstr(&cli1))); + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); return; } fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - DEBUG(0,("open2 of %s failed (%s)\n", fname, cli_errstr(&cli2))); + printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli2)); return; } for (offset=i=0;i n) { fnum--; - slprintf(fname,sizeof(fname)-1,template, fnum,getpid()); + slprintf(fname,sizeof(fname)-1,template, fnum,(int)getpid()); if (cli_unlink(&cli, fname)) { - DEBUG(0,("unlink of %s failed (%s)\n", - fname, cli_errstr(&cli))); + printf("unlink of %s failed (%s)\n", + fname, cli_errstr(&cli)); } } - DEBUG(0,("maxfid test finished\n")); + printf("maxfid test finished\n"); close_connection(&cli); } @@ -740,116 +858,45 @@ static void run_maxfidtest(int n) static void rand_buf(char *buf, int len) { while (len--) { - *buf = sys_random(); + *buf = (char)sys_random(); buf++; } } -#define TORT_BUFFER_SIZE 1024 - /* send random IPC commands */ -static void run_randomipc(int numops) +static void run_randomipc(int dummy) { char *rparam = NULL; char *rdata = NULL; int rdrcnt,rprcnt; - char param[TORT_BUFFER_SIZE]; + pstring param; int api, param_len, i; - int reconnect_count = 500; static struct cli_state cli; - DEBUG(0,("starting random ipc test\n")); - - while (reconnect_count > 0 && open_connection(&cli) != 0) - { - DEBUG(0,("connection failed: retrying %d\n", reconnect_count)); - msleep(sys_random() % 5000); - reconnect_count--; - } + printf("starting random ipc test\n"); - if (reconnect_count == 0) - { + if (!open_connection(&cli)) { return; } - for (i=0;i 0 && open_connection(&cli) != 0) - { - DEBUG(0,("connection failed: retrying %d\n", reconnect_count)); - msleep(sys_random() % 5000); - reconnect_count--; - } - - if (reconnect_count == 0) - { - return; - } - - for (i=0;i 2) { - DEBUG(0,("ERROR: SMBgetatr bug. time is %s", - ctime(&t))); + printf("ERROR: SMBgetatr bug. time is %s", + ctime(&t)); t = time(NULL); } t2 = t-60*60*24; /* 1 day ago */ if (!cli_setatr(&cli, fname, 0, t2)) { - DEBUG(0,("setatr failed (%s)\n", cli_errstr(&cli))); + printf("setatr failed (%s)\n", cli_errstr(&cli)); } if (!cli_getatr(&cli, fname, NULL, NULL, &t)) { - DEBUG(0,("getatr failed (%s)\n", cli_errstr(&cli))); + printf("getatr failed (%s)\n", cli_errstr(&cli)); } if (t != t2) { - DEBUG(0,("ERROR: getatr/setatr bug. times are\n%s", - ctime(&t))); - DEBUG(0,("%s", ctime(&t2))); + printf("ERROR: getatr/setatr bug. times are\n%s", + ctime(&t)); + printf("%s", ctime(&t2)); } cli_unlink(&cli, fname); close_connection(&cli); - DEBUG(0,("attrib test finished\n")); + printf("attrib test finished\n"); } /* This checks a couple of trans2 calls */ -static void run_trans2test(void) +static void run_trans2test(int dummy) { static struct cli_state cli; int fnum; @@ -959,9 +1006,9 @@ static void run_trans2test(void) char *dname = "\\trans2"; char *fname2 = "\\trans2\\trans2.tst"; - DEBUG(0,("starting trans2 test\n")); + printf("starting trans2 test\n"); - if (open_connection(&cli) != 0) { + if (!open_connection(&cli)) { return; } @@ -970,7 +1017,7 @@ static void run_trans2test(void) O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time, NULL, NULL)) { - DEBUG(0,("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli))); + printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli)); } cli_close(&cli, fnum); @@ -982,20 +1029,20 @@ static void run_trans2test(void) cli_close(&cli, fnum); if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) { - DEBUG(0,("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli))); + printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli)); } else { if (c_time != m_time) { - DEBUG(0,("create time=%s", ctime(&c_time))); - DEBUG(0,("modify time=%s", ctime(&m_time))); - DEBUG(0,("This system appears to have sticky create times\n")); + printf("create time=%s", ctime(&c_time)); + printf("modify time=%s", ctime(&m_time)); + printf("This system appears to have sticky create times\n"); } if (a_time % (60*60) == 0) { - DEBUG(0,("access time=%s", ctime(&a_time))); - DEBUG(0,("This system appears to set a midnight access time\n")); + printf("access time=%s", ctime(&a_time)); + printf("This system appears to set a midnight access time\n"); } if (abs(m_time - time(NULL)) > 60*60*24*7) { - DEBUG(0,("ERROR: totally incorrect times - maybe word reversed?\n")); + printf("ERROR: totally incorrect times - maybe word reversed?\n"); } } @@ -1006,11 +1053,11 @@ static void run_trans2test(void) cli_close(&cli, fnum); if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL)) { - DEBUG(0,("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli))); + printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } else { if (w_time < 60*60*24*2) { - DEBUG(0,("write time=%s", ctime(&w_time))); - DEBUG(0,("This system appears to set a initial 0 write time\n")); + printf("write time=%s", ctime(&w_time)); + printf("This system appears to set a initial 0 write time\n"); } } @@ -1020,12 +1067,12 @@ static void run_trans2test(void) /* check if the server updates the directory modification time when creating a new file */ if (!cli_mkdir(&cli, dname)) { - DEBUG(0,("ERROR: mkdir failed (%s)\n", cli_errstr(&cli))); + printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli)); } sleep(3); if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL)) { - DEBUG(0,("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli))); + printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } fnum = cli_open(&cli, fname2, @@ -1034,10 +1081,10 @@ static void run_trans2test(void) cli_close(&cli, fnum); if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL, NULL)) { - DEBUG(0,("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli))); + printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } else { if (m_time2 == m_time) - DEBUG(0,("This system does not update directory modification times\n")); + printf("This system does not update directory modification times\n"); } cli_unlink(&cli, fname2); cli_rmdir(&cli, dname); @@ -1045,105 +1092,298 @@ static void run_trans2test(void) close_connection(&cli); - DEBUG(0,("trans2 test finished\n")); + printf("trans2 test finished\n"); } -static void run_connection(int numops) +/* + this is a harness for some oplock tests + */ +static void run_oplock(int dummy) { - struct cli_state c; - int count = 0; - int failed[NUM_ERR_STATES]; - int i; + static struct cli_state cli1, cli2; + char *fname = "\\lockt1.lck"; + char *fname2 = "\\lockt2.lck"; + int fnum1, fnum2; - DEBUG(0,("Connection test starts:\n")); + printf("starting oplock test\n"); - for (i = 0; i < NUM_ERR_STATES; i++) - { - failed[i] = 0; + if (!open_connection(&cli1)) { + return; } - for (i = 0; i < numops; i++) - { - int err; - DEBUG(0,("Connection test %d %d\n", i, numops)); - if ((err = open_connection(&c))) - { - failed[err]++; - } - count++; + cli_unlink(&cli1, fname); + + cli_sockopt(&cli1, sockops); + + cli1.use_oplocks = True; + + fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + cli1.use_oplocks = False; + + cli_unlink(&cli1, fname); + cli_unlink(&cli1, fname); + + if (!cli_close(&cli1, fnum1)) { + printf("close2 failed (%s)\n", cli_errstr(&cli1)); + return; } - { - int failtotal = 0; + if (!cli_unlink(&cli1, fname)) { + printf("unlink failed (%s)\n", cli_errstr(&cli1)); + return; + } + + + close_connection(&cli1); + + printf("finished oplock test\n"); +} + + +static void list_fn(file_info *finfo, const char *name) +{ + +} + +/* + test directory listing speed + */ +static void run_dirtest(int dummy) +{ + int i; + static struct cli_state cli; + int fnum; + double t1; + + printf("starting directory test\n"); + + if (!open_connection(&cli)) { + return; + } + + cli_sockopt(&cli, sockops); - for (i = 0, failtotal = 0; i < NUM_ERR_STATES; i++) - { - failtotal += failed[i]; + srandom(0); + for (i=0;i TEST1 TEST2 ...\n"); + + printf("\t-U user%%pass\n"); + printf("\t-N numprocs\n"); + printf("\t-n my_netbios_name\n"); + printf("\t-W workgroup\n"); + printf("\t-o num_operations\n"); + printf("\t-O socket_options\n"); + printf("\t-m maximum protocol\n"); + printf("\n\n"); + + printf("tests are:"); + for (i=0;torture_ops[i].name;i++) { + printf(" %s", torture_ops[i].name); + } + printf("\n"); + + printf("default test is ALL\n"); + + exit(1); +} + + + -#define DEBUG_INTERACTIVE True /**************************************************************************** main program ****************************************************************************/ int main(int argc,char *argv[]) { - int nprocs=1, numops=100; - int opt; + int opt, i; char *p; int gotpass = 0; extern char *optarg; extern int optind; - extern BOOL append_log; - extern BOOL timestamp_log; + extern FILE *dbf; + static pstring servicesf = CONFIGFILE; + + dbf = stdout; - DEBUGLEVEL = 0; - pstrcpy(debugf,"./log.torture"); - setup_logging(argv[0], DEBUG_INTERACTIVE); - append_log = True; - timestamp_log = False; + setbuffer(stdout, NULL, 0); charset_initialise(); + lp_load(servicesf,True,False,False); + load_interfaces(); + if (argc < 2) { usage(); } @@ -1164,7 +1404,7 @@ static void create_procs(int nprocs, int numops, void (*fn)(int )) *p = 0; fstrcpy(share, p+1); - get_myname(myname,NULL); + get_myname(myname); if (*username == 0 && getenv("LOGNAME")) { pstrcpy(username,getenv("LOGNAME")); @@ -1174,6 +1414,8 @@ static void create_procs(int nprocs, int numops, void (*fn)(int )) argv++; + fstrcpy(workgroup, lp_workgroup()); + while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:")) != EOF) { switch (opt) { case 'W': @@ -1218,35 +1460,16 @@ static void create_procs(int nprocs, int numops, void (*fn)(int )) } } - printf("host=%s share=%s user=%s myname=%s procs=%d ops=%d\n", - host, share, username, myname, nprocs, numops); + printf("host=%s share=%s user=%s myname=%s\n", + host, share, username, myname); - create_procs(nprocs, numops, run_randomipc); -/* - create_procs(nprocs, numops, run_randomipc_nowait); - - create_procs(nprocs, numops, run_connection); - - run_fdpasstest(); - run_locktest1(); - run_locktest2(); - run_locktest3(numops); - run_unlinktest(); - run_browsetest(); - run_attrtest(); - run_trans2test(); - - create_procs(nprocs, numops, run_maxfidtest); - - - - start_timer(); - create_procs(nprocs, numops, run_torture); - printf("rw_torture: %g secs\n", end_timer()); -*/ - dbgflush(); + if (argc == 1) { + run_test("ALL"); + } else { + for (i=1;i Date: Mon, 13 Dec 1999 13:35:20 +0000 Subject: 2nd phase of head branch sync with SAMBA_2_0 - this delets all the files that were in the head branch but weren't in SAMBA_2_0 (This used to be commit d7b208786590b5a28618590172b8d523627dda09) --- source3/utils/nmb-agent.c | 295 ----------------------------------- source3/utils/smb-agent.c | 385 ---------------------------------------------- 2 files changed, 680 deletions(-) delete mode 100644 source3/utils/nmb-agent.c delete mode 100644 source3/utils/smb-agent.c (limited to 'source3/utils') diff --git a/source3/utils/nmb-agent.c b/source3/utils/nmb-agent.c deleted file mode 100644 index f49983db79..0000000000 --- a/source3/utils/nmb-agent.c +++ /dev/null @@ -1,295 +0,0 @@ -/* - Unix SMB/Netbios implementation. - Version 2 - SMB agent/socket plugin - 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. -*/ - -#include "includes.h" -#include "smb.h" - -#define SECURITY_MASK 0 -#define SECURITY_SET 0 - -/* this forces non-unicode */ -#define CAPABILITY_MASK CAP_UNICODE -#define CAPABILITY_SET 0 - -/* and non-unicode for the client too */ -#define CLI_CAPABILITY_MASK CAP_UNICODE -#define CLI_CAPABILITY_SET 0 - -extern int DEBUGLEVEL; - -static int ClientNMB = -1; - -/**************************************************************************** -terminate sockent connection -****************************************************************************/ -static void free_sock(void *sock) -{ - if (sock != NULL) - { - free(sock); - } -} - -static void filter_reply(struct packet_struct *p, int tr_id) -{ - p->packet.nmb.header.name_trn_id = tr_id; -} - -static BOOL process_cli_sock(struct sock_redir **socks, - uint32 num_socks, - struct sock_redir *sock) -{ - struct packet_struct *p; - struct nmb_state *nmb; - static uint16 trn_id = 0x0; - - p = receive_packet(sock->c, NMB_SOCK_PACKET, 0); - if (p == NULL) - { - DEBUG(0,("client closed connection\n")); - return False; - } - - nmb = (struct nmb_state*)malloc(sizeof(struct nmb_state)); - if (nmb == NULL) - { - free_packet(p); - return False; - } - - sock->s = ClientNMB; - sock->n = nmb; - sock->c_id = p->packet.nmb.header.name_trn_id; - sock->s_id = trn_id; - - trn_id++; - if (trn_id > 0xffff) - { - trn_id = 0x0; - } - - DEBUG(10,("new trn_id: %d\n", trn_id)); - - filter_reply(p, sock->s_id); - - nmb->ip = p->ip; - nmb->port = p->port; - - p->fd = ClientNMB; - p->packet_type = NMB_PACKET; - - if (!send_packet(p)) - { - DEBUG(0,("server is dead\n")); - free_packet(p); - return False; - } - free_packet(p); - return True; -} - -static BOOL process_srv_sock(struct sock_redir **socks, - uint32 num_socks, - int fd) -{ - int nmb_id; - int tr_id; - int i; - - struct packet_struct *p; - - p = receive_packet(fd, NMB_PACKET, 0); - if (p == NULL) - { - return True; - } - -#if 0 - if (!p->packet.nmb.header.response) - { - DEBUG(10,("skipping response packet\n")); - free_packet(p); - return True; - } -#endif - - nmb_id = p->packet.nmb.header.name_trn_id; - DEBUG(10,("process_srv_sock:\tnmb_id:\t%d\n", nmb_id)); - - for (i = 0; i < num_socks; i++) - { - if (socks[i] == NULL) - { - continue; - } - - tr_id = socks[i]->s_id; - - DEBUG(10,("list:\tfd:\t%d\tc_id:\t%d\ttr_id:\t%d\n", - socks[i]->c, - socks[i]->c_id, - tr_id)); - - if (nmb_id != tr_id) - { - continue; - } - - filter_reply(p, socks[i]->c_id); - p->fd = socks[i]->c; - p->packet_type = NMB_SOCK_PACKET; - - if (!send_packet(p)) - { - DEBUG(0,("client is dead\n")); - return False; - } - return True; - } - return True; -} - -static int get_agent_sock(char *id) -{ - fstring dir; - fstring path; - - slprintf(dir, sizeof(dir)-1, "/tmp/.nmb"); - slprintf(path, sizeof(path)-1, "%s/agent", dir); - - return create_pipe_socket(dir, 0777, path, 0777); -} - -static void start_nmb_agent(void) -{ - struct vagent_ops va = - { - free_sock, - get_agent_sock, - process_cli_sock, - process_srv_sock, - NULL, - NULL, - 0 - }; - - CatchChild(); - - start_agent(&va); -} - -/****************************************************************************** - open the socket communication - *****************************************************************************/ -static BOOL open_sockets(BOOL isdaemon, int port) -{ - /* The sockets opened here will be used to receive broadcast - packets *only*. Interface specific sockets are opened in - make_subnet() in namedbsubnet.c. Thus we bind to the - address "0.0.0.0". The parameter 'socket address' is - now deprecated. - */ - - if ( isdaemon ) - ClientNMB = open_socket_in(SOCK_DGRAM, port,0,0); - else - ClientNMB = 0; - - if ( ClientNMB == -1 ) - return( False ); - - /* we are never interested in SIGPIPE */ - BlockSignals(True,SIGPIPE); - - set_socket_options( ClientNMB, "SO_BROADCAST" ); - - DEBUG( 3, ( "open_sockets: Broadcast sockets opened.\n" ) ); - return( True ); -} /* open_sockets */ - -/**************************************************************************** -usage on the program -****************************************************************************/ -static void usage(char *pname) -{ - printf("Usage: %s [-D]", pname); - - printf("\nVersion %s\n",VERSION); - printf("\t-D run as a daemon\n"); - printf("\t-h usage\n"); - printf("\n"); -} - -int main(int argc, char *argv[]) -{ - pstring configfile; - BOOL is_daemon = False; - int opt; - extern pstring debugf; - int global_nmb_port = NMB_PORT; - - TimeInit(); - - pstrcpy(configfile,CONFIGFILE); - - while ((opt = getopt(argc, argv, "Dh")) != EOF) - { - switch (opt) - { - case 'D': - { - is_daemon = True; - break; - } - case 'h': - default: - { - usage(argv[0]); - break; - } - } - } - - slprintf(debugf, sizeof(debugf)-1, "log.%s", argv[0]); - setup_logging(argv[0], !is_daemon); - - charset_initialise(); - - if (!lp_load(configfile,True,False,False)) - { - DEBUG(0,("Unable to load config file\n")); - } - - if (is_daemon) - { - DEBUG(0,("%s: becoming daemon\n", argv[0])); - become_daemon(); - } - - if (!open_sockets(True, global_nmb_port)) - { - return 1; - } - - start_nmb_agent(); - - return 0; -} diff --git a/source3/utils/smb-agent.c b/source3/utils/smb-agent.c deleted file mode 100644 index 2ecfdba7e2..0000000000 --- a/source3/utils/smb-agent.c +++ /dev/null @@ -1,385 +0,0 @@ -/* - Unix SMB/Netbios implementation. - Version 2 - SMB agent/socket plugin - 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. -*/ - -#include "includes.h" -#include "smb.h" - -#define SECURITY_MASK 0 -#define SECURITY_SET 0 - -/* this forces non-unicode */ -#define CAPABILITY_MASK CAP_UNICODE -#define CAPABILITY_SET 0 - -/* and non-unicode for the client too */ -#define CLI_CAPABILITY_MASK CAP_UNICODE -#define CLI_CAPABILITY_SET 0 - -static char packet[BUFFER_SIZE]; - -extern int DEBUGLEVEL; - - -static uint16 mid_offset = 0x0; - -/**************************************************************************** -terminate sockent connection -****************************************************************************/ -static void free_sock(void *sock) -{ - if (sock != NULL) - { - struct cli_state *n = (struct cli_state*)sock; - cli_net_use_del(n->desthost, &n->usr, - False, NULL); - } -} - - -static struct cli_state *init_client_connection(int c) -{ - pstring buf; - struct user_creds usr; - int rl; - uint32 len; - BOOL new_con = False; - CREDS_CMD cmd; - prs_struct ps; - BOOL reuse = False; - - ZERO_STRUCT(usr); - ZERO_STRUCT(cmd); - cmd.cred = &usr; - - ZERO_STRUCT(usr); - - DEBUG(10,("init_client_connection: first request\n")); - - rl = read(c, &buf, sizeof(len)); - - if (rl != sizeof(len)) - { - DEBUG(0,("Unable to read length\n")); - dump_data(0, buf, sizeof(len)); - return NULL; - } - - len = IVAL(buf, 0); - - if (len > sizeof(buf)) - { - DEBUG(0,("length %d too long\n", len)); - return NULL; - } - - rl = read(c, buf, len); - - if (rl < 0) - { - DEBUG(0,("Unable to read from connection\n")); - return NULL; - } - -#ifdef DEBUG_PASSWORD - dump_data(100, buf, rl); -#endif - /* make a static data parsing structure from the api_fd_reply data */ - prs_init(&ps, 0, 4, 0, True); - mem_create(ps.data, buf, 0, len, 0, False); - - if (!creds_io_cmd("creds", &cmd, &ps, 0)) - { - DEBUG(0,("Unable to parse credentials\n")); - mem_free_data(ps.data); - return NULL; - } - - mem_free_data(ps.data); - - if (ps.offset != rl) - { - DEBUG(0,("Buffer size %d %d!\n", ps.offset, rl)); - return NULL; - } - - switch (cmd.command) - { - case AGENT_CMD_CON: - { - new_con = True; - break; - } - case AGENT_CMD_CON_REUSE: - { - new_con = True; - reuse = True; - break; - } - default: - { - DEBUG(0,("unknown command %d\n", cmd.command)); - return NULL; - } - } - - if (new_con) - { - struct cli_state *n; - n = cli_net_use_add(cmd.name, &usr.ntc, False, reuse); - - if (n == NULL) - { - DEBUG(0,("Unable to connect to %s\n", cmd.name)); - return NULL; - } - - mid_offset += MIN(MAX(n->max_mux, 1), MAX_MAX_MUX_LIMIT); - - if (mid_offset > 0xffff) - { - mid_offset = 0x0; - } - DEBUG(10,("new mid offset: %d\n", mid_offset)); - - if (write(c, n, sizeof(*n)) < 0) - { - DEBUG(0,("Could not write connection down pipe.\n")); - cli_net_use_del(cmd.name, &usr.ntc, False, NULL); - return NULL; - } - return n; - } - return NULL; -} - -static void filter_reply(char *buf, int moff) -{ - int msg_type = CVAL(buf,0); - int x; - - if (msg_type != 0x0) return; - - /* alter the mid */ - x = SVAL(buf, smb_mid); - x += moff; - - if (x < 0) - { - x += 0x10000; - } - if (x > 0xffff) - { - x -= 0x10000; - } - - SCVAL(buf, smb_mid, x); - -} - -static BOOL process_cli_sock(struct sock_redir **socks, uint32 num_socks, - struct sock_redir *sock) -{ - struct cli_state *n = (struct cli_state*)sock->n; - if (n == NULL) - { - n = init_client_connection(sock->c); - if (n == NULL) - { - return False; - } - sock->n = (void*)n; - sock->s_id = mid_offset; - sock->s = n->fd; - } - else - { - if (!receive_smb(sock->c, packet, 0)) - { - DEBUG(0,("client closed connection\n")); - return False; - } - - filter_reply(packet, sock->s_id); - /* ignore keep-alives */ - if (CVAL(packet, 0) != 0x85) - { - if (!send_smb(sock->s, packet)) - { - DEBUG(0,("server is dead\n")); - return False; - } - } - } - return True; -} - -static int get_smbmid(char *buf) -{ - int msg_type = CVAL(buf,0); - - if (msg_type != 0x0) - { - return -1; - } - - return SVAL(buf,smb_mid); -} - -static BOOL process_srv_sock(struct sock_redir **socks, uint32 num_socks, - int fd) -{ - int smbmid; - int i; - if (!receive_smb(fd, packet, 0)) - { - DEBUG(0,("server closed connection\n")); - return False; - } - - smbmid = get_smbmid(packet); - - DEBUG(10,("process_srv_sock:\tfd:\t%d\tmid:\t%d\n", fd, smbmid)); - - if (smbmid == -1) - { - return True; - } - - for (i = 0; i < num_socks; i++) - { - int moff; - struct cli_state *n; - if (socks[i] == NULL || socks[i]->n == NULL) - { - continue; - } - moff = socks[i]->s_id; - n = (struct cli_state*)socks[i]->n; - DEBUG(10,("list:\tfd:\t%d\tmid:\t%d\tmoff:\t%d\n", - socks[i]->s, - n->mid, - moff)); - if (smbmid != n->mid + moff) - { - continue; - } - filter_reply(packet, -moff); - if (!send_smb(socks[i]->c, packet)) - { - DEBUG(0,("client is dead\n")); - return False; - } - return True; - } - return False; -} - -static int get_agent_sock(char *id) -{ - fstring path; - fstring dir; - - slprintf(dir, sizeof(dir)-1, "/tmp/.smb.%d", getuid()); - slprintf(path, sizeof(path)-1, "%s/agent", dir); - - return create_pipe_socket(dir, S_IRUSR|S_IWUSR|S_IXUSR, path, 0); -} - -static void start_smb_agent(void) -{ - struct vagent_ops va = - { - free_sock, - get_agent_sock, - process_cli_sock, - process_srv_sock, - NULL, - NULL, - 0 - }; - - CatchChild(); - - start_agent(&va); -} - -/**************************************************************************** -usage on the program -****************************************************************************/ -static void usage(char *pname) -{ - printf("Usage: %s [-D]", pname); - - printf("\nVersion %s\n",VERSION); - printf("\t-D run as a daemon\n"); - printf("\t-h usage\n"); - printf("\n"); -} - -int main(int argc, char *argv[]) -{ - pstring configfile; - BOOL is_daemon = False; - int opt; - extern pstring debugf; - - TimeInit(); - - pstrcpy(configfile,CONFIGFILE); - - while ((opt = getopt(argc, argv, "Dh")) != EOF) - { - switch (opt) - { - case 'D': - { - is_daemon = True; - break; - } - case 'h': - default: - { - usage(argv[0]); - break; - } - } - } - - slprintf(debugf, sizeof(debugf)-1, "log.%s", argv[0]); - setup_logging(argv[0], !is_daemon); - - charset_initialise(); - - if (!lp_load(configfile,True,False,False)) - { - DEBUG(0,("Unable to load config file\n")); - } - - if (is_daemon) - { - DEBUG(0,("%s: becoming daemon\n", argv[0])); - become_daemon(); - } - - start_smb_agent(); - - return 0; -} -- cgit From 418ba2933f90eecf9abed14a43e02f28358d8d37 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 17 Dec 1999 01:52:05 +0000 Subject: more files from 2.0.6 (This used to be commit 4a205795710010c58ae14bcb950912727c4de466) --- source3/utils/make_unicodemap.c | 308 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 308 insertions(+) create mode 100644 source3/utils/make_unicodemap.c (limited to 'source3/utils') diff --git a/source3/utils/make_unicodemap.c b/source3/utils/make_unicodemap.c new file mode 100644 index 0000000000..76c49361be --- /dev/null +++ b/source3/utils/make_unicodemap.c @@ -0,0 +1,308 @@ +/* + 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 \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); +} -- cgit From 0c4b1ea0140ed5418fcbde3077d424ffa08a2dcf Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 21 Dec 1999 03:05:38 +0000 Subject: this was left out from the 2.0.6 merge (This used to be commit 7067aeecabaea8a35f7a27de4b44f1e11afd07b7) --- source3/utils/nbio.c | 236 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) create mode 100644 source3/utils/nbio.c (limited to 'source3/utils') diff --git a/source3/utils/nbio.c b/source3/utils/nbio.c new file mode 100644 index 0000000000..71ac959f11 --- /dev/null +++ b/source3/utils/nbio.c @@ -0,0 +1,236 @@ +#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", + getpid(), 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 Date: Tue, 21 Dec 1999 04:54:30 +0000 Subject: first cut at using the tdb code for the connections structure, the SWAT status page and smbstatus. It made the code _much_ simpler, I wish we'd done a database module a long time ago! (This used to be commit 4951755413c11d4c5b9af4699a6e622056d52433) --- source3/utils/status.c | 384 ++++++++++++++++++++++++------------------------- 1 file changed, 192 insertions(+), 192 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 2cbfbfdaf5..594783bd39 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -36,8 +36,6 @@ #include "includes.h" -struct connect_record crec; - struct session_record{ pid_t pid; uid_t uid; @@ -50,12 +48,13 @@ extern int DEBUGLEVEL; extern FILE *dbf; static pstring Ucrit_username = ""; /* added by OH */ -pid_t Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ -int Ucrit_MaxPid=0; /* added by OH */ -unsigned int Ucrit_IsActive = 0; /* added by OH */ - -int shares_only = 0; /* Added by RJS */ -int locks_only = 0; /* Added by RJS */ +static pid_t Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ +static int Ucrit_MaxPid=0; /* added by OH */ +static unsigned int Ucrit_IsActive = 0; /* added by OH */ +static int verbose, brief; +static int shares_only = 0; /* Added by RJS */ +static int locks_only = 0; /* Added by RJS */ +static BOOL processes_only=False; /* we need these because we link to locking*.o */ void become_root(BOOL save_dir) {} @@ -161,197 +160,198 @@ static int profile_dump(void) } +static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) +{ + static pid_t last_pid; + struct session_record *ptr; + struct connections_data crec; + static int doneone; + + memcpy(&crec, dbuf.dptr, sizeof(crec)); + + if (crec.cnum == -1) return 0; + + if (!process_exists(crec.pid) || !Ucrit_checkUsername(uidtoname(crec.uid))) { + return 0; + } + + if (brief) { + if (!doneone) { + printf("\nSamba version %s\n",VERSION); + printf("PID Username Machine Time logged in\n"); + printf("-------------------------------------------------------------------\n"); + doneone = 1; + } + + ptr=srecs; + while (ptr!=NULL) { + if ((ptr->pid==crec.pid)&&(strncmp(ptr->machine,crec.machine,30)==0)) { + if (ptr->start > crec.start) + ptr->start=crec.start; + break; + } + ptr=ptr->next; + } + if (ptr==NULL) { + ptr=(struct session_record *) malloc(sizeof(struct session_record)); + ptr->uid=crec.uid; + ptr->pid=crec.pid; + ptr->start=crec.start; + strncpy(ptr->machine,crec.machine,30); + ptr->machine[30]='\0'; + ptr->next=srecs; + srecs=ptr; + } + } else { + if (!doneone) { + printf("\nSamba version %s\n",VERSION); + printf("Service uid gid pid machine\n"); + printf("----------------------------------------------\n"); + doneone = 1; + } + + Ucrit_addPid(crec.pid); + if (processes_only) { + if (last_pid != crec.pid) + printf("%d\n",(int)crec.pid); + last_pid = crec.pid; /* XXXX we can still get repeats, have to + add a sort at some time */ + } else { + printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", + crec.name,uidtoname(crec.uid),gidtoname(crec.gid),(int)crec.pid, + crec.machine,crec.addr, + asctime(LocalTime(&crec.start))); + } + } + + return 0; +} + + + int main(int argc, char *argv[]) { - FILE *f; - pstring fname; - int c; - static pstring servicesf = CONFIGFILE; - extern char *optarg; - int verbose = 0, brief =0; - BOOL processes_only=False; - pid_t last_pid=(pid_t)0; - struct session_record *ptr; - int profile_only = 0; - - TimeInit(); - setup_logging(argv[0],True); - - charset_initialise(); - - DEBUGLEVEL = 0; - dbf = stderr; - - if (getuid() != geteuid()) { - printf("smbstatus should not be run setuid\n"); - return(1); - } - - while ((c = getopt(argc, argv, "pdLSs:u:bP")) != EOF) { - switch (c) { - case 'b': - brief = 1; - break; - case 'd': - verbose = 1; - break; - case 'L': - locks_only = 1; - break; - case 'p': - processes_only = 1; - break; - case 'P': - profile_only = 1; - break; - case 'S': - shares_only = 1; - break; - case 's': - pstrcpy(servicesf, optarg); - break; - case 'u': /* added by OH */ - Ucrit_addUsername(optarg); /* added by OH */ - break; - default: - fprintf(stderr, "Usage: %s [-P] [-d] [-L] [-p] [-S] [-s configfile] [-u username]\n", *argv); /* changed by OH */ - return (-1); - } - } - - if (!lp_load(servicesf,False,False,False)) { - fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); - return (-1); - } - - if (verbose) { - printf("using configfile = %s\n", servicesf); - printf("lockdir = %s\n", *lp_lockdir() ? lp_lockdir() : "NULL"); - } - - if (profile_only) { - return profile_dump(); - } - - pstrcpy(fname,lp_lockdir()); - standard_sub_basic(fname); - trim_string(fname,"","/"); - pstrcat(fname,"/STATUS..LCK"); - - f = sys_fopen(fname,"r"); - if (!f) { - printf("Couldn't open status file %s\n",fname); - if (!lp_status(-1)) - printf("You need to have status=yes in your smb config file\n"); - return(0); - } - else if (verbose) { - printf("Opened status file %s\n", fname); - } - - if (!locks_only) { - - if (!processes_only) { - printf("\nSamba version %s\n",VERSION); - - if (brief) - { - printf("PID Username Machine Time logged in\n"); - printf("-------------------------------------------------------------------\n"); - } - else - { - printf("Service uid gid pid machine\n"); - printf("----------------------------------------------\n"); + pstring fname; + int c; + static pstring servicesf = CONFIGFILE; + extern char *optarg; + int profile_only = 0; + TDB_CONTEXT *tdb; + struct session_record *ptr; + + TimeInit(); + setup_logging(argv[0],True); + + charset_initialise(); + + DEBUGLEVEL = 0; + dbf = stderr; + + if (getuid() != geteuid()) { + printf("smbstatus should not be run setuid\n"); + return(1); } - } - - while (!feof(f)) - { - if (fread(&crec,sizeof(crec),1,f) != 1) - break; - if (crec.cnum == -1) continue; - if ( crec.magic == 0x280267 && process_exists(crec.pid) - && Ucrit_checkUsername(uidtoname(crec.uid)) /* added by OH */ - ) - { - if (brief) - { - ptr=srecs; - while (ptr!=NULL) - { - if ((ptr->pid==crec.pid)&&(strncmp(ptr->machine,crec.machine,30)==0)) - { - if (ptr->start > crec.start) - ptr->start=crec.start; + + while ((c = getopt(argc, argv, "pdLSs:u:bP")) != EOF) { + switch (c) { + case 'b': + brief = 1; break; - } - ptr=ptr->next; - } - if (ptr==NULL) - { - ptr=(struct session_record *) malloc(sizeof(struct session_record)); - ptr->uid=crec.uid; - ptr->pid=crec.pid; - ptr->start=crec.start; - strncpy(ptr->machine,crec.machine,30); - ptr->machine[30]='\0'; - ptr->next=srecs; - srecs=ptr; - } - } - else - { - Ucrit_addPid(crec.pid); /* added by OH */ - if (processes_only) { - if (last_pid != crec.pid) - printf("%d\n",(int)crec.pid); - last_pid = crec.pid; /* XXXX we can still get repeats, have to - add a sort at some time */ + case 'd': + verbose = 1; + break; + case 'L': + locks_only = 1; + break; + case 'p': + processes_only = 1; + break; + case 'P': + profile_only = 1; + break; + case 'S': + shares_only = 1; + break; + case 's': + pstrcpy(servicesf, optarg); + break; + case 'u': /* added by OH */ + Ucrit_addUsername(optarg); /* added by OH */ + break; + default: + fprintf(stderr, "Usage: %s [-P] [-d] [-L] [-p] [-S] [-s configfile] [-u username]\n", *argv); /* changed by OH */ + return (-1); } - else - printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", - crec.name,uidtoname(crec.uid),gidtoname(crec.gid),(int)crec.pid, - crec.machine,crec.addr, - asctime(LocalTime(&crec.start))); - } - } - } - fclose(f); - } - if (processes_only) exit(0); + } + + if (!lp_load(servicesf,False,False,False)) { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); + return (-1); + } + + if (verbose) { + printf("using configfile = %s\n", servicesf); + printf("lockdir = %s\n", *lp_lockdir() ? lp_lockdir() : "NULL"); + } + + if (profile_only) { + return profile_dump(); + } + + pstrcpy(fname,lp_lockdir()); + standard_sub_basic(fname); + trim_string(fname,"","/"); + pstrcat(fname,"/connections.tdb"); + + tdb = tdb_open(fname, 0, O_RDONLY, 0); + if (!tdb) { + printf("Couldn't open status file %s\n",fname); + if (!lp_status(-1)) + printf("You need to have status=yes in your smb config file\n"); + return(0); + } else if (verbose) { + printf("Opened status file %s\n", fname); + } + + if (locks_only) goto locks; + + tdb_traverse(tdb, traverse_fn1); + + locks: + if (processes_only) exit(0); - if (brief) - { - ptr=srecs; - while (ptr!=NULL) - { - printf("%-8d%-10.10s%-30.30s%s",(int)ptr->pid,uidtoname(ptr->uid),ptr->machine,asctime(LocalTime(&(ptr->start)))); - ptr=ptr->next; - } - printf("\n"); - exit(0); - } - - printf("\n"); - - if (!shares_only) { - if (!locking_init(1)) { - printf("Can't initialise shared memory - exiting\n"); - exit(1); - } + if (brief) { + ptr=srecs; + while (ptr!=NULL) { + printf("%-8d%-10.10s%-30.30s%s", + (int)ptr->pid,uidtoname(ptr->uid), + ptr->machine, + asctime(LocalTime(&(ptr->start)))); + ptr=ptr->next; + } + printf("\n"); + exit(0); + } + + printf("\n"); + + if (!shares_only) { + if (!locking_init(1)) { + printf("Can't initialise shared memory - exiting\n"); + exit(1); + } + + if (share_mode_forall(print_share_mode) <= 0) + printf("No locked files\n"); + + printf("\n"); + + share_status(stdout); + + locking_end(); + } - if (share_mode_forall(print_share_mode) <= 0) - printf("No locked files\n"); - - printf("\n"); - - share_status(stdout); - - locking_end(); - } - - return (0); + return (0); } -- cgit From 4e1291a83f61a72989045879763d9ef05fd38f71 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 21 Dec 1999 09:25:59 +0000 Subject: converted all our existing shared memory code to use a tdb database instead of either sysv or mmap shared memory or lock files. this means we can now completely remove locking_shm.c locking_slow.c shmem.c shmem_sysv.c and lots of other things also got simpler locking.c got a bit larger, but is much better compartmentalised now (This used to be commit e48c2d9937eea0667b8cd3332e49c06314ef31e7) --- source3/utils/status.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 594783bd39..8f3461c082 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -165,7 +165,6 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) static pid_t last_pid; struct session_record *ptr; struct connections_data crec; - static int doneone; memcpy(&crec, dbuf.dptr, sizeof(crec)); @@ -176,13 +175,6 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) } if (brief) { - if (!doneone) { - printf("\nSamba version %s\n",VERSION); - printf("PID Username Machine Time logged in\n"); - printf("-------------------------------------------------------------------\n"); - doneone = 1; - } - ptr=srecs; while (ptr!=NULL) { if ((ptr->pid==crec.pid)&&(strncmp(ptr->machine,crec.machine,30)==0)) { @@ -203,13 +195,6 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) srecs=ptr; } } else { - if (!doneone) { - printf("\nSamba version %s\n",VERSION); - printf("Service uid gid pid machine\n"); - printf("----------------------------------------------\n"); - doneone = 1; - } - Ucrit_addPid(crec.pid); if (processes_only) { if (last_pid != crec.pid) @@ -292,19 +277,13 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) if (verbose) { printf("using configfile = %s\n", servicesf); - printf("lockdir = %s\n", *lp_lockdir() ? lp_lockdir() : "NULL"); } if (profile_only) { return profile_dump(); } - pstrcpy(fname,lp_lockdir()); - standard_sub_basic(fname); - trim_string(fname,"","/"); - pstrcat(fname,"/connections.tdb"); - - tdb = tdb_open(fname, 0, O_RDONLY, 0); + tdb = tdb_open(lock_path("connections.tdb"), 0, O_RDONLY, 0); if (!tdb) { printf("Couldn't open status file %s\n",fname); if (!lp_status(-1)) @@ -316,6 +295,14 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) if (locks_only) goto locks; + printf("\nSamba version %s\n",VERSION); + if (brief) { + printf("PID Username Machine Time logged in\n"); + printf("-------------------------------------------------------------------\n"); + } else { + printf("Service uid gid pid machine\n"); + printf("----------------------------------------------\n"); + } tdb_traverse(tdb, traverse_fn1); locks: @@ -347,8 +334,6 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) printf("\n"); - share_status(stdout); - locking_end(); } -- cgit From 488115dbcea1e6747b440d1b6d4da829d226a71f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 21 Dec 1999 09:33:45 +0000 Subject: changed message is connections.tdb doesn't exist (This used to be commit 835b9881c0f04d766545d5e9d2926fbaf8bec904) --- source3/utils/status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 8f3461c082..35f91ef2af 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -285,7 +285,7 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) tdb = tdb_open(lock_path("connections.tdb"), 0, O_RDONLY, 0); if (!tdb) { - printf("Couldn't open status file %s\n",fname); + printf("connections.tdb not initialised\n"); if (!lp_status(-1)) printf("You need to have status=yes in your smb config file\n"); return(0); -- cgit From fc4e722127c13b9b3e135ce3813f339eea28b8a5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 22 Dec 1999 01:36:27 +0000 Subject: improved error message in case the lock list is truncated (This used to be commit f4ecc5a8e39ee69c59123b7b3ffbd081f69824ca) --- source3/utils/status.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 35f91ef2af..5111891492 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -324,13 +324,20 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) printf("\n"); if (!shares_only) { + int ret; + if (!locking_init(1)) { printf("Can't initialise shared memory - exiting\n"); exit(1); } - if (share_mode_forall(print_share_mode) <= 0) + ret = share_mode_forall(print_share_mode); + + if (ret == 0) { printf("No locked files\n"); + } else if (ret == -1) { + printf("locked file list truncated\n"); + } printf("\n"); -- cgit From 9a781a8c6de9513ba5f4cafef41379fae96807c1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 2 Jan 2000 23:00:27 +0000 Subject: - added tdb_flags option to tdb_open() - added TDB_CLEAR_IF_FIRST flag to clear the database if this is the first attached process. Useful for non-persistent databases like our locking area (this will also make upgrades to new database layouts easier) - use lock_path() in a couple of places - leave connections database open while smbd running - cleaned up some tdb code a little, using macros for constants (This used to be commit 00e9da3ca577527db392aced62f02c69cfee8f4f) --- source3/utils/status.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 5111891492..3082402d8b 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -261,11 +261,11 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) case 's': pstrcpy(servicesf, optarg); break; - case 'u': /* added by OH */ - Ucrit_addUsername(optarg); /* added by OH */ + case 'u': + Ucrit_addUsername(optarg); break; default: - fprintf(stderr, "Usage: %s [-P] [-d] [-L] [-p] [-S] [-s configfile] [-u username]\n", *argv); /* changed by OH */ + fprintf(stderr, "Usage: %s [-P] [-d] [-L] [-p] [-S] [-s configfile] [-u username]\n", *argv); return (-1); } } @@ -283,7 +283,7 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) return profile_dump(); } - tdb = tdb_open(lock_path("connections.tdb"), 0, O_RDONLY, 0); + tdb = tdb_open(lock_path("connections.tdb"), 0, 0, O_RDONLY, 0); if (!tdb) { printf("connections.tdb not initialised\n"); if (!lp_status(-1)) -- cgit From 574788039f53fada4769731ea3fafe9710417b71 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 3 Jan 2000 03:17:16 +0000 Subject: added the unexpected packet database (unexpected.tdb) this means "nmblookup -S" now always works, even with broken servers the database stores all unexpected replies and these can be accessed by any client. while doing this I cleaned up a couple of functions, and put in place a better trn_id generator. in most places the code got quite a bit simpler due to the addition of simple helper functions. I haven't yet put the code in to take advantage of this for pdc replies - that will be next. Jeremys pdc finding code will then work :) (This used to be commit 280e6359d36c9bc8dcded302f15c3a1db8e3feeb) --- source3/utils/nmblookup.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 2f9bbc6c53..6214c0e45b 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -95,7 +95,7 @@ static BOOL query_one(char *lookup, unsigned int lookup_type) printf("querying %s on %s\n", lookup, inet_ntoa(bcast_addr)); ip_list = name_query(ServerFD,lookup,lookup_type,use_bcast, use_bcast?True:recursion_desired, - bcast_addr,&count,NULL); + bcast_addr,&count); } else { struct in_addr *bcast; for (j=iface_count() - 1; @@ -107,7 +107,7 @@ static BOOL query_one(char *lookup, unsigned int lookup_type) ip_list = name_query(ServerFD,lookup,lookup_type, use_bcast, use_bcast?True:recursion_desired, - *bcast,&count,NULL); + *bcast,&count); } } @@ -128,7 +128,7 @@ static BOOL query_one(char *lookup, unsigned int lookup_type) */ if (find_status) { printf("Looking up status of %s\n",inet_ntoa(ip_list[0])); - name_status(ServerFD,lookup,lookup_type,True,ip_list[0],NULL,NULL,NULL); + name_status(ServerFD,lookup,lookup_type,True,ip_list[0],NULL,NULL); printf("\n"); } @@ -243,7 +243,7 @@ int main(int argc,char *argv[]) fstrcpy(lookup,"*"); ip = *interpret_addr2(argv[i]); printf("Looking up status of %s\n",inet_ntoa(ip)); - name_status(ServerFD,lookup,lookup_type,True,ip,NULL,NULL,NULL); + name_status(ServerFD,lookup,lookup_type,True,ip,NULL,NULL); printf("\n"); continue; } -- cgit From 171da4d78736730557a94b44af9f2d62081b80ba Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 7 Jan 2000 06:55:36 +0000 Subject: this looks like a big commit, but it isn't really :) This fixes our netbios scope handling. We now have a 'netbios scope' option in smb.conf and the scope option is removed from make_nmb_name() this was prompted by a bug in our PDC finding code where it didn't append the scope to the query of the '*' name. (This used to be commit b563be824b8c3141c49558eced7829b48d4ab26f) --- source3/utils/nmblookup.c | 11 ++++++----- source3/utils/rpctorture.c | 5 ++--- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 6214c0e45b..8e26a206ca 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -26,8 +26,6 @@ extern int DEBUGLEVEL; -extern pstring scope; - extern struct in_addr ipzero; static BOOL use_bcast = True; @@ -178,9 +176,12 @@ int main(int argc,char *argv[]) translate_addresses = !translate_addresses; break; case 'i': - fstrcpy(scope,optarg); - strupper(scope); - break; + { + extern pstring global_scope; + pstrcpy(global_scope,optarg); + strupper(global_scope); + } + break; case 'M': find_master = True; break; diff --git a/source3/utils/rpctorture.c b/source3/utils/rpctorture.c index fb08d70011..c80cfe4ade 100644 --- a/source3/utils/rpctorture.c +++ b/source3/utils/rpctorture.c @@ -29,7 +29,6 @@ #define REGISTER 0 #endif -extern pstring scope; extern pstring global_myname; extern pstring user_socket_options; @@ -69,8 +68,8 @@ static BOOL rpcclient_connect(struct client_info *info) struct nmb_name calling; struct nmb_name called; - make_nmb_name(&called , dns_to_netbios_name(info->dest_host ), info->name_type, scope); - make_nmb_name(&calling, dns_to_netbios_name(info->myhostname), 0x0 , scope); + make_nmb_name(&called , dns_to_netbios_name(info->dest_host ), info->name_type); + make_nmb_name(&calling, dns_to_netbios_name(info->myhostname), 0x0); if (!cli_establish_connection(smb_cli, info->dest_host, &info->dest_ip, -- cgit From 6ba295ce0bde0aa8f64f60b1e72d6afec33bfece Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Jan 2000 09:49:52 +0000 Subject: added a DENY test that tests deny mode handling. It produces a matrix of 324 lines (6*6*3*3) of all possible deny mode behaviour. This allows us to compare with NT. We currently don't match :) (This used to be commit 2071105b439e87cb1c7c3a8c1b2046441eb46270) --- source3/utils/torture.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 9dc9d664b2..e5e300930a 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -92,8 +92,8 @@ static BOOL open_connection(struct cli_state *c) ZERO_STRUCTP(c); - make_nmb_name(&calling, myname, 0x0, ""); - make_nmb_name(&called , host, 0x20, ""); + make_nmb_name(&calling, myname, 0x0); + make_nmb_name(&called , host, 0x20); ip = ipzero; @@ -710,6 +710,89 @@ static void run_locktest3(int dummy) } +/* + this produces a matrix of deny mode behaviour + */ +static void run_denytest(int dummy) +{ + static struct cli_state cli1, cli2; + char *fname = "\\lockt1.lck"; + int fnum1, fnum2; + int d1, d2, o1, o2, x=0; + struct { + int v; + char *name; + } deny_modes[] = { + {DENY_DOS, "DENY_DOS"}, + {DENY_ALL, "DENY_ALL"}, + {DENY_WRITE, "DENY_WRITE"}, + {DENY_READ, "DENY_READ"}, + {DENY_NONE, "DENY_NONE"}, + {DENY_FCB, "DENY_FCB"}, + {-1, NULL}}; + struct { + int v; + char *name; + } open_modes[] = { + {O_RDWR, "O_RDWR"}, + {O_RDONLY, "O_RDONLY"}, + {O_WRONLY, "O_WRONLY"}, + {-1, NULL}}; + + if (!open_connection(&cli1) || !open_connection(&cli2)) { + return; + } + cli_sockopt(&cli1, sockops); + cli_sockopt(&cli2, sockops); + + printf("starting denytest\n"); + + cli_unlink(&cli1, fname); + + fnum1 = cli_open(&cli1, fname, O_WRONLY|O_CREAT, DENY_NONE); + cli_write(&cli1, fnum1, 0, fname, 0, strlen(fname)); + cli_close(&cli1, fnum1); + + for (d1=0;deny_modes[d1].name;d1++) for (o1=0;open_modes[o1].name;o1++) + for (d2=0;deny_modes[d2].name;d2++) for (o2=0;open_modes[o2].name;o2++) { + + fnum1 = cli_open(&cli1, fname, open_modes[o1].v, deny_modes[d1].v); + fnum2 = cli_open(&cli2, fname, + open_modes[o2].v | O_CREAT, + deny_modes[d2].v); + + printf("%8s %10s %8s %10s ", + open_modes[o1].name, + deny_modes[d1].name, + open_modes[o2].name, + deny_modes[d2].name); + + if (fnum1 == -1) { + printf("X"); + } else if (fnum2 == -1) { + printf("-"); + } else { + if (cli_read(&cli2, fnum2, (void *)&x, 0, 1) == 1) { + printf("R"); + } + if (cli_write(&cli2, fnum2, 0, (void *)&x, 0, 1) == 1) { + printf("W"); + } + } + + printf("\n"); + cli_close(&cli1, fnum1); + cli_close(&cli2, fnum2); + } + + cli_unlink(&cli1, fname); + + close_connection(&cli1); + close_connection(&cli2); + + printf("finshed denytest\n"); +} + /* test whether fnums and tids open on one VC are available on another (a major security hole) @@ -1302,6 +1385,7 @@ static struct { {"NBWNT", run_nbwnt, 0}, {"OPLOCK", run_oplock, 0}, {"DIR", run_dirtest, 0}, + {"DENY", run_denytest, 0}, {NULL, NULL, 0}}; -- cgit From e8b5cb45155536107a71e1106ad4a624eb559496 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Jan 2000 10:15:53 +0000 Subject: cli_open() wasn't handling DENY_FCB or O_WRONLY correctly. After fixing that I needed to use O_RDWR instead of O_WRONLY in several places to avoid the silly bug in MS servers that doesn't allow getattrE on a file opened with O_WRONLY (This used to be commit e21aa4cb088f348139309d29c85c48c8b777cff5) --- source3/utils/torture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index e5e300930a..e45f4cb568 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -749,7 +749,7 @@ static void run_denytest(int dummy) cli_unlink(&cli1, fname); - fnum1 = cli_open(&cli1, fname, O_WRONLY|O_CREAT, DENY_NONE); + fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT, DENY_NONE); cli_write(&cli1, fnum1, 0, fname, 0, strlen(fname)); cli_close(&cli1, fnum1); -- cgit From c01663c1a941d867a148aed522e6735504c6f64b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Jan 2000 11:37:45 +0000 Subject: extent smbtorture to test with both an exe file and a dat file (This used to be commit dd2ce575047eb57288bff11669512132fd347fda) --- source3/utils/torture.c | 80 ++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 37 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index e45f4cb568..4375cbe231 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -716,9 +716,9 @@ static void run_locktest3(int dummy) static void run_denytest(int dummy) { static struct cli_state cli1, cli2; - char *fname = "\\lockt1.lck"; int fnum1, fnum2; - int d1, d2, o1, o2, x=0; + int f, d1, d2, o1, o2, x=0; + char *fnames[] = {"denytest.exe", "denytest.dat", NULL}; struct { int v; char *name; @@ -747,49 +747,55 @@ static void run_denytest(int dummy) printf("starting denytest\n"); - cli_unlink(&cli1, fname); - - fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT, DENY_NONE); - cli_write(&cli1, fnum1, 0, fname, 0, strlen(fname)); - cli_close(&cli1, fnum1); - - for (d1=0;deny_modes[d1].name;d1++) for (o1=0;open_modes[o1].name;o1++) - for (d2=0;deny_modes[d2].name;d2++) for (o2=0;open_modes[o2].name;o2++) { + for (f=0;fnames[f];f++) { + cli_unlink(&cli1, fnames[f]); - fnum1 = cli_open(&cli1, fname, open_modes[o1].v, deny_modes[d1].v); - fnum2 = cli_open(&cli2, fname, - open_modes[o2].v | O_CREAT, - deny_modes[d2].v); - - printf("%8s %10s %8s %10s ", - open_modes[o1].name, - deny_modes[d1].name, - open_modes[o2].name, - deny_modes[d2].name); + fnum1 = cli_open(&cli1, fnames[f], O_RDWR|O_CREAT, DENY_NONE); + cli_write(&cli1, fnum1, 0, fnames[f], 0, strlen(fnames[f])); + cli_close(&cli1, fnum1); - if (fnum1 == -1) { - printf("X"); - } else if (fnum2 == -1) { - printf("-"); - } else { - if (cli_read(&cli2, fnum2, (void *)&x, 0, 1) == 1) { - printf("R"); - } - if (cli_write(&cli2, fnum2, 0, (void *)&x, 0, 1) == 1) { - printf("W"); + for (d1=0;deny_modes[d1].name;d1++) + for (o1=0;open_modes[o1].name;o1++) + for (d2=0;deny_modes[d2].name;d2++) + for (o2=0;open_modes[o2].name;o2++) { + fnum1 = cli_open(&cli1, fnames[f], + open_modes[o1].v, + deny_modes[d1].v); + fnum2 = cli_open(&cli2, fnames[f], + open_modes[o2].v, + deny_modes[d2].v); + + printf("%s %8s %10s %8s %10s ", + fnames[f], + open_modes[o1].name, + deny_modes[d1].name, + open_modes[o2].name, + deny_modes[d2].name); + + if (fnum1 == -1) { + printf("X"); + } else if (fnum2 == -1) { + printf("-"); + } else { + if (cli_read(&cli2, fnum2, (void *)&x, 0, 1) == 1) { + printf("R"); + } + if (cli_write(&cli2, fnum2, 0, (void *)&x, 0, 1) == 1) { + printf("W"); + } } - } - printf("\n"); - cli_close(&cli1, fnum1); - cli_close(&cli2, fnum2); + printf("\n"); + cli_close(&cli1, fnum1); + cli_close(&cli2, fnum2); + } + + cli_unlink(&cli1, fnames[f]); } - cli_unlink(&cli1, fname); - close_connection(&cli1); close_connection(&cli2); - + printf("finshed denytest\n"); } -- cgit From 0af00edf672eda7556f12745c80873376b85676f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Jan 2000 14:41:20 +0000 Subject: I'm currently designing a new locking system (using a tdb database!) that will make us match NT semantics exactly and do away with the horrible fd multiplexing in smbd. this is some diag stuff to get me started. - added the ability to do read or write locks in clientgen.c - added a LOCK4 test to smbtorture. This produces a report on the server and its locking capabilities. For example, NT4 gives this: the same process cannot set overlapping write locks the same process can set overlapping read locks a different connection cannot set overlapping write locks a different connection can set overlapping read locks a different pid cannot set overlapping write locks a different pid can set overlapping read locks the same process can set the same read lock twice the same process cannot set the same write lock twice the same process cannot override a read lock with a write lock the same process can override a write lock with a read lock a different pid cannot override a write lock with a read lock the same process cannot coalesce read locks this server does strict write locking this server does strict read locking whereas Samba currently gives this: the same process can set overlapping write locks the same process can set overlapping read locks a different connection cannot set overlapping write locks a different connection can set overlapping read locks a different pid can set overlapping write locks a different pid can set overlapping read locks the same process can set the same read lock twice the same process can set the same write lock twice the same process can override a read lock with a write lock the same process can override a write lock with a read lock a different pid can override a write lock with a read lock the same process can coalesce read locks this server does strict write locking this server does strict read locking win95 gives this - I don't understand why! the same process cannot set overlapping write locks the same process cannot set overlapping read locks a different connection cannot set overlapping write locks a different connection cannot set overlapping read locks a different pid cannot set overlapping write locks a different pid cannot set overlapping read locks the same process cannot set the same read lock twice the same process cannot set the same write lock twice the same process cannot override a read lock with a write lock the same process cannot override a write lock with a read lock a different pid cannot override a write lock with a read lock the same process cannot coalesce read locks this server does strict write locking this server does strict read locking (This used to be commit 49637936b6e9478df248c4ef73d818870c73b597) --- source3/utils/torture.c | 150 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 129 insertions(+), 21 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 4375cbe231..b9f0d76581 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -168,7 +168,7 @@ static BOOL check_error(struct cli_state *c, static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len) { - while (!cli_lock(c, fnum, offset, len, -1)) { + while (!cli_lock(c, fnum, offset, len, -1, F_WRLCK)) { if (!check_error(c, ERRDOS, ERRlock, 0)) return False; } return True; @@ -242,7 +242,7 @@ static BOOL rw_torture(struct cli_state *c) printf("unlink failed (%s)\n", cli_errstr(c)); } - if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int), -1)) { + if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int), -1, F_WRLCK)) { printf("unlock failed (%s)\n", cli_errstr(c)); } } @@ -436,13 +436,13 @@ static void run_locktest1(int dummy) return; } - if (!cli_lock(&cli1, fnum1, 0, 4, 0)) { + if (!cli_lock(&cli1, fnum1, 0, 4, 0, F_WRLCK)) { printf("lock1 failed (%s)\n", cli_errstr(&cli1)); return; } - if (cli_lock(&cli2, fnum3, 0, 4, 0)) { + if (cli_lock(&cli2, fnum3, 0, 4, 0, F_WRLCK)) { printf("lock2 succeeded! This is a locking bug\n"); return; } else { @@ -452,7 +452,7 @@ static void run_locktest1(int dummy) printf("Testing lock timeouts\n"); t1 = time(NULL); - if (cli_lock(&cli2, fnum3, 0, 4, 10*1000)) { + if (cli_lock(&cli2, fnum3, 0, 4, 10*1000, F_WRLCK)) { printf("lock3 succeeded! This is a locking bug\n"); return; } else { @@ -469,7 +469,7 @@ static void run_locktest1(int dummy) return; } - if (cli_lock(&cli2, fnum3, 0, 4, 0)) { + if (cli_lock(&cli2, fnum3, 0, 4, 0, F_WRLCK)) { printf("lock4 succeeded! This is a locking bug\n"); return; } else { @@ -550,12 +550,12 @@ static void run_locktest2(int dummy) cli_setpid(&cli, 1); - if (!cli_lock(&cli, fnum1, 0, 4, 0)) { + if (!cli_lock(&cli, fnum1, 0, 4, 0, F_WRLCK)) { printf("lock1 failed (%s)\n", cli_errstr(&cli)); return; } - if (cli_lock(&cli, fnum2, 0, 4, 0)) { + if (cli_lock(&cli, fnum2, 0, 4, 0, F_WRLCK)) { printf("lock2 succeeded! This is a locking bug\n"); } else { if (!check_error(&cli, ERRDOS, ERRlock, 0)) return; @@ -563,11 +563,11 @@ static void run_locktest2(int dummy) cli_setpid(&cli, 2); - if (cli_unlock(&cli, fnum1, 0, 4, 0)) { + if (cli_unlock(&cli, fnum1, 0, 4, 0, F_WRLCK)) { printf("unlock1 succeeded! This is a locking bug\n"); } - if (cli_lock(&cli, fnum3, 0, 4, 0)) { + if (cli_lock(&cli, fnum3, 0, 4, 0, F_WRLCK)) { printf("lock3 succeeded! This is a locking bug\n"); } else { if (!check_error(&cli, ERRDOS, ERRlock, 0)) return; @@ -633,14 +633,14 @@ static void run_locktest3(int dummy) for (offset=i=0;i Date: Thu, 13 Jan 2000 12:11:30 +0000 Subject: greatly expanded the lock4 locking test. we now pass all but one test - that should be fixed soon. (This used to be commit 23bb936e1fdeab2ad697ed946c945ef5ce87357d) --- source3/utils/torture.c | 138 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 93 insertions(+), 45 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index b9f0d76581..e905216d38 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -242,7 +242,7 @@ static BOOL rw_torture(struct cli_state *c) printf("unlink failed (%s)\n", cli_errstr(c)); } - if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int), -1, F_WRLCK)) { + if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int), -1)) { printf("unlock failed (%s)\n", cli_errstr(c)); } } @@ -563,7 +563,7 @@ static void run_locktest2(int dummy) cli_setpid(&cli, 2); - if (cli_unlock(&cli, fnum1, 0, 4, 0, F_WRLCK)) { + if (cli_unlock(&cli, fnum1, 0, 4, 0)) { printf("unlock1 succeeded! This is a locking bug\n"); } @@ -675,14 +675,14 @@ static void run_locktest3(int dummy) for (offset=i=0;i Date: Fri, 14 Jan 2000 00:50:48 +0000 Subject: some more work on the byte range locking note the ugly global_smbpid - I hope that won't bethere for long, I just didn't want to do two lots of major surgery at the one time. Using global_smbpid avoids the big change of getting rid of our inbuf/outbuf interface to reply routines. I'll do that once the locking stuff passes all tests. (This used to be commit f8bebf91abcaa5bda3ec8701f9242f220da8943a) --- source3/utils/torture.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index e905216d38..ba510c0b58 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -168,7 +168,7 @@ static BOOL check_error(struct cli_state *c, static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len) { - while (!cli_lock(c, fnum, offset, len, -1, F_WRLCK)) { + while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) { if (!check_error(c, ERRDOS, ERRlock, 0)) return False; } return True; @@ -436,13 +436,13 @@ static void run_locktest1(int dummy) return; } - if (!cli_lock(&cli1, fnum1, 0, 4, 0, F_WRLCK)) { + if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) { printf("lock1 failed (%s)\n", cli_errstr(&cli1)); return; } - if (cli_lock(&cli2, fnum3, 0, 4, 0, F_WRLCK)) { + if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) { printf("lock2 succeeded! This is a locking bug\n"); return; } else { @@ -452,7 +452,7 @@ static void run_locktest1(int dummy) printf("Testing lock timeouts\n"); t1 = time(NULL); - if (cli_lock(&cli2, fnum3, 0, 4, 10*1000, F_WRLCK)) { + if (cli_lock(&cli2, fnum3, 0, 4, 10*1000, WRITE_LOCK)) { printf("lock3 succeeded! This is a locking bug\n"); return; } else { @@ -469,7 +469,7 @@ static void run_locktest1(int dummy) return; } - if (cli_lock(&cli2, fnum3, 0, 4, 0, F_WRLCK)) { + if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) { printf("lock4 succeeded! This is a locking bug\n"); return; } else { @@ -550,12 +550,14 @@ static void run_locktest2(int dummy) cli_setpid(&cli, 1); - if (!cli_lock(&cli, fnum1, 0, 4, 0, F_WRLCK)) { + sleep(10); + + if (!cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) { printf("lock1 failed (%s)\n", cli_errstr(&cli)); return; } - if (cli_lock(&cli, fnum2, 0, 4, 0, F_WRLCK)) { + if (cli_lock(&cli, fnum2, 0, 4, 0, WRITE_LOCK)) { printf("lock2 succeeded! This is a locking bug\n"); } else { if (!check_error(&cli, ERRDOS, ERRlock, 0)) return; @@ -567,7 +569,7 @@ static void run_locktest2(int dummy) printf("unlock1 succeeded! This is a locking bug\n"); } - if (cli_lock(&cli, fnum3, 0, 4, 0, F_WRLCK)) { + if (cli_lock(&cli, fnum3, 0, 4, 0, WRITE_LOCK)) { printf("lock3 succeeded! This is a locking bug\n"); } else { if (!check_error(&cli, ERRDOS, ERRlock, 0)) return; @@ -633,14 +635,14 @@ static void run_locktest3(int dummy) for (offset=i=0;i Date: Fri, 14 Jan 2000 04:32:57 +0000 Subject: we now pass all byte range locking tests the last piece was to use a smb timeout slightly larger than the locking timeout in bloking locks to prevent a race (This used to be commit 1b54cb4a33a65e62c2e3189b78ef073869a60c75) --- source3/utils/torture.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index ba510c0b58..4539f11a6a 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -242,7 +242,7 @@ static BOOL rw_torture(struct cli_state *c) printf("unlink failed (%s)\n", cli_errstr(c)); } - if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int), -1)) { + if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) { printf("unlock failed (%s)\n", cli_errstr(c)); } } @@ -550,8 +550,6 @@ static void run_locktest2(int dummy) cli_setpid(&cli, 1); - sleep(10); - if (!cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) { printf("lock1 failed (%s)\n", cli_errstr(&cli)); return; @@ -565,7 +563,7 @@ static void run_locktest2(int dummy) cli_setpid(&cli, 2); - if (cli_unlock(&cli, fnum1, 0, 4, 0)) { + if (cli_unlock(&cli, fnum1, 0, 8)) { printf("unlock1 succeeded! This is a locking bug\n"); } @@ -677,14 +675,14 @@ static void run_locktest3(int dummy) for (offset=i=0;i Date: Fri, 14 Jan 2000 08:33:20 +0000 Subject: casts and defines to make solaris happy (This used to be commit 77cf152c02b445f4b6e9de393936dd6e54e6f442) --- source3/utils/nbio.c | 2 +- source3/utils/torture.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nbio.c b/source3/utils/nbio.c index 71ac959f11..f72be36842 100644 --- a/source3/utils/nbio.c +++ b/source3/utils/nbio.c @@ -42,7 +42,7 @@ 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", - getpid(), getpid()); + (int)getpid(), (int)getpid()); system(line); exit(1); } diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 4539f11a6a..fb4367283c 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -1416,7 +1416,7 @@ static void run_dirtest(int dummy) srandom(0); for (i=0;i Date: Sun, 16 Jan 2000 11:14:44 +0000 Subject: added code to allow traversal of the byte range lock database this is used with "smbstatus -B" to dump the lock list (This used to be commit 5f022629146701e6d543f77007dc944e4277ab0c) --- source3/utils/status.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 3082402d8b..c7e52d1834 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -55,6 +55,7 @@ static int verbose, brief; static int shares_only = 0; /* Added by RJS */ static int locks_only = 0; /* Added by RJS */ static BOOL processes_only=False; +static int show_brl; /* we need these because we link to locking*.o */ void become_root(BOOL save_dir) {} @@ -113,6 +114,8 @@ static void print_share_mode(share_mode_entry *e, char *fname) case DENY_DOS: printf("DENY_DOS "); break; case DENY_READ: printf("DENY_READ "); break; case DENY_WRITE:printf("DENY_WRITE "); break; + case 0xFF: + case DENY_FCB: printf("DENY_FCB "); break; } switch (e->share_mode&0xF) { case 0: printf("RDONLY "); break; @@ -138,6 +141,24 @@ static void print_share_mode(share_mode_entry *e, char *fname) } } +static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, + enum brl_type lock_type, + br_off start, br_off size) +{ + static int count; + if (count==0) { + printf("Byte range locks:\n"); + printf(" Pid dev:inode R/W start size\n"); + printf("------------------------------------------------\n"); + } + count++; + + printf("%6d %05x:%05x %s %9.0f %9.0f\n", + (int)pid, (int)dev, (int)ino, + lock_type==READ_LOCK?"R":"W", + (double)start, (double)size); +} + /******************************************************************* dump the elements of the profile structure @@ -238,11 +259,14 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) return(1); } - while ((c = getopt(argc, argv, "pdLSs:u:bP")) != EOF) { + while ((c = getopt(argc, argv, "pdLSs:u:bPB")) != EOF) { switch (c) { case 'b': brief = 1; break; + case 'B': + show_brl = 1; + break; case 'd': verbose = 1; break; @@ -340,6 +364,10 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) } printf("\n"); + + if (show_brl) { + brl_forall(print_brl); + } locking_end(); } -- cgit From b09e4c370e99edb8b206d601b62933b8bed45925 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Jan 2000 12:27:20 +0000 Subject: use GET_DENY_MODE() macro (This used to be commit d9c3e0e61f315ad4d9c3ea6bb6acc8500befe6b4) --- source3/utils/status.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index c7e52d1834..3f618dcd17 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -108,13 +108,12 @@ static void print_share_mode(share_mode_entry *e, char *fname) if (Ucrit_checkPid(e->pid)) { printf("%-5d ",(int)e->pid); - switch ((e->share_mode>>4)&0xF) { + switch (GET_DENY_MODE(e->share_mode)) { case DENY_NONE: printf("DENY_NONE "); break; case DENY_ALL: printf("DENY_ALL "); break; case DENY_DOS: printf("DENY_DOS "); break; case DENY_READ: printf("DENY_READ "); break; case DENY_WRITE:printf("DENY_WRITE "); break; - case 0xFF: case DENY_FCB: printf("DENY_FCB "); break; } switch (e->share_mode&0xF) { -- cgit From 6389b81f9d272da7ed26bb4df61d57fe2e42b074 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Jan 2000 12:28:43 +0000 Subject: renamed DENY to DENY1 added DENY2 test that checks all 648 deny combinations for the case of two opens on the same connection (This used to be commit 01d4c4784dd26bdfc9883907b3170e8b0ea0cd6f) --- source3/utils/torture.c | 100 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 95 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index fb4367283c..ad14461ff5 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -869,12 +869,12 @@ static void run_locktest4(int dummy) /* this produces a matrix of deny mode behaviour */ -static void run_denytest(int dummy) +static void run_denytest1(int dummy) { static struct cli_state cli1, cli2; int fnum1, fnum2; int f, d1, d2, o1, o2, x=0; - char *fnames[] = {"denytest.exe", "denytest.dat", NULL}; + char *fnames[] = {"denytest1.exe", "denytest1.dat", NULL}; struct { int v; char *name; @@ -901,7 +901,7 @@ static void run_denytest(int dummy) cli_sockopt(&cli1, sockops); cli_sockopt(&cli2, sockops); - printf("starting denytest\n"); + printf("starting denytest1\n"); for (f=0;fnames[f];f++) { cli_unlink(&cli1, fnames[f]); @@ -952,7 +952,96 @@ static void run_denytest(int dummy) close_connection(&cli1); close_connection(&cli2); - printf("finshed denytest\n"); + printf("finshed denytest1\n"); +} + + +/* + this produces a matrix of deny mode behaviour for two opens on the + same connection + */ +static void run_denytest2(int dummy) +{ + static struct cli_state cli1; + int fnum1, fnum2; + int f, d1, d2, o1, o2, x=0; + char *fnames[] = {"denytest2.exe", "denytest2.dat", NULL}; + struct { + int v; + char *name; + } deny_modes[] = { + {DENY_DOS, "DENY_DOS"}, + {DENY_ALL, "DENY_ALL"}, + {DENY_WRITE, "DENY_WRITE"}, + {DENY_READ, "DENY_READ"}, + {DENY_NONE, "DENY_NONE"}, + {DENY_FCB, "DENY_FCB"}, + {-1, NULL}}; + struct { + int v; + char *name; + } open_modes[] = { + {O_RDWR, "O_RDWR"}, + {O_RDONLY, "O_RDONLY"}, + {O_WRONLY, "O_WRONLY"}, + {-1, NULL}}; + + if (!open_connection(&cli1)) { + return; + } + cli_sockopt(&cli1, sockops); + + printf("starting denytest2\n"); + + for (f=0;fnames[f];f++) { + cli_unlink(&cli1, fnames[f]); + + fnum1 = cli_open(&cli1, fnames[f], O_RDWR|O_CREAT, DENY_NONE); + cli_write(&cli1, fnum1, 0, fnames[f], 0, strlen(fnames[f])); + cli_close(&cli1, fnum1); + + for (d1=0;deny_modes[d1].name;d1++) + for (o1=0;open_modes[o1].name;o1++) + for (d2=0;deny_modes[d2].name;d2++) + for (o2=0;open_modes[o2].name;o2++) { + fnum1 = cli_open(&cli1, fnames[f], + open_modes[o1].v, + deny_modes[d1].v); + fnum2 = cli_open(&cli1, fnames[f], + open_modes[o2].v, + deny_modes[d2].v); + + printf("%s %8s %10s %8s %10s ", + fnames[f], + open_modes[o1].name, + deny_modes[d1].name, + open_modes[o2].name, + deny_modes[d2].name); + + if (fnum1 == -1) { + printf("X"); + } else if (fnum2 == -1) { + printf("-"); + } else { + if (cli_read(&cli1, fnum2, (void *)&x, 0, 1) == 1) { + printf("R"); + } + if (cli_write(&cli1, fnum2, 0, (void *)&x, 0, 1) == 1) { + printf("W"); + } + } + + printf("\n"); + cli_close(&cli1, fnum1); + cli_close(&cli1, fnum2); + } + + cli_unlink(&cli1, fnames[f]); + } + + close_connection(&cli1); + + printf("finshed denytest2\n"); } /* @@ -1547,7 +1636,8 @@ static struct { {"NBWNT", run_nbwnt, 0}, {"OPLOCK", run_oplock, 0}, {"DIR", run_dirtest, 0}, - {"DENY", run_denytest, 0}, + {"DENY1", run_denytest1, 0}, + {"DENY2", run_denytest2, 0}, {NULL, NULL, 0}}; -- cgit From bbe275e95b86bc7af5a641455cbb379974823f84 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 4 Feb 2000 04:59:31 +0000 Subject: 1) added void* state argument to tdb_traverse. guess what! there were two places i found where it was appropriate to _use_ that third argument, in locking.c and brlock.c! there was a static traverse_function and i removed the static variable, typecast it to a void*, passed it to tdb_traverse and re-cast it back to the traverse_function inside the tdb_traverse function. this makes the use of tdb_traverse() reentrant, which is never going to happen, i know, i just don't like to see statics lying about when there's no need for them. as i had to do in samba-tng, all uses of tdb_traverse modified to take the new void* state argument. 2) disabled rpcclient: referring people to use SAMBA_TNG rpcclient. i don't know how the other samba team members would react if i deleted rpcclient from cvs main. damn, that code's so old, it's unreal. 20 rpcclient commands, instead of about 70 in SAMBA_TNG. (This used to be commit 49d7f0afbc1c5425d53019e234d54ddf205c8e9a) --- source3/utils/status.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 3f618dcd17..5c01409737 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -180,7 +180,7 @@ static int profile_dump(void) } -static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) +static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { static pid_t last_pid; struct session_record *ptr; @@ -326,7 +326,7 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) printf("Service uid gid pid machine\n"); printf("----------------------------------------------\n"); } - tdb_traverse(tdb, traverse_fn1); + tdb_traverse(tdb, traverse_fn1, NULL); locks: if (processes_only) exit(0); -- cgit From 74f0d16da40054e2341674ed8b9a6027b0bf5f1b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 9 Feb 2000 14:10:08 +0000 Subject: added masktest to head branch, in preparation for another assault on the wildcard handling code (This used to be commit 3f77690dade57f4ae9da7196b0aa7a3a43afcc46) --- source3/utils/masktest.c | 435 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 435 insertions(+) create mode 100644 source3/utils/masktest.c (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c new file mode 100644 index 0000000000..b4d919fe7c --- /dev/null +++ b/source3/utils/masktest.c @@ -0,0 +1,435 @@ +/* + 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 + +static char *reg_test(char *pattern, char *file) +{ + static fstring ret; + pstring rpattern; + regex_t preg; + + pattern = 1+strrchr(pattern,'\\'); + file = 1+strrchr(file,'\\'); + + fstrcpy(ret,"---"); + + if (strcmp(file,"..") == 0) file = "."; + if (strcmp(pattern,".") == 0) return ret; + + if (strcmp(pattern,"") == 0) { + ret[2] = '+'; + return ret; + } + + 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); + if (regexec(&preg, ".", 0, NULL, 0) == 0) { + ret[0] = '+'; + ret[1] = '+'; + } + if (regexec(&preg, file, 0, NULL, 0) == 0) { + ret[2] = '+'; + } + regfree(&preg); + + 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, res2)) { + DEBUG(0,("%s %s %s %d mask=[%s] file=[%s]\n", + res1, res2, res3, count, mask, file)); + } + + cli_unlink(cli1, file); + cli_unlink(cli2, file); +} + +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; + } + + 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); + } + } + + while (1) { + l1 = 1 + random() % 20; + l2 = 1 + random() % 20; + pstrcpy(mask,"\\masktest\\"); + pstrcpy(file,"\\masktest\\"); + l = strlen(mask); + for (i=0;i Date: Wed, 9 Feb 2000 14:17:12 +0000 Subject: update masktest for new make_nmb_name() syntax (This used to be commit 3609e835d4f938190f43b958403978c892b4bc9b) --- source3/utils/masktest.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index b4d919fe7c..380a4d7c71 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -120,8 +120,8 @@ struct cli_state *connect_one(char *share) ip = ipzero; - make_nmb_name(&calling, "masktest", 0x0, ""); - make_nmb_name(&called , server, 0x20, ""); + make_nmb_name(&calling, "masktest", 0x0); + make_nmb_name(&called , server, 0x20); again: ip = ipzero; @@ -137,7 +137,7 @@ struct cli_state *connect_one(char *share) DEBUG(0,("session request to %s failed\n", called.name)); cli_shutdown(c); if (strcmp(called.name, "*SMBSERVER")) { - make_nmb_name(&called , "*SMBSERVER", 0x20, ""); + make_nmb_name(&called , "*SMBSERVER", 0x20); goto again; } return NULL; -- cgit From dacbb15e9f36993397daf7bdffca4a714f28163d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Feb 2000 13:43:59 +0000 Subject: the beginnings of a fnmatch() based wildcard matching routine (This used to be commit ef256de9d9a204cf91fe8b636d07400cd0648d1e) --- source3/utils/masktest.c | 86 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 20 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index 380a4d7c71..a1fe6d2186 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -35,7 +35,7 @@ static char *maskchars = "<>\"?*abc."; static char *filechars = "abcdefghijklm."; char *standard_masks[] = {"*", "*.", "*.*", - ".*", "d2.??", "d2\">>", + ".*", "d2.??", "d2\">>", "??", NULL}; char *standard_files[] = {"abc", "abc.", ".abc", "abc.def", "abc.de.f", @@ -45,23 +45,49 @@ char *standard_files[] = {"abc", "abc.", ".abc", #include -static char *reg_test(char *pattern, char *file) +static BOOL reg_match_one(char *pattern, char *file) { - static fstring ret; pstring rpattern; - regex_t preg; + pstring rfile; - pattern = 1+strrchr(pattern,'\\'); - file = 1+strrchr(file,'\\'); + 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); - fstrcpy(ret,"---"); + 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 ret; + if (strcmp(pattern,".") == 0) return False; if (strcmp(pattern,"") == 0) { - ret[2] = '+'; - return ret; + if (strcmp(file,".") == 0) return False; + return True; } pstrcpy(rpattern,"^"); @@ -85,18 +111,27 @@ static char *reg_test(char *pattern, char *file) /* printf("pattern=[%s] rpattern=[%s]\n", pattern, rpattern); */ regcomp(&preg, rpattern, REG_ICASE|REG_NOSUB|REG_EXTENDED); - if (regexec(&preg, ".", 0, NULL, 0) == 0) { - ret[0] = '+'; - ret[1] = '+'; - } - if (regexec(&preg, file, 0, NULL, 0) == 0) { - ret[2] = '+'; - } + 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 @@ -241,13 +276,22 @@ static void testpair(struct cli_state *cli1, struct cli_state *cli2, resultp = res2; cli_list(cli2, mask, aHIDDEN | aDIR, listfn); - if (showall || strcmp(res1, res2)) { - DEBUG(0,("%s %s %s %d mask=[%s] file=[%s]\n", - res1, res2, res3, count, mask, file)); + 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[], @@ -277,6 +321,7 @@ static void test_mask(int argc, char *argv[], goto finished; } +#if 1 for (i=0; standard_masks[i]; i++) { for (j=0; standard_files[j]; j++) { pstrcpy(mask,"\\masktest\\"); @@ -286,6 +331,7 @@ static void test_mask(int argc, char *argv[], testpair(cli1, cli2, mask, file); } } +#endif while (1) { l1 = 1 + random() % 20; -- cgit From 3cf31a194f5721b67b1255e3f168d4bc87d433fc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 15 Feb 2000 19:36:47 +0000 Subject: Added replacement functions sys_popen and sys_pclose. These are based on the glibc source code and are safer than the traditional popen as they don't use a shell to exec the requested command. Now we have these functions they can be tightened up (environment etc.) as required to make a safe popen. It should now be safe to add the environement variable loading code to loadparm.c Jeremy. (This used to be commit b52e92b09d4ca3b66e534f520468dee27065d048) --- source3/utils/make_printerdef.c | 44 ++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index fc1f8ad781..33aec325c2 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -27,7 +27,7 @@ */ char *files_to_copy; -char *driverfile, *datafile, *helpfile, *languagemonitor, *datatype; +char *driverfile, *datafile, *helpfile, *languagemonitor, *datatype, *vendorsetup; char buffer[50][sizeof(pstring)]; char sbuffer[50][sizeof(pstring)]; char sub_dir[50][2][sizeof(pstring)]; @@ -96,13 +96,20 @@ static char *scan(char *chaine,char **entry) i++; } (*entry)[i]='\0'; - pstrcpy(value,temp+i+1); + if (temp[i]!='\0') { + i++; + } + while( temp[i]==' ' && temp[i]!='\0') { + i++; + } + pstrcpy(value,temp+i); return (value); } static void build_subdir(void) { int i=0; + int j=0; char *entry; char *data; @@ -111,12 +118,18 @@ static void build_subdir(void) #ifdef DEBUGIT fprintf(stderr,"\tentry=data %s:%s\n",entry,data); #endif + j = strlen(entry); + while (j) { + if (entry[j-1] != ' ') break; + j--; + } + entry[j] = '\0'; - if (strcmp(data,"11")==0) { + if (strncmp(data,"11",2)==0) { pstrcpy(sub_dir[i][0],entry); pstrcpy(sub_dir[i][1],""); } - if (strcmp(data,"23")==0) { + if (strncmp(data,"23",2)==0) { pstrcpy(sub_dir[i][0],entry); pstrcpy(sub_dir[i][1],"color\\"); } @@ -362,15 +375,21 @@ static void scan_copyfiles(FILE *fichier, char *chaine) else break; } } - if (strlen(files_to_copy) != 0) - pstrcat(files_to_copy,","); - pstrcat(files_to_copy,direc); - pstrcat(files_to_copy,buffer[i]); - fprintf(stderr,"%s%s\n",direc,buffer[i]); + if (*buffer[i] != ';') { + if (strlen(files_to_copy) != 0) + pstrcat(files_to_copy,","); + pstrcat(files_to_copy,direc); + pstrcat(files_to_copy,buffer[i]); + fprintf(stderr,"%s%s\n",direc,buffer[i]); + } i++; } } part=strtok(NULL,","); + if (part) + while( *part ==' ' && *part != '\0') { + part++; + } } while (part!=NULL); fprintf(stderr,"\n"); @@ -385,6 +404,7 @@ static void scan_short_desc(FILE *fichier, char *short_desc) helpfile=0; languagemonitor=0; + vendorsetup=0; datatype="RAW"; if((temp=(char *)malloc(sizeof(pstring))) == NULL) { fprintf(stderr, "scan_short_desc: malloc fail !\n"); @@ -414,6 +434,8 @@ static void scan_short_desc(FILE *fichier, char *short_desc) languagemonitor=scan(buffer[i],&temp); else if (strncasecmp(buffer[i],"DefaultDataType",15)==0) datatype=scan(buffer[i],&temp); + else if (strncasecmp(buffer[i],"VendorSetup",11)==0) + vendorsetup=scan(buffer[i],&temp); i++; } @@ -439,6 +461,8 @@ static void scan_short_desc(FILE *fichier, char *short_desc) languagemonitor=scan(buffer[i],&temp); else if (strncasecmp(buffer[i],"DefaultDataType",15)==0) datatype=scan(buffer[i],&temp); + else if (strncasecmp(buffer[i],"VendorSetup",11)==0) + vendorsetup=scan(buffer[i],&temp); i++; } } @@ -464,6 +488,8 @@ static void scan_short_desc(FILE *fichier, char *short_desc) helpfile?helpfile:"(null)"); fprintf(stderr,"LanguageMonitor: %s\n", languagemonitor?languagemonitor:"(null)"); + fprintf(stderr,"VendorSetup: %s\n", + vendorsetup?vendorsetup:"(null)"); if (copyfiles) scan_copyfiles(fichier,copyfiles); } -- cgit From 0f1eee5c7ac4031cd2a97524b1f65a24d0d618c2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 25 Feb 2000 22:25:25 +0000 Subject: client/client.c: libsmb/clientgen.c: Fixes for Win2k smbclient browsing. Other fixes implement smbpasswd -x user to delete users. Also allows swat to do the same. Jeremy. (This used to be commit 9f6ad046761adecafba59040baa3abc9f0959e65) --- source3/utils/smbpasswd.c | 96 +++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 53 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index ec6ce15f07..dcfafaa8b9 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -63,6 +63,7 @@ static void usage(void) printf(" -R ORDER name resolve order\n"); printf(" -j DOMAIN join domain name\n"); printf(" -a add user\n"); + printf(" -x delete user\n"); printf(" -d disable user\n"); printf(" -e enable user\n"); printf(" -n set no password\n"); @@ -218,20 +219,19 @@ static char *prompt_for_new_password(BOOL stdin_get) /************************************************************* -change a password either locally or remotely + Change a password either locally or remotely. *************************************************************/ + static BOOL password_change(const char *remote_machine, char *user_name, - char *old_passwd, char *new_passwd, - BOOL add_user, BOOL enable_user, - BOOL disable_user, BOOL set_no_password, - BOOL trust_account) + char *old_passwd, char *new_passwd, int local_flags) { BOOL ret; pstring err_str; pstring msg_str; if (remote_machine != NULL) { - if (add_user || enable_user || disable_user || set_no_password || trust_account) { + if (local_flags & (LOCAL_ADD_USER|LOCAL_DELETE_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER| + LOCAL_TRUST_ACCOUNT|LOCAL_SET_NO_PASSWORD)) { /* these things can't be done remotely yet */ return False; } @@ -242,8 +242,7 @@ static BOOL password_change(const char *remote_machine, char *user_name, return ret; } - ret = local_password_change(user_name, trust_account, add_user, enable_user, - disable_user, set_no_password, new_passwd, + ret = local_password_change(user_name, local_flags, new_passwd, err_str, sizeof(err_str), msg_str, sizeof(msg_str)); if(*msg_str) @@ -256,18 +255,15 @@ static BOOL password_change(const char *remote_machine, char *user_name, /************************************************************* -handle password changing for root + Handle password changing for root. *************************************************************/ + static int process_root(int argc, char *argv[]) { struct passwd *pwd; int ch; BOOL joining_domain = False; - BOOL trust_account = False; - BOOL add_user = False; - BOOL disable_user = False; - BOOL enable_user = False; - BOOL set_no_password = False; + int local_flags = 0; BOOL stdin_passwd_get = False; char *user_name = NULL; char *new_domain = NULL; @@ -275,24 +271,37 @@ static int process_root(int argc, char *argv[]) char *old_passwd = NULL; char *remote_machine = NULL; - while ((ch = getopt(argc, argv, "adehmnj:r:sR:D:U:")) != EOF) { + while ((ch = getopt(argc, argv, "a:x:d:e:mnj:r:sR:D:U:")) != EOF) { switch(ch) { case 'a': - add_user = True; + local_flags |= LOCAL_ADD_USER; + user_name = optarg; + break; + case 'x': + local_flags |= LOCAL_DELETE_USER; + user_name = optarg; + new_passwd = "XXXXXX"; break; case 'd': - disable_user = True; + local_flags |= LOCAL_DISABLE_USER; + user_name = optarg; new_passwd = "XXXXXX"; break; case 'e': - enable_user = True; + local_flags |= LOCAL_ENABLE_USER; + user_name = optarg; break; - case 'D': - DEBUGLEVEL = atoi(optarg); + case 'm': + local_flags |= LOCAL_TRUST_ACCOUNT; break; case 'n': - set_no_password = True; + local_flags |= LOCAL_SET_NO_PASSWORD; new_passwd = "NO PASSWORD"; + case 'j': + new_domain = optarg; + strupper(new_domain); + joining_domain = True; + break; case 'r': remote_machine = optarg; break; @@ -305,13 +314,8 @@ static int process_root(int argc, char *argv[]) case 'R': lp_set_name_resolve_order(optarg); break; - case 'm': - trust_account = True; - break; - case 'j': - new_domain = optarg; - strupper(new_domain); - joining_domain = True; + case 'D': + DEBUGLEVEL = atoi(optarg); break; case 'U': user_name = optarg; @@ -326,15 +330,16 @@ static int process_root(int argc, char *argv[]) /* - * Ensure add_user and either remote machine or join domain are + * Ensure add/delete user and either remote machine or join domain are * not both set. */ - if(add_user && ((remote_machine != NULL) || joining_domain)) { + if((local_flags & (LOCAL_ADD_USER|LOCAL_DELETE_USER)) && ((remote_machine != NULL) || joining_domain)) { usage(); } if(joining_domain) { - if (argc != 0) usage(); + if (argc != 0) + usage(); return join_domain(new_domain, remote_machine); } @@ -365,7 +370,7 @@ static int process_root(int argc, char *argv[]) exit(1); } - if (trust_account) { + if (local_flags & LOCAL_TRUST_ACCOUNT) { /* add the $ automatically */ static fstring buf; @@ -378,7 +383,7 @@ static int process_root(int argc, char *argv[]) user_name[strlen(user_name)-1] = 0; } - if (add_user) { + if (local_flags & LOCAL_ADD_USER) { new_passwd = xstrdup(user_name); strlower(new_passwd); } @@ -392,12 +397,6 @@ static int process_root(int argc, char *argv[]) user_name = buf; } - if (!remote_machine && !Get_Pwnam(user_name, True)) { - fprintf(stderr, "User \"%s\" was not found in system password file.\n", - user_name); - exit(1); - } - if (remote_machine != NULL) { old_passwd = get_pass("Old SMB password:",stdin_passwd_get); } @@ -413,7 +412,7 @@ static int process_root(int argc, char *argv[]) * smbpasswd file) then we need to prompt for a new password. */ - if(enable_user) { + if(local_flags & LOCAL_ENABLE_USER) { struct smb_passwd *smb_pass = getsmbpwnam(user_name); if((smb_pass != NULL) && (smb_pass->smb_passwd != NULL)) { new_passwd = "XXXX"; /* Don't care. */ @@ -429,20 +428,12 @@ static int process_root(int argc, char *argv[]) } } - if (!password_change(remote_machine, user_name, old_passwd, new_passwd, - add_user, enable_user, disable_user, set_no_password, - trust_account)) { - fprintf(stderr,"Failed to change password entry for %s\n", user_name); + if (!password_change(remote_machine, user_name, old_passwd, new_passwd, local_flags)) { + fprintf(stderr,"Failed to modify password entry for user %s\n", user_name); return 1; } - if(disable_user) { - printf("User %s disabled.\n", user_name); - } else if(enable_user) { - printf("User %s enabled.\n", user_name); - } else if (set_no_password) { - printf("User %s - set to no password.\n", user_name); - } else { + if(!(local_flags & (LOCAL_ADD_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER|LOCAL_DELETE_USER|LOCAL_SET_NO_PASSWORD))) { struct smb_passwd *smb_pass = getsmbpwnam(user_name); printf("Password changed for user %s.", user_name ); if((smb_pass != NULL) && (smb_pass->acct_ctrl & ACB_DISABLED )) @@ -534,8 +525,7 @@ static int process_nonroot(int argc, char *argv[]) exit(1); } - if (!password_change(remote_machine, user_name, old_passwd, new_passwd, - False, False, False, False, False)) { + if (!password_change(remote_machine, user_name, old_passwd, new_passwd, 0)) { fprintf(stderr,"Failed to change password for %s\n", user_name); return 1; } -- cgit From 50444a0b5fd1bece0dd031840873867d92c9507d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 1 Mar 2000 18:58:50 +0000 Subject: Fixed smbpasswd crash bugs found by Giulio. Jeremy. (This used to be commit 54440428e5dbf5c1e673e881d3a9364e64ad2ad7) --- source3/utils/smbpasswd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index dcfafaa8b9..7a0d0eeea9 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -271,11 +271,10 @@ static int process_root(int argc, char *argv[]) char *old_passwd = NULL; char *remote_machine = NULL; - while ((ch = getopt(argc, argv, "a:x:d:e:mnj:r:sR:D:U:")) != EOF) { + while ((ch = getopt(argc, argv, "ax:d:e:mnj:r:sR:D:U:")) != EOF) { switch(ch) { case 'a': local_flags |= LOCAL_ADD_USER; - user_name = optarg; break; case 'x': local_flags |= LOCAL_DELETE_USER; @@ -297,6 +296,7 @@ static int process_root(int argc, char *argv[]) case 'n': local_flags |= LOCAL_SET_NO_PASSWORD; new_passwd = "NO PASSWORD"; + break; case 'j': new_domain = optarg; strupper(new_domain); @@ -328,7 +328,6 @@ static int process_root(int argc, char *argv[]) argc -= optind; argv += optind; - /* * Ensure add/delete user and either remote machine or join domain are * not both set. -- cgit From 3958c3910658e99fe1cfd737e0cfc126dffc75da Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Tue, 7 Mar 2000 21:55:42 +0000 Subject: added a tcon test: make two tconXs with the same user/pass, open a file with one of them and try to write to the file with the other. (This used to be commit f8d3ce0419aee44e4d5efe1257ce4b27f7511ceb) --- source3/utils/torture.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index ad14461ff5..d6d8c6010b 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -498,6 +498,77 @@ static void run_locktest1(int dummy) printf("Passed locktest1\n"); } +/* + checks for correct tconX support + */ +static void run_tcon_test(int dummy) +{ + static struct cli_state cli1; + char *fname = "\\tcontest.tmp"; + int fnum1; + uint16 cnum; + char buf[4]; + + if (!open_connection(&cli1)) { + return; + } + cli_sockopt(&cli1, sockops); + + printf("starting tcontest\n"); + + cli_unlink(&cli1, fname); + + fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) + { + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + cnum = cli1.cnum; + + if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4) + { + printf("write failed (%s)", cli_errstr(&cli1)); + return; + } + + if (!cli_send_tconX(&cli1, share, "?????", + password, strlen(password)+1)) { + printf("%s refused 2nd tree connect (%s)\n", host, + cli_errstr(&cli1)); + cli_shutdown(&cli1); + return ; + } + + if (cli_write(&cli1, fnum1, 0, buf, 130, 4) == 4) + { + printf("write succeeded (%s)", cli_errstr(&cli1)); + return; + } + + if (cli_close(&cli1, fnum1)) { + printf("close2 succeeded (%s)\n", cli_errstr(&cli1)); + return; + } + + if (!cli_tdis(&cli1)) { + printf("tdis failed (%s)\n", cli_errstr(&cli1)); + return; + } + + cli1.cnum = cnum; + + if (!cli_close(&cli1, fnum1)) { + printf("close2 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + close_connection(&cli1); + + printf("Passed tcontest\n"); +} + /* This test checks that @@ -1638,6 +1709,7 @@ static struct { {"DIR", run_dirtest, 0}, {"DENY1", run_denytest1, 0}, {"DENY2", run_denytest2, 0}, + {"TCON", run_tcon_test, 0}, {NULL, NULL, 0}}; -- cgit From 08607c3e0ce5fa5c43b236ca379ed5aaa66ed858 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 14 Mar 2000 22:04:35 +0000 Subject: Fixed parsing issue with HP printer defs reported by HP. Jeremy. (This used to be commit 035272e6bcc8c43bf4521e4a20b0c35b0901e904) --- source3/utils/make_printerdef.c | 88 +++++++++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 26 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index 33aec325c2..f403ee79bb 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -338,8 +338,8 @@ static void scan_copyfiles(FILE *fichier, char *chaine) fprintf(stderr,"\tsubdir %s:%s\n",sub_dir[i][0],sub_dir[i][1]); #endif if (strcmp(sub_dir[i][0],part)==0) - pstrcpy(direc,sub_dir[i][1]); - i++; + pstrcpy(direc,sub_dir[i][1]); + i++; } i=0; while (*buffer[i]!='\0') { @@ -350,48 +350,84 @@ static void scan_copyfiles(FILE *fichier, char *chaine) * * pscript.hlp = pscript.hl_ * hpdcmon.dll,hpdcmon.dl_ + * MSVCRT.DLL,MSVCRT.DL_,,32 * ctl3dv2.dll,ctl3dv2.dl_,ctl3dv2.tmp * * In the first 2 cases you want the first file name - in the last case * you only want the last file name (at least that is what a Win95 - * machine sent). This may still be wrong but at least I get the same list + * machine sent). In the third case you also want the first file name + * (detect by the last component being just a number ?). + * This may still be wrong but at least I get the same list * of files as seen on a printer test page. */ part = strchr(buffer[i],'='); if (part) { + /* + * Case (1) eg. pscript.hlp = pscript.hl_ - chop after the first name. + */ + *part = '\0'; - while (--part > buffer[i]) - if ((*part == ' ') || (*part =='\t')) *part = '\0'; - else break; - } else { - part = strchr(buffer[i],','); - if (part) { - if ((mpart = strrchr(part+1,','))!=NULL) { - pstrcpy(buffer[i],mpart+1); - } else - *part = '\0'; + + /* + * Now move back to the start and print that. + */ + + while (--part > buffer[i]) { + if ((*part == ' ') || (*part =='\t')) + *part = '\0'; + else + break; + } + } else { + part = strchr(buffer[i],','); + if (part) { + /* + * Cases (2-4) + */ + + if ((mpart = strrchr(part+1,','))!=NULL) { + /* + * Second ',' - case 3 or 4. + * Check if the last part is just a number, + * if so we need the first part. + */ + + char *endptr = NULL; + BOOL isnumber = False; + + mpart++; + (void)strtol(mpart, &endptr, 10); + + isnumber = ((endptr > mpart) && isdigit(*mpart)); + if(!isnumber) + pstrcpy(buffer[i],mpart+1); + else + *part = '\0'; + } else { + *part = '\0'; + } while (--part > buffer[i]) if ((*part == ' ') || (*part =='\t')) *part = '\0'; else break; - } - } - if (*buffer[i] != ';') { + } + } + if (*buffer[i] != ';') { if (strlen(files_to_copy) != 0) pstrcat(files_to_copy,","); - pstrcat(files_to_copy,direc); - pstrcat(files_to_copy,buffer[i]); - fprintf(stderr,"%s%s\n",direc,buffer[i]); - } - i++; - } + pstrcat(files_to_copy,direc); + pstrcat(files_to_copy,buffer[i]); + fprintf(stderr,"%s%s\n",direc,buffer[i]); + } + i++; + } /* end while */ } part=strtok(NULL,","); - if (part) + if (part) { while( *part ==' ' && *part != '\0') { - part++; + part++; } - } - while (part!=NULL); + } + } while (part!=NULL); fprintf(stderr,"\n"); } -- cgit From da2da101177cf0b5d6cf48515ec43cb2bf4af28e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 Mar 2000 09:20:47 +0000 Subject: load smb.conf and interfaces in masktest (to allow for netbios name resolution) (This used to be commit f007531742f5570d5b9b8cb20cab19cd1ab1bfed) --- source3/utils/masktest.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index a1fe6d2186..f7b6ad1b1b 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -394,6 +394,7 @@ static void usage(void) int opt; char *p; int seed; + static pstring servicesf = CONFIGFILE; setlinebuf(stdout); @@ -418,6 +419,9 @@ static void usage(void) TimeInit(); charset_initialise(); + lp_load(servicesf,True,False,False); + load_interfaces(); + if (getenv("USER")) { pstrcpy(username,getenv("USER")); } -- cgit From 59c8a608c2c6fa5fc1d342787cf28d5e00075664 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 25 Apr 2000 00:46:46 +0000 Subject: fixed a memory leak in nmblookup (This used to be commit 49865ea06c96b01a5e5dec84d64b78bf26129be3) --- source3/utils/nmblookup.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 8e26a206ca..546d2f0e15 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -130,6 +130,8 @@ static BOOL query_one(char *lookup, unsigned int lookup_type) printf("\n"); } + safe_free(ip_list); + return (ip_list != NULL); } -- cgit From 65ec80c51d48a98bb120071d77f8cf06f1896d05 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 27 Apr 2000 07:36:06 +0000 Subject: quick hack to get smbtorture working again (This used to be commit 2d37c1f98f45646546ee76743f9df90b1c0b01ae) --- source3/utils/torture.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index d6d8c6010b..deeb304804 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -22,6 +22,8 @@ #define NO_SYSLOG #include "includes.h" +#include +#include static fstring host, workgroup, share, password, username, myname; static int max_protocol = PROTOCOL_NT1; -- cgit From 36db78fedad935aaa689d52d7f58e075f1f71812 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 27 Apr 2000 22:23:04 +0000 Subject: Fixed subtle unlocking bug when a file is closed. We need to store the smbpid used when a file was opened in the files_struct. Else we use the wrong global_smbpid when we are closing the file and trying to remove the brl locks - this causes the brl locks to be left when the file is closed as the samba_context check fails. Jeremy. (This used to be commit 2746e5602e493e5b022764b4b839eb4d2f14363b) --- source3/utils/torture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index deeb304804..1a9e757977 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -930,7 +930,7 @@ static void run_locktest4(int dummy) fail: cli_close(&cli1, fnum1); - cli_close(&cli1, fnum2); + cli_close(&cli2, fnum2); cli_unlink(&cli1, fname); close_connection(&cli1); close_connection(&cli2); -- cgit From 71e7974f3f847759ba6f844ea7f482786cc5db02 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Apr 2000 04:45:16 +0000 Subject: YIPEE!!!!! We finally have a perfect emulation of Microsoft wildcard matching. The routine ms_fnmatch() does wildcard matching with all MS wildcards (including the unicode wildcards), and masktest against a NT4 workstation with hundreds of thousands of random exmaples has not found a single error. amazingly it is only about 60 lines of code, but it has taken us years to get it right. I didn't sleep much last night :) (This used to be commit cc9e007cdfdd300189f89e2a55e4234e47fa842d) --- source3/utils/masktest.c | 94 +++++++++--------------------------------------- 1 file changed, 16 insertions(+), 78 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index f7b6ad1b1b..d1a8ddce4b 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -43,82 +43,15 @@ char *standard_files[] = {"abc", "abc.", ".abc", NULL}; -#include - 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; + return ms_fnmatch(pattern, file)==0; } -static char *reg_test(char *pattern, char *file) +static char *reg_test(char *pattern, char *file, char *short_name) { static fstring ret; fstrcpy(ret, "---"); @@ -128,7 +61,8 @@ static char *reg_test(char *pattern, char *file) if (reg_match_one(pattern, ".")) ret[0] = '+'; if (reg_match_one(pattern, "..")) ret[1] = '+'; - if (reg_match_one(pattern, file)) ret[2] = '+'; + if (reg_match_one(pattern, file) || + (*short_name && reg_match_one(pattern, short_name))) ret[2] = '+'; return ret; } @@ -228,6 +162,7 @@ struct cli_state *connect_one(char *share) } static char *resultp; +static file_info *finfo; void listfn(file_info *f, const char *s) { @@ -238,6 +173,7 @@ void listfn(file_info *f, const char *s) } else { resultp[2] = '+'; } + finfo = f; } @@ -248,12 +184,14 @@ static void testpair(struct cli_state *cli1, struct cli_state *cli2, fstring res1, res2; char *res3; static int count; + fstring short_name; 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)); @@ -269,22 +207,22 @@ static void testpair(struct cli_state *cli1, struct cli_state *cli2, cli_close(cli2, fnum); resultp = res1; + fstrcpy(short_name, ""); + finfo = NULL; cli_list(cli1, mask, aHIDDEN | aDIR, listfn); + if (finfo) { + fstrcpy(short_name, finfo->short_name); + strlower(short_name); + } - res3 = reg_test(mask, file); + res3 = reg_test(mask, file, short_name); 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)); + res1, res2, res3, count, mask, file, short_name)); } cli_unlink(cli1, file); -- cgit From 3727e4aaac043c42d1cdb005f99de9feaededb16 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Apr 2000 11:11:19 +0000 Subject: changed masktest to test the internal algorithm against one server, rather than 2 servers (This used to be commit 0e63b4b36334aeb6de6691436b82e1d9784b1541) --- source3/utils/masktest.c | 108 +++++++++++++---------------------------------- 1 file changed, 30 insertions(+), 78 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index d1a8ddce4b..137866b41c 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -34,15 +34,6 @@ 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}; - - static BOOL reg_match_one(char *pattern, char *file) { if (strcmp(file,"..") == 0) file = "."; @@ -177,74 +168,57 @@ void listfn(file_info *f, const char *s) } -static void testpair(struct cli_state *cli1, struct cli_state *cli2, - char *mask, char *file) +static void testpair(struct cli_state *cli, char *mask, char *file) { int fnum; - fstring res1, res2; - char *res3; + fstring res1; + char *res2; static int count; fstring short_name; count++; fstrcpy(res1, "---"); - fstrcpy(res2, "---"); - - fnum = cli_open(cli1, file, O_CREAT|O_TRUNC|O_RDWR, 0); + fnum = cli_open(cli, file, O_CREAT|O_TRUNC|O_RDWR, 0); if (fnum == -1) { - DEBUG(0,("Can't create %s on cli1\n", file)); + DEBUG(0,("Can't create %s\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); + cli_close(cli, fnum); resultp = res1; fstrcpy(short_name, ""); finfo = NULL; - cli_list(cli1, mask, aHIDDEN | aDIR, listfn); + cli_list(cli, mask, aHIDDEN | aDIR, listfn); if (finfo) { fstrcpy(short_name, finfo->short_name); strlower(short_name); } - res3 = reg_test(mask, file, short_name); + res2 = reg_test(mask, file, short_name); - resultp = res2; - cli_list(cli2, mask, aHIDDEN | aDIR, listfn); - - if (showall || strcmp(res1, res3)) { - DEBUG(0,("%s %s %s %d mask=[%s] file=[%s] mfile=[%s]\n", - res1, res2, res3, count, mask, file, short_name)); + if (showall || strcmp(res1, res2)) { + DEBUG(0,("%s %s %d mask=[%s] file=[%s] mfile=[%s]\n", + res1, res2, count, mask, file, short_name)); } - cli_unlink(cli1, file); - cli_unlink(cli2, file); - + cli_unlink(cli, 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) + struct cli_state *cli) { pstring mask, file; - int l1, l2, i, j, l; + int l1, l2, i, l; int mc_len = strlen(maskchars); int fc_len = strlen(filechars); - cli_mkdir(cli1, "masktest"); - cli_mkdir(cli2, "masktest"); + cli_mkdir(cli, "masktest"); - cli_unlink(cli1, "\\masktest\\*"); - cli_unlink(cli2, "\\masktest\\*"); + cli_unlink(cli, "\\masktest\\*"); if (argc >= 2) { while (argc >= 2) { @@ -252,25 +226,13 @@ static void test_mask(int argc, char *argv[], pstrcpy(file,"\\masktest\\"); pstrcat(mask, argv[0]); pstrcat(file, argv[1]); - testpair(cli1, cli2, mask, file); + testpair(cli, 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; @@ -291,12 +253,11 @@ static void test_mask(int argc, char *argv[], strcmp(file+l,"..") == 0 || strcmp(mask+l,"..") == 0) continue; - testpair(cli1, cli2, mask, file); + testpair(cli, mask, file); } finished: - cli_rmdir(cli1, "\\masktest"); - cli_rmdir(cli2, "\\masktest"); + cli_rmdir(cli, "\\masktest"); } @@ -304,7 +265,7 @@ static void usage(void) { printf( "Usage:\n\ - masktest //server1/share1 //server2/share2 [options..]\n\ + masktest //server/share [options..]\n\ options:\n\ -U user%%pass\n\ -s seed\n\ @@ -314,7 +275,7 @@ static void usage(void) \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\ + way on the servers and internally\n\ ", filechars, maskchars); } @@ -324,8 +285,8 @@ static void usage(void) ****************************************************************************/ int main(int argc,char *argv[]) { - char *share1, *share2; - struct cli_state *cli1, *cli2; + char *share; + struct cli_state *cli; extern char *optarg; extern int optind; extern FILE *dbf; @@ -338,16 +299,14 @@ static void usage(void) dbf = stderr; - if (argv[1][0] == '-' || argc < 3) { + if (argv[1][0] == '-' || argc < 2) { usage(); exit(1); } - share1 = argv[1]; - share2 = argv[2]; + share = argv[1]; - all_string_sub(share1,"/","\\",0); - all_string_sub(share2,"/","\\",0); + all_string_sub(share,"/","\\",0); setup_logging(argv[0],True); @@ -404,20 +363,13 @@ static void usage(void) DEBUG(0,("seed=%d\n", seed)); srandom(seed); - cli1 = connect_one(share1); - if (!cli1) { - DEBUG(0,("Failed to connect to %s\n", share1)); + cli = connect_one(share); + if (!cli) { + DEBUG(0,("Failed to connect to %s\n", share)); 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); + test_mask(argc, argv, cli); return(0); } -- cgit From 23c0cb01ca5b8bafb3ed9f31c3aa672957c2af86 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Apr 2000 12:34:26 +0000 Subject: added cli_list_old() to allow for old style directory listing from masktest (This used to be commit 8a5c8cfa0ede1d119bf9013e321a497beefd4dda) --- source3/utils/masktest.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index 137866b41c..45c113f112 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -30,7 +30,7 @@ static fstring workgroup; static int got_pass; static BOOL showall = False; - +static BOOL old_list = False; static char *maskchars = "<>\"?*abc."; static char *filechars = "abcdefghijklm."; @@ -190,7 +190,11 @@ static void testpair(struct cli_state *cli, char *mask, char *file) resultp = res1; fstrcpy(short_name, ""); finfo = NULL; - cli_list(cli, mask, aHIDDEN | aDIR, listfn); + if (old_list) { + cli_list_old(cli, mask, aHIDDEN | aDIR, listfn); + } else { + cli_list(cli, mask, aHIDDEN | aDIR, listfn); + } if (finfo) { fstrcpy(short_name, finfo->short_name); strlower(short_name); @@ -310,8 +314,8 @@ static void usage(void) setup_logging(argv[0],True); - argc -= 2; - argv += 2; + argc -= 1; + argv += 1; TimeInit(); charset_initialise(); @@ -325,7 +329,7 @@ static void usage(void) seed = time(NULL); - while ((opt = getopt(argc, argv, "U:s:hm:f:a")) != EOF) { + while ((opt = getopt(argc, argv, "U:s:hm:f:ao")) != EOF) { switch (opt) { case 'U': pstrcpy(username,optarg); @@ -351,6 +355,9 @@ static void usage(void) case 'a': showall = 1; break; + case 'o': + old_list = True; + break; default: printf("Unknown option %c (%d)\n", (char)opt, opt); exit(1); -- cgit From 481ca7c67ccbe18c7773d2ddb27d7ebb389e4276 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Apr 2000 14:37:57 +0000 Subject: handle the special rule of *.* for old style listings when old_list is true (This used to be commit cdf4c4c812086d6e7cdc0436f5e31c420dcfb3e5) --- source3/utils/masktest.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index 45c113f112..d8afbddf98 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -39,6 +39,9 @@ static BOOL reg_match_one(char *pattern, char *file) if (strcmp(file,"..") == 0) file = "."; if (strcmp(pattern,".") == 0) return False; + /* oh what a weird world this is */ + if (old_list && strcmp(pattern, "*.*") == 0) return True; + return ms_fnmatch(pattern, file)==0; } -- cgit From 830a9e571eee5330097376e94af7dc0f2d5f2f02 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 1 May 2000 19:43:50 +0000 Subject: locking/posix.c: Fixed double-free nasty crash bug found by insure. utils/make_smbcodepage.c: utils/make_unicodemap.c: Insure 'make install' fixes. Jeremy. (This used to be commit 3b25f7368be3877e9ad27498bc9451ec88d4b07f) --- source3/utils/make_smbcodepage.c | 4 ++++ source3/utils/make_unicodemap.c | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c index f0b68a7bae..1bd3edc263 100644 --- a/source3/utils/make_smbcodepage.c +++ b/source3/utils/make_smbcodepage.c @@ -167,6 +167,7 @@ static int do_compile(int codepage, char *input_file, char *output_file) FILE *fp = NULL; size_t size = 0; char *buf = NULL; + char *orig_buf = NULL; char output_buf[CODEPAGE_HEADER_SIZE + 4 * MAXCODEPAGELINES]; int num_lines = 0; int i = 0; @@ -223,6 +224,8 @@ The maximum size I will believe is 100k.\n", prog_name, size); num_lines = clean_data( &buf, &size); + orig_buf = buf; /* Save for free(). */ + /* There can be a maximum of MAXCODEPAGELINES lines. */ if(num_lines > MAXCODEPAGELINES) { @@ -300,6 +303,7 @@ definition file. File %s has %d.\n", prog_name, MAXCODEPAGELINES, input_file, nu fclose(fp); + free(orig_buf); return 0; } diff --git a/source3/utils/make_unicodemap.c b/source3/utils/make_unicodemap.c index 76c49361be..ff9bb19b6f 100644 --- a/source3/utils/make_unicodemap.c +++ b/source3/utils/make_unicodemap.c @@ -139,6 +139,7 @@ static int do_compile(const char *codepage, const char *input_file, const char * size_t size = 0; size_t offset = 0; char *buf = NULL; + char *orig_buf = NULL; char *output_buf = NULL; uint16 cp_to_ucs2[65536]; uint16 ucs2_to_cp[65536]; @@ -186,6 +187,8 @@ static int do_compile(const char *codepage, const char *input_file, const char * num_lines = clean_data( &buf, &size); + orig_buf = buf; /* Store for free(). */ + /* * Initialize the output data. */ @@ -285,7 +288,9 @@ static int do_compile(const char *codepage, const char *input_file, const char * } fclose(fp); - + + free(orig_buf); + free(output_buf); return 0; } -- cgit From 37a6e44ad846598aedc8cb7306c1aef86d930756 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 3 May 2000 02:24:56 +0000 Subject: Added read overlay write lock on same fnum test to locktest2. Added locktest5 for locking stacks. Jeremy. (This used to be commit 65399ae1f058886b8779a01fb35fe3080cc3c145) --- source3/utils/torture.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 1a9e757977..1e0ed29a28 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -628,8 +628,20 @@ static void run_locktest2(int dummy) return; } + if (cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) { + printf("WRITE lock1 succeeded! This is a locking bug\n"); + } else { + if (!check_error(&cli, ERRDOS, ERRlock, 0)) return; + } + if (cli_lock(&cli, fnum2, 0, 4, 0, WRITE_LOCK)) { - printf("lock2 succeeded! This is a locking bug\n"); + printf("WRITE lock2 succeeded! This is a locking bug\n"); + } else { + if (!check_error(&cli, ERRDOS, ERRlock, 0)) return; + } + + if (cli_lock(&cli, fnum2, 0, 4, 0, READ_LOCK)) { + printf("READ lock2 succeeded! This is a locking bug\n"); } else { if (!check_error(&cli, ERRDOS, ERRlock, 0)) return; } @@ -938,6 +950,109 @@ static void run_locktest4(int dummy) printf("finished locktest4\n"); } +/* + looks at lock upgrade/downgrade. +*/ +static void run_locktest5(int dummy) +{ + static struct cli_state cli1, cli2; + char *fname = "\\lockt5.lck"; + int fnum1, fnum2, fnum3; + BOOL ret; + char buf[1000]; + + if (!open_connection(&cli1) || !open_connection(&cli2)) { + return; + } + + cli_sockopt(&cli1, sockops); + cli_sockopt(&cli2, sockops); + + printf("starting locktest5\n"); + + cli_unlink(&cli1, fname); + + fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE); + fnum3 = cli_open(&cli1, fname, O_RDWR, DENY_NONE); + + memset(buf, 0, sizeof(buf)); + + if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { + printf("Failed to create file\n"); + goto fail; + } + + ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) && + cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK); + EXPECTED(ret, True); + printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot"); + + ret = cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK); + EXPECTED(ret, False); + + printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot"); + + /* Unlock the process 2 lock. */ + cli_unlock(&cli2, fnum2, 0, 4); + + ret = cli_lock(&cli1, fnum3, 0, 4, 0, READ_LOCK); + EXPECTED(ret, False); + + printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot"); + + /* Unlock the process 1 fnum3 lock. */ + cli_unlock(&cli1, fnum3, 0, 4); + + /* Stack 2 more locks here. */ + ret = cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK) && + cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK); + + EXPECTED(ret, True); + printf("the same process %s stack read locks\n", ret?"can":"cannot"); + + /* Unlock the first process lock, then check this was the WRITE lock that was + removed. */ + + ret = cli_unlock(&cli1, fnum1, 0, 4) && + cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK); + + EXPECTED(ret, True); + printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ"); + + /* Unlock the process 2 lock. */ + cli_unlock(&cli2, fnum2, 0, 4); + + /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */ + + ret = cli_unlock(&cli1, fnum1, 0, 4) && + cli_unlock(&cli1, fnum1, 0, 4) && + cli_unlock(&cli1, fnum1, 0, 4); + + EXPECTED(ret, True); + printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot"); + + /* Ensure the next unlock fails. */ + ret = cli_unlock(&cli1, fnum1, 0, 4); + EXPECTED(ret, False); + printf("the same process %s count the lock stack\n", !ret?"can":"cannot"); + + /* Ensure connection 2 can get a write lock. */ + ret = cli_lock(&cli2, fnum2, 0, 4, 0, WRITE_LOCK); + EXPECTED(ret, True); + + printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot"); + + fail: + cli_close(&cli1, fnum1); + cli_close(&cli2, fnum2); + cli_unlink(&cli1, fname); + close_connection(&cli1); + close_connection(&cli2); + + printf("finished locktest5\n"); +} + /* this produces a matrix of deny mode behaviour @@ -1698,6 +1813,7 @@ static struct { {"LOCK2", run_locktest2, 0}, {"LOCK3", run_locktest3, 0}, {"LOCK4", run_locktest4, 0}, + {"LOCK5", run_locktest5, 0}, {"UNLINK", run_unlinktest, 0}, {"BROWSE", run_browsetest, 0}, {"ATTR", run_attrtest, 0}, -- cgit From 1d3d724dd1f1f6c8b329c49cc2d49e2e99499821 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 3 May 2000 13:54:28 +0000 Subject: added a nasty lock testing program it opens 2 connections to each of 2 servers, and opens 2 fnums on the same file on each connection (a total of 8 file descriptors) then it does random lock/unlock/reopen requests in a 100 byte range on the file and compares the results from the 2 servers. strangely enough, NT fails this test against itself right now - I'm still trying to figure that out. (This used to be commit 2f14d7c9bca5e170b8d2c169801cb200021fd467) --- source3/utils/locktest.c | 340 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 340 insertions(+) create mode 100644 source3/utils/locktest.c (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c new file mode 100644 index 0000000000..44b5d92469 --- /dev/null +++ b/source3/utils/locktest.c @@ -0,0 +1,340 @@ +/* + 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" + +static fstring password; +static fstring username; +static fstring workgroup; +static int got_pass; +static int numops = 1000; + +#define FILENAME "locktest.dat" +#define LOCKRANGE 100 + +#define READ_PCT 75 +#define LOCK_PCT 45 +#define UNLOCK_PCT 45 + +/* each server has two connections open to it. Each connection has two file + descriptors open on the file - 8 file descriptors in total + + we then do random locking ops in tamdem on the 4 fnums from each + server and ensure that the results match + */ +static void test_locks(struct cli_state *cli[2][2]) +{ + int fnum[2][2][2]; + int server, conn, f; + + cli_unlink(cli[0][0], FILENAME); + cli_unlink(cli[1][0], FILENAME); + + for (server=0;server<2;server++) + for (conn=0;conn<2;conn++) + for (f=0;f<2;f++) { + fnum[server][conn][f] = cli_open(cli[server][conn], FILENAME, + O_RDWR|O_CREAT, + DENY_NONE); + if (fnum[server][conn][f] == -1) { + fprintf(stderr,"Failed to open fnum[%d][%d][%d]\n", + server, conn, f); + return; + } + } + + while (numops--) { + int start, len, op, r; + BOOL ret1, ret2; + + conn = random() % 2; + f = random() % 2; + start = random() % (LOCKRANGE-1); + len = 1 + random() % (LOCKRANGE-start); + + r = random() % 100; + + if (r < READ_PCT) { + op = READ_LOCK; + } else { + op = WRITE_LOCK; + } + + r = random() % 100; + + if (r < LOCK_PCT) { + /* set a lock */ + ret1 = cli_lock(cli[0][conn], + fnum[0][conn][f], + start, len, 0, op); + ret2 = cli_lock(cli[1][conn], + fnum[1][conn][f], + start, len, 0, op); + if (ret1 != ret2) { + printf("lock(%d): server1 gave %d server2 gave %d\n", + numops, (int)ret1, (int)ret2); + return; + } + } else if (r < LOCK_PCT+UNLOCK_PCT) { + /* unset a lock */ + /* set a lock */ + ret1 = cli_unlock(cli[0][conn], + fnum[0][conn][f], + start, len); + ret2 = cli_unlock(cli[1][conn], + fnum[1][conn][f], + start, len); + if (ret1 != ret2) { + printf("unlock(%d): server1 gave %d server2 gave %d\n", + numops, (int)ret1, (int)ret2); + return; + } + } else { + /* reopen the file */ + cli_close(cli[0][conn], fnum[0][conn][f]); + cli_close(cli[1][conn], fnum[1][conn][f]); + fnum[0][conn][f] = cli_open(cli[0][conn], FILENAME, + O_RDWR|O_CREAT, + DENY_NONE); + fnum[1][conn][f] = cli_open(cli[1][conn], FILENAME, + O_RDWR|O_CREAT, + DENY_NONE); + if (fnum[0][conn][f] == -1) { + printf("failed to reopen on share1\n"); + return; + } + if (fnum[1][conn][f] == -1) { + printf("failed to reopen on share2\n"); + return; + } + } + if (numops % 100 == 0) { + printf("%d\n", numops); + } + } +} + + +/***************************************************** +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; + fstring server; + struct in_addr ip; + extern struct in_addr ipzero; + + fstrcpy(server,share+2); + share = strchr(server,'\\'); + if (!share) return NULL; + *share = 0; + share++; + + server_n = server; + + ip = ipzero; + + make_nmb_name(&calling, "locktest", 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 void usage(void) +{ + printf( +"Usage:\n\ + locktest //server1/share1 //server2/share2 [options..]\n\ + options:\n\ + -U user%%pass\n\ + -s seed\n\ +"); +} + +/**************************************************************************** + main program +****************************************************************************/ + int main(int argc,char *argv[]) +{ + char *share1, *share2; + struct cli_state *cli[2][2]; + 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:ho:")) != 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 'o': + numops = atoi(optarg); + break; + case 'h': + usage(); + exit(1); + default: + printf("Unknown option %c (%d)\n", (char)opt, opt); + exit(1); + } + } + + argc -= optind; + argv += optind; + + DEBUG(0,("seed=%d\n", seed)); + srandom(seed); + + cli[0][0] = connect_one(share1); + cli[0][1] = connect_one(share1); + if (!cli[0][0] || !cli[0][1]) { + DEBUG(0,("Failed to connect to %s\n", share1)); + exit(1); + } + + cli[1][0] = connect_one(share2); + cli[1][1] = connect_one(share2); + if (!cli[1][0] || !cli[1][1]) { + DEBUG(0,("Failed to connect to %s\n", share2)); + exit(1); + } + + test_locks(cli); + + return(0); +} -- cgit From 380d02c219eb35f2d7b6585c3b7644b80c561b78 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 3 May 2000 14:49:15 +0000 Subject: improved the lock test program (This used to be commit a0a3931c6e5824121bf4a8d075ef24b9b70e8aa1) --- source3/utils/locktest.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 44b5d92469..025a473370 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -28,11 +28,12 @@ static fstring username; static fstring workgroup; static int got_pass; static int numops = 1000; +static BOOL showall; #define FILENAME "locktest.dat" #define LOCKRANGE 100 -#define READ_PCT 75 +#define READ_PCT 50 #define LOCK_PCT 45 #define UNLOCK_PCT 45 @@ -45,7 +46,7 @@ static int numops = 1000; static void test_locks(struct cli_state *cli[2][2]) { int fnum[2][2][2]; - int server, conn, f; + int server, conn, f, n; cli_unlink(cli[0][0], FILENAME); cli_unlink(cli[1][0], FILENAME); @@ -63,7 +64,7 @@ static void test_locks(struct cli_state *cli[2][2]) } } - while (numops--) { + for (n=0; n %d:%d\n", + n, conn, f, start, len, op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", + ret1, ret2); } + if (ret1 != ret2) return; } else if (r < LOCK_PCT+UNLOCK_PCT) { /* unset a lock */ /* set a lock */ @@ -104,10 +106,10 @@ static void test_locks(struct cli_state *cli[2][2]) ret2 = cli_unlock(cli[1][conn], fnum[1][conn][f], start, len); - if (ret1 != ret2) { - printf("unlock(%d): server1 gave %d server2 gave %d\n", - numops, (int)ret1, (int)ret2); - return; + if (showall || ret1 != ret2) { + printf("%5d unlock conn=%d f=%d %d:%d -> %d:%d\n", + n, conn, f, start, len, + ret1, ret2); } } else { /* reopen the file */ @@ -127,9 +129,14 @@ static void test_locks(struct cli_state *cli[2][2]) printf("failed to reopen on share2\n"); return; } + if (showall) { + printf("%5d reopen conn=%d f=%d\n", + n, conn, f); + } + if (ret1 != ret2) return; } - if (numops % 100 == 0) { - printf("%d\n", numops); + if (n % 100 == 0) { + printf("%d\n", n); } } } @@ -238,6 +245,8 @@ static void usage(void) options:\n\ -U user%%pass\n\ -s seed\n\ + -o numops\n\ + -a (show all ops)\n\ "); } @@ -288,7 +297,7 @@ static void usage(void) seed = time(NULL); - while ((opt = getopt(argc, argv, "U:s:ho:")) != EOF) { + while ((opt = getopt(argc, argv, "U:s:ho:a")) != EOF) { switch (opt) { case 'U': pstrcpy(username,optarg); @@ -305,6 +314,9 @@ static void usage(void) case 'o': numops = atoi(optarg); break; + case 'a': + showall = True; + break; case 'h': usage(); exit(1); -- cgit From 82e6018ad808a2b85500012283d69f6cbf7b5e6c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 4 May 2000 01:40:51 +0000 Subject: added ability to present lock tests (This used to be commit 3fc6a467fc3dfd2a59d4509ec52172d2dd048c80) --- source3/utils/locktest.c | 56 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 16 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 025a473370..a0b9e80147 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -37,6 +37,21 @@ static BOOL showall; #define LOCK_PCT 45 #define UNLOCK_PCT 45 +enum op_type {OP_lock=0, OP_unlock, OP_reopen}; + +struct preset { + int r1, r2; + int conn, f; + int start, len; + int rw; +} preset[] = { +{86, 37, 0, 1, 29, 41, WRITE_LOCK}, +{46, 21, 0, 1, 55, 7, READ_LOCK}, +{51, 35, 0, 0, 79, 2, WRITE_LOCK}, +{69, 97, 0, 1, }, +{35, 27, 1, 1, 31, 45, READ_LOCK}, + }; + /* each server has two connections open to it. Each connection has two file descriptors open on the file - 8 file descriptors in total @@ -65,25 +80,34 @@ static void test_locks(struct cli_state *cli[2][2]) } for (n=0; n %d:%d\n", - n, conn, f, start, len, op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", + printf("%5d r1=%d r2=%d lock conn=%d f=%d %d:%d op=%s -> %d:%d\n", + n, r1, r2, conn, f, start, len, op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", ret1, ret2); } if (ret1 != ret2) return; - } else if (r < LOCK_PCT+UNLOCK_PCT) { + } else if (r2 < LOCK_PCT+UNLOCK_PCT) { /* unset a lock */ /* set a lock */ ret1 = cli_unlock(cli[0][conn], @@ -107,8 +131,8 @@ static void test_locks(struct cli_state *cli[2][2]) fnum[1][conn][f], start, len); if (showall || ret1 != ret2) { - printf("%5d unlock conn=%d f=%d %d:%d -> %d:%d\n", - n, conn, f, start, len, + printf("%5d r1=%d r2=%d unlock conn=%d f=%d %d:%d -> %d:%d\n", + n, r1, r2, conn, f, start, len, ret1, ret2); } } else { @@ -130,8 +154,8 @@ static void test_locks(struct cli_state *cli[2][2]) return; } if (showall) { - printf("%5d reopen conn=%d f=%d\n", - n, conn, f); + printf("%5d r1=%d r2=%d reopen conn=%d f=%d\n", + n, r1, r2, conn, f); } if (ret1 != ret2) return; } -- cgit From 1246072d99666182fec480a5640dab136b6edff1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 4 May 2000 02:01:48 +0000 Subject: fixed a uninit memory read that insure found (This used to be commit 43fe5b98b4514d59e1c4bbc54a628cfbd771fc4f) --- source3/utils/locktest.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index a0b9e80147..f125ab241a 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -37,19 +37,17 @@ static BOOL showall; #define LOCK_PCT 45 #define UNLOCK_PCT 45 -enum op_type {OP_lock=0, OP_unlock, OP_reopen}; - struct preset { int r1, r2; int conn, f; int start, len; int rw; } preset[] = { -{86, 37, 0, 1, 29, 41, WRITE_LOCK}, +{86, 37, 0, 1, 0, 29+41, WRITE_LOCK}, {46, 21, 0, 1, 55, 7, READ_LOCK}, {51, 35, 0, 0, 79, 2, WRITE_LOCK}, -{69, 97, 0, 1, }, -{35, 27, 1, 1, 31, 45, READ_LOCK}, +{69, 97, 0, 1, 0, 0, 0}, +{35, 27, 1, 1, 1, 31+45, READ_LOCK}, }; /* each server has two connections open to it. Each connection has two file @@ -157,7 +155,6 @@ static void test_locks(struct cli_state *cli[2][2]) printf("%5d r1=%d r2=%d reopen conn=%d f=%d\n", n, r1, r2, conn, f); } - if (ret1 != ret2) return; } if (n % 100 == 0) { printf("%d\n", n); -- cgit From e6bc1dd64d19155190057b551b781e4436567ace Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 4 May 2000 02:12:33 +0000 Subject: found a much simpler case that kills the posix locking (This used to be commit b703cecf81dc62234171eaaa4c0cae448f144e1f) --- source3/utils/locktest.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index f125ab241a..9d8d539727 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -43,11 +43,11 @@ struct preset { int start, len; int rw; } preset[] = { -{86, 37, 0, 1, 0, 29+41, WRITE_LOCK}, -{46, 21, 0, 1, 55, 7, READ_LOCK}, -{51, 35, 0, 0, 79, 2, WRITE_LOCK}, -{69, 97, 0, 1, 0, 0, 0}, -{35, 27, 1, 1, 1, 31+45, READ_LOCK}, +{86, 37, 0, 1, 0, 3, WRITE_LOCK}, +{46, 21, 0, 1, 1, 1, READ_LOCK}, +{51, 35, 0, 0, 10, 1, WRITE_LOCK}, +{69, 97, 0, 1, 0, 0, 0}, +{35, 27, 1, 1, 0, 3, READ_LOCK}, }; /* each server has two connections open to it. Each connection has two file -- cgit From a5da647e10bdba17e6904d1538a976649d5ff513 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 4 May 2000 04:14:23 +0000 Subject: added -A analyze mode to locktest - it can now automatically prune the list of locks that cause a failure (This used to be commit 0beee59432f17f90a1c4c2c68a7ea6022b5d0908) --- source3/utils/locktest.c | 381 ++++++++++++++++++++++++++++++----------------- 1 file changed, 242 insertions(+), 139 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 9d8d539727..9396bd8447 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -29,139 +29,26 @@ static fstring workgroup; static int got_pass; static int numops = 1000; static BOOL showall; +static BOOL analyze; #define FILENAME "locktest.dat" #define LOCKRANGE 100 #define READ_PCT 50 -#define LOCK_PCT 45 -#define UNLOCK_PCT 45 +#define LOCK_PCT 25 +#define UNLOCK_PCT 65 -struct preset { +struct record { int r1, r2; int conn, f; int start, len; - int rw; -} preset[] = { -{86, 37, 0, 1, 0, 3, WRITE_LOCK}, -{46, 21, 0, 1, 1, 1, READ_LOCK}, -{51, 35, 0, 0, 10, 1, WRITE_LOCK}, -{69, 97, 0, 1, 0, 0, 0}, -{35, 27, 1, 1, 0, 3, READ_LOCK}, - }; - -/* each server has two connections open to it. Each connection has two file - descriptors open on the file - 8 file descriptors in total - - we then do random locking ops in tamdem on the 4 fnums from each - server and ensure that the results match - */ -static void test_locks(struct cli_state *cli[2][2]) -{ - int fnum[2][2][2]; - int server, conn, f, n; - - cli_unlink(cli[0][0], FILENAME); - cli_unlink(cli[1][0], FILENAME); - - for (server=0;server<2;server++) - for (conn=0;conn<2;conn++) - for (f=0;f<2;f++) { - fnum[server][conn][f] = cli_open(cli[server][conn], FILENAME, - O_RDWR|O_CREAT, - DENY_NONE); - if (fnum[server][conn][f] == -1) { - fprintf(stderr,"Failed to open fnum[%d][%d][%d]\n", - server, conn, f); - return; - } - } - - for (n=0; n %d:%d\n", - n, r1, r2, conn, f, start, len, op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", - ret1, ret2); - } - if (ret1 != ret2) return; - } else if (r2 < LOCK_PCT+UNLOCK_PCT) { - /* unset a lock */ - /* set a lock */ - ret1 = cli_unlock(cli[0][conn], - fnum[0][conn][f], - start, len); - ret2 = cli_unlock(cli[1][conn], - fnum[1][conn][f], - start, len); - if (showall || ret1 != ret2) { - printf("%5d r1=%d r2=%d unlock conn=%d f=%d %d:%d -> %d:%d\n", - n, r1, r2, conn, f, start, len, - ret1, ret2); - } - } else { - /* reopen the file */ - cli_close(cli[0][conn], fnum[0][conn][f]); - cli_close(cli[1][conn], fnum[1][conn][f]); - fnum[0][conn][f] = cli_open(cli[0][conn], FILENAME, - O_RDWR|O_CREAT, - DENY_NONE); - fnum[1][conn][f] = cli_open(cli[1][conn], FILENAME, - O_RDWR|O_CREAT, - DENY_NONE); - if (fnum[0][conn][f] == -1) { - printf("failed to reopen on share1\n"); - return; - } - if (fnum[1][conn][f] == -1) { - printf("failed to reopen on share2\n"); - return; - } - if (showall) { - printf("%5d r1=%d r2=%d reopen conn=%d f=%d\n", - n, r1, r2, conn, f); - } - } - if (n % 100 == 0) { - printf("%d\n", n); - } - } -} +static struct record preset[] = { + }; +static struct record *recorded; /***************************************************** return a connection to a server @@ -258,6 +145,234 @@ struct cli_state *connect_one(char *share) } +static void reconnect(struct cli_state *cli[2][2], char *share1, char *share2) +{ + int server, conn; + char *share[2]; + share[0] = share1; + share[1] = share2; + + for (server=0;server<2;server++) + for (conn=0;conn<2;conn++) { + if (cli[server][conn]) { + cli_shutdown(cli[server][conn]); + free(cli[server][conn]); + cli[server][conn] = NULL; + } + cli[server][conn] = connect_one(share[server]); + if (!cli[server][conn]) { + DEBUG(0,("Failed to connect to %s\n", share[server])); + exit(1); + } + } +} + + + +static BOOL test_one(struct cli_state *cli[2][2], + int fnum[2][2][2], + struct record *rec) +{ + int conn = rec->conn; + int f = rec->f; + int start = rec->start; + int len = rec->len; + int r1 = rec->r1; + int r2 = rec->r2; + int op; + BOOL ret1, ret2; + + if (r1 < READ_PCT) { + op = READ_LOCK; + } else { + op = WRITE_LOCK; + } + + if (r2 < LOCK_PCT) { + /* set a lock */ + ret1 = cli_lock(cli[0][conn], + fnum[0][conn][f], + start, len, 0, op); + ret2 = cli_lock(cli[1][conn], + fnum[1][conn][f], + start, len, 0, op); + if (showall || ret1 != ret2) { + printf("lock conn=%d f=%d range=%d:%d op=%s -> %d:%d\n", + conn, f, start, len, op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", + ret1, ret2); + } + if (ret1 != ret2) return False; + } else if (r2 < LOCK_PCT+UNLOCK_PCT) { + /* unset a lock */ + ret1 = cli_unlock(cli[0][conn], + fnum[0][conn][f], + start, len); + ret2 = cli_unlock(cli[1][conn], + fnum[1][conn][f], + start, len); + if (showall || ret1 != ret2) { + printf("unlock conn=%d f=%d %d:%d -> %d:%d\n", + conn, f, start, len, + ret1, ret2); + } + if (ret1 != ret2) return False; + } else { + /* reopen the file */ + cli_close(cli[0][conn], fnum[0][conn][f]); + cli_close(cli[1][conn], fnum[1][conn][f]); + fnum[0][conn][f] = cli_open(cli[0][conn], FILENAME, + O_RDWR|O_CREAT, + DENY_NONE); + fnum[1][conn][f] = cli_open(cli[1][conn], FILENAME, + O_RDWR|O_CREAT, + DENY_NONE); + if (fnum[0][conn][f] == -1) { + printf("failed to reopen on share1\n"); + return False; + } + if (fnum[1][conn][f] == -1) { + printf("failed to reopen on share2\n"); + return False; + } + if (showall) { + printf("reopen conn=%d f=%d\n", + conn, f); + } + } + return True; +} + +static void open_files(struct cli_state *cli[2][2], + int fnum[2][2][2]) +{ + int server, conn, f; + + for (server=0;server<2;server++) + for (conn=0;conn<2;conn++) + for (f=0;f<2;f++) { + if (fnum[server][conn][f] != -1) { + cli_close(cli[server][conn], fnum[server][conn][f]); + } + fnum[server][conn][f] = cli_open(cli[server][conn], FILENAME, + O_RDWR|O_CREAT, + DENY_NONE); + if (fnum[server][conn][f] == -1) { + fprintf(stderr,"Failed to open fnum[%d][%d][%d]\n", + server, conn, f); + exit(1); + } + } +} + + +static int retest(struct cli_state *cli[2][2], + int fnum[2][2][2], + int n) +{ + int i; + printf("retesting %d ...\n", n); + open_files(cli, fnum); + for (i=0; i Date: Thu, 4 May 2000 06:29:13 +0000 Subject: fixed message text (This used to be commit 99e522023eae7cf1a88e5de50f2b09df3ea318d3) --- source3/utils/status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 5c01409737..edc861d267 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -350,7 +350,7 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st int ret; if (!locking_init(1)) { - printf("Can't initialise shared memory - exiting\n"); + printf("Can't initialise locking module - exiting\n"); exit(1); } -- cgit From 876dd8d9aabbf3a2f79bde50cce9399b39bb17f0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 4 May 2000 06:30:17 +0000 Subject: more locktest improvements the current preset tests show a very interesting NT bug - it sometimes refuses a lock that it shouldn't. (This used to be commit 85b5dc64cf7cc80567f9069a48c4d20c10ccec01) --- source3/utils/locktest.c | 112 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 81 insertions(+), 31 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 9396bd8447..2e5a4fb65b 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -37,19 +37,36 @@ static BOOL analyze; #define READ_PCT 50 #define LOCK_PCT 25 #define UNLOCK_PCT 65 +#define RANGE_MULTIPLE 1 struct record { - int r1, r2; - int conn, f; + char r1, r2; + char conn, f; int start, len; - BOOL needed; + char needed; }; static struct record preset[] = { +#if 1 +{36, 5, 1, 1, 1, 2, 1}, +{ 2, 6, 0, 1, 0, 2, 1}, +{53, 92, 1, 1, 0, 0, 1}, +{99, 11, 1, 1, 2, 1, 1}, +#endif }; static struct record *recorded; +static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, + enum brl_type lock_type, + br_off start, br_off size) +{ + printf("%6d %05x:%05x %s %9.0f %9.0f\n", + (int)pid, (int)dev, (int)ino, + lock_type==READ_LOCK?"R":"W", + (double)start, (double)size); +} + /***************************************************** return a connection to a server *******************************************************/ @@ -61,6 +78,8 @@ struct cli_state *connect_one(char *share) fstring server; struct in_addr ip; extern struct in_addr ipzero; + fstring myname; + static int count; fstrcpy(server,share+2); share = strchr(server,'\\'); @@ -72,7 +91,9 @@ struct cli_state *connect_one(char *share) ip = ipzero; - make_nmb_name(&calling, "locktest", 0x0); + slprintf(myname,sizeof(myname), "lock-%d-%d", getpid(), count++); + + make_nmb_name(&calling, myname, 0x0); make_nmb_name(&called , server, 0x20); again: @@ -145,16 +166,23 @@ struct cli_state *connect_one(char *share) } -static void reconnect(struct cli_state *cli[2][2], char *share1, char *share2) +static void reconnect(struct cli_state *cli[2][2], int fnum[2][2][2], + char *share1, char *share2) { - int server, conn; + int server, conn, f; char *share[2]; share[0] = share1; share[1] = share2; + + for (server=0;server<2;server++) for (conn=0;conn<2;conn++) { if (cli[server][conn]) { + for (f=0;f<2;f++) { + cli_close(cli[server][conn], fnum[server][conn][f]); + } + cli_ulogoff(cli[server][conn]); cli_shutdown(cli[server][conn]); free(cli[server][conn]); cli[server][conn] = NULL; @@ -201,6 +229,7 @@ static BOOL test_one(struct cli_state *cli[2][2], conn, f, start, len, op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", ret1, ret2); } + if (showall) brl_forall(print_brl); if (ret1 != ret2) return False; } else if (r2 < LOCK_PCT+UNLOCK_PCT) { /* unset a lock */ @@ -215,6 +244,7 @@ static BOOL test_one(struct cli_state *cli[2][2], conn, f, start, len, ret1, ret2); } + if (showall) brl_forall(print_brl); if (ret1 != ret2) return False; } else { /* reopen the file */ @@ -237,12 +267,13 @@ static BOOL test_one(struct cli_state *cli[2][2], if (showall) { printf("reopen conn=%d f=%d\n", conn, f); + brl_forall(print_brl); } } return True; } -static void open_files(struct cli_state *cli[2][2], +static void close_files(struct cli_state *cli[2][2], int fnum[2][2][2]) { int server, conn, f; @@ -252,7 +283,21 @@ static void open_files(struct cli_state *cli[2][2], for (f=0;f<2;f++) { if (fnum[server][conn][f] != -1) { cli_close(cli[server][conn], fnum[server][conn][f]); + fnum[server][conn][f] = -1; } + } + cli_unlink(cli[0][0], FILENAME); + cli_unlink(cli[1][0], FILENAME); +} + +static void open_files(struct cli_state *cli[2][2], + int fnum[2][2][2]) +{ + int server, conn, f; + + for (server=0;server<2;server++) + for (conn=0;conn<2;conn++) + for (f=0;f<2;f++) { fnum[server][conn][f] = cli_open(cli[server][conn], FILENAME, O_RDWR|O_CREAT, DENY_NONE); @@ -270,15 +315,14 @@ static int retest(struct cli_state *cli[2][2], int n) { int i; - printf("retesting %d ...\n", n); - open_files(cli, fnum); + printf("testing %d ...\n", n); for (i=0; i Date: Thu, 4 May 2000 06:57:26 +0000 Subject: need LOCKING_OBJ in locktest now (This used to be commit 89e71994450f479a0f3839f192d868924626fc84) --- source3/utils/locktest.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 2e5a4fb65b..0d1c1719a8 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -37,7 +37,7 @@ static BOOL analyze; #define READ_PCT 50 #define LOCK_PCT 25 #define UNLOCK_PCT 65 -#define RANGE_MULTIPLE 1 +#define RANGE_MULTIPLE 32 struct record { char r1, r2; @@ -47,13 +47,17 @@ struct record { }; static struct record preset[] = { -#if 1 +#if 0 {36, 5, 1, 1, 1, 2, 1}, { 2, 6, 0, 1, 0, 2, 1}, {53, 92, 1, 1, 0, 0, 1}, {99, 11, 1, 1, 2, 1, 1}, #endif - }; +{36, 5, 1, 1, 1888, 960, 1}, +{47, 23, 0, 1, 0, 2176, 1}, +{84, 95, 1, 1, 3072, 96, 1}, +{65, 14, 0, 0, 2752, 352, 1}, +}; static struct record *recorded; -- cgit From 420d7e02dca5c207091ded625082b4f5df2b9c65 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 4 May 2000 08:58:07 +0000 Subject: an even simpler example of NT gettings its locking code wrong. This one doesn't even need two connections to the box, just two file handles. it is a very simple case actually, and one I think will happen quite a lot in real life. I wonder how they haven't noticed it? I checked and W2K has the same bug. (This used to be commit 0b335e415818028ac0daad5f99c2fd9086a2a656) --- source3/utils/locktest.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 0d1c1719a8..d52d023f25 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -38,6 +38,8 @@ static BOOL analyze; #define LOCK_PCT 25 #define UNLOCK_PCT 65 #define RANGE_MULTIPLE 32 +#define NCONNECTIONS 2 +#define NFILES 2 struct record { char r1, r2; @@ -47,16 +49,10 @@ struct record { }; static struct record preset[] = { -#if 0 -{36, 5, 1, 1, 1, 2, 1}, -{ 2, 6, 0, 1, 0, 2, 1}, -{53, 92, 1, 1, 0, 0, 1}, -{99, 11, 1, 1, 2, 1, 1}, -#endif -{36, 5, 1, 1, 1888, 960, 1}, -{47, 23, 0, 1, 0, 2176, 1}, -{84, 95, 1, 1, 3072, 96, 1}, -{65, 14, 0, 0, 2752, 352, 1}, +{36, 5, 0, 0, 0, 8, 1}, +{ 2, 6, 0, 1, 0, 1, 1}, +{53, 92, 0, 0, 0, 0, 1}, +{99, 11, 0, 0, 7, 1, 1}, }; static struct record *recorded; @@ -178,12 +174,10 @@ static void reconnect(struct cli_state *cli[2][2], int fnum[2][2][2], share[0] = share1; share[1] = share2; - - for (server=0;server<2;server++) - for (conn=0;conn<2;conn++) { + for (conn=0;conn Date: Thu, 4 May 2000 09:31:57 +0000 Subject: added a test for the NT byte range lock into smbtorture (This used to be commit 7cfd45cc56e01a20a122c7742dc7e6a4ed59415f) --- source3/utils/torture.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 1e0ed29a28..40920f79c3 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -803,7 +803,7 @@ static void run_locktest4(int dummy) { static struct cli_state cli1, cli2; char *fname = "\\lockt4.lck"; - int fnum1, fnum2; + int fnum1, fnum2, f; BOOL ret; char buf[1000]; @@ -940,6 +940,21 @@ static void run_locktest4(int dummy) EXPECTED(ret, True); printf("the same process %s remove the first lock first\n", ret?"does":"doesn't"); + cli_close(&cli1, fnum1); + cli_close(&cli2, fnum2); + fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE); + f = cli_open(&cli1, fname, O_RDWR, DENY_NONE); + ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) && + cli_lock(&cli1, f, 0, 1, 0, READ_LOCK) && + cli_close(&cli1, fnum1) && + ((fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE)) != -1) && + cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK); + cli_close(&cli1, f); + EXPECTED(ret, True); + printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't"); + + + fail: cli_close(&cli1, fnum1); cli_close(&cli2, fnum2); -- cgit From f74ea2b78b2aaa4621936c87487f2e9c2072144f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 4 May 2000 09:32:21 +0000 Subject: parameterize the lock timeout (This used to be commit 98ad4095ccc8d0349d05e6e9223eaad057029626) --- source3/utils/locktest.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index d52d023f25..8738116a04 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -40,6 +40,7 @@ static BOOL analyze; #define RANGE_MULTIPLE 32 #define NCONNECTIONS 2 #define NFILES 2 +#define LOCK_TIMEOUT 0 struct record { char r1, r2; @@ -218,10 +219,10 @@ static BOOL test_one(struct cli_state *cli[2][2], /* set a lock */ ret1 = cli_lock(cli[0][conn], fnum[0][conn][f], - start, len, 0, op); + start, len, LOCK_TIMEOUT, op); ret2 = cli_lock(cli[1][conn], fnum[1][conn][f], - start, len, 0, op); + start, len, LOCK_TIMEOUT, op); if (showall || ret1 != ret2) { printf("lock conn=%d f=%d range=%d:%d op=%s -> %d:%d\n", conn, f, start, len, op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", -- cgit From 045469493c2870cb1d63c964b18afc5e2210dcd5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 4 May 2000 21:57:28 +0000 Subject: rpc_server/srv_lsa.c: Bring into sync with 2.0.x. rpc_server/srv_pipe_hnd.c: Bring into sync with 2.0.x. smbd/blocking.c: Improve blocking debug reporting. utils/torture.c: Added check for NT locking bug. Jeremy. (This used to be commit e8ff6d3fb5537c39611a5784bf7216ae812acd27) --- source3/utils/torture.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 40920f79c3..e74106609d 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -998,8 +998,20 @@ static void run_locktest5(int dummy) goto fail; } + /* Check for NT bug... */ + ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) && + cli_lock(&cli1, fnum3, 0, 1, 0, READ_LOCK); + cli_close(&cli1, fnum1); + fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE); + ret = cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK); + EXPECTED(ret, True); + printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has"); + cli_close(&cli1, fnum1); + fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE); + cli_unlock(&cli1, fnum3, 0, 1); + ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) && - cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK); + cli_lock(&cli1, fnum1, 1, 1, 0, READ_LOCK); EXPECTED(ret, True); printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot"); @@ -1040,7 +1052,7 @@ static void run_locktest5(int dummy) /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */ - ret = cli_unlock(&cli1, fnum1, 0, 4) && + ret = cli_unlock(&cli1, fnum1, 1, 1) && cli_unlock(&cli1, fnum1, 0, 4) && cli_unlock(&cli1, fnum1, 0, 4); -- cgit From c7845863bb4e2e98a3cd2ee1e61a5cf448723863 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 5 May 2000 00:46:38 +0000 Subject: example of broken posix lock behaviour (This used to be commit b3999f3b20d470b9c873b297e7aeb043da61588d) --- source3/utils/locktest.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 8738116a04..3b2d2be13e 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -50,6 +50,14 @@ struct record { }; static struct record preset[] = { +{77, 11, 0, 0, 2432, 480, 1}, +{13, 11, 0, 0, 2624, 224, 1}, +{16, 19, 0, 1, 448, 1344, 1}, +{21, 96, 0, 0, 2144, 640, 1}, +{53, 5, 1, 1, 2336, 608, 1}, + + + {36, 5, 0, 0, 0, 8, 1}, { 2, 6, 0, 1, 0, 1, 1}, {53, 92, 0, 0, 0, 0, 1}, -- cgit From a6280d37c618223bab87b6f7d338070de55f27b9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 5 May 2000 01:11:23 +0000 Subject: nasty hack to print posix locks (This used to be commit efc9752f1e00b38abe3b5d3a98627a9fe6122bc4) --- source3/utils/locktest.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 3b2d2be13e..7aa32325a4 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -42,6 +42,9 @@ static BOOL analyze; #define NFILES 2 #define LOCK_TIMEOUT 0 +#define NASTY_POSIX_LOCK_HACK 1 + + struct record { char r1, r2; char conn, f; @@ -74,6 +77,20 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, (int)pid, (int)dev, (int)ino, lock_type==READ_LOCK?"R":"W", (double)start, (double)size); + +#if NASTY_POSIX_LOCK_HACK + { + pstring cmd; + static SMB_INO_T lastino; + + if (lastino != ino) { + slprintf(cmd, sizeof(cmd), + "egrep POSIX.*%d /proc/locks", (int)ino); + system(cmd); + } + lastino = ino; + } +#endif } /***************************************************** -- cgit From 8ea45ac5ced9cd45cc082a736532b5f771635810 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 5 May 2000 01:20:25 +0000 Subject: make debug easier to read (This used to be commit d64bb07f0ad0efa1a20015b620ae33fb082b1e44) --- source3/utils/locktest.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 7aa32325a4..106fce8063 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -73,11 +73,6 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, enum brl_type lock_type, br_off start, br_off size) { - printf("%6d %05x:%05x %s %9.0f %9.0f\n", - (int)pid, (int)dev, (int)ino, - lock_type==READ_LOCK?"R":"W", - (double)start, (double)size); - #if NASTY_POSIX_LOCK_HACK { pstring cmd; @@ -91,6 +86,12 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, lastino = ino; } #endif + + printf("%6d %05x:%05x %s %9.0f %9.0f %9.0f\n", + (int)pid, (int)dev, (int)ino, + lock_type==READ_LOCK?"R":"W", + (double)start, (double)size, (double)start+size); + } /***************************************************** -- cgit From 044b5690066a6673ee78b1fae6bffda9bd6afbc4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 5 May 2000 01:26:52 +0000 Subject: make debug easier to read (This used to be commit c14a2616441b2f3357a081c6dbae7d5b677e5a12) --- source3/utils/locktest.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 106fce8063..04eb28b236 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -87,10 +87,10 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, } #endif - printf("%6d %05x:%05x %s %9.0f %9.0f %9.0f\n", + printf("%6d %05x:%05x %s %.0f:%.0f(%.0f)\n", (int)pid, (int)dev, (int)ino, lock_type==READ_LOCK?"R":"W", - (double)start, (double)size, (double)start+size); + (double)start, (double)start+size-1,(double)size); } @@ -250,8 +250,10 @@ static BOOL test_one(struct cli_state *cli[2][2], fnum[1][conn][f], start, len, LOCK_TIMEOUT, op); if (showall || ret1 != ret2) { - printf("lock conn=%d f=%d range=%d:%d op=%s -> %d:%d\n", - conn, f, start, len, op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", + printf("lock conn=%d f=%d range=%d:%d(%d) op=%s -> %d:%d\n", + conn, f, + start, start+len-1, len, + op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", ret1, ret2); } if (showall) brl_forall(print_brl); @@ -265,8 +267,9 @@ static BOOL test_one(struct cli_state *cli[2][2], fnum[1][conn][f], start, len); if (showall || ret1 != ret2) { - printf("unlock conn=%d f=%d %d:%d -> %d:%d\n", - conn, f, start, len, + printf("unlock conn=%d f=%d range=%d:%d(%d) -> %d:%d\n", + conn, f, + start, start+len-1, len, ret1, ret2); } if (showall) brl_forall(print_brl); -- cgit From 5612f6a2aa1c9ebd6e8c1d5224f2396a6d7b60b9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 6 May 2000 01:36:59 +0000 Subject: signed/unsigned fixes so we can handle a lock base close to 2^32 (This used to be commit 0ce2ca5ccdd0e2e7711dcbf66b72a183b2692cfe) --- source3/utils/locktest.c | 60 +++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 04eb28b236..475e20fa66 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -33,11 +33,16 @@ static BOOL analyze; #define FILENAME "locktest.dat" #define LOCKRANGE 100 +#define LOCKBASE 0 + +/* +#define LOCKBASE (0x40000000 - 50) +*/ #define READ_PCT 50 #define LOCK_PCT 25 #define UNLOCK_PCT 65 -#define RANGE_MULTIPLE 32 +#define RANGE_MULTIPLE 1 #define NCONNECTIONS 2 #define NFILES 2 #define LOCK_TIMEOUT 0 @@ -48,19 +53,11 @@ static BOOL analyze; struct record { char r1, r2; char conn, f; - int start, len; + unsigned start, len; char needed; }; static struct record preset[] = { -{77, 11, 0, 0, 2432, 480, 1}, -{13, 11, 0, 0, 2624, 224, 1}, -{16, 19, 0, 1, 448, 1344, 1}, -{21, 96, 0, 0, 2144, 640, 1}, -{53, 5, 1, 1, 2336, 608, 1}, - - - {36, 5, 0, 0, 0, 8, 1}, { 2, 6, 0, 1, 0, 1, 1}, {53, 92, 0, 0, 0, 0, 1}, @@ -80,7 +77,7 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, if (lastino != ino) { slprintf(cmd, sizeof(cmd), - "egrep POSIX.*%d /proc/locks", (int)ino); + "egrep POSIX.*%u /proc/locks", (int)ino); system(cmd); } lastino = ino; @@ -118,7 +115,7 @@ struct cli_state *connect_one(char *share) ip = ipzero; - slprintf(myname,sizeof(myname), "lock-%d-%d", getpid(), count++); + slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++); make_nmb_name(&calling, myname, 0x0); make_nmb_name(&called , server, 0x20); @@ -226,13 +223,13 @@ static BOOL test_one(struct cli_state *cli[2][2], int fnum[2][2][2], struct record *rec) { - int conn = rec->conn; - int f = rec->f; - int start = rec->start; - int len = rec->len; - int r1 = rec->r1; - int r2 = rec->r2; - int op; + unsigned conn = rec->conn; + unsigned f = rec->f; + unsigned start = rec->start; + unsigned len = rec->len; + unsigned r1 = rec->r1; + unsigned r2 = rec->r2; + unsigned op; BOOL ret1, ret2; if (r1 < READ_PCT) { @@ -250,7 +247,7 @@ static BOOL test_one(struct cli_state *cli[2][2], fnum[1][conn][f], start, len, LOCK_TIMEOUT, op); if (showall || ret1 != ret2) { - printf("lock conn=%d f=%d range=%d:%d(%d) op=%s -> %d:%d\n", + printf("lock conn=%u f=%u range=%u:%u(%u) op=%s -> %u:%u\n", conn, f, start, start+len-1, len, op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", @@ -267,7 +264,7 @@ static BOOL test_one(struct cli_state *cli[2][2], fnum[1][conn][f], start, len); if (showall || ret1 != ret2) { - printf("unlock conn=%d f=%d range=%d:%d(%d) -> %d:%d\n", + printf("unlock conn=%u f=%u range=%u:%u(%u) -> %u:%u\n", conn, f, start, start+len-1, len, ret1, ret2); @@ -293,7 +290,7 @@ static BOOL test_one(struct cli_state *cli[2][2], return False; } if (showall) { - printf("reopen conn=%d f=%d\n", + printf("reopen conn=%u f=%u\n", conn, f); brl_forall(print_brl); } @@ -302,7 +299,7 @@ static BOOL test_one(struct cli_state *cli[2][2], } static void close_files(struct cli_state *cli[2][2], - int fnum[2][2][2]) + int fnum[2][2][2]) { int server, conn, f; @@ -330,7 +327,7 @@ static void open_files(struct cli_state *cli[2][2], O_RDWR|O_CREAT, DENY_NONE); if (fnum[server][conn][f] == -1) { - fprintf(stderr,"Failed to open fnum[%d][%d][%d]\n", + fprintf(stderr,"Failed to open fnum[%u][%u][%u]\n", server, conn, f); exit(1); } @@ -343,10 +340,10 @@ static int retest(struct cli_state *cli[2][2], int n) { int i; - printf("testing %d ...\n", n); + printf("testing %u ...\n", n); for (i=0; i Date: Mon, 8 May 2000 10:42:21 +0000 Subject: added secrets.tdb and changed storage of trust account password to use it (This used to be commit 88ad00b82acc4636ab57dfe710af08ea85b82ff1) --- source3/utils/smbpasswd.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 7a0d0eeea9..047a69419c 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -96,23 +96,13 @@ static int join_domain(char *domain, char *remote) return 1; } - /* - * Create the machine account password file. - */ - if(!trust_password_lock( domain, global_myname, True)) { - fprintf(stderr, "Unable to open the machine account password file for \ -machine %s in domain %s.\n", global_myname, domain); - return 1; - } - /* * Write the old machine account password. */ - if(!set_trust_account_password( orig_trust_passwd_hash)) { + if(!set_trust_account_password(domain, orig_trust_passwd_hash)) { fprintf(stderr, "Unable to write the machine account password for \ machine %s in domain %s.\n", global_myname, domain); - trust_password_unlock(); return 1; } @@ -127,15 +117,13 @@ machine %s in domain %s.\n", global_myname, domain); if(!*remote_machine) { fprintf(stderr, "No password server list given in smb.conf - \ unable to join domain.\n"); - trust_password_unlock(); return 1; } ret = change_trust_account_password( domain, remote_machine); - trust_password_unlock(); if(!ret) { - trust_password_delete( domain, global_myname); + trust_password_delete(domain); fprintf(stderr,"Unable to join domain %s.\n",domain); } else { printf("Joined domain %s.\n",domain); @@ -579,6 +567,7 @@ int main(int argc, char **argv) codepage_initialise(lp_client_code_page()); load_interfaces(); + secrets_init(); /* Check the effective uid - make sure we are not setuid */ if ((geteuid() == (uid_t)0) && (getuid() != (uid_t)0)) { -- cgit From 6c52c1a5c76b871ecb415962b2ea7fed64f8e10a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 22 May 2000 23:38:56 +0000 Subject: Added -W workgroup command line option. Added call to codepage_initialise(). (This used to be commit fcb8e2fbe2deabfc2f8d7e69dd23dca9740c6dc1) --- source3/utils/locktest.c | 7 ++++++- source3/utils/masktest.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 475e20fa66..482167a45a 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -454,6 +454,7 @@ static void usage(void) "Usage:\n\ locktest //server1/share1 //server2/share2 [options..]\n\ options:\n\ + -W workgroup\n\ -U user%%pass\n\ -s seed\n\ -o numops\n\ @@ -497,6 +498,7 @@ static void usage(void) TimeInit(); charset_initialise(); + codepage_initialise(lp_client_code_page()); lp_load(servicesf,True,False,False); load_interfaces(); @@ -507,7 +509,7 @@ static void usage(void) seed = time(NULL); - while ((opt = getopt(argc, argv, "U:s:ho:aA")) != EOF) { + while ((opt = getopt(argc, argv, "U:s:ho:aAW:")) != EOF) { switch (opt) { case 'U': pstrcpy(username,optarg); @@ -533,6 +535,9 @@ static void usage(void) case 'h': usage(); exit(1); + case 'W': + pstrcpy(workgroup, optarg); + break; default: printf("Unknown option %c (%d)\n", (char)opt, opt); exit(1); diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index d8afbddf98..a3eb95bcae 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -274,6 +274,7 @@ static void usage(void) "Usage:\n\ masktest //server/share [options..]\n\ options:\n\ + -W workgroup\n\ -U user%%pass\n\ -s seed\n\ -f filechars (default %s)\n\ @@ -322,6 +323,7 @@ static void usage(void) TimeInit(); charset_initialise(); + codepage_initialise(lp_client_code_page()); lp_load(servicesf,True,False,False); load_interfaces(); @@ -332,7 +334,7 @@ static void usage(void) seed = time(NULL); - while ((opt = getopt(argc, argv, "U:s:hm:f:ao")) != EOF) { + while ((opt = getopt(argc, argv, "U:s:hm:f:aoW:")) != EOF) { switch (opt) { case 'U': pstrcpy(username,optarg); @@ -361,6 +363,9 @@ static void usage(void) case 'o': old_list = True; break; + case 'W': + pstrcpy(workgroup, optarg); + break; default: printf("Unknown option %c (%d)\n", (char)opt, opt); exit(1); -- cgit From fb66b3b6e6f7de7ffbbf2ae3537be7a115597b39 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 24 May 2000 05:40:03 +0000 Subject: torture test: same cli_state: open file rw/denynone, open *same* file r/denynone. write to file (fd1) read from file (fd2). compare. repeat. two cli_states: open file rw/denynone (cli1), open *same* file r/denynone (cli2). write to file (fd1) read from file (fd2). compare. repeat. (This used to be commit 0a993f37830938a8d4262c6b7913af502bbf015f) --- source3/utils/torture.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index e74106609d..8f22c011e1 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -270,6 +270,95 @@ static void run_torture(int dummy) close_connection(&cli); } +static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2) +{ + char *lockfname = "\\torture.lck"; + int fnum1; + int fnum2; + int i; + char buf[131072]; + char buf_rd[131072]; + + if (!cli_unlink(c1, lockfname)) { + printf("unlink failed (%s)\n", cli_errstr(c1)); + } + + fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL, + DENY_NONE); + if (fnum1 == -1) { + printf("first open read/write of %s failed (%s)\n", + lockfname, cli_errstr(c1)); + return False; + } + fnum2 = cli_open(c2, lockfname, O_RDONLY, + DENY_NONE); + if (fnum2 == -1) { + printf("second open read-only of %s failed (%s)\n", + lockfname, cli_errstr(c2)); + cli_close(c1, fnum1); + return False; + } + + for (i=0;i Date: Wed, 24 May 2000 05:47:08 +0000 Subject: use lp_workgroup() use \\ in front of filenames (This used to be commit 9c64f47c164e6ac31a27940fffb415b0b47cd089) --- source3/utils/locktest.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 482167a45a..9a02cf20ca 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -25,13 +25,12 @@ static fstring password; static fstring username; -static fstring workgroup; static int got_pass; static int numops = 1000; static BOOL showall; static BOOL analyze; -#define FILENAME "locktest.dat" +#define FILENAME "\\locktest.dat" #define LOCKRANGE 100 #define LOCKBASE 0 @@ -58,10 +57,12 @@ struct record { }; static struct record preset[] = { +#if 0 {36, 5, 0, 0, 0, 8, 1}, { 2, 6, 0, 1, 0, 1, 1}, {53, 92, 0, 0, 0, 0, 1}, {99, 11, 0, 0, 7, 1, 1}, +#endif }; static struct record *recorded; @@ -158,7 +159,7 @@ struct cli_state *connect_one(char *share) if (!cli_session_setup(c, username, password, strlen(password), password, strlen(password), - workgroup)) { + lp_workgroup())) { DEBUG(0,("session setup failed: %s\n", cli_errstr(c))); return NULL; } -- cgit From c29b72cd4f644c7750ee99313dee64441f78f076 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 May 2000 05:56:34 +0000 Subject: use lp_workgroup() use \\ in front of filenames get short name via a separate trans2 level 260 call (This used to be commit 5fd4dbf72e317bc47ab11b0b3f2e15d0c58879c8) --- source3/utils/masktest.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index a3eb95bcae..dc394dddb5 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -26,7 +26,6 @@ extern int DEBUGLEVEL; static fstring password; static fstring username; -static fstring workgroup; static int got_pass; static BOOL showall = False; @@ -124,7 +123,7 @@ struct cli_state *connect_one(char *share) if (!cli_session_setup(c, username, password, strlen(password), password, strlen(password), - workgroup)) { + lp_workgroup())) { DEBUG(0,("session setup failed: %s\n", cli_errstr(c))); return NULL; } @@ -170,6 +169,15 @@ void listfn(file_info *f, const char *s) finfo = f; } +static void get_short_name(struct cli_state *cli, + char *name, fstring short_name) +{ + cli_list(cli, name, aHIDDEN | aDIR, listfn); + if (finfo) { + fstrcpy(short_name, finfo->short_name); + strlower(short_name); + } +} static void testpair(struct cli_state *cli, char *mask, char *file) { @@ -197,10 +205,8 @@ static void testpair(struct cli_state *cli, char *mask, char *file) cli_list_old(cli, mask, aHIDDEN | aDIR, listfn); } else { cli_list(cli, mask, aHIDDEN | aDIR, listfn); - } - if (finfo) { - fstrcpy(short_name, finfo->short_name); - strlower(short_name); + finfo = NULL; + get_short_name(cli, file, short_name); } res2 = reg_test(mask, file, short_name); @@ -223,7 +229,7 @@ static void test_mask(int argc, char *argv[], int mc_len = strlen(maskchars); int fc_len = strlen(filechars); - cli_mkdir(cli, "masktest"); + cli_mkdir(cli, "\\masktest"); cli_unlink(cli, "\\masktest\\*"); @@ -363,9 +369,6 @@ static void usage(void) case 'o': old_list = True; break; - case 'W': - pstrcpy(workgroup, optarg); - break; default: printf("Unknown option %c (%d)\n", (char)opt, opt); exit(1); -- cgit From aabf523cafaf3ee528a51dff71332c8073670971 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 May 2000 06:01:05 +0000 Subject: use \\ in front of filenames (This used to be commit a92f8c8620272bcbdd73741b8e87f8d5fac45b49) --- source3/utils/torture.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 8f22c011e1..0a3edc4e98 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -1178,7 +1178,7 @@ static void run_denytest1(int dummy) static struct cli_state cli1, cli2; int fnum1, fnum2; int f, d1, d2, o1, o2, x=0; - char *fnames[] = {"denytest1.exe", "denytest1.dat", NULL}; + char *fnames[] = {"\\denytest1.exe", "\\denytest1.dat", NULL}; struct { int v; char *name; @@ -1269,7 +1269,7 @@ static void run_denytest2(int dummy) static struct cli_state cli1; int fnum1, fnum2; int f, d1, d2, o1, o2, x=0; - char *fnames[] = {"denytest2.exe", "denytest2.dat", NULL}; + char *fnames[] = {"\\denytest2.exe", "\\denytest2.dat", NULL}; struct { int v; char *name; -- cgit From 951492548151795acc378b7b13afca2712cbdcf0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 May 2000 07:15:54 +0000 Subject: added -u hide_unlock_fails option (This used to be commit fc8c460a618c25ffa46ab808a241dab466d2666b) --- source3/utils/locktest.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 9a02cf20ca..e2d05b7aa0 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -29,6 +29,7 @@ static int got_pass; static int numops = 1000; static BOOL showall; static BOOL analyze; +static BOOL hide_unlock_fails; #define FILENAME "\\locktest.dat" #define LOCKRANGE 100 @@ -264,14 +265,14 @@ static BOOL test_one(struct cli_state *cli[2][2], ret2 = cli_unlock(cli[1][conn], fnum[1][conn][f], start, len); - if (showall || ret1 != ret2) { + if (showall || (!hide_unlock_fails && (ret1 != ret2))) { printf("unlock conn=%u f=%u range=%u:%u(%u) -> %u:%u\n", conn, f, start, start+len-1, len, ret1, ret2); } if (showall) brl_forall(print_brl); - if (ret1 != ret2) return False; + if (!hide_unlock_fails && ret1 != ret2) return False; } else { /* reopen the file */ cli_close(cli[0][conn], fnum[0][conn][f]); @@ -459,6 +460,7 @@ static void usage(void) -U user%%pass\n\ -s seed\n\ -o numops\n\ + -u hide unlock fails\n\ -a (show all ops)\n\ "); } @@ -524,6 +526,9 @@ static void usage(void) case 's': seed = atoi(optarg); break; + case 'u': + hide_unlock_fails = True; + break; case 'o': numops = atoi(optarg); break; -- cgit From d87a20e8c5254780b1855f92332706780cba4255 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 May 2000 07:18:34 +0000 Subject: we don't do "revalidate = yes" any more (This used to be commit 289d3cac38ae271175697f98d3eb01a21f3678a7) --- source3/utils/testparm.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index e4f603e0ce..009fed80ea 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -49,11 +49,6 @@ static int do_global_checks(void) int ret = 0; SMB_STRUCT_STAT st; - if (lp_security() > SEC_SHARE && lp_revalidate(-1)) { - printf("WARNING: the 'revalidate' parameter is ignored in all but \ -'security=share' mode.\n"); - } - if (lp_security() == SEC_DOMAIN && !lp_encrypted_passwords()) { printf("ERROR: in 'security=domain' mode the 'encrypt passwords' parameter must also be set to 'true'.\n"); ret = 1; -- cgit From 0fca9817b16bdd2fe6f25fb2dd1836dac108a141 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 24 May 2000 07:29:45 +0000 Subject: 2nd evil simultaneous read-write test. forks. one writer. others are readers. writes between 1 and 20 bytes. reads as much as possible. compares. repeat until end of buffer (fixed size: 131072 bytes) reached. (This used to be commit 26f51a7abbfa9bd9051969dffaebe3cdf9e93c8f) --- source3/utils/torture.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 0a3edc4e98..a3a39d83d7 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -29,7 +29,9 @@ static fstring host, workgroup, share, password, username, myname; static int max_protocol = PROTOCOL_NT1; static char *sockops="TCP_NODELAY"; static int nprocs=1, numops=100; +static int procnum; /* records process count number when forking */ static struct cli_state current_cli; +static fstring randomfname; static double create_procs(void (*fn)(int)); @@ -270,6 +272,101 @@ static void run_torture(int dummy) close_connection(&cli); } +static BOOL rw_torture3(struct cli_state *c, char *lockfname) +{ + int fnum = -1; + int i = 0; + char buf[131072]; + char buf_rd[131072]; + unsigned count; + unsigned countprev = 0; + unsigned sent = 0; + + srandom(1); + for (i = 0; i < sizeof(buf); i += sizeof(uint32)) + { + SIVAL(buf, i, sys_random()); + } + + if (procnum == 0) + { + fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL, + DENY_NONE); + if (fnum == -1) { + printf("first open read/write of %s failed (%s)\n", + lockfname, cli_errstr(c)); + return False; + } + } + else + { + for (i = 0; i < 500 && fnum == -1; i++) + { + fnum = cli_open(c, lockfname, O_RDONLY, + DENY_NONE); + msleep(10); + } + if (fnum == -1) { + printf("second open read-only of %s failed (%s)\n", + lockfname, cli_errstr(c)); + return False; + } + } + + i = 0; + for (count = 0; count < sizeof(buf); count += sent) + { + if (count >= countprev) { + printf("%d %8d\r", i, count); + fflush(stdout); + i++; + countprev += (sizeof(buf) / 20); + } + + if (procnum == 0) + { + sent = ((unsigned)sys_random()%(20))+ 1; + if (sent > sizeof(buf) - count) + { + sent = sizeof(buf) - count; + } + + if (cli_write(c, fnum, 0, buf+count, count, sent) != sent) { + printf("write failed (%s)\n", cli_errstr(c)); + } + } + else + { + sent = cli_read(c, fnum, buf_rd+count, count, + sizeof(buf)-count); + if (sent < 0) + { + printf("read failed offset:%d size:%d (%s)\n", + count, sizeof(buf)-count, + cli_errstr(c)); + sent = 0; + } + if (sent > 0) + { + if (memcmp(buf_rd+count, buf+count, sent) != 0) + { + printf("read/write compare failed\n"); + printf("offset: %d req %d recvd %d\n", + count, sizeof(buf)-count, sent); + break; + } + } + } + + } + + if (!cli_close(c, fnum)) { + printf("close failed (%s)\n", cli_errstr(c)); + } + + return True; +} + static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2) { char *lockfname = "\\torture.lck"; @@ -359,6 +456,21 @@ static void run_readwritetest(int dummy) close_connection(&cli2); } +static void run_readwritemulti(int dummy) +{ + static struct cli_state cli; + BOOL test; + + cli = current_cli; + + cli_sockopt(&cli, sockops); + + printf("run_readwritemulti: fname %s\n", randomfname); + test = rw_torture3(&cli, randomfname); + + close_connection(&cli); +} + int line_count = 0; /* run a test that simulates an approximate netbench client load */ @@ -1860,6 +1972,7 @@ static double create_procs(void (*fn)(int)) memset((char *)child_status, 0, sizeof(int)*nprocs); for (i=0;i Date: Wed, 24 May 2000 21:11:34 +0000 Subject: minor fixes (This used to be commit 4d00314ec5b056101b05c38cc68dd4934c83c825) --- source3/utils/locktest.c | 4 ---- source3/utils/masktest.c | 7 ++++--- 2 files changed, 4 insertions(+), 7 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index e2d05b7aa0..2c24b7d36e 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -456,7 +456,6 @@ static void usage(void) "Usage:\n\ locktest //server1/share1 //server2/share2 [options..]\n\ options:\n\ - -W workgroup\n\ -U user%%pass\n\ -s seed\n\ -o numops\n\ @@ -541,9 +540,6 @@ static void usage(void) case 'h': usage(); exit(1); - case 'W': - pstrcpy(workgroup, optarg); - break; default: printf("Unknown option %c (%d)\n", (char)opt, opt); exit(1); diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index dc394dddb5..434494a92a 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -204,9 +204,10 @@ static void testpair(struct cli_state *cli, char *mask, char *file) if (old_list) { cli_list_old(cli, mask, aHIDDEN | aDIR, listfn); } else { - cli_list(cli, mask, aHIDDEN | aDIR, listfn); - finfo = NULL; get_short_name(cli, file, short_name); + finfo = NULL; + fstrcpy(res1, "---"); + cli_list(cli, mask, aHIDDEN | aDIR, listfn); } res2 = reg_test(mask, file, short_name); @@ -218,7 +219,7 @@ static void testpair(struct cli_state *cli, char *mask, char *file) cli_unlink(cli, file); - if (count % 500 == 0) DEBUG(0,("%d\n", count)); + if (count % 100 == 0) DEBUG(0,("%d\n", count)); } static void test_mask(int argc, char *argv[], -- cgit From fae1164304c39b43f231a952faf8cc91a9cca088 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 27 May 2000 00:28:02 +0000 Subject: move srandom to after connect so random stuff in clientgen doesn't change seed (This used to be commit d9322d01e0ac09852924eb6059ecf116e75ee398) --- source3/utils/masktest.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index 434494a92a..3fc7431519 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -379,8 +379,6 @@ static void usage(void) argc -= optind; argv += optind; - DEBUG(0,("seed=%d\n", seed)); - srandom(seed); cli = connect_one(share); if (!cli) { @@ -388,6 +386,10 @@ static void usage(void) exit(1); } + /* need to init seed after connect as clientgen uses random numbers */ + DEBUG(0,("seed=%d\n", seed)); + srandom(seed); + test_mask(argc, argv, cli); return(0); -- cgit From a0e1930489523b3c9682e6f90db710553cd70084 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 27 May 2000 00:29:10 +0000 Subject: fixed bugs in fdpass tests (This used to be commit ee4f6335adb2a781eea7e1f6b520d79ea1197427) --- source3/utils/torture.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index a3a39d83d7..aa2737af30 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -1466,7 +1466,7 @@ security hole) */ static void run_fdpasstest(int dummy) { - static struct cli_state cli1, cli2; + static struct cli_state cli1, cli2, cli3; char *fname = "\\fdpass.tst"; int fnum1; pstring buf; @@ -1492,12 +1492,12 @@ static void run_fdpasstest(int dummy) return; } - cli2.vuid = cli1.vuid; - cli2.cnum = cli1.cnum; - cli2.pid = cli1.pid; - + cli3 = cli2; + cli3.vuid = cli1.vuid; + cli3.cnum = cli1.cnum; + cli3.pid = cli1.pid; - if (cli_read(&cli2, fnum1, buf, 0, 13) == 13) { + if (cli_read(&cli3, fnum1, buf, 0, 13) == 13) { printf("read succeeded! nasty security hole [%s]\n", buf); return; @@ -1588,13 +1588,16 @@ static void run_maxfidtest(int dummy) break; } fnum++; + if (fnum % 100 == 0) printf("%d\r", fnum); } + printf("%d\n", fnum); printf("cleaning up\n"); - while (fnum > n) { + while (fnum > 0) { fnum--; slprintf(fname,sizeof(fname)-1,template, fnum,(int)getpid()); - if (cli_unlink(&cli, fname)) { + cli_close(&cli, fnum); + if (!cli_unlink(&cli, fname)) { printf("unlink of %s failed (%s)\n", fname, cli_errstr(&cli)); } -- cgit From cbeb0aa3f2d20e8587a0de5a340ca2901d49f174 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 3 Jun 2000 06:34:40 +0000 Subject: moved secrets fns into secrets.c (This used to be commit 16355a9c66a2bdab1feb8914a40bbea5272bb170) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 047a69419c..7f26c1d0e9 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -100,7 +100,7 @@ static int join_domain(char *domain, char *remote) * Write the old machine account password. */ - if(!set_trust_account_password(domain, orig_trust_passwd_hash)) { + if(!secrets_store_trust_account_password(domain, orig_trust_passwd_hash)) { fprintf(stderr, "Unable to write the machine account password for \ machine %s in domain %s.\n", global_myname, domain); return 1; -- cgit From 92972280af2cf3a37c6f4928337f6a8fdd152f3d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 5 Jun 2000 09:40:58 +0000 Subject: added -O (use oplocks) option to locktest (This used to be commit 56ba49382fbdbe5672c3a72faaca21f20a53752b) --- source3/utils/locktest.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 2c24b7d36e..ec121956d5 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -30,6 +30,7 @@ static int numops = 1000; static BOOL showall; static BOOL analyze; static BOOL hide_unlock_fails; +static BOOL use_oplocks; #define FILENAME "\\locktest.dat" #define LOCKRANGE 100 @@ -188,6 +189,8 @@ struct cli_state *connect_one(char *share) DEBUG(4,(" tconx ok\n")); + c->use_oplocks = use_oplocks; + return c; } @@ -461,6 +464,7 @@ static void usage(void) -o numops\n\ -u hide unlock fails\n\ -a (show all ops)\n\ + -O use oplocks\n\ "); } @@ -511,7 +515,7 @@ static void usage(void) seed = time(NULL); - while ((opt = getopt(argc, argv, "U:s:ho:aAW:")) != EOF) { + while ((opt = getopt(argc, argv, "U:s:ho:aAW:O")) != EOF) { switch (opt) { case 'U': pstrcpy(username,optarg); @@ -531,6 +535,9 @@ static void usage(void) case 'o': numops = atoi(optarg); break; + case 'O': + use_oplocks = True; + break; case 'a': showall = True; break; -- cgit From 7df31cb494a0cec411e08e22ee2ae837dff06807 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 5 Jun 2000 13:53:56 +0000 Subject: added locktest2 this uses 16 open file descriptors on 2 servers, with each server accessed both via POSIX call and SMB calls. The idea is to test NFS/SMB locking interaction. Unfortunately the NT NFS locking implementation is so badly broken that we don't have anything to test against (This used to be commit 581498fe6b2efe44c1229dd12b9a6506b11747d0) --- source3/utils/locktest2.c | 626 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 626 insertions(+) create mode 100644 source3/utils/locktest2.c (limited to 'source3/utils') diff --git a/source3/utils/locktest2.c b/source3/utils/locktest2.c new file mode 100644 index 0000000000..36b32d6460 --- /dev/null +++ b/source3/utils/locktest2.c @@ -0,0 +1,626 @@ +/* + Unix SMB/Netbios implementation. + Version 2.0 + byte range lock tester - with local filesystem support + 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" + +static fstring password; +static fstring username; +static int got_pass; +static int numops = 1000; +static BOOL showall; +static BOOL analyze; +static BOOL hide_unlock_fails; +static BOOL use_oplocks; + +#define FILENAME "\\locktest.dat" +#define LOCKRANGE 100 +#define LOCKBASE 0 + +/* +#define LOCKBASE (0x40000000 - 50) +*/ + +#define READ_PCT 50 +#define LOCK_PCT 25 +#define UNLOCK_PCT 65 +#define RANGE_MULTIPLE 1 + +#define NSERVERS 2 +#define NCONNECTIONS 2 +#define NUMFSTYPES 2 +#define NFILES 2 +#define LOCK_TIMEOUT 0 + +#define FSTYPE_SMB 0 +#define FSTYPE_NFS 1 + +struct record { + char r1, r2; + char conn, f, fstype; + unsigned start, len; + char needed; +}; + +static struct record *recorded; + +static int try_open(struct cli_state *c, char *nfs, int fstype, char *fname, int flags) +{ + pstring path; + + switch (fstype) { + case FSTYPE_SMB: + return cli_open(c, fname, flags, DENY_NONE); + + case FSTYPE_NFS: + slprintf(path, sizeof(path), "%s%s", nfs, fname); + pstring_sub(path,"\\", "/"); + return open(path, flags, 0666); + } + + return -1; +} + +static BOOL try_close(struct cli_state *c, int fstype, int fd) +{ + switch (fstype) { + case FSTYPE_SMB: + return cli_close(c, fd); + + case FSTYPE_NFS: + return close(fd) == 0; + } + + return False; +} + +static BOOL try_lock(struct cli_state *c, int fstype, + int fd, unsigned start, unsigned len, + int op) +{ + struct flock lock; + + switch (fstype) { + case FSTYPE_SMB: + return cli_lock(c, fd, start, len, LOCK_TIMEOUT, op); + + case FSTYPE_NFS: + lock.l_type = (op==READ_LOCK) ? F_RDLCK:F_WRLCK; + lock.l_whence = SEEK_SET; + lock.l_start = start; + lock.l_len = len; + lock.l_pid = getpid(); + return fcntl(fd,F_SETLK,&lock) == 0; + } + + return False; +} + +static BOOL try_unlock(struct cli_state *c, int fstype, + int fd, unsigned start, unsigned len) +{ + struct flock lock; + + switch (fstype) { + case FSTYPE_SMB: + return cli_unlock(c, fd, start, len); + + case FSTYPE_NFS: + lock.l_type = F_UNLCK; + lock.l_whence = SEEK_SET; + lock.l_start = start; + lock.l_len = len; + lock.l_pid = getpid(); + return fcntl(fd,F_SETLK,&lock) == 0; + } + + return False; +} + +static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, + enum brl_type lock_type, + br_off start, br_off size) +{ + printf("%6d %05x:%05x %s %.0f:%.0f(%.0f)\n", + (int)pid, (int)dev, (int)ino, + lock_type==READ_LOCK?"R":"W", + (double)start, (double)start+size-1,(double)size); + +} + +/***************************************************** +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; + fstring server; + struct in_addr ip; + extern struct in_addr ipzero; + fstring myname; + static int count; + + fstrcpy(server,share+2); + share = strchr(server,'\\'); + if (!share) return NULL; + *share = 0; + share++; + + server_n = server; + + ip = ipzero; + + slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++); + + make_nmb_name(&calling, myname, 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), + lp_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")); + + c->use_oplocks = use_oplocks; + + return c; +} + + +static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], + char *nfs[NSERVERS], + int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES], + char *share1, char *share2) +{ + int server, conn, f, fstype; + char *share[2]; + share[0] = share1; + share[1] = share2; + + fstype = FSTYPE_SMB; + + for (server=0;serverconn; + unsigned f = rec->f; + unsigned fstype = rec->fstype; + unsigned start = rec->start; + unsigned len = rec->len; + unsigned r1 = rec->r1; + unsigned r2 = rec->r2; + unsigned op; + int server; + BOOL ret[NSERVERS]; + + if (r1 < READ_PCT) { + op = READ_LOCK; + } else { + op = WRITE_LOCK; + } + + if (r2 < LOCK_PCT) { + /* set a lock */ + for (server=0;server %u:%u\n", + conn, fstype, f, + start, start+len-1, len, + op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", + ret[0], ret[1]); + } + if (showall) brl_forall(print_brl); + if (ret[0] != ret[1]) return False; + } else if (r2 < LOCK_PCT+UNLOCK_PCT) { + /* unset a lock */ + for (server=0;server %u:%u\n", + conn, fstype, f, + start, start+len-1, len, + ret[0], ret[1]); + } + if (showall) brl_forall(print_brl); + if (!hide_unlock_fails && ret[0] != ret[1]) return False; + } else { + /* reopen the file */ + for (server=0;server Date: Mon, 5 Jun 2000 13:54:26 +0000 Subject: don't ue nasty /proc/locks hack by default (This used to be commit 62d72dd67ba41b90fefc4308139cd488b3fcb3fa) --- source3/utils/locktest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index ec121956d5..9bccf24443 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -1,7 +1,7 @@ /* Unix SMB/Netbios implementation. Version 2.0 - mask_match tester + randomised byte range lock tester Copyright (C) Andrew Tridgell 1999 This program is free software; you can redistribute it and/or modify @@ -48,7 +48,7 @@ static BOOL use_oplocks; #define NFILES 2 #define LOCK_TIMEOUT 0 -#define NASTY_POSIX_LOCK_HACK 1 +#define NASTY_POSIX_LOCK_HACK 0 struct record { -- cgit From 8843a6379d7c1cf59f0f3673cbc567b09994b7d2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 11 Jun 2000 05:57:58 +0000 Subject: Linux kernel oplocks now seem to work, but need a _lot_ of testing I had to modify sys_select() to not loop on EINTR. I added a wrapper called sys_select_intr() which gives the old behaviour. (This used to be commit b28cc4163bc2faaa80c5782fc02c8f03c410cdeb) --- source3/utils/smbfilter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c index 81b10e4519..5d11c74d14 100644 --- a/source3/utils/smbfilter.c +++ b/source3/utils/smbfilter.c @@ -120,7 +120,7 @@ static void filter_child(int c, struct in_addr dest_ip) if (s != -1) FD_SET(s, &fds); if (c != -1) FD_SET(c, &fds); - num = sys_select(MAX(s+1, c+1),&fds,NULL); + num = sys_select_intr(MAX(s+1, c+1),&fds,NULL); if (num <= 0) continue; if (c != -1 && FD_ISSET(c, &fds)) { @@ -184,7 +184,7 @@ static void start_filter(char *desthost) FD_ZERO(&fds); FD_SET(s, &fds); - num = sys_select(s+1,&fds,NULL); + num = sys_select_intr(s+1,&fds,NULL); if (num > 0) { c = accept(s, &addr, &in_addrlen); if (c != -1) { -- cgit From ec33db96d510ab483989df13d4bd4e63c9d0b6b2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 13 Jun 2000 09:33:43 +0000 Subject: added -L switch to tell smbtorture to use oplocks (This used to be commit 73033d0803317c7de017cac7f7669f4afb08e7c0) --- source3/utils/nbio.c | 2 -- source3/utils/torture.c | 9 +++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nbio.c b/source3/utils/nbio.c index f72be36842..973f7d0628 100644 --- a/source3/utils/nbio.c +++ b/source3/utils/nbio.c @@ -50,8 +50,6 @@ static void sigsegv(int sig) 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; } diff --git a/source3/utils/torture.c b/source3/utils/torture.c index aa2737af30..a53ba1ce60 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -32,6 +32,7 @@ static int nprocs=1, numops=100; static int procnum; /* records process count number when forking */ static struct cli_state current_cli; static fstring randomfname; +static BOOL use_oplocks; static double create_procs(void (*fn)(int)); @@ -107,6 +108,7 @@ static BOOL open_connection(struct cli_state *c) } c->timeout = 120000; /* set a really long timeout (2 minutes) */ + if (use_oplocks) c->use_oplocks = True; if (!cli_session_request(c, &calling, &called)) { printf("%s rejected the session\n",host); @@ -1565,7 +1567,6 @@ static void run_maxfidtest(int dummy) fstring fname; int fnum; int retries=4; - int n = numops; cli = current_cli; @@ -2109,6 +2110,7 @@ static void usage(void) printf("\t-o num_operations\n"); printf("\t-O socket_options\n"); printf("\t-m maximum protocol\n"); + printf("\t-L use oplocks\n"); printf("\n\n"); printf("tests are:"); @@ -2180,7 +2182,7 @@ static void usage(void) fstrcpy(workgroup, lp_workgroup()); - while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:")) != EOF) { + while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:L")) != EOF) { switch (opt) { case 'W': fstrcpy(workgroup,optarg); @@ -2197,6 +2199,9 @@ static void usage(void) case 'O': sockops = optarg; break; + case 'L': + use_oplocks = True; + break; case 'n': fstrcpy(myname, optarg); break; -- cgit From e28124601045b01c238558d9d1281e41d719a12e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 13 Jun 2000 15:47:23 +0000 Subject: allow for lots of connections per server (This used to be commit 4bbc218922d2b1f40d50a611a389c9956851050f) --- source3/utils/locktest.c | 151 ++++++++++++++++++++++++----------------------- 1 file changed, 76 insertions(+), 75 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 9bccf24443..78627c22ad 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -41,11 +41,12 @@ static BOOL use_oplocks; */ #define READ_PCT 50 -#define LOCK_PCT 25 -#define UNLOCK_PCT 65 +#define LOCK_PCT 35 +#define UNLOCK_PCT 55 #define RANGE_MULTIPLE 1 -#define NCONNECTIONS 2 -#define NFILES 2 +#define NSERVERS 2 +#define NCONNECTIONS 6 +#define NFILES 4 #define LOCK_TIMEOUT 0 #define NASTY_POSIX_LOCK_HACK 0 @@ -94,6 +95,14 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, } + +static void show_locks(void) +{ + brl_forall(print_brl); + system("cat /proc/locks"); +} + + /***************************************************** return a connection to a server *******************************************************/ @@ -195,15 +204,12 @@ struct cli_state *connect_one(char *share) } -static void reconnect(struct cli_state *cli[2][2], int fnum[2][2][2], - char *share1, char *share2) +static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NSERVERS][NCONNECTIONS][NFILES], + char *share[NSERVERS]) { int server, conn, f; - char *share[2]; - share[0] = share1; - share[1] = share2; - for (server=0;server<2;server++) + for (server=0;serverconn; @@ -235,7 +241,8 @@ static BOOL test_one(struct cli_state *cli[2][2], unsigned r1 = rec->r1; unsigned r2 = rec->r2; unsigned op; - BOOL ret1, ret2; + int server; + BOOL ret[NSERVERS]; if (r1 < READ_PCT) { op = READ_LOCK; @@ -245,70 +252,64 @@ static BOOL test_one(struct cli_state *cli[2][2], if (r2 < LOCK_PCT) { /* set a lock */ - ret1 = cli_lock(cli[0][conn], - fnum[0][conn][f], - start, len, LOCK_TIMEOUT, op); - ret2 = cli_lock(cli[1][conn], - fnum[1][conn][f], - start, len, LOCK_TIMEOUT, op); - if (showall || ret1 != ret2) { + for (server=0;server %u:%u\n", conn, f, start, start+len-1, len, op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", - ret1, ret2); + ret[0], ret[1]); } - if (showall) brl_forall(print_brl); - if (ret1 != ret2) return False; + if (showall || ret[0] != ret[1]) show_locks(); + if (ret[0] != ret[1]) return False; } else if (r2 < LOCK_PCT+UNLOCK_PCT) { /* unset a lock */ - ret1 = cli_unlock(cli[0][conn], - fnum[0][conn][f], - start, len); - ret2 = cli_unlock(cli[1][conn], - fnum[1][conn][f], - start, len); - if (showall || (!hide_unlock_fails && (ret1 != ret2))) { + for (server=0;server %u:%u\n", conn, f, start, start+len-1, len, - ret1, ret2); + ret[0], ret[1]); } - if (showall) brl_forall(print_brl); - if (!hide_unlock_fails && ret1 != ret2) return False; + if (showall || ret[0] != ret[1]) show_locks(); + if (!hide_unlock_fails && ret[0] != ret[1]) return False; } else { /* reopen the file */ - cli_close(cli[0][conn], fnum[0][conn][f]); - cli_close(cli[1][conn], fnum[1][conn][f]); - fnum[0][conn][f] = cli_open(cli[0][conn], FILENAME, - O_RDWR|O_CREAT, - DENY_NONE); - fnum[1][conn][f] = cli_open(cli[1][conn], FILENAME, - O_RDWR|O_CREAT, - DENY_NONE); - if (fnum[0][conn][f] == -1) { - printf("failed to reopen on share1\n"); - return False; + for (server=0;server Date: Tue, 13 Jun 2000 15:47:44 +0000 Subject: argv parsing fixes (This used to be commit 502751cc62df7395683dc45d15887535baa5656b) --- source3/utils/locktest2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest2.c b/source3/utils/locktest2.c index 36b32d6460..0391aa2942 100644 --- a/source3/utils/locktest2.c +++ b/source3/utils/locktest2.c @@ -515,7 +515,7 @@ static void usage(void) { printf( "Usage:\n\ - locktest //server1/share1 //server2/share2 [options..]\n\ + locktest //server1/share1 //server2/share2 /path1 /path2 [options..]\n\ options:\n\ -U user%%pass\n\ -s seed\n\ @@ -544,7 +544,7 @@ static void usage(void) dbf = stderr; - if (argv[1][0] == '-' || argc < 5) { + if (argc < 5 || argv[1][0] == '-') { usage(); exit(1); } -- cgit From 30fdd204f44cd06b716736e7fd64942a8d7b6f84 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Tue, 13 Jun 2000 20:41:15 +0000 Subject: If I use nmblookup to search for node ZOOB#1B and there is no such name registered within the search space, nmblookup would report name_query failed to find name ZOOB I've changed it to report any non-zero type, so the above message becomes name_query failed to find name ZOOB#1B If the query is for ZOOB or even ZOOB#00 then the old style error message is given. Chris -)----- (This used to be commit 5ecf0c61718afbc7106e853d327428bd72f77690) --- source3/utils/nmblookup.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 546d2f0e15..15188f6768 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -261,14 +261,16 @@ int main(int argc,char *argv[]) } p = strchr(lookup,'#'); - if (p) { - *p = 0; - sscanf(p+1,"%x",&lookup_type); + *p = '\0'; + sscanf(++p,"%x",&lookup_type); } if (!query_one(lookup, lookup_type)) { - printf("name_query failed to find name %s\n", lookup); + printf( "name_query failed to find name %s", lookup ); + if( 0 != lookup_type ) + printf( "#%02x", lookup_type ); + printf( "\n" ); } } -- cgit From b41b1daa36c9ff48616fe23c99da1a00bf11ff84 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 15 Jun 2000 09:31:34 +0000 Subject: add -d debuglevel option (This used to be commit 448f21325f8ff53f3ff5e45c22e07f7164529bc9) --- source3/utils/torture.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index a53ba1ce60..5a5754a21a 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -2103,6 +2103,7 @@ static void usage(void) printf("Usage: smbtorture //server/share TEST1 TEST2 ...\n"); + printf("\t-d debuglevel\n"); printf("\t-U user%%pass\n"); printf("\t-N numprocs\n"); printf("\t-n my_netbios_name\n"); @@ -2182,7 +2183,7 @@ static void usage(void) fstrcpy(workgroup, lp_workgroup()); - while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:L")) != EOF) { + while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:Ld:")) != EOF) { switch (opt) { case 'W': fstrcpy(workgroup,optarg); @@ -2196,6 +2197,9 @@ static void usage(void) case 'o': numops = atoi(optarg); break; + case 'd': + DEBUGLEVEL = atoi(optarg); + break; case 'O': sockops = optarg; break; -- cgit From 7d9b43c8e0bee8d52151c5dc471d0a02e3e8c9a0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 29 Jun 2000 08:22:00 +0000 Subject: slightly saner defaults (This used to be commit fae3acc574c6e78121e6a1d464b67a15fb025304) --- source3/utils/locktest.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index 78627c22ad..c5d0472420 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -45,8 +45,8 @@ static BOOL use_oplocks; #define UNLOCK_PCT 55 #define RANGE_MULTIPLE 1 #define NSERVERS 2 -#define NCONNECTIONS 6 -#define NFILES 4 +#define NCONNECTIONS 2 +#define NFILES 2 #define LOCK_TIMEOUT 0 #define NASTY_POSIX_LOCK_HACK 0 @@ -99,7 +99,7 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, static void show_locks(void) { brl_forall(print_brl); - system("cat /proc/locks"); + /* system("cat /proc/locks"); */ } -- cgit From c1254449a2d6fb17655829bc1db02b918b6a2798 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Jul 2000 03:54:07 +0000 Subject: the smbw sample prog (This used to be commit 0afcc0d3368472ed4b49167dc4b7d907b0ccdc25) --- source3/utils/smbw_sample.c | 93 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 source3/utils/smbw_sample.c (limited to 'source3/utils') diff --git a/source3/utils/smbw_sample.c b/source3/utils/smbw_sample.c new file mode 100644 index 0000000000..d98d5cbe22 --- /dev/null +++ b/source3/utils/smbw_sample.c @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include + +static void usage(void) +{ + printf(" +smbw_sample - a sample program that uses smbw + +smbw_sample path + + options: + -W workgroup + -l logfile + -P prefix + -d debuglevel + -U username%password + -R resolve order + +note that path must start with /smb/ +"); +} + +int main(int argc, char *argv[]) +{ + DIR *dir; + struct dirent *dent; + int opt; + char *p; + extern char *optarg; + extern int optind; + char *path; + + charset_initialise(); + smbw_setup_shared(); + + while ((opt = getopt(argc, argv, "W:U:R:d:P:l:hL:")) != EOF) { + switch (opt) { + case 'W': + smbw_setshared("WORKGROUP", optarg); + break; + case 'l': + smbw_setshared("LOGFILE", optarg); + break; + case 'P': + smbw_setshared("PREFIX", optarg); + break; + case 'd': + smbw_setshared("DEBUG", optarg); + break; + case 'U': + p = strchr(optarg,'%'); + if (p) { + *p=0; + smbw_setshared("PASSWORD",p+1); + } + smbw_setshared("USER", optarg); + break; + case 'R': + smbw_setshared("RESOLVE_ORDER",optarg); + break; + case 'h': + default: + usage(); + } + } + + argc -= optind; + argv += optind; + + if (argc < 1) { + usage(); + exit(1); + } + + path = argv[0]; + + smbw_init(); + + dir = smbw_opendir(path); + if (!dir) { + printf("failed to open %s\n", path); + exit(1); + } + + while ((dent = smbw_readdir(dir))) { + printf("%s\n", dent->d_name); + } + smbw_closedir(dir); + return 0; +} -- cgit From ac56d8f848ab6d057cee84ee85945594b65597c4 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Tue, 18 Jul 2000 20:15:15 +0000 Subject: Removed the sanity check on the WINS SERVER parameter because it simply checked to see that only one server was listed. As I am working on an enhancement that allows multiple servers to be listed...this was a bit contrary. ;) (This used to be commit 1b718f67675e52520f193a8c71c110246e70723f) --- source3/utils/testparm.c | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 009fed80ea..dcf114bc91 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -137,23 +137,6 @@ via the %%o substitution. With encrypted passwords this is not possible.\n", lp_ } } - /* - * WINS server line sanity checks. - */ - - if(*lp_wins_server()) { - fstring server; - int count = 0; - char *p = lp_wins_server(); - - while(next_token(&p,server,LIST_SEP,sizeof(server))) - count++; - if(count > 1) { - printf("ERROR: the 'wins server' parameter must only contain one WINS server.\n"); - ret = -1; - } - } - return ret; } -- cgit From 18db0514fddf15c9aa5eeefa18891bbf3e0637f5 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 26 Jul 2000 03:55:17 +0000 Subject: Fixed memory leaks in root and non-root password changing. (This used to be commit f3a4f81a5e51e411f1c7c6245597cca01e9ad5b2) --- source3/utils/smbpasswd.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 7f26c1d0e9..318047db20 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -193,16 +193,18 @@ static char *prompt_for_new_password(BOOL stdin_get) p = get_pass("New SMB password:", stdin_get); fstrcpy(new_passwd, p); + safe_free(p); p = get_pass("Retype new SMB password:", stdin_get); if (strcmp(p, new_passwd)) { fprintf(stderr, "Mismatch - password unchanged.\n"); ZERO_ARRAY(new_passwd); + safe_free(p); return NULL; } - return xstrdup(p); + return p; } @@ -249,7 +251,7 @@ static BOOL password_change(const char *remote_machine, char *user_name, static int process_root(int argc, char *argv[]) { struct passwd *pwd; - int ch; + int result = 0, ch; BOOL joining_domain = False; int local_flags = 0; BOOL stdin_passwd_get = False; @@ -417,7 +419,8 @@ static int process_root(int argc, char *argv[]) if (!password_change(remote_machine, user_name, old_passwd, new_passwd, local_flags)) { fprintf(stderr,"Failed to modify password entry for user %s\n", user_name); - return 1; + result = 1; + goto done; } if(!(local_flags & (LOCAL_ADD_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER|LOCAL_DELETE_USER|LOCAL_SET_NO_PASSWORD))) { @@ -429,7 +432,10 @@ static int process_root(int argc, char *argv[]) printf(" User has no password flag set."); printf("\n"); } - return 0; + + done: + safe_free(new_passwd); + return result; } @@ -439,7 +445,7 @@ handle password changing for non-root static int process_nonroot(int argc, char *argv[]) { struct passwd *pwd = NULL; - int ch; + int result = 0, ch; BOOL stdin_passwd_get = False; char *old_passwd = NULL; char *remote_machine = NULL; @@ -514,11 +520,18 @@ static int process_nonroot(int argc, char *argv[]) if (!password_change(remote_machine, user_name, old_passwd, new_passwd, 0)) { fprintf(stderr,"Failed to change password for %s\n", user_name); - return 1; + result = 1; + goto done; } printf("Password changed for user %s\n", user_name); - return 0; + + done: + safe_free(old_passwd); + safe_free(new_passwd); + safe_free(user_name); + + return result; } -- cgit From 0d7df3ee013bbad33a4fa230e0941c5021af0a71 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 9 Aug 2000 00:11:01 +0000 Subject: fixed help string (This used to be commit 16afa46797a4cdaa6e3b668caf6d910c08bec9b4) --- source3/utils/smbw_sample.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbw_sample.c b/source3/utils/smbw_sample.c index d98d5cbe22..999dcaef47 100644 --- a/source3/utils/smbw_sample.c +++ b/source3/utils/smbw_sample.c @@ -16,7 +16,7 @@ smbw_sample path -l logfile -P prefix -d debuglevel - -U username%password + -U username%%password -R resolve order note that path must start with /smb/ @@ -64,6 +64,7 @@ int main(int argc, char *argv[]) case 'h': default: usage(); + exit(1); } } -- cgit From d8ad8a0d74be4e2243ded4385692e7586fe75127 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 21 Aug 2000 19:30:19 +0000 Subject: Fix for safe_free freeing static strings. From Robert August Vincent, II. Jeremy. (This used to be commit bd844fcd3023ab956eb7ab369475955a88bcca14) --- source3/utils/smbpasswd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 318047db20..d9fa46fe4c 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -269,12 +269,12 @@ static int process_root(int argc, char *argv[]) case 'x': local_flags |= LOCAL_DELETE_USER; user_name = optarg; - new_passwd = "XXXXXX"; + new_passwd = xstrdup("XXXXXX"); break; case 'd': local_flags |= LOCAL_DISABLE_USER; user_name = optarg; - new_passwd = "XXXXXX"; + new_passwd = xstrdup("XXXXXX"); break; case 'e': local_flags |= LOCAL_ENABLE_USER; @@ -285,7 +285,7 @@ static int process_root(int argc, char *argv[]) break; case 'n': local_flags |= LOCAL_SET_NO_PASSWORD; - new_passwd = "NO PASSWORD"; + new_passwd = xstrdup("NO PASSWORD"); break; case 'j': new_domain = optarg; @@ -344,7 +344,7 @@ static int process_root(int argc, char *argv[]) break; case 2: user_name = argv[0]; - new_passwd = argv[1]; + new_passwd = xstrdup(argv[1]); break; default: usage(); @@ -373,6 +373,7 @@ static int process_root(int argc, char *argv[]) } if (local_flags & LOCAL_ADD_USER) { + safe_free(new_passwd); new_passwd = xstrdup(user_name); strlower(new_passwd); } @@ -404,7 +405,7 @@ static int process_root(int argc, char *argv[]) if(local_flags & LOCAL_ENABLE_USER) { struct smb_passwd *smb_pass = getsmbpwnam(user_name); if((smb_pass != NULL) && (smb_pass->smb_passwd != NULL)) { - new_passwd = "XXXX"; /* Don't care. */ + new_passwd = xstrdup("XXXX"); /* Don't care. */ } } -- cgit From fe47e8efe2e7136ad6fe0ee0b05a672daf3b359a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 11 Sep 2000 07:03:10 +0000 Subject: a simple test program I use to test the debug message system (This used to be commit db1ec05f89071cd1ae4b190dda843b38e2d97cef) --- source3/utils/msgtest.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 source3/utils/msgtest.c (limited to 'source3/utils') diff --git a/source3/utils/msgtest.c b/source3/utils/msgtest.c new file mode 100644 index 0000000000..c0ced262d7 --- /dev/null +++ b/source3/utils/msgtest.c @@ -0,0 +1,63 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + status reporting + Copyright (C) Andrew Tridgell 1994-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. + + Revision History: + + 12 aug 96: Erik.Devriendt@te6.siemens.be + added support for shared memory implementation of share mode locking + + 21-Jul-1998: rsharpe@ns.aus.com (Richard Sharpe) + Added -L (locks only) -S (shares only) flags and code + +*/ + +/* + * This program reports current SMB connections + */ + +#define NO_SYSLOG + +#include "includes.h" + + + + int main(int argc, char *argv[]) +{ + pid_t pid; + int level; + static pstring servicesf = CONFIGFILE; + + TimeInit(); + setup_logging(argv[0],True); + + charset_initialise(); + + lp_load(servicesf,False,False,False); + + message_init(); + + pid = atoi(argv[1]); + level = atoi(argv[2]); + + debug_message_send(pid, level); + + return (0); +} + -- cgit From f0ce4f7ae3b58f45b70598e3a44539e3e12291ce Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Sep 2000 06:13:25 +0000 Subject: - changed the msg_type to be an int instead of an enum so that it is easier to add new message types to messages.h without breaking old binaries - added a MSG_FORCE_ELECTION message to force nmbd to hold an election (This used to be commit f1c49ca7ce56bc39259041a71479e84ebf53eeca) --- source3/utils/msgtest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/msgtest.c b/source3/utils/msgtest.c index c0ced262d7..22d7a9a331 100644 --- a/source3/utils/msgtest.c +++ b/source3/utils/msgtest.c @@ -56,7 +56,7 @@ pid = atoi(argv[1]); level = atoi(argv[2]); - debug_message_send(pid, level); + message_send_pid(pid, MSG_FORCE_ELECTION, NULL, 0); return (0); } -- cgit From df89b4853954b7dcc86839167760cf72af693656 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Sep 2000 06:57:25 +0000 Subject: - fixed some memory leaks in the messages code - added a MSG_PING message for performance testing. (This used to be commit e779f834dbb875669c3aa0a35b324aa13f0c8c36) --- source3/utils/msgtest.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/msgtest.c b/source3/utils/msgtest.c index 22d7a9a331..4821aef80b 100644 --- a/source3/utils/msgtest.c +++ b/source3/utils/msgtest.c @@ -36,12 +36,21 @@ #include "includes.h" +static int pong_count; + +/**************************************************************************** +a useful function for testing the message system +****************************************************************************/ +void pong_message(int msg_type, pid_t src, void *buf, size_t len) +{ + pong_count++; +} int main(int argc, char *argv[]) { pid_t pid; - int level; + int i, n; static pstring servicesf = CONFIGFILE; TimeInit(); @@ -54,9 +63,18 @@ message_init(); pid = atoi(argv[1]); - level = atoi(argv[2]); + n = atoi(argv[2]); + + message_register(MSG_PONG, pong_message); + + for (i=0;i Date: Wed, 13 Sep 2000 07:07:17 +0000 Subject: first cut at smbcontrol program. It currently allows syntax like: smbcontrol nmbd debug 7 smbcontrol smbd debug 9 smbcontrol 3278 debug 1 smbcontrol nmbd force-election (This used to be commit 5f91c24636f5d82486f22c10bc55e060f9c518bf) --- source3/utils/msgtest.c | 18 ++---- source3/utils/smbcontrol.c | 155 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+), 14 deletions(-) create mode 100644 source3/utils/smbcontrol.c (limited to 'source3/utils') diff --git a/source3/utils/msgtest.c b/source3/utils/msgtest.c index 4821aef80b..858166e697 100644 --- a/source3/utils/msgtest.c +++ b/source3/utils/msgtest.c @@ -1,8 +1,7 @@ /* Unix SMB/Netbios implementation. - Version 1.9. - status reporting - Copyright (C) Andrew Tridgell 1994-1998 + Version 3.0 + Copyright (C) Andrew Tridgell 2000 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 @@ -17,19 +16,10 @@ 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. - - Revision History: - - 12 aug 96: Erik.Devriendt@te6.siemens.be - added support for shared memory implementation of share mode locking - - 21-Jul-1998: rsharpe@ns.aus.com (Richard Sharpe) - Added -L (locks only) -S (shares only) flags and code - */ /* - * This program reports current SMB connections + test code for internal messaging */ #define NO_SYSLOG @@ -71,7 +61,7 @@ void pong_message(int msg_type, pid_t src, void *buf, size_t len) message_send_pid(pid, MSG_PING, NULL, 0); } - while (pong_count < n) { + while (pong_count < i) { message_dispatch(); msleep(1); } diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c new file mode 100644 index 0000000000..b31b53473c --- /dev/null +++ b/source3/utils/smbcontrol.c @@ -0,0 +1,155 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + program to send control messages to Samba processes + Copyright (C) Andrew Tridgell 1994-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" + +static struct { + char *name; + int value; +} msg_types[] = { + {"debug", MSG_DEBUG}, + {"force-election", MSG_FORCE_ELECTION}, + {"ping", MSG_PING}, + {NULL, -1} +}; + +static void usage(void) +{ + int i; + printf("Usage: smbcontrol \n\n"); + printf("\t is one of \"nmbd\", \"smbd\" or a process ID\n"); + printf("\t is one of: "); + for (i=0; msg_types[i].name; i++) printf("%s, ", msg_types[i].name); + printf("\n"); + exit(1); +} + +static int pong_count; + +/**************************************************************************** +a useful function for testing the message system +****************************************************************************/ +void pong_function(int msg_type, pid_t src, void *buf, size_t len) +{ + pong_count++; +} + +/**************************************************************************** +send a message to a named destination +****************************************************************************/ +static BOOL send_message(char *dest, int msg_type, void *buf, int len) +{ + pid_t pid; + + /* "smbd" is the only broadcast operation */ + if (strequal(dest,"smbd")) { + return message_send_all(msg_type, buf, len); + } else if (strequal(dest,"nmbd")) { + pid = pidfile_pid(dest); + if (pid == 0) { + fprintf(stderr,"Can't find pid for nmbd\n"); + return False; + } + } else { + pid = atoi(dest); + if (pid == 0) { + fprintf(stderr,"Not a valid pid\n"); + return False; + } + } + + return message_send_pid(pid, msg_type, buf, len); +} + +/**************************************************************************** +evaluate a message type string +****************************************************************************/ +static int parse_type(char *mtype) +{ + int i; + for (i=0;msg_types[i].name;i++) { + if (strequal(mtype, msg_types[i].name)) return msg_types[i].value; + } + return -1; +} + + + int main(int argc, char *argv[]) +{ + char *dest; + int i, n, v; + pstring servicesf = CONFIGFILE; + int mtype; + + TimeInit(); + setup_logging(argv[0],True); + + charset_initialise(); + lp_load(servicesf,False,False,False); + + message_init(); + + if (argc < 3) usage(); + + dest = argv[1]; + mtype = parse_type(argv[2]); + if (mtype == -1) { + fprintf(stderr,"Couldn't resolve message type: %s\n", argv[2]); + exit(1); + } + + argc -= 2; + argv += 2; + + switch (mtype) { + case MSG_DEBUG: + if (argc < 2) { + fprintf(stderr,"MSG_DEBUG needs a parameter\n"); + exit(1); + } + v = atoi(argv[1]); + send_message(dest, MSG_DEBUG, &v, sizeof(int)); + break; + + case MSG_FORCE_ELECTION: + if (!strequal(dest, "nmbd")) { + fprintf(stderr,"force-election can only be sent to nmbd\n"); + exit(1); + } + send_message(dest, MSG_FORCE_ELECTION, NULL, 0); + break; + + case MSG_PING: + message_register(MSG_PONG, pong_function); + n = atoi(argv[1]); + for (i=0;i Date: Tue, 26 Sep 2000 05:44:42 +0000 Subject: added NEGNOWAIT. sent to secure@microsoft.com (This used to be commit b21179331802aace566671dcff6db22cdf4b3e81) --- source3/utils/torture.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 5a5754a21a..4267aab118 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -89,7 +89,7 @@ static void *shm_setup(int size) } -static BOOL open_connection(struct cli_state *c) +static BOOL open_nbt_connection(struct cli_state *c) { struct nmb_name called, calling; struct in_addr ip; @@ -116,6 +116,17 @@ static BOOL open_connection(struct cli_state *c) return False; } + return True; +} + +static BOOL open_connection(struct cli_state *c) +{ + ZERO_STRUCTP(c); + + if (!open_nbt_connection(c)) { + return False; + } + if (!cli_negprot(c)) { printf("%s rejected the negprot (%s)\n",host, cli_errstr(c)); cli_shutdown(c); @@ -142,7 +153,6 @@ static BOOL open_connection(struct cli_state *c) } - static void close_connection(struct cli_state *c) { if (!cli_tdis(c)) { @@ -1617,6 +1627,28 @@ static void rand_buf(char *buf, int len) } } +/* send smb negprot commands, not reading the response */ +static void run_negprot_nowait(int dummy) +{ + int i; + static struct cli_state cli; + + printf("starting negprot nowait test\n"); + + if (!open_nbt_connection(&cli)) { + return; + } + + for (i=0;i<50000;i++) { + cli_negprot_send(&cli); + } + + close_connection(&cli); + + printf("finished negprot nowait test\n"); +} + + /* send random IPC commands */ static void run_randomipc(int dummy) { @@ -2054,6 +2086,7 @@ static struct { {"MAXFID", run_maxfidtest, FLAG_MULTIPROC}, {"TORTURE",run_torture, FLAG_MULTIPROC}, {"RANDOMIPC", run_randomipc, 0}, + {"NEGNOWAIT", run_negprot_nowait, 0}, {"NBW95", run_nbw95, 0}, {"NBWNT", run_nbwnt, 0}, {"OPLOCK", run_oplock, 0}, -- cgit From e600c12b6b2cd4e0ad0d145b0ad6d0b92113392f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 29 Sep 2000 04:43:07 +0000 Subject: use the 64 bit locking interface in locktest (This used to be commit 1ece7f1ffd7d0b61d6acea03819fb857ea556b4b) --- source3/utils/locktest.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c index c5d0472420..80dbba1e37 100644 --- a/source3/utils/locktest.c +++ b/source3/utils/locktest.c @@ -33,8 +33,8 @@ static BOOL hide_unlock_fails; static BOOL use_oplocks; #define FILENAME "\\locktest.dat" -#define LOCKRANGE 100 -#define LOCKBASE 0 +#define LOCKRANGE 1000 +#define LOCKBASE 0; /* #define LOCKBASE (0x40000000 - 50) @@ -55,7 +55,7 @@ static BOOL use_oplocks; struct record { char r1, r2; char conn, f; - unsigned start, len; + SMB_BIG_UINT start, len; char needed; }; @@ -236,8 +236,8 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS], { unsigned conn = rec->conn; unsigned f = rec->f; - unsigned start = rec->start; - unsigned len = rec->len; + SMB_BIG_UINT start = rec->start; + SMB_BIG_UINT len = rec->len; unsigned r1 = rec->r1; unsigned r2 = rec->r2; unsigned op; @@ -253,14 +253,14 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS], if (r2 < LOCK_PCT) { /* set a lock */ for (server=0;server %u:%u\n", + printf("lock conn=%u f=%u range=%.0f:%.0f(%.0f) op=%s -> %u:%u\n", conn, f, - start, start+len-1, len, + (double)start, (double)start+len-1, (double)len, op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", ret[0], ret[1]); } @@ -269,14 +269,14 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS], } else if (r2 < LOCK_PCT+UNLOCK_PCT) { /* unset a lock */ for (server=0;server %u:%u\n", + printf("unlock conn=%u f=%u range=%.0f:%.0f(%.0f) -> %u:%u\n", conn, f, - start, start+len-1, len, + (double)start, (double)start+len-1, (double)len, ret[0], ret[1]); } if (showall || ret[0] != ret[1]) show_locks(); @@ -442,13 +442,13 @@ static void test_locks(char *share[NSERVERS]) close_files(cli, fnum); for (i=0;i Date: Fri, 29 Sep 2000 20:08:00 +0000 Subject: utils/smbcontrol.c: Fixes from Herb for interactive use. printing/nt_printing.c: No C++ comments please :-). Jeremy. (This used to be commit dd9f668108215f18240458fc33bf872a6fc9e6be) --- source3/utils/smbcontrol.c | 111 +++++++++++++++++++++++++++++++++------------ 1 file changed, 82 insertions(+), 29 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index b31b53473c..cedb13620d 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -33,15 +33,20 @@ static struct { {NULL, -1} }; -static void usage(void) +static void usage(BOOL doexit) { int i; - printf("Usage: smbcontrol \n\n"); + if (doexit) { + printf("Usage: smbcontrol -i\n"); + printf(" smbcontrol \n\n"); + } else { + printf(" \n\n"); + } printf("\t is one of \"nmbd\", \"smbd\" or a process ID\n"); printf("\t is one of: "); for (i=0; msg_types[i].name; i++) printf("%s, ", msg_types[i].name); printf("\n"); - exit(1); + if (doexit) exit(1); } static int pong_count; @@ -94,54 +99,45 @@ static int parse_type(char *mtype) } - int main(int argc, char *argv[]) +/**************************************************************************** +do command +****************************************************************************/ +static BOOL do_command(char *dest, char *msg_name, char *params) { - char *dest; int i, n, v; - pstring servicesf = CONFIGFILE; int mtype; - TimeInit(); - setup_logging(argv[0],True); - - charset_initialise(); - lp_load(servicesf,False,False,False); - - message_init(); - - if (argc < 3) usage(); - - dest = argv[1]; - mtype = parse_type(argv[2]); + mtype = parse_type(msg_name); if (mtype == -1) { - fprintf(stderr,"Couldn't resolve message type: %s\n", argv[2]); - exit(1); + fprintf(stderr,"Couldn't resolve message type: %s\n", msg_name); + return(False); } - argc -= 2; - argv += 2; - switch (mtype) { case MSG_DEBUG: - if (argc < 2) { + if (!params) { fprintf(stderr,"MSG_DEBUG needs a parameter\n"); - exit(1); + return(False); } - v = atoi(argv[1]); + v = atoi(params); send_message(dest, MSG_DEBUG, &v, sizeof(int)); break; case MSG_FORCE_ELECTION: if (!strequal(dest, "nmbd")) { fprintf(stderr,"force-election can only be sent to nmbd\n"); - exit(1); + return(False); } send_message(dest, MSG_FORCE_ELECTION, NULL, 0); break; case MSG_PING: message_register(MSG_PONG, pong_function); - n = atoi(argv[1]); + if (!params) { + fprintf(stderr,"MSG_PING needs a parameter\n"); + return(False); + } + n = atoi(params); for (i=0;i 2 ? argv[2] : 0)); + } + + while (True) { + char *myargv[3]; + int myargc; + + printf("smbcontrol> "); + if (!gets(temp)) break; + myargc = 0; + while ((myargc < 3) && + (myargv[myargc] = strtok(myargc?NULL:temp," \t"))) { + myargc++; + } + if (!myargc) break; + if (myargc < 2) + usage(False); + else if (!do_command(myargv[0],myargv[1],myargc > 2 ? myargv[2] : 0)) + usage(False); + } + return(0); } -- cgit From 74d4a3b7410547d9f65bfc26de5f22c623574afd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 6 Oct 2000 23:01:47 +0000 Subject: Added Herb's fixes to HEAD. Jeremy. (This used to be commit 4862d2ab1163310d844b929fb17239b4f4cb1a99) --- source3/utils/smbcontrol.c | 61 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index cedb13620d..306f7ee269 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -30,6 +30,8 @@ static struct { {"debug", MSG_DEBUG}, {"force-election", MSG_FORCE_ELECTION}, {"ping", MSG_PING}, + {"profile", MSG_PROFILE}, + {"debuglevel", MSG_REQ_DEBUGLEVEL}, {NULL, -1} }; @@ -44,12 +46,17 @@ static void usage(BOOL doexit) } printf("\t is one of \"nmbd\", \"smbd\" or a process ID\n"); printf("\t is one of: "); - for (i=0; msg_types[i].name; i++) printf("%s, ", msg_types[i].name); + for (i=0; msg_types[i].name; i++) + printf("%s%s", i?", ":"",msg_types[i].name); printf("\n"); if (doexit) exit(1); } static int pong_count; +static BOOL got_level; +static BOOL pong_registered = False; +static BOOL debuglevel_registered = False; + /**************************************************************************** a useful function for testing the message system @@ -57,6 +64,19 @@ a useful function for testing the message system void pong_function(int msg_type, pid_t src, void *buf, size_t len) { pong_count++; + printf("PONG\n"); +} + +/**************************************************************************** +Prints out the current Debug level returned by MSG_DEBUGLEVEL +****************************************************************************/ +void debuglevel_function(int msg_type, pid_t src, void *buf, size_t len) +{ + int level; + memcpy(&level, buf, sizeof(int)); + + printf("Current debug level is %d\n",level); + got_level = True; } /**************************************************************************** @@ -123,6 +143,25 @@ static BOOL do_command(char *dest, char *msg_name, char *params) send_message(dest, MSG_DEBUG, &v, sizeof(int)); break; + case MSG_PROFILE: + if (!params) { + fprintf(stderr,"MSG_PROFILE needs a parameter\n"); + return(False); + } + if (strequal(params, "on")) { + v = 2; + } else if (strequal(params, "off")) { + v = 0; + } else if (strequal(params, "count")) { + v = 1; + } else { + fprintf(stderr, + "MSG_PROFILE parameter must be on, off, or count\n"); + return(False); + } + send_message(dest, MSG_PROFILE, &v, sizeof(int)); + break; + case MSG_FORCE_ELECTION: if (!strequal(dest, "nmbd")) { fprintf(stderr,"force-election can only be sent to nmbd\n"); @@ -131,13 +170,31 @@ static BOOL do_command(char *dest, char *msg_name, char *params) send_message(dest, MSG_FORCE_ELECTION, NULL, 0); break; + case MSG_REQ_DEBUGLEVEL: + if (!debuglevel_registered) { + message_register(MSG_DEBUGLEVEL, debuglevel_function); + debuglevel_registered = True; + } + if (strequal(dest, "nmbd") || strequal(dest, "smbd")) { + fprintf(stderr,"debuglevel can only be sent to a PID\n"); + return(False); + } + got_level = False; + send_message(dest, MSG_REQ_DEBUGLEVEL, NULL, 0); + while (!got_level) message_dispatch(); + break; + case MSG_PING: - message_register(MSG_PONG, pong_function); + if (!pong_registered) { + message_register(MSG_PONG, pong_function); + pong_registered = True; + } if (!params) { fprintf(stderr,"MSG_PING needs a parameter\n"); return(False); } n = atoi(params); + pong_count = 0; for (i=0;i Date: Tue, 10 Oct 2000 05:05:35 +0000 Subject: don't use gets() ! (This used to be commit e4ea0a5975d3539803c78cac2229550a6e89c4b4) --- source3/utils/smbcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 306f7ee269..62019d4036 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -248,10 +248,10 @@ static BOOL do_command(char *dest, char *msg_name, char *params) int myargc; printf("smbcontrol> "); - if (!gets(temp)) break; + if (!fgets(temp, sizeof(temp)-1, stdin)) break; myargc = 0; while ((myargc < 3) && - (myargv[myargc] = strtok(myargc?NULL:temp," \t"))) { + (myargv[myargc] = strtok(myargc?NULL:temp," \t\n"))) { myargc++; } if (!myargc) break; -- cgit From 8719c27726d3412edd0781beb956f48f76a62fb6 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 11 Oct 2000 05:31:39 +0000 Subject: changes to sync with 2.2. tree .cvsignore remove config.h - not in this directory include/profile.h profile changes lib/messages.c added message to return debug level libsmb/clierror.c cast to get rid of compiler warning libsmb/smbencrypt.c cast to get rid of compiler warning profile/profile.c add flush profile stats changes for profile struct rpc_parse/parse_samr.c fix for compiler warning rpc_server/srv_samr.c cast to get rid of compiler warning smbd/ipc.c profile stats message.c profile stats smbd/negprot.c profile stats smbd/nttrans.c profile stats smbd/trans2.c profile stats utils/smbcontrol.c new flush stats command (This used to be commit bbb24daa25dca4e4b6b1f8942cd84ee3aa1bed8e) --- source3/utils/smbcontrol.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 62019d4036..3d17ec1123 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -148,15 +148,17 @@ static BOOL do_command(char *dest, char *msg_name, char *params) fprintf(stderr,"MSG_PROFILE needs a parameter\n"); return(False); } - if (strequal(params, "on")) { - v = 2; - } else if (strequal(params, "off")) { + if (strequal(params, "off")) { v = 0; } else if (strequal(params, "count")) { v = 1; + } else if (strequal(params, "on")) { + v = 2; + } else if (strequal(params, "flush")) { + v = 3; } else { fprintf(stderr, - "MSG_PROFILE parameter must be on, off, or count\n"); + "MSG_PROFILE parameter must be off, count, on, or flush\n"); return(False); } send_message(dest, MSG_PROFILE, &v, sizeof(int)); -- cgit From 2cddf134e698e19d07b31ef68b325bc1c7070782 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 11 Oct 2000 16:24:20 +0000 Subject: Simple cleanup, but I also changed the value of the dlevel parameter passed to open_socket_in() from within the open_sockets() function. This has some effect on the way port numbers are assigned. Basically, if we use the -r switch we are saying 'use port 137'. If we can't do that, there should be an error message and a failure. If we don't use -r then we simply select the first available port. The way it was working, if we selected -r and port 137 was in use, wierd things would happen as open_socket_in() tried to find another port. (This used to be commit f09cb41ad86b233253758de7ef2781589ac07b86) --- source3/utils/nmblookup.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 15188f6768..2cdd85fae8 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -34,7 +34,7 @@ static struct in_addr bcast_addr; static BOOL recursion_desired = False; static BOOL translate_addresses = False; static int ServerFD= -1; -static int RootPort = 0; +static int RootPort = False; static BOOL find_status=False; /**************************************************************************** @@ -43,14 +43,14 @@ static BOOL find_status=False; static BOOL open_sockets(void) { ServerFD = open_socket_in( SOCK_DGRAM, - (RootPort ? 137 :0), - 3, + (RootPort ? 137 : 0), + (RootPort ? 0 : 3), interpret_addr(lp_socket_address()), True ); if (ServerFD == -1) return(False); - set_socket_options(ServerFD,"SO_BROADCAST"); + set_socket_options( ServerFD, "SO_BROADCAST" ); DEBUG(3, ("Socket opened.\n")); return True; @@ -200,7 +200,7 @@ int main(int argc,char *argv[]) pstrcpy(servicesf, optarg); break; case 'r': - RootPort = -1; + RootPort = True; break; case 'h': usage(); -- cgit From ca4acd520e01a568266f13e3c4ce77ce2ed8d77e Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Thu, 12 Oct 2000 00:29:01 +0000 Subject: print source PID in PONG and debuglevel message. Allow request debuglevel message to go to any dest. Put timeout for commands that expect a reply. sync with 2.2 branch (This used to be commit 45632bb813da06d0139aa32b9ab99d472dcfaf25) --- source3/utils/smbcontrol.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 3d17ec1123..dff0dd3300 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -35,6 +35,10 @@ static struct { {NULL, -1} }; +time_t timeout_start; + +#define MAX_WAIT 10 + static void usage(BOOL doexit) { int i; @@ -64,7 +68,7 @@ a useful function for testing the message system void pong_function(int msg_type, pid_t src, void *buf, size_t len) { pong_count++; - printf("PONG\n"); + printf("PONG from PID %d\n",src); } /**************************************************************************** @@ -75,7 +79,7 @@ void debuglevel_function(int msg_type, pid_t src, void *buf, size_t len) int level; memcpy(&level, buf, sizeof(int)); - printf("Current debug level is %d\n",level); + printf("Current debug level of PID %d is %d\n",src,level); got_level = True; } @@ -126,6 +130,7 @@ static BOOL do_command(char *dest, char *msg_name, char *params) { int i, n, v; int mtype; + BOOL retval; mtype = parse_type(msg_name); if (mtype == -1) { @@ -177,13 +182,18 @@ static BOOL do_command(char *dest, char *msg_name, char *params) message_register(MSG_DEBUGLEVEL, debuglevel_function); debuglevel_registered = True; } - if (strequal(dest, "nmbd") || strequal(dest, "smbd")) { - fprintf(stderr,"debuglevel can only be sent to a PID\n"); - return(False); - } got_level = False; - send_message(dest, MSG_REQ_DEBUGLEVEL, NULL, 0); - while (!got_level) message_dispatch(); + retval = send_message(dest, MSG_REQ_DEBUGLEVEL, NULL, 0); + if (retval) { + timeout_start = time(NULL); + while (!got_level) { + message_dispatch(); + if ((time(NULL) - timeout_start) > MAX_WAIT) { + fprintf(stderr,"debuglevel timeout\n"); + break; + } + } + } break; case MSG_PING: @@ -198,9 +208,19 @@ static BOOL do_command(char *dest, char *msg_name, char *params) n = atoi(params); pong_count = 0; for (i=0;i MAX_WAIT) { + fprintf(stderr,"PING timeout\n"); + break; + } + } } - while (pong_count < n) message_dispatch(); break; } -- cgit From 53ce2f7012d55e200082fa7bc04b27d9dcfcf706 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Thu, 12 Oct 2000 17:58:40 +0000 Subject: lib/messages.c add debug print for receipt of PING and REQ_DEBUGLEVEL messages utils/smbcontrol.c allow "q" to exit interactive mode. Exit on error from message_init. (This used to be commit cda8c0439113dcce02a681b0aaddf69326c0ec9a) --- source3/utils/smbcontrol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index dff0dd3300..57f6149bcd 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -242,7 +242,7 @@ static BOOL do_command(char *dest, char *msg_name, char *params) charset_initialise(); lp_load(servicesf,False,False,False); - message_init(); + if (!message_init()) exit(1); if (argc < 2) usage(True); @@ -277,6 +277,7 @@ static BOOL do_command(char *dest, char *msg_name, char *params) myargc++; } if (!myargc) break; + if (strequal(myargv[0],"q")) break; if (myargc < 2) usage(False); else if (!do_command(myargv[0],myargv[1],myargc > 2 ? myargv[2] : 0)) -- cgit From c97023b14c942f7261808159a0d192926239b704 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 10 Nov 2000 22:07:57 +0000 Subject: Merge in Herb's changes from 2.2. Jeremy. (This used to be commit 24d76c5fbda29d89c96d7c22193ec2eb93ad3887) --- source3/utils/smbcontrol.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 57f6149bcd..c059ccb6ec 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -19,8 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" static struct { @@ -32,6 +30,7 @@ static struct { {"ping", MSG_PING}, {"profile", MSG_PROFILE}, {"debuglevel", MSG_REQ_DEBUGLEVEL}, + {"printer-notify", MSG_PRINTER_NOTIFY}, {NULL, -1} }; @@ -196,6 +195,19 @@ static BOOL do_command(char *dest, char *msg_name, char *params) } break; + case MSG_PRINTER_NOTIFY: + if (!strequal(dest, "smbd")) { + fprintf(stderr,"printer-notify can only be sent to smbd\n"); + return(False); + } + if (!params) { + fprintf(stderr, "printer-notify needs a printer name\n"); + return (False); + } + retval = send_message(dest, MSG_PRINTER_NOTIFY, params, + strlen(params) + 1); + break; + case MSG_PING: if (!pong_registered) { message_register(MSG_PONG, pong_function); -- cgit From 20838bb9ed25d7a325831041f371c11731ff6283 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 11 Nov 2000 00:33:33 +0000 Subject: Merge of Herb's profiling code. Jeremy. (This used to be commit 3be056c71aa8e0a4ba70d397107199004bdb7d3f) --- source3/utils/smbcontrol.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index c059ccb6ec..a273f82151 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -29,6 +29,7 @@ static struct { {"force-election", MSG_FORCE_ELECTION}, {"ping", MSG_PING}, {"profile", MSG_PROFILE}, + {"profilelevel", MSG_REQ_PROFILELEVEL}, {"debuglevel", MSG_REQ_DEBUGLEVEL}, {"printer-notify", MSG_PRINTER_NOTIFY}, {NULL, -1} @@ -59,6 +60,7 @@ static int pong_count; static BOOL got_level; static BOOL pong_registered = False; static BOOL debuglevel_registered = False; +static BOOL profilelevel_registered = False; /**************************************************************************** @@ -82,6 +84,34 @@ void debuglevel_function(int msg_type, pid_t src, void *buf, size_t len) got_level = True; } +/**************************************************************************** +Prints out the current Profile level returned by MSG_PROFILELEVEL +****************************************************************************/ +void profilelevel_function(int msg_type, pid_t src, void *buf, size_t len) +{ + int level; + char *s; + memcpy(&level, buf, sizeof(int)); + + if (level) { + switch (level) { + case 1: + s = "off"; + break; + case 3: + s = "count only"; + break; + case 7: + s = "count and time"; + break; + } + printf("Profiling %s on PID %d\n",s,src); + } else { + printf("Profiling not available on PID %d\n",src); + } + got_level = True; +} + /**************************************************************************** send a message to a named destination ****************************************************************************/ @@ -176,6 +206,25 @@ static BOOL do_command(char *dest, char *msg_name, char *params) send_message(dest, MSG_FORCE_ELECTION, NULL, 0); break; + case MSG_REQ_PROFILELEVEL: + if (!profilelevel_registered) { + message_register(MSG_PROFILELEVEL, profilelevel_function); + profilelevel_registered = True; + } + got_level = False; + retval = send_message(dest, MSG_REQ_PROFILELEVEL, NULL, 0); + if (retval) { + timeout_start = time(NULL); + while (!got_level) { + message_dispatch(); + if ((time(NULL) - timeout_start) > MAX_WAIT) { + fprintf(stderr,"profilelevel timeout\n"); + break; + } + } + } + break; + case MSG_REQ_DEBUGLEVEL: if (!debuglevel_registered) { message_register(MSG_DEBUGLEVEL, debuglevel_function); -- cgit From 9fede0dc0dbad51528cd1384023d24549c3f0ba4 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 13 Nov 2000 23:03:34 +0000 Subject: Large commit which restructures the local password storage API. Currently the only backend which works is smbpasswd (tdb, LDAP, and NIS+) are broken, but they were somewhat broken before. :) The following functions implement the storage manipulation interface /*The following definitions come from passdb/pdb_smbpasswd.c */ BOOL pdb_setsampwent (BOOL update); void pdb_endsampwent (void); SAM_ACCOUNT* pdb_getsampwent (void); SAM_ACCOUNT* pdb_getsampwnam (char *username); SAM_ACCOUNT* pdb_getsampwuid (uid_t uid); SAM_ACCOUNT* pdb_getsampwrid (uint32 rid); BOOL pdb_add_sam_account (SAM_ACCOUNT *sampass); BOOL pdb_update_sam_account (SAM_ACCOUNT *sampass, BOOL override); BOOL pdb_delete_sam_account (char* username); There is also a host of pdb_set..() and pdb_get..() functions for manipulating SAM_ACCOUNT struct members. Note that the struct passdb_ops {} has gone away. Also notice that struct smb_passwd (formally in smb.h) has been moved to passdb/pdb_smbpasswd.c and is not accessed outisde of static internal functions in this file. All local password searches should make use of the the SAM_ACCOUNT struct and the previously mentioned functions. I'll write some documentation for this later. The next step is to fix the TDB passdb backend, then work on spliting the backends out into share libraries, and finally get the LDAP backend going. What works and may not: o domain logons from Win9x works o domain logons from WinNT 4 works o user and group enumeration as implemented by Tim works o file and print access works o changing password from Win9x & NT ummm...i'll fix this tonight :) If I broke anything else, just yell and I'll fix it. I think it should be fairly quite. -- jerry (This used to be commit 0b92d0838ebdbe24f34f17e313ecbf61a0301389) --- source3/utils/smbpasswd.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index d9fa46fe4c..d6a0c3dba8 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -221,12 +221,13 @@ static BOOL password_change(const char *remote_machine, char *user_name, if (remote_machine != NULL) { if (local_flags & (LOCAL_ADD_USER|LOCAL_DELETE_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER| - LOCAL_TRUST_ACCOUNT|LOCAL_SET_NO_PASSWORD)) { + LOCAL_TRUST_ACCOUNT|LOCAL_SET_NO_PASSWORD)) + { /* these things can't be done remotely yet */ return False; } - ret = remote_password_change(remote_machine, user_name, - old_passwd, new_passwd, err_str, sizeof(err_str)); + ret = remote_password_change(remote_machine, user_name, old_passwd, + new_passwd, err_str, sizeof(err_str)); if(*err_str) fprintf(stderr, err_str); return ret; @@ -402,9 +403,11 @@ static int process_root(int argc, char *argv[]) * smbpasswd file) then we need to prompt for a new password. */ - if(local_flags & LOCAL_ENABLE_USER) { - struct smb_passwd *smb_pass = getsmbpwnam(user_name); - if((smb_pass != NULL) && (smb_pass->smb_passwd != NULL)) { + if(local_flags & LOCAL_ENABLE_USER) + { + SAM_ACCOUNT *sampass = pdb_getsampwnam(user_name); + if((sampass != NULL) && (pdb_get_lanman_passwd(sampass) != NULL)) + { new_passwd = xstrdup("XXXX"); /* Don't care. */ } } @@ -418,18 +421,20 @@ static int process_root(int argc, char *argv[]) } } - if (!password_change(remote_machine, user_name, old_passwd, new_passwd, local_flags)) { + if (!password_change(remote_machine, user_name, old_passwd, new_passwd, local_flags)) + { fprintf(stderr,"Failed to modify password entry for user %s\n", user_name); result = 1; goto done; } - if(!(local_flags & (LOCAL_ADD_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER|LOCAL_DELETE_USER|LOCAL_SET_NO_PASSWORD))) { - struct smb_passwd *smb_pass = getsmbpwnam(user_name); + if(!(local_flags & (LOCAL_ADD_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER|LOCAL_DELETE_USER|LOCAL_SET_NO_PASSWORD))) + { + SAM_ACCOUNT *sampass = pdb_getsampwnam(user_name); printf("Password changed for user %s.", user_name ); - if((smb_pass != NULL) && (smb_pass->acct_ctrl & ACB_DISABLED )) + if( (sampass != NULL) && (pdb_get_acct_ctrl(sampass)&ACB_DISABLED) ) printf(" User has disabled flag set."); - if((smb_pass != NULL) && (smb_pass->acct_ctrl & ACB_PWNOTREQ)) + if((sampass != NULL) && (pdb_get_acct_ctrl(sampass) & ACB_PWNOTREQ) ) printf(" User has no password flag set."); printf("\n"); } @@ -554,7 +559,7 @@ int main(int argc, char **argv) charset_initialise(); - if(!initialize_password_db()) { + if(!initialize_password_db(True)) { fprintf(stderr, "Can't setup password database vectors.\n"); exit(1); } -- cgit From 6f58dd587124c8b85fc62177b26129aaea5819b0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 16 Nov 2000 00:59:18 +0000 Subject: Ok - fixed a bug in our levelII oplock code. We need to break a level II on a byte range lock (write lock only, but Win2k breaks on read lock also so I do the same) - if you think about why, this is obvious. Also fixed our client code to do level II oplocks, if requested, and fixed the code where we would assume the client wanted level II if it advertised itself as being level II capable - it may not want that. Jeremy. (This used to be commit 213cd0b5192307cd4b0026cae94b2f52fb1b0c02) --- source3/utils/torture.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 120 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 4267aab118..d9aa6bfca0 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -33,6 +33,7 @@ static int procnum; /* records process count number when forking */ static struct cli_state current_cli; static fstring randomfname; static BOOL use_oplocks; +static BOOL use_level_II_oplocks; static double create_procs(void (*fn)(int)); @@ -109,6 +110,7 @@ static BOOL open_nbt_connection(struct cli_state *c) c->timeout = 120000; /* set a really long timeout (2 minutes) */ if (use_oplocks) c->use_oplocks = True; + if (use_level_II_oplocks) c->use_level_II_oplocks = True; if (!cli_session_request(c, &calling, &called)) { printf("%s rejected the session\n",host); @@ -1885,13 +1887,13 @@ static void run_trans2test(int dummy) /* this is a harness for some oplock tests */ -static void run_oplock(int dummy) +static void run_oplock1(int dummy) { static struct cli_state cli1; char *fname = "\\lockt1.lck"; int fnum1; - printf("starting oplock test\n"); + printf("starting oplock test 1\n"); if (!open_connection(&cli1)) { return; @@ -1927,7 +1929,120 @@ static void run_oplock(int dummy) close_connection(&cli1); - printf("finished oplock test\n"); + printf("finished oplock test 1\n"); +} + +static void run_oplock2(int dummy) +{ + static struct cli_state cli1, cli2; + char *fname = "\\lockt2.lck"; + int fnum1, fnum2; + int saved_use_oplocks = use_oplocks; + char buf[4]; + + use_level_II_oplocks = True; + use_oplocks = True; + + printf("starting oplock test 2\n"); + + if (!open_connection(&cli1)) { + use_level_II_oplocks = False; + use_oplocks = saved_use_oplocks; + return; + } + + cli1.use_oplocks = True; + cli1.use_level_II_oplocks = True; + + if (!open_connection(&cli2)) { + use_level_II_oplocks = False; + use_oplocks = saved_use_oplocks; + return; + } + + cli2.use_oplocks = True; + cli2.use_level_II_oplocks = True; + + cli_unlink(&cli1, fname); + + cli_sockopt(&cli1, sockops); + cli_sockopt(&cli2, sockops); + + fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + /* Don't need the globals any more. */ + use_level_II_oplocks = False; + use_oplocks = saved_use_oplocks; + + if (fork() == 0) { + /* Child code */ + fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + printf("second open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + exit(0); + } + + sleep(2); + + if (!cli_close(&cli2, fnum2)) { + printf("close2 failed (%s)\n", cli_errstr(&cli1)); + } + + exit(0); + } + + sleep(2); + + /* Ensure cli1 processes the break. */ + + if (cli_read(&cli1, fnum1, buf, 0, 4) != 4) { + printf("read on fnum1 failed (%s)\n", cli_errstr(&cli1)); + } + + /* Should now be at level II. */ + /* Test if sending a write locks causes a break to none. */ + + if (!cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK)) { + printf("lock failed (%s)\n", cli_errstr(&cli1)); + } + + cli_unlock(&cli, fnum1, 0, 4); + + sleep(2); + + if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) { + printf("lock failed (%s)\n", cli_errstr(&cli1)); + } + + cli_unlock(&cli, fnum1, 0, 4); + + sleep(2); + + cli_read(&cli1, fnum1, buf, 0, 4); + +#if 0 + if (cli_write(&cli1, fnum1, 0, buf, 0, 4) != 4) { + printf("write on fnum1 failed (%s)\n", cli_errstr(&cli1)); + } +#endif + + if (!cli_close(&cli1, fnum1)) { + printf("close1 failed (%s)\n", cli_errstr(&cli1)); + } + + sleep(4); + + if (!cli_unlink(&cli1, fname)) { + printf("unlink failed (%s)\n", cli_errstr(&cli1)); + } + + close_connection(&cli1); + + printf("finished oplock test 2\n"); } @@ -2089,7 +2204,8 @@ static struct { {"NEGNOWAIT", run_negprot_nowait, 0}, {"NBW95", run_nbw95, 0}, {"NBWNT", run_nbwnt, 0}, - {"OPLOCK", run_oplock, 0}, + {"OPLOCK1", run_oplock1, 0}, + {"OPLOCK2", run_oplock2, 0}, {"DIR", run_dirtest, 0}, {"DENY1", run_denytest1, 0}, {"DENY2", run_denytest2, 0}, -- cgit From cdac09614ef426092ed1b1de480fe90c3c4cdd83 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 16 Nov 2000 21:38:24 +0000 Subject: Fix for a problem with the new messaging system. If a sender is using the messaging system as a notification mechanism, and the speed of notification greatly exceeds the speed of message recovery, then you get a massively (>75Mb) growing tdb. If the message is a simple notification, then the message is static, and you only need one of them in transit to a target process at any one time. This patch adds a BOOL "allow_duplicates" to the message_send_XX primitives. If set to False, then before sending a message the sender checks the existing message queue for a target pid for a duplicate of this message, and doesn't add to it if one already exists. Also added code into msgtest.c to test this. Jeremy. (This used to be commit 3aa7995660395ecb85c8e35b638fa9fbbb952558) --- source3/utils/msgtest.c | 29 +++++++++++++++++++++++++++-- source3/utils/smbcontrol.c | 20 ++++++++++---------- 2 files changed, 37 insertions(+), 12 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/msgtest.c b/source3/utils/msgtest.c index 858166e697..3fbf95af8f 100644 --- a/source3/utils/msgtest.c +++ b/source3/utils/msgtest.c @@ -36,12 +36,12 @@ void pong_message(int msg_type, pid_t src, void *buf, size_t len) pong_count++; } - int main(int argc, char *argv[]) { pid_t pid; int i, n; static pstring servicesf = CONFIGFILE; + char buf[12]; TimeInit(); setup_logging(argv[0],True); @@ -52,13 +52,18 @@ void pong_message(int msg_type, pid_t src, void *buf, size_t len) message_init(); + if (argc != 3) { + fprintf(stderr, "%s: Usage - %s pid count\n", argv[0], argv[0]); + exit(1); + } + pid = atoi(argv[1]); n = atoi(argv[2]); message_register(MSG_PONG, pong_message); for (i=0;i Date: Fri, 17 Nov 2000 01:20:03 +0000 Subject: support smbcontrol sending messages to itself (for testing purposes) (This used to be commit 5dfae86dab50fba1890d0ce33fa9d68f12bc0bfa) --- source3/utils/smbcontrol.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 815f9fddff..991d1d77d2 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -128,6 +128,8 @@ static BOOL send_message(char *dest, int msg_type, void *buf, int len, BOOL dupl fprintf(stderr,"Can't find pid for nmbd\n"); return False; } + } else if (strequal(dest,"self")) { + pid = getpid(); } else { pid = atoi(dest); if (pid == 0) { -- cgit From 83bd9298836dda6dd237a94ca5d0f748568e7882 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 3 Dec 2000 02:19:27 +0000 Subject: a prootype program for querying/setting a security decsriptor on a remote machine it is by no means complete, expect more commits soon (This used to be commit f2f9859b700085cce0ed0c12d8780ad554255ea4) --- source3/utils/smbcacls.c | 233 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 233 insertions(+) create mode 100644 source3/utils/smbcacls.c (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c new file mode 100644 index 0000000000..46fecd681c --- /dev/null +++ b/source3/utils/smbcacls.c @@ -0,0 +1,233 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + + Copyright (C) Andrew Tridgell 2000 + + 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" + +static fstring password; +static fstring username; +static int got_pass; + + + + +/***************************************************** +dump the acls for a file +*******************************************************/ +static void cacl_dump(struct cli_state *cli, char *filename) +{ + int fnum; + + fnum = cli_open(cli, filename, O_RDONLY, 0); + if (fnum == -1) { + printf("Failed to open %s\n", filename); + return; + } + + cli_query_secdesc(cli, fnum); + + sleep(1); + + cli_close(cli, fnum); +} + + +/***************************************************** +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; + fstring server; + struct in_addr ip; + extern struct in_addr ipzero; + extern pstring global_myname; + + fstrcpy(server,share+2); + share = strchr(server,'\\'); + if (!share) return NULL; + *share = 0; + share++; + + server_n = server; + + ip = ipzero; + + make_nmb_name(&calling, global_myname, 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), + lp_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 void usage(void) +{ + printf( +"Usage:\n\ + smbcacls //server1/share1 filename\n\n"); +} + +/**************************************************************************** + main program +****************************************************************************/ + int main(int argc,char *argv[]) +{ + char *share; + char *filename; + extern char *optarg; + extern int optind; + extern FILE *dbf; + int opt; + char *p; + int seed; + static pstring servicesf = CONFIGFILE; + struct cli_state *cli; + + setlinebuf(stdout); + + dbf = stderr; + + if (argc < 4 || argv[1][0] == '-') { + usage(); + exit(1); + } + + setup_logging(argv[0],True); + + share = argv[1]; + filename = argv[2]; + all_string_sub(share,"/","\\",0); + + argc -= 2; + argv += 2; + + TimeInit(); + charset_initialise(); + + lp_load(servicesf,True,False,False); + codepage_initialise(lp_client_code_page()); + load_interfaces(); + + if (getenv("USER")) { + pstrcpy(username,getenv("USER")); + } + + seed = time(NULL); + + while ((opt = getopt(argc, argv, "U:h")) != EOF) { + switch (opt) { + case 'U': + pstrcpy(username,optarg); + p = strchr(username,'%'); + if (p) { + *p = 0; + pstrcpy(password, p+1); + got_pass = 1; + } + break; + case 'h': + usage(); + exit(1); + default: + printf("Unknown option %c (%d)\n", (char)opt, opt); + exit(1); + } + } + + argc -= optind; + argv += optind; + + cli = connect_one(share); + if (!cli) exit(1); + + cacl_dump(cli, filename); + + return(0); +} -- cgit From c93f686f0106383cbc519eb9e1f4a781f445849e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 3 Dec 2000 05:24:16 +0000 Subject: added basic ability to dump remote file acls (This used to be commit c6c90dc8e163d874748e2020cc140134cffcfe32) --- source3/utils/smbcacls.c | 58 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 6 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 46fecd681c..52d02fed28 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -28,6 +28,48 @@ static fstring username; static int got_pass; +/* print a ascii version of a security descriptor on a FILE handle */ +static void sec_desc_print(FILE *f, SEC_DESC *sd) +{ + fstring sidstr; + int i; + + /* Print owner and group sid */ + + if (sd->owner_sid) { + sid_to_string(sidstr, sd->owner_sid); + } else { + fstrcpy(sidstr, ""); + } + + printf("%s\n", sidstr); + + if (sd->grp_sid) { + sid_to_string(sidstr, sd->grp_sid); + } else { + fstrcpy(sidstr, ""); + } + + fprintf(f, "%s\n", sidstr); + + /* Print aces */ + + if (!sd->dacl) { + return; + } + + for (i = 0; i < sd->dacl->num_aces; i++) { + SEC_ACE *ace = &sd->dacl->ace[i]; + fstring sidstr; + + sid_to_string(sidstr, &ace->sid); + + fprintf(f, "%d %d 0x%08x %s\n", ace->type, ace->flags, + ace->info.mask, sidstr); + } +} + + /***************************************************** @@ -36,6 +78,7 @@ dump the acls for a file static void cacl_dump(struct cli_state *cli, char *filename) { int fnum; + SEC_DESC *sd; fnum = cli_open(cli, filename, O_RDONLY, 0); if (fnum == -1) { @@ -43,9 +86,16 @@ static void cacl_dump(struct cli_state *cli, char *filename) return; } - cli_query_secdesc(cli, fnum); + sd = cli_query_secdesc(cli, fnum); + + if (!sd) { + printf("ERROR: secdesc query failed\n"); + return; + } + + sec_desc_print(stdout, sd); - sleep(1); + free_sec_desc(&sd); cli_close(cli, fnum); } @@ -127,10 +177,6 @@ struct cli_state *connect_one(char *share) * 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")); -- cgit From 4fee254d678033dffa6d0ed82e55ec59d65fcd03 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 3 Dec 2000 07:36:15 +0000 Subject: getting/setting acls now works. The SIDs are still numeric, the next step is to support usernames etc (This used to be commit 6cea1647fcbc6f5a903c691273dcec44fcda1fc4) --- source3/utils/smbcacls.c | 164 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 155 insertions(+), 9 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 52d02fed28..414c8c78fd 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -34,6 +34,8 @@ static void sec_desc_print(FILE *f, SEC_DESC *sd) fstring sidstr; int i; + printf("REVISION:%x TYPE:%x\n", sd->revision, sd->type); + /* Print owner and group sid */ if (sd->owner_sid) { @@ -42,7 +44,7 @@ static void sec_desc_print(FILE *f, SEC_DESC *sd) fstrcpy(sidstr, ""); } - printf("%s\n", sidstr); + printf("OWNER:%s\n", sidstr); if (sd->grp_sid) { sid_to_string(sidstr, sd->grp_sid); @@ -50,26 +52,130 @@ static void sec_desc_print(FILE *f, SEC_DESC *sd) fstrcpy(sidstr, ""); } - fprintf(f, "%s\n", sidstr); + fprintf(f, "GROUP:%s\n", sidstr); /* Print aces */ + for (i = 0; sd->dacl && i < sd->dacl->num_aces; i++) { + SEC_ACE *ace = &sd->dacl->ace[i]; + fstring sidstr; - if (!sd->dacl) { - return; + sid_to_string(sidstr, &ace->sid); + + fprintf(f, "DACL:%x:%x:%08x:%s\n", ace->type, ace->flags, + ace->info.mask, sidstr); } - for (i = 0; i < sd->dacl->num_aces; i++) { - SEC_ACE *ace = &sd->dacl->ace[i]; + for (i = 0; sd->sacl && i < sd->sacl->num_aces; i++) { + SEC_ACE *ace = &sd->sacl->ace[i]; fstring sidstr; sid_to_string(sidstr, &ace->sid); - fprintf(f, "%d %d 0x%08x %s\n", ace->type, ace->flags, + fprintf(f, "SACL:%x:%x:%08x:%s\n", ace->type, ace->flags, ace->info.mask, sidstr); } } +/* add an ACE to a list of ACEs in a SEC_ACL */ +static BOOL add_acl(SEC_ACL **acl, SEC_ACE *ace) +{ + if (! *acl) { + *acl = (SEC_ACL *)calloc(1, sizeof(*acl)); + if (! *acl) return False; + (*acl)->revision = 3; + } + + (*acl)->ace = Realloc((*acl)->ace,(1+((*acl)->num_aces))*sizeof(SEC_ACE)); + if (!(*acl)->ace) return False; + memcpy(&((*acl)->ace[(*acl)->num_aces]), ace, sizeof(SEC_ACE)); + (*acl)->num_aces++; + return True; +} + +/* parse a ascii version of a security descriptor */ +static SEC_DESC *sec_desc_parse(char *str) +{ + char *p = str; + fstring tok; + SEC_DESC *sd, *ret; + int sd_size; + + sd = (SEC_DESC *)calloc(1, sizeof(SEC_DESC)); + if (!sd) return NULL; + + while (next_token(&p, tok, " \t,\r\n", sizeof(tok))) { + + if (strncmp(tok,"REVISION:", 9) == 0) { + sd->revision = strtol(tok+9, NULL, 16); + } + + if (strncmp(tok,"TYPE:", 5) == 0) { + sd->type = strtol(tok+5, NULL, 16); + } + + if (strncmp(tok,"OWNER:", 6) == 0) { + sd->owner_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID)); + if (!sd->owner_sid || + !string_to_sid(sd->owner_sid, tok+6)) { + printf("Failed to parse owner sid\n"); + return NULL; + } + } + + if (strncmp(tok,"GROUP:", 6) == 0) { + sd->grp_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID)); + if (!sd->grp_sid || + !string_to_sid(sd->grp_sid, tok+6)) { + printf("Failed to parse group sid\n"); + return NULL; + } + } + + if (strncmp(tok,"DACL:", 5) == 0) { + fstring s; + unsigned atype, aflags, amask; + SEC_ACE ace; + ZERO_STRUCT(ace); + if (sscanf(tok+5, "%x:%x:%08x:%s", + &atype, &aflags, &amask,s) != 4 || + !string_to_sid(&ace.sid, s)) { + printf("Failed to parse DACL\n"); + return NULL; + } + ace.type = atype; + ace.flags = aflags; + ace.info.mask = amask; + add_acl(&sd->dacl, &ace); + } + + if (strncmp(tok,"SACL:", 5) == 0) { + fstring s; + unsigned atype, aflags, amask; + SEC_ACE ace; + ZERO_STRUCT(ace); + if (sscanf(tok+5, "%x:%x:%08x:%s", + &atype, &aflags, &amask,s) != 4 || + !string_to_sid(&ace.sid, s)) { + printf("Failed to parse SACL\n"); + return NULL; + } + ace.type = atype; + ace.flags = aflags; + ace.info.mask = amask; + add_acl(&sd->sacl, &ace); + } + } + + ret = make_sec_desc(sd->revision, sd->type, sd->owner_sid, sd->grp_sid, + sd->sacl, sd->dacl, &sd_size); + + free_sec_desc(&sd); + + return ret; +} + + /***************************************************** @@ -100,6 +206,38 @@ static void cacl_dump(struct cli_state *cli, char *filename) cli_close(cli, fnum); } +/***************************************************** +set the ACLs on a file given an ascii description +*******************************************************/ +static void cacl_set(struct cli_state *cli, char *filename, char *set_acl) +{ + int fnum; + SEC_DESC *sd; + + sd = sec_desc_parse(set_acl); + if (!sd) { + printf("Failed to parse security descriptor\n"); + return; + } + + fnum = cli_open(cli, filename, O_RDONLY, 0); + if (fnum == -1) { + printf("Failed to open %s\n", filename); + return; + } + + /* sec_desc_print(stdout, sd); */ + + if (!cli_set_secdesc(cli, fnum, sd)) { + printf("ERROR: secdesc set failed\n"); + return; + } + + free_sec_desc(&sd); + + cli_close(cli, fnum); +} + /***************************************************** return a connection to a server @@ -215,6 +353,7 @@ static void usage(void) int seed; static pstring servicesf = CONFIGFILE; struct cli_state *cli; + char *set_acl = NULL; setlinebuf(stdout); @@ -247,7 +386,7 @@ static void usage(void) seed = time(NULL); - while ((opt = getopt(argc, argv, "U:h")) != EOF) { + while ((opt = getopt(argc, argv, "U:hs:")) != EOF) { switch (opt) { case 'U': pstrcpy(username,optarg); @@ -258,6 +397,9 @@ static void usage(void) got_pass = 1; } break; + case 's': + set_acl = optarg; + break; case 'h': usage(); exit(1); @@ -273,7 +415,11 @@ static void usage(void) cli = connect_one(share); if (!cli) exit(1); - cacl_dump(cli, filename); + if (set_acl) { + cacl_set(cli, filename, set_acl); + } else { + cacl_dump(cli, filename); + } return(0); } -- cgit From 3b22b74f9d68f275ace669712078a14530137f07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 3 Dec 2000 08:35:11 +0000 Subject: - better parsing - started to add non-numeric support (This used to be commit fd4c03aef692cd8ef9a29b60a4d66fe898430317) --- source3/utils/smbcacls.c | 187 +++++++++++++++++++++++++++++++---------------- 1 file changed, 123 insertions(+), 64 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 414c8c78fd..7f0ffcdcbb 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -27,58 +27,91 @@ static fstring password; static fstring username; static int got_pass; +/* numeric is set when the user wants numeric SIDs and ACEs rather + than going via LSA calls to resolve them */ +static int numeric; -/* print a ascii version of a security descriptor on a FILE handle */ -static void sec_desc_print(FILE *f, SEC_DESC *sd) +/* convert a SID to a string, either numeric or username/group */ +static void SidToString(fstring str, DOM_SID *sid) { - fstring sidstr; - int i; - - printf("REVISION:%x TYPE:%x\n", sd->revision, sd->type); - - /* Print owner and group sid */ - - if (sd->owner_sid) { - sid_to_string(sidstr, sd->owner_sid); + if (numeric) { + sid_to_string(str, sid); } else { - fstrcpy(sidstr, ""); + printf("need to add LSA lookups\n"); + sid_to_string(str, sid); } +} - printf("OWNER:%s\n", sidstr); - - if (sd->grp_sid) { - sid_to_string(sidstr, sd->grp_sid); +/* convert a string to a SID, either numeric or username/group */ +static BOOL StringToSid(DOM_SID *sid, fstring str) +{ + if (strncmp(str,"S-", 2) == 0) { + return string_to_sid(sid, str); } else { - fstrcpy(sidstr, ""); + printf("need to add LSA lookups\n"); + return False; } +} - fprintf(f, "GROUP:%s\n", sidstr); - /* Print aces */ - for (i = 0; sd->dacl && i < sd->dacl->num_aces; i++) { - SEC_ACE *ace = &sd->dacl->ace[i]; - fstring sidstr; +/* print an ACE on a FILE, using either numeric or ascii representation */ +static void print_ace(FILE *f, SEC_ACE *ace) +{ + fstring sidstr; + char *perm; - sid_to_string(sidstr, &ace->sid); + SidToString(sidstr, &ace->sid); - fprintf(f, "DACL:%x:%x:%08x:%s\n", ace->type, ace->flags, - ace->info.mask, sidstr); + fprintf(f, "%s:", sidstr); + + if (numeric) { + fprintf(f, "%x/%x/%08x\n", + ace->type, ace->flags, ace->info.mask); + return; } - for (i = 0; sd->sacl && i < sd->sacl->num_aces; i++) { - SEC_ACE *ace = &sd->sacl->ace[i]; - fstring sidstr; + /* this interpretation is almost certainly wrong, Tim, please + have a look at these */ + if (ace->info.mask == 0x001f01ff) { + perm = "F"; + } else if (ace->info.mask == 0x001301bf) { + perm = "C"; + } else if (ace->info.mask == 0x001200a9) { + perm = "R"; + } else if (ace->info.mask == 0x00000000) { + perm = "N"; + } else { + perm = "?"; + } - sid_to_string(sidstr, &ace->sid); + fprintf(f,"%s\n", perm); +} - fprintf(f, "SACL:%x:%x:%08x:%s\n", ace->type, ace->flags, - ace->info.mask, sidstr); + +/* parse an ACE in the same format as print_ace() */ +static BOOL parse_ace(SEC_ACE *ace, char *str) +{ + char *p; + unsigned atype, aflags, amask; + ZERO_STRUCTP(ace); + p = strchr(str,':'); + if (!p) return False; + *p = 0; + if (sscanf(p+1, "%x/%x/%08x", + &atype, &aflags, &amask) != 3 || + !StringToSid(&ace->sid, str)) { + return False; } + ace->type = atype; + ace->flags = aflags; + ace->info.mask = amask; + return True; } + /* add an ACE to a list of ACEs in a SEC_ACL */ -static BOOL add_acl(SEC_ACL **acl, SEC_ACE *ace) +static BOOL add_ace(SEC_ACL **acl, SEC_ACE *ace) { if (! *acl) { *acl = (SEC_ACL *)calloc(1, sizeof(*acl)); @@ -117,7 +150,7 @@ static SEC_DESC *sec_desc_parse(char *str) if (strncmp(tok,"OWNER:", 6) == 0) { sd->owner_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID)); if (!sd->owner_sid || - !string_to_sid(sd->owner_sid, tok+6)) { + !StringToSid(sd->owner_sid, tok+6)) { printf("Failed to parse owner sid\n"); return NULL; } @@ -126,44 +159,28 @@ static SEC_DESC *sec_desc_parse(char *str) if (strncmp(tok,"GROUP:", 6) == 0) { sd->grp_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID)); if (!sd->grp_sid || - !string_to_sid(sd->grp_sid, tok+6)) { + !StringToSid(sd->grp_sid, tok+6)) { printf("Failed to parse group sid\n"); return NULL; } } if (strncmp(tok,"DACL:", 5) == 0) { - fstring s; - unsigned atype, aflags, amask; SEC_ACE ace; - ZERO_STRUCT(ace); - if (sscanf(tok+5, "%x:%x:%08x:%s", - &atype, &aflags, &amask,s) != 4 || - !string_to_sid(&ace.sid, s)) { + if (!parse_ace(&ace, tok+5) || + !add_ace(&sd->dacl, &ace)) { printf("Failed to parse DACL\n"); return NULL; } - ace.type = atype; - ace.flags = aflags; - ace.info.mask = amask; - add_acl(&sd->dacl, &ace); } if (strncmp(tok,"SACL:", 5) == 0) { - fstring s; - unsigned atype, aflags, amask; SEC_ACE ace; - ZERO_STRUCT(ace); - if (sscanf(tok+5, "%x:%x:%08x:%s", - &atype, &aflags, &amask,s) != 4 || - !string_to_sid(&ace.sid, s)) { + if (!parse_ace(&ace, tok+5) || + !add_ace(&sd->sacl, &ace)) { printf("Failed to parse SACL\n"); return NULL; } - ace.type = atype; - ace.flags = aflags; - ace.info.mask = amask; - add_acl(&sd->sacl, &ace); } } @@ -176,6 +193,50 @@ static SEC_DESC *sec_desc_parse(char *str) } +/* print a ascii version of a security descriptor on a FILE handle */ +static void sec_desc_print(FILE *f, SEC_DESC *sd) +{ + fstring sidstr; + int i; + + printf("REVISION:%x TYPE:%x\n", sd->revision, sd->type); + + /* Print owner and group sid */ + + if (sd->owner_sid) { + SidToString(sidstr, sd->owner_sid); + } else { + fstrcpy(sidstr, ""); + } + + printf("OWNER:%s\n", sidstr); + + if (sd->grp_sid) { + SidToString(sidstr, sd->grp_sid); + } else { + fstrcpy(sidstr, ""); + } + + fprintf(f, "GROUP:%s\n", sidstr); + + /* Print aces */ + for (i = 0; sd->dacl && i < sd->dacl->num_aces; i++) { + SEC_ACE *ace = &sd->dacl->ace[i]; + fprintf(f, "DACL:"); + print_ace(f, ace); + } + + for (i = 0; sd->sacl && i < sd->sacl->num_aces; i++) { + SEC_ACE *ace = &sd->sacl->ace[i]; + fstring sidstr; + + SidToString(sidstr, &ace->sid); + + fprintf(f, "SACL:%s:%x:%x:%08x\n", sidstr, + ace->type, ace->flags, + ace->info.mask); + } +} /***************************************************** @@ -308,14 +369,6 @@ struct cli_state *connect_one(char *share) 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. - */ - DEBUG(4,(" session setup ok\n")); if (!cli_send_tconX(c, share, "?????", @@ -386,7 +439,7 @@ static void usage(void) seed = time(NULL); - while ((opt = getopt(argc, argv, "U:hs:")) != EOF) { + while ((opt = getopt(argc, argv, "U:nhS:")) != EOF) { switch (opt) { case 'U': pstrcpy(username,optarg); @@ -397,9 +450,15 @@ static void usage(void) got_pass = 1; } break; - case 's': + + case 'S': set_acl = optarg; break; + + case 'n': + numeric = 1; + break; + case 'h': usage(); exit(1); -- cgit From dc3251b460544ee60f34bf97b67a0f4ead17e443 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 3 Dec 2000 11:05:11 +0000 Subject: cleaner parsing and default handling (This used to be commit f8dbd2b799545a8e1e33eceb6739b5b606cdc4b9) --- source3/utils/smbcacls.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 7f0ffcdcbb..f18899d01d 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -1,5 +1,6 @@ /* Unix SMB/Netbios implementation. + ACL get/set utility Version 3.0 Copyright (C) Andrew Tridgell 2000 @@ -131,35 +132,36 @@ static SEC_DESC *sec_desc_parse(char *str) { char *p = str; fstring tok; - SEC_DESC *sd, *ret; + SEC_DESC *ret; int sd_size; - - sd = (SEC_DESC *)calloc(1, sizeof(SEC_DESC)); - if (!sd) return NULL; + DOM_SID *grp_sid=NULL, *owner_sid=NULL; + SEC_ACL *dacl=NULL, *sacl=NULL; + int revision=1; + int type=0x8004; while (next_token(&p, tok, " \t,\r\n", sizeof(tok))) { if (strncmp(tok,"REVISION:", 9) == 0) { - sd->revision = strtol(tok+9, NULL, 16); + revision = strtol(tok+9, NULL, 16); } if (strncmp(tok,"TYPE:", 5) == 0) { - sd->type = strtol(tok+5, NULL, 16); + type = strtol(tok+5, NULL, 16); } if (strncmp(tok,"OWNER:", 6) == 0) { - sd->owner_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID)); - if (!sd->owner_sid || - !StringToSid(sd->owner_sid, tok+6)) { + owner_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID)); + if (!owner_sid || + !StringToSid(owner_sid, tok+6)) { printf("Failed to parse owner sid\n"); return NULL; } } if (strncmp(tok,"GROUP:", 6) == 0) { - sd->grp_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID)); - if (!sd->grp_sid || - !StringToSid(sd->grp_sid, tok+6)) { + grp_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID)); + if (!grp_sid || + !StringToSid(grp_sid, tok+6)) { printf("Failed to parse group sid\n"); return NULL; } @@ -168,7 +170,7 @@ static SEC_DESC *sec_desc_parse(char *str) if (strncmp(tok,"DACL:", 5) == 0) { SEC_ACE ace; if (!parse_ace(&ace, tok+5) || - !add_ace(&sd->dacl, &ace)) { + !add_ace(&dacl, &ace)) { printf("Failed to parse DACL\n"); return NULL; } @@ -177,17 +179,20 @@ static SEC_DESC *sec_desc_parse(char *str) if (strncmp(tok,"SACL:", 5) == 0) { SEC_ACE ace; if (!parse_ace(&ace, tok+5) || - !add_ace(&sd->sacl, &ace)) { + !add_ace(&sacl, &ace)) { printf("Failed to parse SACL\n"); return NULL; } } } - ret = make_sec_desc(sd->revision, sd->type, sd->owner_sid, sd->grp_sid, - sd->sacl, sd->dacl, &sd_size); + ret = make_sec_desc(revision, type, owner_sid, grp_sid, + sacl, dacl, &sd_size); - free_sec_desc(&sd); + free_sec_acl(&sacl); + free_sec_acl(&dacl); + if (grp_sid) free(grp_sid); + if (owner_sid) free(owner_sid); return ret; } -- cgit From 0cb1c512f1fdcc719ad4d071fe7905444ac76b3f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 3 Dec 2000 12:41:28 +0000 Subject: - added help - added add/modify/delete/set as separate operations (This used to be commit cb324b53c61ee7e4bf0aa5d1fb773672a2674c0f) --- source3/utils/smbcacls.c | 130 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 118 insertions(+), 12 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index f18899d01d..8a88469999 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -32,6 +32,9 @@ static int got_pass; than going via LSA calls to resolve them */ static int numeric; +enum acl_mode {ACL_SET, ACL_DELETE, ACL_MODIFY, ACL_ADD}; + + /* convert a SID to a string, either numeric or username/group */ static void SidToString(fstring str, DOM_SID *sid) { @@ -79,7 +82,7 @@ static void print_ace(FILE *f, SEC_ACE *ace) perm = "C"; } else if (ace->info.mask == 0x001200a9) { perm = "R"; - } else if (ace->info.mask == 0x00000000) { + } else if (ace->info.mask == 0x00080000) { perm = "N"; } else { perm = "?"; @@ -275,12 +278,14 @@ static void cacl_dump(struct cli_state *cli, char *filename) /***************************************************** set the ACLs on a file given an ascii description *******************************************************/ -static void cacl_set(struct cli_state *cli, char *filename, char *set_acl) +static void cacl_set(struct cli_state *cli, char *filename, + char *acl, enum acl_mode mode) { int fnum; - SEC_DESC *sd; + SEC_DESC *sd, *old; + int i, j; - sd = sec_desc_parse(set_acl); + sd = sec_desc_parse(acl); if (!sd) { printf("Failed to parse security descriptor\n"); return; @@ -292,14 +297,89 @@ static void cacl_set(struct cli_state *cli, char *filename, char *set_acl) return; } - /* sec_desc_print(stdout, sd); */ + old = cli_query_secdesc(cli, fnum); + + /* the logic here is rather more complex than I would like */ + switch (mode) { + case ACL_DELETE: + for (i=0;sd->dacl && idacl->num_aces;i++) { + for (j=0;old->dacl && jdacl->num_aces;j++) { + if (sec_ace_equal(&sd->dacl->ace[i], + &old->dacl->ace[j])) { + if (j == old->dacl->num_aces-1) { + free(old->dacl->ace); + old->dacl->ace=NULL; + free(old->dacl); + old->dacl = NULL; + } else { + old->dacl->ace[j] = old->dacl->ace[j+1]; + old->dacl->num_aces--; + } + j--; + } + } + } + for (i=0;sd->sacl && isacl->num_aces;i++) { + for (j=0;old->sacl && jsacl->num_aces;j++) { + if (sec_ace_equal(&sd->sacl->ace[i], + &old->sacl->ace[j])) { + if (j == old->sacl->num_aces-1) { + free(old->sacl->ace); + old->sacl->ace=NULL; + free(old->sacl); + old->sacl = NULL; + } else { + old->sacl->ace[j] = old->sacl->ace[j+1]; + old->sacl->num_aces--; + } + j--; + } + } + } + break; + + case ACL_MODIFY: + for (i=0;sd->dacl && idacl->num_aces;i++) { + for (j=0;old->dacl && jdacl->num_aces;j++) { + if (sid_equal(&sd->dacl->ace[i].sid, + &old->dacl->ace[j].sid)) { + old->dacl->ace[j] = sd->dacl->ace[i]; + } + } + } + for (i=0;sd->sacl && isacl->num_aces;i++) { + for (j=0;old->sacl && jsacl->num_aces;j++) { + if (sid_equal(&sd->sacl->ace[i].sid, + &old->sacl->ace[j].sid)) { + old->sacl->ace[j] = sd->sacl->ace[i]; + } + } + } + break; + + case ACL_ADD: + for (i=0;sd->dacl && idacl->num_aces;i++) { + add_ace(&old->dacl, &sd->dacl->ace[i]); + } + for (i=0;sd->sacl && isacl->num_aces;i++) { + add_ace(&old->sacl, &sd->sacl->ace[i]); + } + break; + + case ACL_SET: + free_sec_desc(&old); + old = sd; + break; + + } - if (!cli_set_secdesc(cli, fnum, sd)) { + if (!cli_set_secdesc(cli, fnum, old)) { printf("ERROR: secdesc set failed\n"); return; } free_sec_desc(&sd); + free_sec_desc(&old); cli_close(cli, fnum); } @@ -393,7 +473,16 @@ static void usage(void) { printf( "Usage:\n\ - smbcacls //server1/share1 filename\n\n"); + smbcacls //server1/share1 filename [options]\n\n\ +\n\ + -D delete an acl\n\ + -M modify an acl\n\ + -A add an acl\n\ + -S set acls\n\ +\n\ + an acl is of the form SID:type/flags/mask\n\ + you can string acls together with spaces, commas or newlines\n\ +"); } /**************************************************************************** @@ -411,7 +500,8 @@ static void usage(void) int seed; static pstring servicesf = CONFIGFILE; struct cli_state *cli; - char *set_acl = NULL; + enum acl_mode mode; + char *acl = NULL; setlinebuf(stdout); @@ -444,7 +534,7 @@ static void usage(void) seed = time(NULL); - while ((opt = getopt(argc, argv, "U:nhS:")) != EOF) { + while ((opt = getopt(argc, argv, "U:nhS:D:A:M:")) != EOF) { switch (opt) { case 'U': pstrcpy(username,optarg); @@ -457,7 +547,23 @@ static void usage(void) break; case 'S': - set_acl = optarg; + acl = optarg; + mode = ACL_SET; + break; + + case 'D': + acl = optarg; + mode = ACL_DELETE; + break; + + case 'M': + acl = optarg; + mode = ACL_MODIFY; + break; + + case 'A': + acl = optarg; + mode = ACL_ADD; break; case 'n': @@ -479,8 +585,8 @@ static void usage(void) cli = connect_one(share); if (!cli) exit(1); - if (set_acl) { - cacl_set(cli, filename, set_acl); + if (acl) { + cacl_set(cli, filename, acl, mode); } else { cacl_dump(cli, filename); } -- cgit From a4c11729b2c36dd26773685f1256e1c6e33c511d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Dec 2000 00:33:08 +0000 Subject: - with -D only delete first match - fixed delete bug (This used to be commit 1e0d5f069592ebce58c35e95b0dcdbc5516dd268) --- source3/utils/smbcacls.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 8a88469999..65c88b479e 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -283,7 +283,7 @@ static void cacl_set(struct cli_state *cli, char *filename, { int fnum; SEC_DESC *sd, *old; - int i, j; + int i, j, sd_size; sd = sec_desc_parse(acl); if (!sd) { @@ -306,16 +306,18 @@ static void cacl_set(struct cli_state *cli, char *filename, for (j=0;old->dacl && jdacl->num_aces;j++) { if (sec_ace_equal(&sd->dacl->ace[i], &old->dacl->ace[j])) { - if (j == old->dacl->num_aces-1) { + if (j != old->dacl->num_aces-1) { + old->dacl->ace[j] = old->dacl->ace[j+1]; + } + old->dacl->num_aces--; + if (old->dacl->num_aces == 0) { free(old->dacl->ace); old->dacl->ace=NULL; free(old->dacl); old->dacl = NULL; - } else { - old->dacl->ace[j] = old->dacl->ace[j+1]; - old->dacl->num_aces--; + old->off_dacl = 0; } - j--; + break; } } } @@ -323,16 +325,18 @@ static void cacl_set(struct cli_state *cli, char *filename, for (j=0;old->sacl && jsacl->num_aces;j++) { if (sec_ace_equal(&sd->sacl->ace[i], &old->sacl->ace[j])) { - if (j == old->sacl->num_aces-1) { + if (j != old->sacl->num_aces-1) { + old->sacl->ace[j] = old->sacl->ace[j+1]; + } + old->sacl->num_aces--; + if (old->sacl->num_aces == 0) { free(old->sacl->ace); old->sacl->ace=NULL; free(old->sacl); old->sacl = NULL; - } else { - old->sacl->ace[j] = old->sacl->ace[j+1]; - old->sacl->num_aces--; + old->off_sacl = 0; } - j--; + break; } } } @@ -373,7 +377,14 @@ static void cacl_set(struct cli_state *cli, char *filename, } - if (!cli_set_secdesc(cli, fnum, old)) { + if (sd != old) { + free_sec_desc(&sd); + } + + sd = make_sec_desc(old->revision, old->type, old->owner_sid, old->grp_sid, + old->sacl, old->dacl, &sd_size); + + if (!cli_set_secdesc(cli, fnum, sd)) { printf("ERROR: secdesc set failed\n"); return; } -- cgit From 0884d6ab52a1d4e0afa23910a21432bd648d761d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Dec 2000 00:35:31 +0000 Subject: fixed SACL bug (This used to be commit 077ee4a7ac7fa8f274269bfc5130d5abff9f35e0) --- source3/utils/smbcacls.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 65c88b479e..776ff19715 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -233,17 +233,12 @@ static void sec_desc_print(FILE *f, SEC_DESC *sd) fprintf(f, "DACL:"); print_ace(f, ace); } - for (i = 0; sd->sacl && i < sd->sacl->num_aces; i++) { SEC_ACE *ace = &sd->sacl->ace[i]; - fstring sidstr; - - SidToString(sidstr, &ace->sid); - - fprintf(f, "SACL:%s:%x:%x:%08x\n", sidstr, - ace->type, ace->flags, - ace->info.mask); + fprintf(f, "SACL:"); + print_ace(f, ace); } + } -- cgit From 6399b62175bed1bade82a8d9f3a40fd5c7693073 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Dec 2000 02:01:57 +0000 Subject: fixed acls set bug (This used to be commit 44524958ed3a0d56b0504b044bf640ceffebb704) --- source3/utils/smbcacls.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 776ff19715..7f2ab8cf53 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -97,18 +97,19 @@ static BOOL parse_ace(SEC_ACE *ace, char *str) { char *p; unsigned atype, aflags, amask; + DOM_SID sid; + SEC_ACCESS mask; ZERO_STRUCTP(ace); p = strchr(str,':'); if (!p) return False; *p = 0; if (sscanf(p+1, "%x/%x/%08x", &atype, &aflags, &amask) != 3 || - !StringToSid(&ace->sid, str)) { + !StringToSid(&sid, str)) { return False; } - ace->type = atype; - ace->flags = aflags; - ace->info.mask = amask; + mask.mask = amask; + init_sec_ace(ace, &sid, atype, mask, aflags); return True; } @@ -117,16 +118,20 @@ static BOOL parse_ace(SEC_ACE *ace, char *str) /* add an ACE to a list of ACEs in a SEC_ACL */ static BOOL add_ace(SEC_ACL **acl, SEC_ACE *ace) { + SEC_ACL *new; + SEC_ACE *aces; if (! *acl) { - *acl = (SEC_ACL *)calloc(1, sizeof(*acl)); - if (! *acl) return False; - (*acl)->revision = 3; + (*acl) = make_sec_acl(3, 1, ace); + return True; } - (*acl)->ace = Realloc((*acl)->ace,(1+((*acl)->num_aces))*sizeof(SEC_ACE)); - if (!(*acl)->ace) return False; - memcpy(&((*acl)->ace[(*acl)->num_aces]), ace, sizeof(SEC_ACE)); - (*acl)->num_aces++; + aces = calloc(1+(*acl)->num_aces,sizeof(SEC_ACE)); + memcpy(aces, (*acl)->ace, (*acl)->num_aces * sizeof(SEC_ACE)); + memcpy(aces+(*acl)->num_aces, ace, sizeof(SEC_ACE)); + new = make_sec_acl((*acl)->revision,1+(*acl)->num_aces, aces); + free_sec_acl(acl); + free(aces); + (*acl) = new; return True; } @@ -189,7 +194,7 @@ static SEC_DESC *sec_desc_parse(char *str) } } - ret = make_sec_desc(revision, type, owner_sid, grp_sid, + ret = make_sec_desc(revision, owner_sid, grp_sid, sacl, dacl, &sd_size); free_sec_acl(&sacl); @@ -376,7 +381,7 @@ static void cacl_set(struct cli_state *cli, char *filename, free_sec_desc(&sd); } - sd = make_sec_desc(old->revision, old->type, old->owner_sid, old->grp_sid, + sd = make_sec_desc(old->revision, old->owner_sid, old->grp_sid, old->sacl, old->dacl, &sd_size); if (!cli_set_secdesc(cli, fnum, sd)) { -- cgit From 576a106d033337088b969a2a63dd7e5616cc1d72 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Dec 2000 03:27:02 +0000 Subject: signed/unsigned warning fixed (This used to be commit 71adecd163b13169d359b69f61e8e70e2f140277) --- source3/utils/smbcacls.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 7f2ab8cf53..def5fadbad 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -141,7 +141,7 @@ static SEC_DESC *sec_desc_parse(char *str) char *p = str; fstring tok; SEC_DESC *ret; - int sd_size; + unsigned sd_size; DOM_SID *grp_sid=NULL, *owner_sid=NULL; SEC_ACL *dacl=NULL, *sacl=NULL; int revision=1; @@ -283,7 +283,8 @@ static void cacl_set(struct cli_state *cli, char *filename, { int fnum; SEC_DESC *sd, *old; - int i, j, sd_size; + int i, j; + unsigned sd_size; sd = sec_desc_parse(acl); if (!sd) { -- cgit From 5092ad82bac2d8aa07122dfdb26a425a35e1084a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Dec 2000 04:58:40 +0000 Subject: removed SACL support (as it doesn't work with w2k if you ask for SACLs) (This used to be commit 52b27d75e12eeeb52b3a93952900809c2ee0b992) --- source3/utils/smbcacls.c | 59 ++++++------------------------------------------ 1 file changed, 7 insertions(+), 52 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index def5fadbad..f2e8c9cbd4 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -143,7 +143,7 @@ static SEC_DESC *sec_desc_parse(char *str) SEC_DESC *ret; unsigned sd_size; DOM_SID *grp_sid=NULL, *owner_sid=NULL; - SEC_ACL *dacl=NULL, *sacl=NULL; + SEC_ACL *dacl=NULL; int revision=1; int type=0x8004; @@ -175,29 +175,19 @@ static SEC_DESC *sec_desc_parse(char *str) } } - if (strncmp(tok,"DACL:", 5) == 0) { + if (strncmp(tok,"ACL:", 4) == 0) { SEC_ACE ace; - if (!parse_ace(&ace, tok+5) || + if (!parse_ace(&ace, tok+4) || !add_ace(&dacl, &ace)) { - printf("Failed to parse DACL\n"); - return NULL; - } - } - - if (strncmp(tok,"SACL:", 5) == 0) { - SEC_ACE ace; - if (!parse_ace(&ace, tok+5) || - !add_ace(&sacl, &ace)) { - printf("Failed to parse SACL\n"); + printf("Failed to parse ACL\n"); return NULL; } } } ret = make_sec_desc(revision, owner_sid, grp_sid, - sacl, dacl, &sd_size); + NULL, dacl, &sd_size); - free_sec_acl(&sacl); free_sec_acl(&dacl); if (grp_sid) free(grp_sid); if (owner_sid) free(owner_sid); @@ -235,12 +225,7 @@ static void sec_desc_print(FILE *f, SEC_DESC *sd) /* Print aces */ for (i = 0; sd->dacl && i < sd->dacl->num_aces; i++) { SEC_ACE *ace = &sd->dacl->ace[i]; - fprintf(f, "DACL:"); - print_ace(f, ace); - } - for (i = 0; sd->sacl && i < sd->sacl->num_aces; i++) { - SEC_ACE *ace = &sd->sacl->ace[i]; - fprintf(f, "SACL:"); + fprintf(f, "ACL:"); print_ace(f, ace); } @@ -322,25 +307,6 @@ static void cacl_set(struct cli_state *cli, char *filename, } } } - for (i=0;sd->sacl && isacl->num_aces;i++) { - for (j=0;old->sacl && jsacl->num_aces;j++) { - if (sec_ace_equal(&sd->sacl->ace[i], - &old->sacl->ace[j])) { - if (j != old->sacl->num_aces-1) { - old->sacl->ace[j] = old->sacl->ace[j+1]; - } - old->sacl->num_aces--; - if (old->sacl->num_aces == 0) { - free(old->sacl->ace); - old->sacl->ace=NULL; - free(old->sacl); - old->sacl = NULL; - old->off_sacl = 0; - } - break; - } - } - } break; case ACL_MODIFY: @@ -352,23 +318,12 @@ static void cacl_set(struct cli_state *cli, char *filename, } } } - for (i=0;sd->sacl && isacl->num_aces;i++) { - for (j=0;old->sacl && jsacl->num_aces;j++) { - if (sid_equal(&sd->sacl->ace[i].sid, - &old->sacl->ace[j].sid)) { - old->sacl->ace[j] = sd->sacl->ace[i]; - } - } - } break; case ACL_ADD: for (i=0;sd->dacl && idacl->num_aces;i++) { add_ace(&old->dacl, &sd->dacl->ace[i]); } - for (i=0;sd->sacl && isacl->num_aces;i++) { - add_ace(&old->sacl, &sd->sacl->ace[i]); - } break; case ACL_SET: @@ -383,7 +338,7 @@ static void cacl_set(struct cli_state *cli, char *filename, } sd = make_sec_desc(old->revision, old->owner_sid, old->grp_sid, - old->sacl, old->dacl, &sd_size); + NULL, old->dacl, &sd_size); if (!cli_set_secdesc(cli, fnum, sd)) { printf("ERROR: secdesc set failed\n"); -- cgit From 252e3ba1283574511dc8ff3a07be4271cfee9a15 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 4 Dec 2000 06:14:28 +0000 Subject: Mask value now displayed as READ/CHANGE/FULL for standard permissions, or RWXDPO for special permissions. Append 0x to values printed as hex. Spruced up the help message. (This used to be commit 8a20318c5626f7328fd911144c54fe92426532c5) --- source3/utils/smbcacls.c | 93 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 27 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index f2e8c9cbd4..b2fef1ec83 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -20,8 +20,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" static fstring password; @@ -34,6 +32,29 @@ static int numeric; enum acl_mode {ACL_SET, ACL_DELETE, ACL_MODIFY, ACL_ADD}; +struct perm_value { + char *perm; + uint32 mask; +}; + +/* These values discovered by inspection */ + +static struct perm_value special_values[] = { + { "R", 0x00120089 }, + { "W", 0x00120116 }, + { "X", 0x001200a0 }, + { "D", 0x00010000 }, + { "P", 0x00040000 }, + { "O", 0x00080000 }, + { NULL, 0 }, +}; + +static struct perm_value standard_values[] = { + { "READ", 0x001200a9 }, + { "CHANGE", 0x001301bf }, + { "FULL", 0x001f01ff }, + { NULL, 0 }, +}; /* convert a SID to a string, either numeric or username/group */ static void SidToString(fstring str, DOM_SID *sid) @@ -61,34 +82,51 @@ static BOOL StringToSid(DOM_SID *sid, fstring str) /* print an ACE on a FILE, using either numeric or ascii representation */ static void print_ace(FILE *f, SEC_ACE *ace) { + struct perm_value *v; fstring sidstr; - char *perm; SidToString(sidstr, &ace->sid); fprintf(f, "%s:", sidstr); if (numeric) { - fprintf(f, "%x/%x/%08x\n", + fprintf(f, "%d/%d/0x%08x\n", ace->type, ace->flags, ace->info.mask); return; } - /* this interpretation is almost certainly wrong, Tim, please - have a look at these */ - if (ace->info.mask == 0x001f01ff) { - perm = "F"; - } else if (ace->info.mask == 0x001301bf) { - perm = "C"; - } else if (ace->info.mask == 0x001200a9) { - perm = "R"; - } else if (ace->info.mask == 0x00080000) { - perm = "N"; + /* Ace type */ + + if (ace->type == SEC_ACE_TYPE_ACCESS_ALLOWED) { + fprintf(f, "ALLOWED"); + } else if (ace->type == SEC_ACE_TYPE_ACCESS_DENIED) { + fprintf(f, "DENIED"); } else { - perm = "?"; + fprintf(f, "%d", ace->type); } - fprintf(f,"%s\n", perm); + /* Not sure what flags can be set in a file ACL */ + + fprintf(f, "/%d/", ace->flags); + + /* Standard permissions */ + + for (v = standard_values; v->perm; v++) { + if (ace->info.mask == v->mask) { + fprintf(f, "%s\n", v->perm); + return; + } + } + + /* Special permissions */ + + for (v = special_values; v->perm; v++) { + if ((ace->info.mask & v->mask) == v->mask) { + fprintf(f, "%s", v->perm); + } + } + + fprintf(f, "\n"); } @@ -113,8 +151,6 @@ static BOOL parse_ace(SEC_ACE *ace, char *str) return True; } - - /* add an ACE to a list of ACEs in a SEC_ACL */ static BOOL add_ace(SEC_ACL **acl, SEC_ACE *ace) { @@ -202,7 +238,7 @@ static void sec_desc_print(FILE *f, SEC_DESC *sd) fstring sidstr; int i; - printf("REVISION:%x TYPE:%x\n", sd->revision, sd->type); + printf("REVISION:%d\nTYPE:0x%x\n", sd->revision, sd->type); /* Print owner and group sid */ @@ -439,16 +475,18 @@ struct cli_state *connect_one(char *share) static void usage(void) { printf( -"Usage:\n\ - smbcacls //server1/share1 filename [options]\n\n\ +"Usage: smbcacls //server1/share1 filename [options]\n\n\ \n\ - -D delete an acl\n\ - -M modify an acl\n\ - -A add an acl\n\ - -S set acls\n\ +\t-D delete an acl\n\ +\t-M modify an acl\n\ +\t-A add an acl\n\ +\t-S set acls\n\ +\t-U username set the network username\n\ +\t-n don't resolve sids or masks to names\n\ +\t-h print help\n\ \n\ - an acl is of the form SID:type/flags/mask\n\ - you can string acls together with spaces, commas or newlines\n\ +An acl is of the form SID:type/flags/mask\n\ +You can string acls together with spaces, commas or newlines\n\ "); } @@ -540,6 +578,7 @@ static void usage(void) case 'h': usage(); exit(1); + default: printf("Unknown option %c (%d)\n", (char)opt, opt); exit(1); -- cgit From 3d43b2db28db679ac4d779da853bd3f04873c9e8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Dec 2000 06:39:31 +0000 Subject: fixed setting ACLs on directories (This used to be commit 117956ecb1878f09708a5dc76ec81ad3cfa8d809) --- source3/utils/smbcacls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index b2fef1ec83..52a5ea769c 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -276,7 +276,7 @@ static void cacl_dump(struct cli_state *cli, char *filename) int fnum; SEC_DESC *sd; - fnum = cli_open(cli, filename, O_RDONLY, 0); + fnum = cli_nt_create(cli, filename); if (fnum == -1) { printf("Failed to open %s\n", filename); return; @@ -313,7 +313,7 @@ static void cacl_set(struct cli_state *cli, char *filename, return; } - fnum = cli_open(cli, filename, O_RDONLY, 0); + fnum = cli_nt_create(cli, filename); if (fnum == -1) { printf("Failed to open %s\n", filename); return; -- cgit From 92abcbc04005181262a866dc1e1322ee0f0c813a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 4 Dec 2000 06:43:36 +0000 Subject: Removed lsa lookup warnings (I'll remember). Print an error if -M refers to a non-existent ACL. (This used to be commit ee6f5a9672795c884cabe80e98e5b0fb3c793539) --- source3/utils/smbcacls.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 52a5ea769c..5f750c358e 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -62,7 +62,9 @@ static void SidToString(fstring str, DOM_SID *sid) if (numeric) { sid_to_string(str, sid); } else { - printf("need to add LSA lookups\n"); + + /* Need to add LSA lookups */ + sid_to_string(str, sid); } } @@ -73,8 +75,10 @@ static BOOL StringToSid(DOM_SID *sid, fstring str) if (strncmp(str,"S-", 2) == 0) { return string_to_sid(sid, str); } else { - printf("need to add LSA lookups\n"); - return False; + + /* Need to add LSA lookups */ + + return string_to_sid(sid, str); } } @@ -347,13 +351,24 @@ static void cacl_set(struct cli_state *cli, char *filename, case ACL_MODIFY: for (i=0;sd->dacl && idacl->num_aces;i++) { + BOOL found = False; + for (j=0;old->dacl && jdacl->num_aces;j++) { if (sid_equal(&sd->dacl->ace[i].sid, &old->dacl->ace[j].sid)) { old->dacl->ace[j] = sd->dacl->ace[i]; + found = True; } } + + if (!found) { + fstring str; + + SidToString(str, &sd->dacl->ace[i].sid); + printf("ACL for SID %s not found\n", str); + } } + break; case ACL_ADD: @@ -485,7 +500,7 @@ static void usage(void) \t-n don't resolve sids or masks to names\n\ \t-h print help\n\ \n\ -An acl is of the form SID:type/flags/mask\n\ +An acl is of the form ACL::type/flags/mask\n\ You can string acls together with spaces, commas or newlines\n\ "); } -- cgit From 54100bac69641254f512bfe6d1449e8d217e5af5 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 4 Dec 2000 06:46:52 +0000 Subject: Added some cli_errstr() calls. (This used to be commit faaa71a032bc27d073c39da42fc2928ea3226698) --- source3/utils/smbcacls.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 5f750c358e..47d57c1110 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -282,14 +282,14 @@ static void cacl_dump(struct cli_state *cli, char *filename) fnum = cli_nt_create(cli, filename); if (fnum == -1) { - printf("Failed to open %s\n", filename); + printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); return; } sd = cli_query_secdesc(cli, fnum); if (!sd) { - printf("ERROR: secdesc query failed\n"); + printf("ERROR: secdesc query failed: %s\n", cli_errstr(cli)); return; } @@ -319,7 +319,7 @@ static void cacl_set(struct cli_state *cli, char *filename, fnum = cli_nt_create(cli, filename); if (fnum == -1) { - printf("Failed to open %s\n", filename); + printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); return; } @@ -392,7 +392,7 @@ static void cacl_set(struct cli_state *cli, char *filename, NULL, old->dacl, &sd_size); if (!cli_set_secdesc(cli, fnum, sd)) { - printf("ERROR: secdesc set failed\n"); + printf("ERROR: secdesc set failed: %s\n", cli_errstr(cli)); return; } -- cgit From 723c9b87e77a54976e21aa0b23dcb2c055449473 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Dec 2000 07:27:35 +0000 Subject: fixed the parsing again and got setting acls working with w2k (This used to be commit 374d08be6443738d6a450801866fd6e046322e2c) --- source3/utils/smbcacls.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 47d57c1110..7f6275c6ca 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -145,7 +145,7 @@ static BOOL parse_ace(SEC_ACE *ace, char *str) p = strchr(str,':'); if (!p) return False; *p = 0; - if (sscanf(p+1, "%x/%x/%08x", + if (sscanf(p+1, "%i/%i/%i", &atype, &aflags, &amask) != 3 || !StringToSid(&sid, str)) { return False; @@ -280,7 +280,7 @@ static void cacl_dump(struct cli_state *cli, char *filename) int fnum; SEC_DESC *sd; - fnum = cli_nt_create(cli, filename); + fnum = cli_nt_create(cli, filename, 0x20000); if (fnum == -1) { printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); return; @@ -317,7 +317,7 @@ static void cacl_set(struct cli_state *cli, char *filename, return; } - fnum = cli_nt_create(cli, filename); + fnum = cli_nt_create(cli, filename, MAXIMUM_ALLOWED_ACCESS | 0x60000); if (fnum == -1) { printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); return; -- cgit From 3eee7625b1c497a6f87a2d11710a4d7c4ff58fa1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Dec 2000 07:38:06 +0000 Subject: added a comment (This used to be commit 032442802f73948e3af2c86fee0d58f82e47f673) --- source3/utils/smbcacls.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 7f6275c6ca..570a0b3155 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -317,6 +317,8 @@ static void cacl_set(struct cli_state *cli, char *filename, return; } + /* the desired access below is the only one I could find that works with + NT4, W2KP and Samba */ fnum = cli_nt_create(cli, filename, MAXIMUM_ALLOWED_ACCESS | 0x60000); if (fnum == -1) { printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); -- cgit From b6e03bf737a559364c9916cee53cfe73473911d5 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 6 Dec 2000 18:18:48 +0000 Subject: added passdb editor (rough form with a few bugs) Should work with all backends. --jerry (This used to be commit fc43c63f481cdf22c3515cc0f0d744c662b4f83d) --- source3/utils/pdbedit.c | 692 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 692 insertions(+) create mode 100644 source3/utils/pdbedit.c (limited to 'source3/utils') diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c new file mode 100644 index 0000000000..cd77cbc436 --- /dev/null +++ b/source3/utils/pdbedit.c @@ -0,0 +1,692 @@ +/* + * Unix SMB/Netbios implementation. Version 1.9. tdbedit module. Copyright + * (C) Simo Sorce 2000 + * + * 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. + */ + +/* base uid for trust accounts is set to 60000 ! + * May be we should add the defines in smb.h to make it possible having + * different values on different platforms? + */ + +#define BASE_MACHINE_UID 60000 +#define MAX_MACHINE_UID 65500 /* 5500 trust acconts aren't enough? */ + +#include "includes.h" + +extern pstring global_myname; +extern int DEBUGLEVEL; + +/* + * Next two lines needed for SunOS and don't + * hurt anything else... + */ +extern char *optarg; +extern int optind; + +/********************************************************* + Print command usage on stderr and die. +**********************************************************/ +static void usage(void) +{ + if (getuid() == 0) { + printf("tdbedit options\n"); + } else { + printf("You need to be root to use this tool!\n"); + } + printf("(actually to add a user you need to use smbpasswd)\n"); + printf("options:\n"); + printf(" -l list usernames\n"); + printf(" -v verbose output\n"); + printf(" -w smbpasswd file style\n"); + printf(" -u username print user's info\n"); + printf(" -f fullname set Full Name\n"); + printf(" -h homedir set home directory\n"); + printf(" -d drive set home dir drive\n"); + printf(" -s script set logon script\n"); + printf(" -p profile set profile path\n"); + printf(" -a create new account\n"); + printf(" -m it is a machine trust\n"); + printf(" -x delete this user\n"); + printf(" -i file import account from file (smbpasswd style)\n"); + exit(1); +} +/********************************************************* + Print info from sam structure +**********************************************************/ +static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdstyle) +{ + /* TODO: chaeck if entry is a user or a workstation */ + if (!sam_pwent) return -1; + + if (verbosity) + { + printf ("username: %s\n", sam_pwent->username); + printf ("user ID/Group: %d/%d\n", sam_pwent->uid, + sam_pwent->gid); + printf ("user RID/GRID: %d/%d\n", sam_pwent->user_rid, + sam_pwent->group_rid); + printf ("Full Name: %s\n", sam_pwent->full_name); + printf ("Home Directory: %s\n", sam_pwent->home_dir); + printf ("HomeDir Drive: %s\n", sam_pwent->dir_drive); + printf ("Logon Script: %s\n", sam_pwent->logon_script); + printf ("Profile Path: %s\n", sam_pwent->profile_path); + } + else if (smbpwdstyle) + { + char lm_passwd[33]; + char nt_passwd[33]; + pdb_gethexpwd(pdb_get_lanman_passwd(sam_pwent), lm_passwd); + pdb_gethexpwd(pdb_get_nt_passwd(sam_pwent), nt_passwd); + + printf ("%s:%d:%s:%s:%s:LCT-%08x:\n", + pdb_get_username(sam_pwent), + pdb_get_uid(sam_pwent), + lm_passwd, + nt_passwd, + pdb_encode_acct_ctrl(pdb_get_acct_ctrl(sam_pwent),NEW_PW_FORMAT_SPACE_PADDED_LEN), + (uint32)pdb_get_pass_last_set_time(sam_pwent)); + } + else + { + printf ("%s:%d:%s\n", sam_pwent->username, sam_pwent->uid, sam_pwent->full_name); + } + + return 0; +} + +/********************************************************* + Get an Print User Info +**********************************************************/ +static int print_user_info (char *username, BOOL verbosity, BOOL smbpwdstyle) +{ + SAM_ACCOUNT *sam_pwent; + + sam_pwent = pdb_getsampwnam (username); + if (sam_pwent) return print_sam_info (sam_pwent, verbosity, smbpwdstyle); + else fprintf (stderr, "Username not found!\n"); + return -1; +} + +/********************************************************* + List Users +**********************************************************/ +static int print_users_list (BOOL verbosity, BOOL smbpwdstyle) +{ + SAM_ACCOUNT *sam_pwent; + BOOL ret; + + ret = pdb_setsampwent(False); + if (ret && errno == ENOENT) { + fprintf (stderr,"Password database not found!\n"); + exit(1); + } + + while ((sam_pwent = pdb_getsampwent ())) + { + if (verbosity) printf ("---------------\n"); + print_sam_info (sam_pwent, verbosity, smbpwdstyle); + } + + pdb_endsampwent (); + return 0; +} + +/********************************************************* + Set User Info +**********************************************************/ +static int set_user_info (char *username, char *fullname, char *homedir, char *drive, char *script, char *profile) +{ + SAM_ACCOUNT *sam_pwent; + + sam_pwent = pdb_getsampwnam (username); + if (!sam_pwent) + { + fprintf (stderr, "Username not found!\n"); + return -1; + } + + if (fullname) sam_pwent->full_name = fullname; + if (homedir) sam_pwent->home_dir = homedir; + if (drive) sam_pwent->dir_drive = drive; + if (script) sam_pwent->logon_script = script; + if (profile) sam_pwent->profile_path = profile; + + if (pdb_update_sam_account (sam_pwent, TRUE)) print_user_info (username, TRUE, FALSE); + else + { + fprintf (stderr, "Unable to modify entry!\n"); + return -1; + } + return 0; +} + +/********************************************************* + Add New User +**********************************************************/ +static int new_user (char *username, char *fullname, char *homedir, char *drive, char *script, char *profile) +{ + SAM_ACCOUNT sam_pwent; + struct passwd *pwd = NULL; + uchar new_p16[16]; + uchar new_nt_p16[16]; + char *password1, *password2; + + if (pdb_getsampwnam (username)) + { + fprintf (stderr, "Username already exist in database!\n"); + return -1; + } + + if (!(pwd = sys_getpwnam(username))) + { + fprintf (stderr, "User %s does not exist in system passwd!\n", username); + return -1; + } + + password1 = getpass("new password:"); + password2 = getpass("retype new password:"); + if (strcmp (password1, password2)) + { + fprintf (stderr, "Passwords does not match!\n"); + return -1; + } + nt_lm_owf_gen (password1, new_nt_p16, new_p16); + + sam_pwent.username = username; + if (fullname) sam_pwent.full_name = fullname; + if (homedir) sam_pwent.home_dir = homedir; + if (drive) sam_pwent.dir_drive = drive; + if (script) sam_pwent.logon_script = script; + if (profile) sam_pwent.profile_path = profile; + + /* TODO: Check uid not being in MACHINE UID range!! */ + sam_pwent.uid = pwd->pw_uid; + sam_pwent.gid = pwd->pw_gid; + sam_pwent.user_rid = pdb_uid_to_user_rid (pwd->pw_uid); + sam_pwent.group_rid = pdb_gid_to_group_rid (pwd->pw_gid); + sam_pwent.lm_pw = new_p16; + sam_pwent.nt_pw = new_nt_p16; + sam_pwent.acct_ctrl = ACB_NORMAL; + + if (pdb_add_sam_account (&sam_pwent)) print_user_info (username, TRUE, FALSE); + else + { + fprintf (stderr, "Unable to add user!\n"); + return -1; + } + return 0; +} + +/********************************************************* + Add New Machine +**********************************************************/ +static int new_machine (char *machinename) +{ + SAM_ACCOUNT sam_pwent; + uchar new_p16[16]; + uchar new_nt_p16[16]; + char name[16]; + char *password = NULL; + uid_t uid; + + if (machinename[strlen (machinename) -1] == '$') machinename[strlen (machinename) -1] = '\0'; + + safe_strcpy (name, machinename, 16); + safe_strcat (name, "$", 16); + + string_set (&password, machinename); + strlower(password); + nt_lm_owf_gen (password, new_nt_p16, new_p16); + + sam_pwent.username = name; + + for (uid=BASE_MACHINE_UID; uid<=MAX_MACHINE_UID; uid++) if (!(pdb_getsampwuid (uid))) break; + if (uid>MAX_MACHINE_UID) + { + fprintf (stderr, "No more free UIDs available to Machine accounts!\n"); + return -1; + } + sam_pwent.uid = uid; + sam_pwent.gid = BASE_MACHINE_UID; /* TODO: set there more appropriate value!! */ + sam_pwent.user_rid = pdb_uid_to_user_rid (uid); + sam_pwent.group_rid = pdb_gid_to_group_rid (BASE_MACHINE_UID); + sam_pwent.lm_pw = new_p16; + sam_pwent.nt_pw = new_nt_p16; + sam_pwent.acct_ctrl = ACB_WSTRUST; + + if (pdb_add_sam_account (&sam_pwent)) print_user_info (name, TRUE, FALSE); + else + { + fprintf (stderr, "Unable to add machine!\n"); + return -1; + } + return 0; +} + +/********************************************************* + Delete user entry +**********************************************************/ +static int delete_user_entry (char *username) +{ + return pdb_delete_sam_account (username); +} + +/********************************************************* + Delete machine entry +**********************************************************/ +static int delete_machine_entry (char *machinename) +{ + char name[16]; + + safe_strcpy (name, machinename, 16); + if (name[strlen(name)] != '$') + { + safe_strcat (name, "$", 16); + } + return pdb_delete_sam_account (name); +} + +/********************************************************* + Import smbpasswd style file +**********************************************************/ +static int import_users (char *filename) +{ + FILE *fp = NULL; + SAM_ACCOUNT sam_pwent; + static pstring user_name; + static unsigned char smbpwd[16]; + static unsigned char smbntpwd[16]; + char linebuf[256]; + size_t linebuf_len; + unsigned char c; + unsigned char *p; + long uidval; + int line = 0; + int good = 0; + + if((fp = sys_fopen(filename, "rb")) == NULL) + { + fprintf (stderr, "%s\n", strerror (ferror (fp))); + return -1; + } + + while (!feof(fp)) + { + /*Get a new line*/ + linebuf[0] = '\0'; + fgets(linebuf, 256, fp); + if (ferror(fp)) + { + fprintf (stderr, "%s\n", strerror (ferror (fp))); + return -1; + } + if ((linebuf_len = strlen(linebuf)) == 0) + { + line++; + continue; + } + if (linebuf[linebuf_len - 1] != '\n') + { + c = '\0'; + while (!ferror(fp) && !feof(fp)) + { + c = fgetc(fp); + if (c == '\n') break; + } + } + else linebuf[linebuf_len - 1] = '\0'; + linebuf[linebuf_len] = '\0'; + if ((linebuf[0] == 0) && feof(fp)) + { + /*end of file!!*/ + return 0; + } + line++; + if (linebuf[0] == '#' || linebuf[0] == '\0') continue; + + pdb_init_sam (&sam_pwent); + sam_pwent.acct_ctrl = ACB_NORMAL; + + /* Get user name */ + p = (unsigned char *) strchr(linebuf, ':'); + if (p == NULL) + { + fprintf (stderr, "Error: malformed password entry at line %d !!\n", line); + continue; + } + strncpy(user_name, linebuf, PTR_DIFF(p, linebuf)); + user_name[PTR_DIFF(p, linebuf)] = '\0'; + + /* Get smb uid. */ + p++; + if(*p == '-') + { + fprintf (stderr, "Error: negative uid at line %d\n", line); + continue; + } + if (!isdigit(*p)) + { + fprintf (stderr, "Error: malformed password entry at line %d (uid not number)\n", line); + continue; + } + uidval = atoi((char *) p); + while (*p && isdigit(*p)) p++; + if (*p != ':') + { + fprintf (stderr, "Error: malformed password entry at line %d (no : after uid)\n", line); + continue; + } + + sam_pwent.username = user_name; + sam_pwent.uid = uidval; + + /* Get passwords */ + p++; + if (*p == '*' || *p == 'X') + { + /* Password deliberately invalid */ + fprintf (stderr, "Warning: entry invalidated for user %s\n", user_name); + sam_pwent.lm_pw = NULL; + sam_pwent.nt_pw = NULL; + sam_pwent.acct_ctrl |= ACB_DISABLED; + } + else + { + if (linebuf_len < (PTR_DIFF(p, linebuf) + 33)) + { + fprintf (stderr, "Error: malformed password entry at line %d (password too short)\n",line); + continue; + } + if (p[32] != ':') + { + fprintf (stderr, "Error: malformed password entry at line %d (no terminating :)\n",line); + continue; + } + if (!strncasecmp((char *) p, "NO PASSWORD", 11)) + { + sam_pwent.lm_pw = NULL; + sam_pwent.acct_ctrl |= ACB_PWNOTREQ; + } + else + { + if (!pdb_gethexpwd((char *)p, smbpwd)) + { + fprintf (stderr, "Error: malformed Lanman password entry at line %d (non hex chars)\n", line); + continue; + } + sam_pwent.lm_pw = smbpwd; + } + /* NT password */ + sam_pwent.nt_pw = NULL; + p += 33; + if ((linebuf_len >= (PTR_DIFF(p, linebuf) + 33)) && (p[32] == ':')) + { + if (*p != '*' && *p != 'X') + { + if (pdb_gethexpwd((char *)p,smbntpwd)) + { + sam_pwent.nt_pw = smbntpwd; + } + } + p += 33; + } + } + + /* Get ACCT_CTRL field if any */ + if (*p == '[') + { + unsigned char *end_p = (unsigned char *)strchr((char *)p, ']'); + + sam_pwent.acct_ctrl = pdb_decode_acct_ctrl((char*)p); + if(sam_pwent.acct_ctrl == 0) sam_pwent.acct_ctrl = ACB_NORMAL; + + /* Get last change time */ + if(end_p) p = end_p + 1; + if(*p == ':') + { + p++; + if(*p && (StrnCaseCmp((char *)p, "LCT-", 4)==0)) + { + int i; + + p += 4; + for(i = 0; i < 8; i++) + { + if(p[i] == '\0' || !isxdigit(p[i])) break; + } + if(i == 8) + { + sam_pwent.pass_last_set_time = (time_t)strtol((char *)p, NULL, 16); + } + } + } + } + + /* Test if workstation */ + else + { + if(sam_pwent.username[strlen(sam_pwent.username) - 1] == '$') + { + sam_pwent.acct_ctrl &= ~ACB_NORMAL; + sam_pwent.acct_ctrl |= ACB_WSTRUST; + } + } + if (sam_pwent.acct_ctrl & ACB_WSTRUST) + { + if (!(BASE_MACHINE_UID <= uidval <= MAX_MACHINE_UID)) + { + fprintf (stderr, "Warning: Machine UID out of normal range %d-%d\n", + BASE_MACHINE_UID, + MAX_MACHINE_UID); + } + sam_pwent.gid = BASE_MACHINE_UID; + } + + /* Test if user is valid */ + if (sam_pwent.acct_ctrl & ACB_NORMAL) + { + struct passwd *pwd = NULL; + + if (pdb_getsampwnam (user_name)) + { + fprintf (stderr, "Error: Username already exist in database!\n"); + continue; + } + if (!(pwd = sys_getpwnam(user_name))) + { + fprintf (stderr, "Error: User %s does not exist in system passwd!\n", user_name); + continue; + } + sam_pwent.gid = pwd->pw_gid; + } + + /* Fill in sam_pwent structure */ + sam_pwent.user_rid = pdb_uid_to_user_rid (sam_pwent.uid); + sam_pwent.group_rid = pdb_gid_to_group_rid (sam_pwent.gid); + /* TODO: set also full_name, home_dir, dir_drive, logon_script, profile_path, ecc... + * when defaults will be available (after passdb redesign) + * let them blank just now they are not used anyway + */ + + /* Now ADD the entry */ + if (!(pdb_add_sam_account (&sam_pwent))) + { + fprintf (stderr, "Unable to add user entry!\n"); + continue; + } + printf ("%s imported!\n", user_name); + good++; + } + printf ("%d lines read.\n%d entryes imported\n", line, good); + + return 0; +} + +/********************************************************* + Start here. +**********************************************************/ +int main (int argc, char **argv) +{ + int ch; + static pstring servicesf = CONFIGFILE; + BOOL list_users = FALSE; + BOOL verbose = FALSE; + BOOL spstyle = FALSE; + BOOL setparms = FALSE; + BOOL machine = FALSE; + BOOL add_user = FALSE; + BOOL delete_user = FALSE; + BOOL import = FALSE; + char *user_name = NULL; + char *full_name = NULL; + char *home_dir = NULL; + char *home_drive = NULL; + char *logon_script = NULL; + char *profile_path = NULL; + char *smbpasswd = NULL; + + TimeInit(); + + setup_logging("tdbedit", True); + + charset_initialise(); + + if (argc < 2) + + { + usage(); + return 0; + } + + if(!initialize_password_db(True)) { + fprintf(stderr, "Can't setup password database vectors.\n"); + exit(1); + } + + if (!lp_load(servicesf,True,False,False)) { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", + servicesf); + exit(1); + } + + while ((ch = getopt(argc, argv, "ad:f:h:i:lmp:s:u:vwx")) != EOF) { + switch(ch) { + case 'a': + add_user = TRUE; + break; + case 'm': + machine = TRUE; + break; + case 'l': + list_users = TRUE; + break; + case 'v': + verbose = TRUE; + break; + case 'w': + spstyle = TRUE; + break; + case 'u': + user_name = optarg; + break; + case 'f': + setparms = TRUE; + full_name = optarg; + break; + case 'h': + setparms = TRUE; + home_dir = optarg; + break; + case 'd': + setparms = TRUE; + home_drive = optarg; + break; + case 's': + setparms = TRUE; + logon_script = optarg; + break; + case 'p': + setparms = TRUE; + profile_path = optarg; + break; + case 'x': + delete_user = TRUE; + break; + case 'i': + import = TRUE; + smbpasswd = optarg; + break; + default: + usage(); + } + } + if (((add_user?1:0) + (delete_user?1:0) + (list_users?1:0) + (import?1:0) + (setparms?1:0)) > 1) + { + fprintf (stderr, "Incompatible options on command line!\n"); + usage(); + exit(1); + } + + if (add_user) + { + if (!user_name) + { + fprintf (stderr, "Username not specified! (use -u option)\n"); + return -1; + } + if (machine) return new_machine (user_name); + else return new_user (user_name, full_name, home_dir, home_drive, logon_script, profile_path); + } + + if (delete_user) + { + if (!user_name) + { + fprintf (stderr, "Username not specified! (use -u option)\n"); + return -1; + } + if (machine) return delete_machine_entry (user_name); + else return delete_user_entry (user_name); + } + + if (user_name) + { + if (setparms) set_user_info ( user_name, + full_name, + home_dir, + home_drive, + logon_script, + profile_path); + + else return print_user_info (user_name, verbose, spstyle); + + return 0; + } + + + if (list_users) + return print_users_list (verbose, spstyle); + + if (import) + return import_users (smbpasswd); + + usage(); + + return 0; +} + + -- cgit From 34402b75b5628684ee527c0fd2e263412ee2a008 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 7 Dec 2000 06:05:57 +0000 Subject: Added undocumented -t command for testing parsing of acl entries. Print out hex value for ace mask if we can't decode it. We can now parse FULL,CHANGE,READ as well as combos of RWXDPO as ace mask values. Clarified usage message. Bomb out if excess args are given. (This used to be commit ed5bda119a984e124d24f168db15e15da62ceaa5) --- source3/utils/smbcacls.c | 129 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 118 insertions(+), 11 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 570a0b3155..4d6622b0ef 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -25,6 +25,7 @@ static fstring password; static fstring username; static int got_pass; +static int test_args; /* numeric is set when the user wants numeric SIDs and ACEs rather than going via LSA calls to resolve them */ @@ -88,6 +89,8 @@ static void print_ace(FILE *f, SEC_ACE *ace) { struct perm_value *v; fstring sidstr; + int do_print = 0; + uint32 got_mask; SidToString(sidstr, &ace->sid); @@ -122,11 +125,27 @@ static void print_ace(FILE *f, SEC_ACE *ace) } } - /* Special permissions */ + /* Special permissions. Print out a hex value if we have + leftover bits in the mask. */ + got_mask = ace->info.mask; + + again: for (v = special_values; v->perm; v++) { if ((ace->info.mask & v->mask) == v->mask) { - fprintf(f, "%s", v->perm); + if (do_print) { + fprintf(f, "%s", v->perm); + } + got_mask &= ~v->mask; + } + } + + if (!do_print) { + if (got_mask != 0) { + fprintf(f, "0x%08x", ace->info.mask); + } else { + do_print = 1; + goto again; } } @@ -138,18 +157,89 @@ static void print_ace(FILE *f, SEC_ACE *ace) static BOOL parse_ace(SEC_ACE *ace, char *str) { char *p; + fstring tok; unsigned atype, aflags, amask; DOM_SID sid; SEC_ACCESS mask; + struct perm_value *v; + ZERO_STRUCTP(ace); p = strchr(str,':'); if (!p) return False; - *p = 0; - if (sscanf(p+1, "%i/%i/%i", - &atype, &aflags, &amask) != 3 || - !StringToSid(&sid, str)) { + *p = '\0'; + p++; + + /* Try to parse numeric form */ + + if (sscanf(p, "%i/%i/%i", &atype, &aflags, &amask) == 3 && + StringToSid(&sid, str)) { + goto done; + } + + /* Try to parse text form */ + + if (!string_to_sid(&sid, str)) { + return False; + } + + if (!next_token(&p, tok, "/", sizeof(fstring))) { + return False; + } + + if (strncmp(tok, "ALLOWED", strlen("ALLOWED")) == 0) { + atype = SEC_ACE_TYPE_ACCESS_ALLOWED; + } else if (strncmp(tok, "DENIED", strlen("DENIED")) == 0) { + atype = SEC_ACE_TYPE_ACCESS_DENIED; + } else { + return False; + } + + /* Only numeric form accepted for flags at present */ + + if (!(next_token(NULL, tok, "/", sizeof(fstring)) && + sscanf(tok, "%i", &aflags))) { + return False; + } + + if (!next_token(NULL, tok, "/", sizeof(fstring))) { return False; } + + if (strncmp(tok, "0x", 2) == 0) { + if (sscanf(tok, "%i", &amask) != 1) { + return False; + } + goto done; + } + + for (v = standard_values; v->perm; v++) { + if (strcmp(tok, v->perm) == 0) { + amask = v->mask; + goto done; + } + } + + p = tok; + + while(*p) { + BOOL found = False; + + for (v = special_values; v->perm; v++) { + if (v->perm[0] == *p) { + amask |= v->mask; + found = True; + } + } + + if (!found) return False; + p++; + } + + if (*p) { + return False; + } + + done: mask.mask = amask; init_sec_ace(ace, &sid, atype, mask, aflags); return True; @@ -229,6 +319,7 @@ static SEC_DESC *sec_desc_parse(char *str) NULL, dacl, &sd_size); free_sec_acl(&dacl); + if (grp_sid) free(grp_sid); if (owner_sid) free(owner_sid); @@ -280,6 +371,8 @@ static void cacl_dump(struct cli_state *cli, char *filename) int fnum; SEC_DESC *sd; + if (test_args) return; + fnum = cli_nt_create(cli, filename, 0x20000); if (fnum == -1) { printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); @@ -317,6 +410,8 @@ static void cacl_set(struct cli_state *cli, char *filename, return; } + if (test_args) return; + /* the desired access below is the only one I could find that works with NT4, W2KP and Samba */ fnum = cli_nt_create(cli, filename, MAXIMUM_ALLOWED_ACCESS | 0x60000); @@ -492,16 +587,17 @@ struct cli_state *connect_one(char *share) static void usage(void) { printf( -"Usage: smbcacls //server1/share1 filename [options]\n\n\ +"Usage: smbcacls //server1/share1 filename -U username [options]\n\ \n\ \t-D delete an acl\n\ \t-M modify an acl\n\ \t-A add an acl\n\ \t-S set acls\n\ -\t-U username set the network username\n\ \t-n don't resolve sids or masks to names\n\ \t-h print help\n\ \n\ +The username can be of the form username%%password or\n\ +workgroup\\username%%password.\n\n\ An acl is of the form ACL::type/flags/mask\n\ You can string acls together with spaces, commas or newlines\n\ "); @@ -556,7 +652,7 @@ You can string acls together with spaces, commas or newlines\n\ seed = time(NULL); - while ((opt = getopt(argc, argv, "U:nhS:D:A:M:")) != EOF) { + while ((opt = getopt(argc, argv, "U:nhS:D:A:M:t")) != EOF) { switch (opt) { case 'U': pstrcpy(username,optarg); @@ -592,6 +688,10 @@ You can string acls together with spaces, commas or newlines\n\ numeric = 1; break; + case 't': + test_args = 1; + break; + case 'h': usage(); exit(1); @@ -604,9 +704,16 @@ You can string acls together with spaces, commas or newlines\n\ argc -= optind; argv += optind; + + if (argc > 0) { + usage(); + exit(1); + } - cli = connect_one(share); - if (!cli) exit(1); + if (!test_args) { + cli = connect_one(share); + if (!cli) exit(1); + } if (acl) { cacl_set(cli, filename, acl, mode); -- cgit From ccb5cbf175c43455a956d42b2815a4529ab9383f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 11 Dec 2000 21:09:48 +0000 Subject: Fixed very subtle bug returning correct error on an open, when we have a choice of invalid share mode and access denied. We must return the access denied by preference, but also remember to break the oplocks... This is needed for multi-user MS-Access. Jeremy. (This used to be commit 7eb7241442ea0f1e065b009c3cccd5821b89a8b6) --- source3/utils/torture.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index d9aa6bfca0..cd348f67fd 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -2010,7 +2010,7 @@ static void run_oplock2(int dummy) printf("lock failed (%s)\n", cli_errstr(&cli1)); } - cli_unlock(&cli, fnum1, 0, 4); + cli_unlock(&cli1, fnum1, 0, 4); sleep(2); @@ -2018,7 +2018,7 @@ static void run_oplock2(int dummy) printf("lock failed (%s)\n", cli_errstr(&cli1)); } - cli_unlock(&cli, fnum1, 0, 4); + cli_unlock(&cli1, fnum1, 0, 4); sleep(2); @@ -2045,6 +2045,72 @@ static void run_oplock2(int dummy) printf("finished oplock test 2\n"); } +/* + Test open mode returns on read-only files. + */ +static void run_opentest(int dummy) +{ + static struct cli_state cli1; + char *fname = "\\readonly.file"; + int fnum1, fnum2; + uint8 eclass; + uint32 errnum; + + printf("starting open test\n"); + + if (!open_connection(&cli1)) { + return; + } + + cli_setatr(&cli1, fname, 0, 0); + cli_unlink(&cli1, fname); + + cli_sockopt(&cli1, sockops); + + fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + if (!cli_close(&cli1, fnum1)) { + printf("close2 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + if (!cli_setatr(&cli1, fname, aRONLY, 0)) { + printf("cli_setatr failed (%s)\n", cli_errstr(&cli1)); + return; + } + + fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + /* This will fail - but the error should be ERRnoaccess, not ERRshare. */ + fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL); + + cli_error( &cli1, &eclass, &errnum, NULL); + + if (eclass != ERRDOS || errnum != ERRnoaccess) { + printf("wrong error code (%x,%x) = %s\n", (unsigned int)eclass, + (unsigned int)errnum, cli_errstr(&cli1) ); + } else { + printf("correct error code ERRDOS/ERRnoaccess returned\n"); + } + + + cli_close(&cli1, fnum1); + + cli_setatr(&cli1, fname, 0, 0); + cli_unlink(&cli1, fname); + + close_connection(&cli1); + + printf("finished open test 1\n"); +} static void list_fn(file_info *finfo, const char *name) { @@ -2212,6 +2278,7 @@ static struct { {"TCON", run_tcon_test, 0}, {"RW1", run_readwritetest, 0}, {"RW2", run_readwritemulti, FLAG_MULTIPROC}, + {"OPEN", run_opentest, 0}, {NULL, NULL, 0}}; -- cgit From cbddae005f1e6e787be925fab6e4b34f2a3471f0 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 12 Dec 2000 06:06:10 +0000 Subject: Better error checking for ACL parsing. Print an error when attempting to delete a non-existent ACL. (This used to be commit d119782d0d8d2738650da47fa11134d26134ce17) --- source3/utils/smbcacls.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 4d6622b0ef..aff5244fc5 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -281,10 +281,12 @@ static SEC_DESC *sec_desc_parse(char *str) if (strncmp(tok,"REVISION:", 9) == 0) { revision = strtol(tok+9, NULL, 16); + continue; } if (strncmp(tok,"TYPE:", 5) == 0) { type = strtol(tok+5, NULL, 16); + continue; } if (strncmp(tok,"OWNER:", 6) == 0) { @@ -294,6 +296,7 @@ static SEC_DESC *sec_desc_parse(char *str) printf("Failed to parse owner sid\n"); return NULL; } + continue; } if (strncmp(tok,"GROUP:", 6) == 0) { @@ -303,6 +306,7 @@ static SEC_DESC *sec_desc_parse(char *str) printf("Failed to parse group sid\n"); return NULL; } + continue; } if (strncmp(tok,"ACL:", 4) == 0) { @@ -312,7 +316,11 @@ static SEC_DESC *sec_desc_parse(char *str) printf("Failed to parse ACL\n"); return NULL; } + continue; } + + printf("Failed to parse security descriptor\n"); + return NULL; } ret = make_sec_desc(revision, owner_sid, grp_sid, @@ -405,11 +413,8 @@ static void cacl_set(struct cli_state *cli, char *filename, unsigned sd_size; sd = sec_desc_parse(acl); - if (!sd) { - printf("Failed to parse security descriptor\n"); - return; - } + if (!sd) return; if (test_args) return; /* the desired access below is the only one I could find that works with @@ -426,6 +431,8 @@ static void cacl_set(struct cli_state *cli, char *filename, switch (mode) { case ACL_DELETE: for (i=0;sd->dacl && idacl->num_aces;i++) { + BOOL found = False; + for (j=0;old->dacl && jdacl->num_aces;j++) { if (sec_ace_equal(&sd->dacl->ace[i], &old->dacl->ace[j])) { @@ -440,9 +447,17 @@ static void cacl_set(struct cli_state *cli, char *filename, old->dacl = NULL; old->off_dacl = 0; } + found = True; break; } } + + if (!found) { + fstring str; + + SidToString(str, &sd->dacl->ace[i].sid); + printf("ACL for SID %s not found\n", str); + } } break; @@ -475,10 +490,9 @@ static void cacl_set(struct cli_state *cli, char *filename, break; case ACL_SET: - free_sec_desc(&old); - old = sd; + free_sec_desc(&old); + old = sd; break; - } if (sd != old) { -- cgit From 76dca9c1fb42ea461dbf95e7357385e8692bc94b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 12 Dec 2000 06:14:01 +0000 Subject: Don't print out the security descriptor type as it is automatically calculated by the new make_sec_desc() function. (This used to be commit 6fd5dc81458317e106f5ea24958cefe4146c90a6) --- source3/utils/smbcacls.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index aff5244fc5..ae852b3e3c 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -275,7 +275,6 @@ static SEC_DESC *sec_desc_parse(char *str) DOM_SID *grp_sid=NULL, *owner_sid=NULL; SEC_ACL *dacl=NULL; int revision=1; - int type=0x8004; while (next_token(&p, tok, " \t,\r\n", sizeof(tok))) { @@ -284,11 +283,6 @@ static SEC_DESC *sec_desc_parse(char *str) continue; } - if (strncmp(tok,"TYPE:", 5) == 0) { - type = strtol(tok+5, NULL, 16); - continue; - } - if (strncmp(tok,"OWNER:", 6) == 0) { owner_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID)); if (!owner_sid || @@ -341,7 +335,7 @@ static void sec_desc_print(FILE *f, SEC_DESC *sd) fstring sidstr; int i; - printf("REVISION:%d\nTYPE:0x%x\n", sd->revision, sd->type); + printf("REVISION:%d\n", sd->revision); /* Print owner and group sid */ -- cgit From 56ee3e2e2f19164e7d0f873a43be2cfb5970d2f3 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 13 Dec 2000 12:53:42 +0000 Subject: Convert names to sids when modifying ACLs. Convert sids to names when displaying ACLs. (This used to be commit 5001bbc64be62af1597eb334e5b530b415d62a6b) --- source3/utils/smbcacls.c | 78 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index ae852b3e3c..1ffd7495d0 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -24,6 +24,7 @@ static fstring password; static fstring username; +static fstring server; static int got_pass; static int test_args; @@ -60,27 +61,85 @@ static struct perm_value standard_values[] = { /* convert a SID to a string, either numeric or username/group */ static void SidToString(fstring str, DOM_SID *sid) { - if (numeric) { + struct cli_state cli; + POLICY_HND pol; + struct ntuser_creds creds; + char **names; + uint32 *types; + int num_names; + + ZERO_STRUCT(creds); + ZERO_STRUCT(cli); + ZERO_STRUCT(pol); + + creds.pwd.null_pwd = 1; + + if (numeric || !cli_lsa_initialise(&cli, server, &creds) || + cli_lsa_open_policy(&cli, True, SEC_RIGHTS_MAXIMUM_ALLOWED, + &pol) != NT_STATUS_NOPROBLEMO || + cli_lsa_lookup_sids(&cli, &pol, 1, sid, &names, &types, + &num_names) != NT_STATUS_NOPROBLEMO) { sid_to_string(str, sid); - } else { + goto done; + } - /* Need to add LSA lookups */ + fstrcpy(str, names[0]); - sid_to_string(str, sid); + safe_free(names[0]); + safe_free(names); + safe_free(types); + + done: + if (cli.initialised) { + cli_lsa_close(&cli, &pol); + cli_lsa_shutdown(&cli); } } /* convert a string to a SID, either numeric or username/group */ static BOOL StringToSid(DOM_SID *sid, fstring str) { - if (strncmp(str,"S-", 2) == 0) { + uint32 *types; + struct cli_state cli; + struct ntuser_creds creds; + POLICY_HND pol; + int num_sids; + BOOL result = True; + DOM_SID *sids; + + /* Short cut */ + + if (strncmp(str, "S-", 2) == 0) { return string_to_sid(sid, str); - } else { + } - /* Need to add LSA lookups */ + ZERO_STRUCT(creds); + ZERO_STRUCT(cli); + ZERO_STRUCT(pol); - return string_to_sid(sid, str); + creds.pwd.null_pwd = 1; + + if (!cli_lsa_initialise(&cli, server, &creds) || + cli_lsa_open_policy(&cli, True, SEC_RIGHTS_MAXIMUM_ALLOWED, + &pol) != NT_STATUS_NOPROBLEMO || + cli_lsa_lookup_names(&cli, &pol, 1, &str, &sids, &types, + &num_sids) != NT_STATUS_NOPROBLEMO) { + result = string_to_sid(sid, str); + goto done; + } + + sid_copy(sid, &sids[0]); + + safe_free(sids); + safe_free(types); + + done: + if (cli.initialised) { + cli_lsa_close(&cli, &pol); + cli_lsa_shutdown(&cli); } + + return result; } @@ -178,7 +237,7 @@ static BOOL parse_ace(SEC_ACE *ace, char *str) /* Try to parse text form */ - if (!string_to_sid(&sid, str)) { + if (!StringToSid(&sid, str)) { return False; } @@ -516,7 +575,6 @@ struct cli_state *connect_one(char *share) struct cli_state *c; struct nmb_name called, calling; char *server_n; - fstring server; struct in_addr ip; extern struct in_addr ipzero; extern pstring global_myname; -- cgit From 237e74730c4d28754d2cc8f531683513522a95a3 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 14 Dec 2000 03:27:53 +0000 Subject: Cache lsa connection and policy handle for resolving names and sids. (This used to be commit 09d2d972fd6f70bdf62f25936494968ef597b98b) --- source3/utils/smbcacls.c | 104 +++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 48 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 1ffd7495d0..a7f95f5f5e 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -4,6 +4,7 @@ Version 3.0 Copyright (C) Andrew Tridgell 2000 + Copyright (C) Tim Potter 2000 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 @@ -58,72 +59,84 @@ static struct perm_value standard_values[] = { { NULL, 0 }, }; +struct cli_state lsa_cli; +POLICY_HND pol; +struct ntuser_creds creds; +BOOL got_policy_hnd; + +/* Open cli connection and policy handle */ + +static BOOL open_policy_hnd(void) +{ + creds.pwd.null_pwd = 1; + + /* Initialise cli LSA connection */ + + if (!lsa_cli.initialised && + !cli_lsa_initialise(&lsa_cli, server, &creds)) { + return False; + } + + /* Open policy handle */ + + if (!got_policy_hnd) { + if (cli_lsa_open_policy(&lsa_cli, True, + SEC_RIGHTS_MAXIMUM_ALLOWED, &pol) + != NT_STATUS_NOPROBLEMO) { + return False; + } + + got_policy_hnd = True; + } + + return True; +} + /* convert a SID to a string, either numeric or username/group */ static void SidToString(fstring str, DOM_SID *sid) { - struct cli_state cli; - POLICY_HND pol; - struct ntuser_creds creds; - char **names; - uint32 *types; + char **names = NULL; + uint32 *types = NULL; int num_names; - ZERO_STRUCT(creds); - ZERO_STRUCT(cli); - ZERO_STRUCT(pol); + sid_to_string(str, sid); - creds.pwd.null_pwd = 1; + if (numeric) return; - if (numeric || !cli_lsa_initialise(&cli, server, &creds) || - cli_lsa_open_policy(&cli, True, SEC_RIGHTS_MAXIMUM_ALLOWED, - &pol) != NT_STATUS_NOPROBLEMO || - cli_lsa_lookup_sids(&cli, &pol, 1, sid, &names, &types, - &num_names) != NT_STATUS_NOPROBLEMO) { - sid_to_string(str, sid); - goto done; - } + /* Ask LSA to convert the sid to a name */ - fstrcpy(str, names[0]); + if (open_policy_hnd() && + cli_lsa_lookup_sids(&lsa_cli, &pol, 1, sid, &names, &types, + &num_names) == NT_STATUS_NOPROBLEMO) { - safe_free(names[0]); - safe_free(names); - safe_free(types); + /* Converted OK */ - done: - if (cli.initialised) { - cli_lsa_close(&cli, &pol); - cli_lsa_shutdown(&cli); + fstrcpy(str, names[0]); + + safe_free(names[0]); + safe_free(names); + safe_free(types); } } /* convert a string to a SID, either numeric or username/group */ static BOOL StringToSid(DOM_SID *sid, fstring str) { - uint32 *types; - struct cli_state cli; - struct ntuser_creds creds; - POLICY_HND pol; + uint32 *types = NULL; + DOM_SID *sids = NULL; int num_sids; - BOOL result = True; - DOM_SID *sids; + BOOL result = False; /* Short cut */ if (strncmp(str, "S-", 2) == 0) { - return string_to_sid(sid, str); + result = string_to_sid(sid, str); + goto done; } - ZERO_STRUCT(creds); - ZERO_STRUCT(cli); - ZERO_STRUCT(pol); - - creds.pwd.null_pwd = 1; - - if (!cli_lsa_initialise(&cli, server, &creds) || - cli_lsa_open_policy(&cli, True, SEC_RIGHTS_MAXIMUM_ALLOWED, - &pol) != NT_STATUS_NOPROBLEMO || - cli_lsa_lookup_names(&cli, &pol, 1, &str, &sids, &types, - &num_sids) != NT_STATUS_NOPROBLEMO) { + if (open_policy_hnd() && + cli_lsa_lookup_names(&lsa_cli, &pol, 1, &str, &sids, &types, + &num_sids) == NT_STATUS_NOPROBLEMO) { result = string_to_sid(sid, str); goto done; } @@ -134,11 +147,6 @@ static BOOL StringToSid(DOM_SID *sid, fstring str) safe_free(types); done: - if (cli.initialised) { - cli_lsa_close(&cli, &pol); - cli_lsa_shutdown(&cli); - } - return result; } -- cgit From 624431c98b78185bf402562d4194a98d86a60bcc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 14 Dec 2000 05:38:05 +0000 Subject: Renamed parameters and variables called acl to the_acl as it conflicts with a Solaris system call. (This used to be commit 5e547ddcb526be5562db9213c5b36e505e735a2e) --- source3/utils/smbcacls.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index a7f95f5f5e..c017c16bdf 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -313,22 +313,22 @@ static BOOL parse_ace(SEC_ACE *ace, char *str) } /* add an ACE to a list of ACEs in a SEC_ACL */ -static BOOL add_ace(SEC_ACL **acl, SEC_ACE *ace) +static BOOL add_ace(SEC_ACL **the_acl, SEC_ACE *ace) { SEC_ACL *new; SEC_ACE *aces; - if (! *acl) { - (*acl) = make_sec_acl(3, 1, ace); + if (! *the_acl) { + (*the_acl) = make_sec_acl(3, 1, ace); return True; } - aces = calloc(1+(*acl)->num_aces,sizeof(SEC_ACE)); - memcpy(aces, (*acl)->ace, (*acl)->num_aces * sizeof(SEC_ACE)); - memcpy(aces+(*acl)->num_aces, ace, sizeof(SEC_ACE)); - new = make_sec_acl((*acl)->revision,1+(*acl)->num_aces, aces); - free_sec_acl(acl); + aces = calloc(1+(*the_acl)->num_aces,sizeof(SEC_ACE)); + memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE)); + memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE)); + new = make_sec_acl((*the_acl)->revision,1+(*the_acl)->num_aces, aces); + free_sec_acl(the_acl); free(aces); - (*acl) = new; + (*the_acl) = new; return True; } @@ -466,14 +466,14 @@ static void cacl_dump(struct cli_state *cli, char *filename) set the ACLs on a file given an ascii description *******************************************************/ static void cacl_set(struct cli_state *cli, char *filename, - char *acl, enum acl_mode mode) + char *the_acl, enum acl_mode mode) { int fnum; SEC_DESC *sd, *old; int i, j; unsigned sd_size; - sd = sec_desc_parse(acl); + sd = sec_desc_parse(the_acl); if (!sd) return; if (test_args) return; @@ -693,7 +693,7 @@ You can string acls together with spaces, commas or newlines\n\ static pstring servicesf = CONFIGFILE; struct cli_state *cli; enum acl_mode mode; - char *acl = NULL; + char *the_acl = NULL; setlinebuf(stdout); @@ -739,22 +739,22 @@ You can string acls together with spaces, commas or newlines\n\ break; case 'S': - acl = optarg; + the_acl = optarg; mode = ACL_SET; break; case 'D': - acl = optarg; + the_acl = optarg; mode = ACL_DELETE; break; case 'M': - acl = optarg; + the_acl = optarg; mode = ACL_MODIFY; break; case 'A': - acl = optarg; + the_acl = optarg; mode = ACL_ADD; break; @@ -789,8 +789,8 @@ You can string acls together with spaces, commas or newlines\n\ if (!cli) exit(1); } - if (acl) { - cacl_set(cli, filename, acl, mode); + if (the_acl) { + cacl_set(cli, filename, the_acl, mode); } else { cacl_dump(cli, filename); } -- cgit From 369f5fd1d7a6e6298bc3cbe01e3aaed0106f6cf4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 15 Dec 2000 01:02:11 +0000 Subject: Fixed memory leaks in lsa_XX calls. Fixed memory leaks in smbcacls. Merged in fixes from appliance-head and 2.2. Fixed multiple connection.tdb open problem. Jeremy. (This used to be commit 0a40bc83e14c69a09948ec09bb6fc5026c4f4c14) --- source3/utils/smbcacls.c | 24 +++++++++++++++++------- source3/utils/smbcontrol.c | 9 ++++++++- 2 files changed, 25 insertions(+), 8 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index c017c16bdf..3240438a7a 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -120,12 +120,12 @@ static void SidToString(fstring str, DOM_SID *sid) } /* convert a string to a SID, either numeric or username/group */ -static BOOL StringToSid(DOM_SID *sid, fstring str) +static BOOL StringToSid(DOM_SID *sid, char *str) { uint32 *types = NULL; DOM_SID *sids = NULL; int num_sids; - BOOL result = False; + BOOL result = True; /* Short cut */ @@ -136,7 +136,7 @@ static BOOL StringToSid(DOM_SID *sid, fstring str) if (open_policy_hnd() && cli_lsa_lookup_names(&lsa_cli, &pol, 1, &str, &sids, &types, - &num_sids) == NT_STATUS_NOPROBLEMO) { + &num_sids) != NT_STATUS_NOPROBLEMO) { result = string_to_sid(sid, str); goto done; } @@ -147,6 +147,7 @@ static BOOL StringToSid(DOM_SID *sid, fstring str) safe_free(types); done: + return result; } @@ -372,9 +373,12 @@ static SEC_DESC *sec_desc_parse(char *str) if (strncmp(tok,"ACL:", 4) == 0) { SEC_ACE ace; - if (!parse_ace(&ace, tok+4) || - !add_ace(&dacl, &ace)) { - printf("Failed to parse ACL\n"); + if (!parse_ace(&ace, tok+4)) { + printf("Failed to parse ACL %s\n", tok); + return NULL; + } + if(!add_ace(&dacl, &ace)) { + printf("Failed to add ACL %s\n", tok); return NULL; } continue; @@ -565,7 +569,6 @@ static void cacl_set(struct cli_state *cli, char *filename, if (!cli_set_secdesc(cli, fnum, sd)) { printf("ERROR: secdesc set failed: %s\n", cli_errstr(cli)); - return; } free_sec_desc(&sd); @@ -607,12 +610,15 @@ struct cli_state *connect_one(char *share) 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)); + cli_shutdown(c); + safe_free(c); return NULL; } if (!cli_session_request(c, &calling, &called)) { DEBUG(0,("session request to %s failed\n", called.name)); cli_shutdown(c); + safe_free(c); if (strcmp(called.name, "*SMBSERVER")) { make_nmb_name(&called , "*SMBSERVER", 0x20); goto again; @@ -625,6 +631,7 @@ struct cli_state *connect_one(char *share) if (!cli_negprot(c)) { DEBUG(0,("protocol negotiation failed\n")); cli_shutdown(c); + safe_free(c); return NULL; } @@ -640,6 +647,8 @@ struct cli_state *connect_one(char *share) password, strlen(password), lp_workgroup())) { DEBUG(0,("session setup failed: %s\n", cli_errstr(c))); + cli_shutdown(c); + safe_free(c); return NULL; } @@ -649,6 +658,7 @@ struct cli_state *connect_one(char *share) password, strlen(password)+1)) { DEBUG(0,("tree connect failed: %s\n", cli_errstr(c))); cli_shutdown(c); + safe_free(c); return NULL; } diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 991d1d77d2..87d00eecbd 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -118,10 +118,17 @@ send a message to a named destination static BOOL send_message(char *dest, int msg_type, void *buf, int len, BOOL duplicates) { pid_t pid; + TDB_CONTEXT *the_tdb; + + the_tdb = tdb_open(lock_path("connections.tdb"), 0, 0, O_RDONLY, 0); + if (!the_tdb) { + fprintf(stderr,"Failed to open connections database in send_message.\n"); + return False; + } /* "smbd" is the only broadcast operation */ if (strequal(dest,"smbd")) { - return message_send_all(msg_type, buf, len, duplicates); + return message_send_all(the_tdb,msg_type, buf, len, duplicates); } else if (strequal(dest,"nmbd")) { pid = pidfile_pid(dest); if (pid == 0) { -- cgit From 8325948287bde09dd2ad1039f3008a42930809dd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 16 Dec 2000 00:08:05 +0000 Subject: Added -C username and -G username that allow a user (usually Administrator) to change the ownership or group ownership of a file to any arbitrary user from the UNIX command line. This will show the people who quote NT manuals at us about how this is "impossible" how their operating system really works :-). Jeremy. (This used to be commit 12f88c9ba731bdded626b9d011cfc8d2ba09010e) --- source3/utils/smbcacls.c | 66 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 3240438a7a..f8059a8b8b 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -5,6 +5,7 @@ Copyright (C) Andrew Tridgell 2000 Copyright (C) Tim Potter 2000 + Copyright (C) Jeremy Allison 2000 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 @@ -24,7 +25,8 @@ #include "includes.h" static fstring password; -static fstring username; +static pstring username; +static pstring owner_username; static fstring server; static int got_pass; static int test_args; @@ -33,7 +35,8 @@ static int test_args; than going via LSA calls to resolve them */ static int numeric; -enum acl_mode {ACL_SET, ACL_DELETE, ACL_MODIFY, ACL_ADD}; +enum acl_mode {ACL_SET, ACL_DELETE, ACL_MODIFY, ACL_ADD }; +enum chown_mode {REQUEST_NONE, REQUEST_CHOWN, REQUEST_CHGRP}; struct perm_value { char *perm; @@ -466,6 +469,44 @@ static void cacl_dump(struct cli_state *cli, char *filename) cli_close(cli, fnum); } +/***************************************************** +Change the ownership or group ownership of a file. Just +because the NT docs say this can't be done :-). JRA. +*******************************************************/ + +static void owner_set(struct cli_state *cli, enum chown_mode change_mode, char *filename, char *new_username) +{ + int fnum; + DOM_SID sid; + SEC_DESC *sd, *old; + size_t sd_size; + + fnum = cli_nt_create(cli, filename, READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS); + if (fnum == -1) { + printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); + return; + } + + if (!StringToSid(&sid, new_username)) + return; + + old = cli_query_secdesc(cli, fnum); + + sd = make_sec_desc(old->revision, + (change_mode == REQUEST_CHOWN) ? &sid : old->owner_sid, + (change_mode == REQUEST_CHGRP) ? &sid : old->grp_sid, + NULL, old->dacl, &sd_size); + + if (!cli_set_secdesc(cli, fnum, sd)) { + printf("ERROR: secdesc set failed: %s\n", cli_errstr(cli)); + } + + free_sec_desc(&sd); + free_sec_desc(&old); + + cli_close(cli, fnum); +} + /***************************************************** set the ACLs on a file given an ascii description *******************************************************/ @@ -475,7 +516,7 @@ static void cacl_set(struct cli_state *cli, char *filename, int fnum; SEC_DESC *sd, *old; int i, j; - unsigned sd_size; + size_t sd_size; sd = sec_desc_parse(the_acl); @@ -677,6 +718,8 @@ static void usage(void) \t-M modify an acl\n\ \t-A add an acl\n\ \t-S set acls\n\ +\t-C username change ownership of a file\n\ +\t-G username change group ownership of a file\n\ \t-n don't resolve sids or masks to names\n\ \t-h print help\n\ \n\ @@ -704,6 +747,7 @@ You can string acls together with spaces, commas or newlines\n\ struct cli_state *cli; enum acl_mode mode; char *the_acl = NULL; + enum chown_mode change_mode = REQUEST_NONE; setlinebuf(stdout); @@ -736,7 +780,7 @@ You can string acls together with spaces, commas or newlines\n\ seed = time(NULL); - while ((opt = getopt(argc, argv, "U:nhS:D:A:M:t")) != EOF) { + while ((opt = getopt(argc, argv, "U:nhS:D:A:M:C:G:t")) != EOF) { switch (opt) { case 'U': pstrcpy(username,optarg); @@ -768,6 +812,16 @@ You can string acls together with spaces, commas or newlines\n\ mode = ACL_ADD; break; + case 'C': + pstrcpy(owner_username,optarg); + change_mode = REQUEST_CHOWN; + break; + + case 'G': + pstrcpy(owner_username,optarg); + change_mode = REQUEST_CHGRP; + break; + case 'n': numeric = 1; break; @@ -799,7 +853,9 @@ You can string acls together with spaces, commas or newlines\n\ if (!cli) exit(1); } - if (the_acl) { + if (change_mode != REQUEST_NONE) { + owner_set(cli, change_mode, filename, owner_username); + } else if (the_acl) { cacl_set(cli, filename, the_acl, mode); } else { cacl_dump(cli, filename); -- cgit From abb9a2de72073a8a6f332b60d74af9eb6c3d6f25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 20 Dec 2000 03:22:51 +0000 Subject: implemented a much nicer name_status() interface. It now returns a list of structures rather than the dodgy parsing code we had before this also gets smbw working correctly with no initial workgroup (using name_status_find on __MSBROWSE__ returns) (This used to be commit f2be88a8738a39ca5c98936edb7537cd701348a1) --- source3/utils/nmblookup.c | 57 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 6 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 2cdd85fae8..4e85f6ac45 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -80,6 +80,55 @@ static void usage(void) printf("\n"); } +/**************************************************************************** +turn a node status flags field into a string +****************************************************************************/ +static char *node_status_flags(unsigned char flags) +{ + static fstring ret; + fstrcpy(ret,""); + + fstrcat(ret, (flags & 0x80) ? " " : " "); + if ((flags & 0x60) == 0x00) fstrcat(ret,"B "); + if ((flags & 0x60) == 0x20) fstrcat(ret,"P "); + if ((flags & 0x60) == 0x40) fstrcat(ret,"M "); + if ((flags & 0x60) == 0x60) fstrcat(ret,"H "); + if (flags & 0x10) fstrcat(ret," "); + if (flags & 0x08) fstrcat(ret," "); + if (flags & 0x04) fstrcat(ret," "); + if (flags & 0x02) fstrcat(ret," "); + + return ret; +} + +/**************************************************************************** +do a node status query +****************************************************************************/ +static void do_node_status(int fd, char *name, int type, struct in_addr ip) +{ + struct nmb_name nname; + int count, i, j; + struct node_status *status; + fstring cleanname; + + printf("Looking up status of %s\n",inet_ntoa(ip)); + make_nmb_name(&nname, name, type); + status = name_status_query(fd,&nname,ip, &count); + if (status) { + for (i=0;i - %s\n", + cleanname,status[i].type, + node_status_flags(status[i].flags)); + } + free(status); + } + printf("\n"); +} + /**************************************************************************** send out one query @@ -125,9 +174,7 @@ static BOOL query_one(char *lookup, unsigned int lookup_type) was valid - ie. name_query returned true. */ if (find_status) { - printf("Looking up status of %s\n",inet_ntoa(ip_list[0])); - name_status(ServerFD,lookup,lookup_type,True,ip_list[0],NULL,NULL); - printf("\n"); + do_node_status(ServerFD, lookup, lookup_type, ip_list[0]); } safe_free(ip_list); @@ -245,9 +292,7 @@ int main(int argc,char *argv[]) { fstrcpy(lookup,"*"); ip = *interpret_addr2(argv[i]); - printf("Looking up status of %s\n",inet_ntoa(ip)); - name_status(ServerFD,lookup,lookup_type,True,ip,NULL,NULL); - printf("\n"); + do_node_status(ServerFD, lookup, lookup_type, ip); continue; } -- cgit From d15bef816ddbbeb505f72f1682d6fa48b2900edb Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 21 Dec 2000 00:12:59 +0000 Subject: Cleaned up SidToString() and StringToSid() exit paths. Can now use user%password format in $USER environment variable. -U option is now optional. (This used to be commit e21f2ef4fbfae1451d77b53291a78646dee9cfce) --- source3/utils/smbcacls.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index f8059a8b8b..bff80e7e5f 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -108,18 +108,19 @@ static void SidToString(fstring str, DOM_SID *sid) /* Ask LSA to convert the sid to a name */ - if (open_policy_hnd() && + if (!open_policy_hnd() || cli_lsa_lookup_sids(&lsa_cli, &pol, 1, sid, &names, &types, - &num_names) == NT_STATUS_NOPROBLEMO) { - - /* Converted OK */ - - fstrcpy(str, names[0]); - - safe_free(names[0]); - safe_free(names); - safe_free(types); + &num_names) != NT_STATUS_NOPROBLEMO) { + return; } + + /* Converted OK */ + + fstrcpy(str, names[0]); + + safe_free(names[0]); + safe_free(names); + safe_free(types); } /* convert a string to a SID, either numeric or username/group */ @@ -130,14 +131,11 @@ static BOOL StringToSid(DOM_SID *sid, char *str) int num_sids; BOOL result = True; - /* Short cut */ - if (strncmp(str, "S-", 2) == 0) { - result = string_to_sid(sid, str); - goto done; + return string_to_sid(sid, str); } - if (open_policy_hnd() && + if (!open_policy_hnd() || cli_lsa_lookup_names(&lsa_cli, &pol, 1, &str, &sids, &types, &num_sids) != NT_STATUS_NOPROBLEMO) { result = string_to_sid(sid, str); @@ -712,7 +710,7 @@ struct cli_state *connect_one(char *share) static void usage(void) { printf( -"Usage: smbcacls //server1/share1 filename -U username [options]\n\ +"Usage: smbcacls //server1/share1 filename [options]\n\ \n\ \t-D delete an acl\n\ \t-M modify an acl\n\ @@ -753,7 +751,7 @@ You can string acls together with spaces, commas or newlines\n\ dbf = stderr; - if (argc < 4 || argv[1][0] == '-') { + if (argc < 3 || argv[1][0] == '-') { usage(); exit(1); } @@ -776,6 +774,14 @@ You can string acls together with spaces, commas or newlines\n\ if (getenv("USER")) { pstrcpy(username,getenv("USER")); + + if ((p=strchr(username,'%'))) { + *p = 0; + pstrcpy(password,p+1); + got_pass = True; + memset(strchr(getenv("USER"), '%') + 1, 'X', + strlen(password)); + } } seed = time(NULL); @@ -848,11 +854,15 @@ You can string acls together with spaces, commas or newlines\n\ exit(1); } + /* Make connection to server */ + if (!test_args) { cli = connect_one(share); if (!cli) exit(1); } + /* Perform requested action */ + if (change_mode != REQUEST_NONE) { owner_set(cli, change_mode, filename, owner_username); } else if (the_acl) { -- cgit From 855bcea38e1c6264dced36c85fa949210f9c37a4 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 21 Dec 2000 05:28:39 +0000 Subject: Some systems seem to only accept a ntcreate&x with a unicode filename despite samba negotiating ascii filenames. Retry with unicode pathnames if the ascii version fails. Convert all forward slashes to backslashes in the filename argument. (This used to be commit 935b77573ec82bece6211a9f61c800ef1c8c9aa4) --- source3/utils/smbcacls.c | 50 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index bff80e7e5f..d73699264f 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -436,6 +436,29 @@ static void sec_desc_print(FILE *f, SEC_DESC *sd) } +/* Some systems seem to require unicode pathnames for the ntcreate&x call + despite Samba negotiating ascii filenames. Try with unicode pathname if + the ascii version fails. */ + +int do_cli_nt_create(struct cli_state *cli, char *fname, uint32 DesiredAccess) +{ + int result; + + result = cli_nt_create(cli, fname, DesiredAccess); + + if (result == -1) { + uint32 errnum, nt_rpc_error; + uint8 errclass; + + cli_error(cli, &errclass, &errnum, &nt_rpc_error); + + if (errclass == ERRDOS && errnum == ERRbadpath) { + result = cli_nt_create_uni(cli, fname, DesiredAccess); + } + } + + return result; +} /***************************************************** dump the acls for a file @@ -447,7 +470,7 @@ static void cacl_dump(struct cli_state *cli, char *filename) if (test_args) return; - fnum = cli_nt_create(cli, filename, 0x20000); + fnum = do_cli_nt_create(cli, filename, 0x20000); if (fnum == -1) { printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); return; @@ -479,7 +502,10 @@ static void owner_set(struct cli_state *cli, enum chown_mode change_mode, char * SEC_DESC *sd, *old; size_t sd_size; - fnum = cli_nt_create(cli, filename, READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS); + fnum = do_cli_nt_create(cli, filename, + READ_CONTROL_ACCESS | WRITE_DAC_ACCESS + | WRITE_OWNER_ACCESS); + if (fnum == -1) { printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); return; @@ -521,9 +547,12 @@ static void cacl_set(struct cli_state *cli, char *filename, if (!sd) return; if (test_args) return; - /* the desired access below is the only one I could find that works with - NT4, W2KP and Samba */ - fnum = cli_nt_create(cli, filename, MAXIMUM_ALLOWED_ACCESS | 0x60000); + /* The desired access below is the only one I could find that works + with NT4, W2KP and Samba */ + + fnum = do_cli_nt_create(cli, filename, + MAXIMUM_ALLOWED_ACCESS | 0x60000); + if (fnum == -1) { printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); return; @@ -861,6 +890,17 @@ You can string acls together with spaces, commas or newlines\n\ if (!cli) exit(1); } + + { + char *s; + + s = filename; + while(*s) { + if (*s == '/') *s = '\\'; + s++; + } + } + /* Perform requested action */ if (change_mode != REQUEST_NONE) { -- cgit From ca727bd638934f0ab581507809d0f294495aaef2 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 21 Dec 2000 06:21:26 +0000 Subject: Don't call string_to_sid after cli_lsa_lookup_names() fails. Can't use space as a ACL separator as it breaks NT user/group names that contain spaces (i.e most of the default ones). The MSDN is contradictory over the exact ordering of ACE entries in an ACL. However NT4 gives a "The information may have been modified by a computer running Windows NT 5.0" if denied ACEs do not appear before allowed ACEs. Sort ACE list before calling cli_set_secdesc(). (This used to be commit 01a89978ff4b9fcc813c4f251ddfe23c0485a696) --- source3/utils/smbcacls.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index d73699264f..a193a14043 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -138,7 +138,7 @@ static BOOL StringToSid(DOM_SID *sid, char *str) if (!open_policy_hnd() || cli_lsa_lookup_names(&lsa_cli, &pol, 1, &str, &sids, &types, &num_sids) != NT_STATUS_NOPROBLEMO) { - result = string_to_sid(sid, str); + result = False; goto done; } @@ -345,7 +345,7 @@ static SEC_DESC *sec_desc_parse(char *str) SEC_ACL *dacl=NULL; int revision=1; - while (next_token(&p, tok, " \t,\r\n", sizeof(tok))) { + while (next_token(&p, tok, "\t,\r\n", sizeof(tok))) { if (strncmp(tok,"REVISION:", 9) == 0) { revision = strtol(tok+9, NULL, 16); @@ -531,6 +531,51 @@ static void owner_set(struct cli_state *cli, enum chown_mode change_mode, char * cli_close(cli, fnum); } +/* The MSDN is contradictory over the ordering of ACE entries in an ACL. + However NT4 gives a "The information may have been modified by a + computer running Windows NT 5.0" if denied ACEs do not appear before + allowed ACEs. */ + +static void sort_acl(SEC_ACL *the_acl) +{ + SEC_ACE *tmp_ace; + int i, ace_ndx = 0; + BOOL do_denied = True; + + tmp_ace = (SEC_ACE *)malloc(sizeof(SEC_ACE) * the_acl->num_aces); + + if (!tmp_ace) return; + + copy_aces: + + for (i = 0; i < the_acl->num_aces; i++) { + + /* Copy denied ACEs */ + + if (do_denied && + the_acl->ace[i].type == SEC_ACE_TYPE_ACCESS_DENIED) { + tmp_ace[ace_ndx] = the_acl->ace[i]; + ace_ndx++; + } + + /* Copy other ACEs */ + + if (!do_denied && + the_acl->ace[i].type != SEC_ACE_TYPE_ACCESS_DENIED) { + tmp_ace[ace_ndx] = the_acl->ace[i]; + ace_ndx++; + } + } + + if (do_denied) { + do_denied = False; + goto copy_aces; + } + + free(the_acl->ace); + the_acl->ace = tmp_ace; +} + /***************************************************** set the ACLs on a file given an ascii description *******************************************************/ @@ -632,6 +677,12 @@ static void cacl_set(struct cli_state *cli, char *filename, free_sec_desc(&sd); } + /* Denied ACE entries must come before allowed ones */ + + sort_acl(old->dacl); + + /* Create new security descriptor and set it */ + sd = make_sec_desc(old->revision, old->owner_sid, old->grp_sid, NULL, old->dacl, &sd_size); @@ -639,6 +690,8 @@ static void cacl_set(struct cli_state *cli, char *filename, printf("ERROR: secdesc set failed: %s\n", cli_errstr(cli)); } + /* Clean up */ + free_sec_desc(&sd); free_sec_desc(&old); -- cgit From 1459f1022c8a1b7be6d0e148ebe1a6bef2941b50 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 21 Dec 2000 23:36:25 +0000 Subject: Return appropriate exit codes for various situations: 0 for success 1 if operation failed 2 command line parse error (This used to be commit b4773618acb60b62b20b01ff7ba749984c1379fb) --- source3/utils/smbcacls.c | 54 ++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 22 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index a193a14043..7600989655 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -37,6 +37,7 @@ static int numeric; enum acl_mode {ACL_SET, ACL_DELETE, ACL_MODIFY, ACL_ADD }; enum chown_mode {REQUEST_NONE, REQUEST_CHOWN, REQUEST_CHGRP}; +enum exit_values {EXIT_OK, EXIT_FAILED, EXIT_PARSE_ERROR}; struct perm_value { char *perm; @@ -463,24 +464,24 @@ int do_cli_nt_create(struct cli_state *cli, char *fname, uint32 DesiredAccess) /***************************************************** dump the acls for a file *******************************************************/ -static void cacl_dump(struct cli_state *cli, char *filename) +static int cacl_dump(struct cli_state *cli, char *filename) { int fnum; SEC_DESC *sd; - if (test_args) return; + if (test_args) return EXIT_OK; fnum = do_cli_nt_create(cli, filename, 0x20000); if (fnum == -1) { printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); - return; + return EXIT_FAILED; } sd = cli_query_secdesc(cli, fnum); if (!sd) { printf("ERROR: secdesc query failed: %s\n", cli_errstr(cli)); - return; + return EXIT_FAILED; } sec_desc_print(stdout, sd); @@ -488,6 +489,8 @@ static void cacl_dump(struct cli_state *cli, char *filename) free_sec_desc(&sd); cli_close(cli, fnum); + + return EXIT_OK; } /***************************************************** @@ -495,7 +498,8 @@ Change the ownership or group ownership of a file. Just because the NT docs say this can't be done :-). JRA. *******************************************************/ -static void owner_set(struct cli_state *cli, enum chown_mode change_mode, char *filename, char *new_username) +static int owner_set(struct cli_state *cli, enum chown_mode change_mode, + char *filename, char *new_username) { int fnum; DOM_SID sid; @@ -508,11 +512,11 @@ static void owner_set(struct cli_state *cli, enum chown_mode change_mode, char * if (fnum == -1) { printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); - return; + return EXIT_FAILED; } if (!StringToSid(&sid, new_username)) - return; + return EXIT_PARSE_ERROR; old = cli_query_secdesc(cli, fnum); @@ -529,6 +533,8 @@ static void owner_set(struct cli_state *cli, enum chown_mode change_mode, char * free_sec_desc(&old); cli_close(cli, fnum); + + return EXIT_OK; } /* The MSDN is contradictory over the ordering of ACE entries in an ACL. @@ -579,18 +585,19 @@ static void sort_acl(SEC_ACL *the_acl) /***************************************************** set the ACLs on a file given an ascii description *******************************************************/ -static void cacl_set(struct cli_state *cli, char *filename, - char *the_acl, enum acl_mode mode) +static int cacl_set(struct cli_state *cli, char *filename, + char *the_acl, enum acl_mode mode) { int fnum; SEC_DESC *sd, *old; int i, j; size_t sd_size; + int result = EXIT_OK; sd = sec_desc_parse(the_acl); - if (!sd) return; - if (test_args) return; + if (!sd) return EXIT_PARSE_ERROR; + if (test_args) return EXIT_OK; /* The desired access below is the only one I could find that works with NT4, W2KP and Samba */ @@ -600,7 +607,7 @@ static void cacl_set(struct cli_state *cli, char *filename, if (fnum == -1) { printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); - return; + return EXIT_FAILED; } old = cli_query_secdesc(cli, fnum); @@ -688,6 +695,7 @@ static void cacl_set(struct cli_state *cli, char *filename, if (!cli_set_secdesc(cli, fnum, sd)) { printf("ERROR: secdesc set failed: %s\n", cli_errstr(cli)); + result = EXIT_FAILED; } /* Clean up */ @@ -696,6 +704,8 @@ static void cacl_set(struct cli_state *cli, char *filename, free_sec_desc(&old); cli_close(cli, fnum); + + return result; } @@ -828,6 +838,7 @@ You can string acls together with spaces, commas or newlines\n\ enum acl_mode mode; char *the_acl = NULL; enum chown_mode change_mode = REQUEST_NONE; + int result; setlinebuf(stdout); @@ -835,7 +846,7 @@ You can string acls together with spaces, commas or newlines\n\ if (argc < 3 || argv[1][0] == '-') { usage(); - exit(1); + exit(EXIT_PARSE_ERROR); } setup_logging(argv[0],True); @@ -920,11 +931,11 @@ You can string acls together with spaces, commas or newlines\n\ case 'h': usage(); - exit(1); + exit(EXIT_PARSE_ERROR); default: printf("Unknown option %c (%d)\n", (char)opt, opt); - exit(1); + exit(EXIT_PARSE_ERROR); } } @@ -933,17 +944,16 @@ You can string acls together with spaces, commas or newlines\n\ if (argc > 0) { usage(); - exit(1); + exit(EXIT_PARSE_ERROR); } /* Make connection to server */ if (!test_args) { cli = connect_one(share); - if (!cli) exit(1); + if (!cli) exit(EXIT_FAILED); } - { char *s; @@ -957,12 +967,12 @@ You can string acls together with spaces, commas or newlines\n\ /* Perform requested action */ if (change_mode != REQUEST_NONE) { - owner_set(cli, change_mode, filename, owner_username); + result = owner_set(cli, change_mode, filename, owner_username); } else if (the_acl) { - cacl_set(cli, filename, the_acl, mode); + result = cacl_set(cli, filename, the_acl, mode); } else { - cacl_dump(cli, filename); + result = cacl_dump(cli, filename); } - return(0); + return result; } -- cgit From 92ebc81734a8a4165f88eeba9c05a05ea2917584 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Thu, 4 Jan 2001 11:35:55 +0000 Subject: I need a callback arg for cli_NetServerEnum and cli_RNetShareEnum, so I had to modifiy any routine that calls it to pass NULL and so forth. Should have no impact. It compiles OK. (This used to be commit 7f862e387f935a2125481338eee850afcb8d82ba) --- source3/utils/torture.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index cd348f67fd..fc917702d3 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -1690,7 +1690,7 @@ static void run_randomipc(int dummy) static void browse_callback(const char *sname, uint32 stype, - const char *comment) + const char *comment, void *state) { printf("\t%20.20s %08x %s\n", sname, stype, comment); } @@ -1714,12 +1714,12 @@ static void run_browsetest(int dummy) printf("domain list:\n"); cli_NetServerEnum(&cli, cli.server_domain, SV_TYPE_DOMAIN_ENUM, - browse_callback); + browse_callback, NULL); printf("machine list:\n"); cli_NetServerEnum(&cli, cli.server_domain, SV_TYPE_ALL, - browse_callback); + browse_callback, NULL); close_connection(&cli); -- cgit From dca808cbc4b52e38701f814f7aac043ddd1ca1c1 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Fri, 5 Jan 2001 13:11:29 +0000 Subject: Needed a callback arg on cli_list ... (This used to be commit d45e667a74fc2fcbf69c4819d480269c03dbfae4) --- source3/utils/masktest.c | 8 ++++---- source3/utils/torture.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index 3fc7431519..981a508f0a 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -157,7 +157,7 @@ struct cli_state *connect_one(char *share) static char *resultp; static file_info *finfo; -void listfn(file_info *f, const char *s) +void listfn(file_info *f, const char *s, void *state) { if (strcmp(f->name,".") == 0) { resultp[0] = '+'; @@ -172,7 +172,7 @@ void listfn(file_info *f, const char *s) static void get_short_name(struct cli_state *cli, char *name, fstring short_name) { - cli_list(cli, name, aHIDDEN | aDIR, listfn); + cli_list(cli, name, aHIDDEN | aDIR, listfn, NULL); if (finfo) { fstrcpy(short_name, finfo->short_name); strlower(short_name); @@ -202,12 +202,12 @@ static void testpair(struct cli_state *cli, char *mask, char *file) fstrcpy(short_name, ""); finfo = NULL; if (old_list) { - cli_list_old(cli, mask, aHIDDEN | aDIR, listfn); + cli_list_old(cli, mask, aHIDDEN | aDIR, listfn, NULL); } else { get_short_name(cli, file, short_name); finfo = NULL; fstrcpy(res1, "---"); - cli_list(cli, mask, aHIDDEN | aDIR, listfn); + cli_list(cli, mask, aHIDDEN | aDIR, listfn, NULL); } res2 = reg_test(mask, file, short_name); diff --git a/source3/utils/torture.c b/source3/utils/torture.c index fc917702d3..40b4b123e9 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -2112,7 +2112,7 @@ static void run_opentest(int dummy) printf("finished open test 1\n"); } -static void list_fn(file_info *finfo, const char *name) +static void list_fn(file_info *finfo, const char *name, void *state) { } @@ -2149,9 +2149,9 @@ static void run_dirtest(int dummy) t1 = end_timer(); - printf("Matched %d\n", cli_list(&cli, "a*.*", 0, list_fn)); - printf("Matched %d\n", cli_list(&cli, "b*.*", 0, list_fn)); - printf("Matched %d\n", cli_list(&cli, "xyzabc", 0, list_fn)); + printf("Matched %d\n", cli_list(&cli, "a*.*", 0, list_fn, NULL)); + printf("Matched %d\n", cli_list(&cli, "b*.*", 0, list_fn, NULL)); + printf("Matched %d\n", cli_list(&cli, "xyzabc", 0, list_fn, NULL)); printf("dirtest core %g seconds\n", end_timer() - t1); -- cgit From ea1e6f9e7bc845ddf93a1603d7e43050be0e7917 Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Thu, 11 Jan 2001 23:21:17 +0000 Subject: Changes from APPLIANCE_HEAD: source/lib/smbpasswd.c - Only call load_interfaces() when doing a network related operation. This means you can add, remove, enable or disable smbpasswd entries without a network. Changing passwords always requires a network. (This used to be commit e2193c3a360562dd66a16c8f23f8cf3eed20b8cf) --- source3/utils/smbpasswd.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index d6a0c3dba8..cb86669728 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -327,6 +327,12 @@ static int process_root(int argc, char *argv[]) usage(); } + /* Only load interfaces if we are doing network operations. */ + + if (joining_domain || remote_machine) { + load_interfaces(); + } + if(joining_domain) { if (argc != 0) usage(); @@ -506,11 +512,13 @@ static int process_nonroot(int argc, char *argv[]) * via a remote machine (even if that machine is * localhost). */ + + load_interfaces(); /* Delayed from main() */ + if (remote_machine == NULL) { remote_machine = "127.0.0.1"; } - if (remote_machine != NULL) { old_passwd = get_pass("Old SMB password:",stdin_passwd_get); } @@ -585,7 +593,6 @@ int main(int argc, char **argv) codepage_initialise(lp_client_code_page()); - load_interfaces(); secrets_init(); /* Check the effective uid - make sure we are not setuid */ -- cgit From a699e9b572bc3b6684ff46d205d3175aca6dee0a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 23 Jan 2001 17:33:35 +0000 Subject: Some systems don't support SEC_RIGHTS_MAXIMUM_ALLOWED for lsa_open_policy() but NT sends 0x2000000 so we might as well do it too. (This used to be commit 394e17645b777be767cd1c69be3f5efe7a703d85) --- source3/utils/smbcacls.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 7600989655..a4b14df0c9 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -84,8 +84,12 @@ static BOOL open_policy_hnd(void) /* Open policy handle */ if (!got_policy_hnd) { + + /* Some systems don't support SEC_RIGHTS_MAXIMUM_ALLOWED, + but NT sends 0x2000000 so we might as well do it too. */ + if (cli_lsa_open_policy(&lsa_cli, True, - SEC_RIGHTS_MAXIMUM_ALLOWED, &pol) + GENERIC_EXECUTE_ACCESS, &pol) != NT_STATUS_NOPROBLEMO) { return False; } -- cgit From 94fc44a93c46cece9b9fa947bff62087dbcd89fa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 12 Feb 2001 16:18:02 +0000 Subject: Merge of JohnR's changes to appliance-head, JF's changes to 2.2, updated the POSIX_ACL code to be in sync. Jeremy. (This used to be commit c0517d6f4e3079feca1309fd1ea7b21e83f0de02) --- source3/utils/smbcontrol.c | 51 +++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 19 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 87d00eecbd..26c01ced9e 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -77,10 +77,17 @@ Prints out the current Debug level returned by MSG_DEBUGLEVEL ****************************************************************************/ void debuglevel_function(int msg_type, pid_t src, void *buf, size_t len) { - int level; - memcpy(&level, buf, sizeof(int)); + int i; + int debuglevel_class[DBGC_LAST]; + + memcpy(debuglevel_class, buf, len); + + printf("Current debug level of PID %d is %d ",src, debuglevel_class[0]); + for (i=1;i:level\n"); + return(False); + } else + send_message(dest, MSG_DEBUG, debuglevel_class, sizeof(debuglevel_class), False); break; case MSG_PROFILE: - if (!params) { + if (!params[0]) { fprintf(stderr,"MSG_PROFILE needs a parameter\n"); return(False); } - if (strequal(params, "off")) { + if (strequal(params[0], "off")) { v = 0; - } else if (strequal(params, "count")) { + } else if (strequal(params[0], "count")) { v = 1; - } else if (strequal(params, "on")) { + } else if (strequal(params[0], "on")) { v = 2; - } else if (strequal(params, "flush")) { + } else if (strequal(params[0], "flush")) { v = 3; } else { fprintf(stderr, @@ -258,12 +271,12 @@ static BOOL do_command(char *dest, char *msg_name, char *params) fprintf(stderr,"printer-notify can only be sent to smbd\n"); return(False); } - if (!params) { + if (!params[0]) { fprintf(stderr, "printer-notify needs a printer name\n"); return (False); } - retval = send_message(dest, MSG_PRINTER_NOTIFY, params, - strlen(params) + 1, False); + retval = send_message(dest, MSG_PRINTER_NOTIFY, params[0], + strlen(params[0]) + 1, False); break; case MSG_PING: @@ -271,11 +284,11 @@ static BOOL do_command(char *dest, char *msg_name, char *params) message_register(MSG_PONG, pong_function); pong_registered = True; } - if (!params) { + if (!params[0]) { fprintf(stderr,"MSG_PING needs a parameter\n"); return(False); } - n = atoi(params); + n = atoi(params[0]); pong_count = 0; for (i=0;i 2 ? argv[2] : 0)); + return (do_command(argv[0],argv[1],argc > 2 ? &argv[2] : 0)); } while (True) { @@ -350,7 +363,7 @@ static BOOL do_command(char *dest, char *msg_name, char *params) if (strequal(myargv[0],"q")) break; if (myargc < 2) usage(False); - else if (!do_command(myargv[0],myargv[1],myargc > 2 ? myargv[2] : 0)) + else if (!do_command(myargv[0],myargv[1],myargc > 2 ? &myargv[2] : 0)) usage(False); } return(0); -- cgit From ca677a6d8d361e5ab7a9794cfaafcb231b379a1d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 20 Feb 2001 10:13:04 +0000 Subject: playing with CAP_NT_SMBS (This used to be commit 3eff509a65d164d66eb70f51ef115acd7328266c) --- source3/utils/smbfilter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c index 5d11c74d14..833221b10b 100644 --- a/source3/utils/smbfilter.c +++ b/source3/utils/smbfilter.c @@ -26,11 +26,11 @@ #define SECURITY_SET 0 /* this forces non-unicode */ -#define CAPABILITY_MASK CAP_UNICODE +#define CAPABILITY_MASK (CAP_NT_SMBS | CAP_RPC_REMOTE_APIS) #define CAPABILITY_SET 0 /* and non-unicode for the client too */ -#define CLI_CAPABILITY_MASK CAP_UNICODE +#define CLI_CAPABILITY_MASK 0 #define CLI_CAPABILITY_SET 0 static char *netbiosname; -- cgit From 6cb19fbd3a0da051010fd704bfd1dfe5bc594210 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 20 Feb 2001 23:53:06 +0000 Subject: don't need _uni hack now (This used to be commit f191271986d085cc73b62c8d3de8ab7b326c19c0) --- source3/utils/smbcacls.c | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index a4b14df0c9..f68a2c2c6b 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -441,30 +441,6 @@ static void sec_desc_print(FILE *f, SEC_DESC *sd) } -/* Some systems seem to require unicode pathnames for the ntcreate&x call - despite Samba negotiating ascii filenames. Try with unicode pathname if - the ascii version fails. */ - -int do_cli_nt_create(struct cli_state *cli, char *fname, uint32 DesiredAccess) -{ - int result; - - result = cli_nt_create(cli, fname, DesiredAccess); - - if (result == -1) { - uint32 errnum, nt_rpc_error; - uint8 errclass; - - cli_error(cli, &errclass, &errnum, &nt_rpc_error); - - if (errclass == ERRDOS && errnum == ERRbadpath) { - result = cli_nt_create_uni(cli, fname, DesiredAccess); - } - } - - return result; -} - /***************************************************** dump the acls for a file *******************************************************/ @@ -475,7 +451,7 @@ static int cacl_dump(struct cli_state *cli, char *filename) if (test_args) return EXIT_OK; - fnum = do_cli_nt_create(cli, filename, 0x20000); + fnum = cli_nt_create(cli, filename, 0x20000); if (fnum == -1) { printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); return EXIT_FAILED; @@ -510,9 +486,9 @@ static int owner_set(struct cli_state *cli, enum chown_mode change_mode, SEC_DESC *sd, *old; size_t sd_size; - fnum = do_cli_nt_create(cli, filename, - READ_CONTROL_ACCESS | WRITE_DAC_ACCESS - | WRITE_OWNER_ACCESS); + fnum = cli_nt_create(cli, filename, + READ_CONTROL_ACCESS | WRITE_DAC_ACCESS + | WRITE_OWNER_ACCESS); if (fnum == -1) { printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); @@ -606,8 +582,8 @@ static int cacl_set(struct cli_state *cli, char *filename, /* The desired access below is the only one I could find that works with NT4, W2KP and Samba */ - fnum = do_cli_nt_create(cli, filename, - MAXIMUM_ALLOWED_ACCESS | 0x60000); + fnum = cli_nt_create(cli, filename, + MAXIMUM_ALLOWED_ACCESS | 0x60000); if (fnum == -1) { printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); -- cgit From 7fb8d5a00bf0e13f5198c3f1cdae1343d636bdd0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 21 Feb 2001 04:13:47 +0000 Subject: fixed a crash bug in smbpasswd (the user can come from optarg, so we can't free it) (This used to be commit 56ffb58effe80f7c62a9de6ba4f634d995fbc4e6) --- source3/utils/smbpasswd.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index cb86669728..d20760bee1 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -543,7 +543,6 @@ static int process_nonroot(int argc, char *argv[]) done: safe_free(old_passwd); safe_free(new_passwd); - safe_free(user_name); return result; } -- cgit From 9ccbc1de06fa240db716c5e497853b7f31f1225f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 Feb 2001 03:40:01 +0000 Subject: cope with filer/NT/samba all in one binary. yeah. we now don't open rw for acls (This used to be commit c0f57c3fe636c5a5885c6b2ed4723252597533eb) --- source3/utils/smbcacls.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index f68a2c2c6b..0aa2c4399d 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -31,6 +31,9 @@ static fstring server; static int got_pass; static int test_args; +#define CREATE_ACCESS_READ READ_CONTROL_ACCESS +#define CREATE_ACCESS_WRITE (WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS) + /* numeric is set when the user wants numeric SIDs and ACEs rather than going via LSA calls to resolve them */ static int numeric; @@ -451,7 +454,7 @@ static int cacl_dump(struct cli_state *cli, char *filename) if (test_args) return EXIT_OK; - fnum = cli_nt_create(cli, filename, 0x20000); + fnum = cli_nt_create(cli, filename, CREATE_ACCESS_READ); if (fnum == -1) { printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); return EXIT_FAILED; @@ -486,9 +489,7 @@ static int owner_set(struct cli_state *cli, enum chown_mode change_mode, SEC_DESC *sd, *old; size_t sd_size; - fnum = cli_nt_create(cli, filename, - READ_CONTROL_ACCESS | WRITE_DAC_ACCESS - | WRITE_OWNER_ACCESS); + fnum = cli_nt_create(cli, filename, CREATE_ACCESS_READ); if (fnum == -1) { printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); @@ -500,11 +501,25 @@ static int owner_set(struct cli_state *cli, enum chown_mode change_mode, old = cli_query_secdesc(cli, fnum); + cli_close(cli, fnum); + + if (!old) { + printf("owner_set: Failed to query old descriptor\n"); + return EXIT_FAILED; + } + sd = make_sec_desc(old->revision, (change_mode == REQUEST_CHOWN) ? &sid : old->owner_sid, (change_mode == REQUEST_CHGRP) ? &sid : old->grp_sid, NULL, old->dacl, &sd_size); + fnum = cli_nt_create(cli, filename, CREATE_ACCESS_WRITE); + + if (fnum == -1) { + printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); + return EXIT_FAILED; + } + if (!cli_set_secdesc(cli, fnum, sd)) { printf("ERROR: secdesc set failed: %s\n", cli_errstr(cli)); } @@ -582,16 +597,22 @@ static int cacl_set(struct cli_state *cli, char *filename, /* The desired access below is the only one I could find that works with NT4, W2KP and Samba */ - fnum = cli_nt_create(cli, filename, - MAXIMUM_ALLOWED_ACCESS | 0x60000); + fnum = cli_nt_create(cli, filename, CREATE_ACCESS_READ); if (fnum == -1) { - printf("Failed to open %s: %s\n", filename, cli_errstr(cli)); + printf("cacl_set failed to open %s: %s\n", filename, cli_errstr(cli)); return EXIT_FAILED; } old = cli_query_secdesc(cli, fnum); + if (!old) { + printf("calc_set: Failed to query old descriptor\n"); + return EXIT_FAILED; + } + + cli_close(cli, fnum); + /* the logic here is rather more complex than I would like */ switch (mode) { case ACL_DELETE: @@ -673,6 +694,13 @@ static int cacl_set(struct cli_state *cli, char *filename, sd = make_sec_desc(old->revision, old->owner_sid, old->grp_sid, NULL, old->dacl, &sd_size); + fnum = cli_nt_create(cli, filename, CREATE_ACCESS_WRITE); + + if (fnum == -1) { + printf("cacl_set failed to open %s: %s\n", filename, cli_errstr(cli)); + return EXIT_FAILED; + } + if (!cli_set_secdesc(cli, fnum, sd)) { printf("ERROR: secdesc set failed: %s\n", cli_errstr(cli)); result = EXIT_FAILED; -- cgit From 4e1de143b38e2fb64dd3c7d4030e939b53c8db0f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 Feb 2001 06:22:20 +0000 Subject: - workaround filer lsa lookup bug for unknown sids - add \ at start of name if not needed (another filer workaround) (This used to be commit 48ab6297a1b462e03f70a4d90d50b21982d0d90d) --- source3/utils/smbcacls.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 0aa2c4399d..bef16d349c 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -118,7 +118,8 @@ static void SidToString(fstring str, DOM_SID *sid) if (!open_policy_hnd() || cli_lsa_lookup_sids(&lsa_cli, &pol, 1, sid, &names, &types, - &num_names) != NT_STATUS_NOPROBLEMO) { + &num_names) != NT_STATUS_NOPROBLEMO || + !names || !names[0]) { return; } @@ -834,7 +835,7 @@ You can string acls together with spaces, commas or newlines\n\ int main(int argc,char *argv[]) { char *share; - char *filename; + pstring filename; extern char *optarg; extern int optind; extern FILE *dbf; @@ -860,7 +861,7 @@ You can string acls together with spaces, commas or newlines\n\ setup_logging(argv[0],True); share = argv[1]; - filename = argv[2]; + pstrcpy(filename, argv[2]); all_string_sub(share,"/","\\",0); argc -= 2; @@ -962,14 +963,12 @@ You can string acls together with spaces, commas or newlines\n\ if (!cli) exit(EXIT_FAILED); } - { - char *s; - - s = filename; - while(*s) { - if (*s == '/') *s = '\\'; - s++; - } + all_string_sub(filename, "/", "\\", 0); + if (filename[0] != '\\') { + pstring s; + s[0] = '\\'; + safe_strcpy(&s[1], filename, sizeof(pstring)-1); + pstrcpy(filename, s); } /* Perform requested action */ -- cgit From 6022747b5bbc3197d3a0e246c57caf1b7ad04b2d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 Feb 2001 06:24:28 +0000 Subject: fixed character set init in smbw_sample (This used to be commit c43593ad069670fb47b8e98248254c739bb7ab18) --- source3/utils/smbw_sample.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/smbw_sample.c b/source3/utils/smbw_sample.c index 999dcaef47..db92af9510 100644 --- a/source3/utils/smbw_sample.c +++ b/source3/utils/smbw_sample.c @@ -34,6 +34,8 @@ int main(int argc, char *argv[]) char *path; charset_initialise(); + lp_load(CONFIGFILE,1,0,0); + codepage_initialise(lp_client_code_page()); smbw_setup_shared(); while ((opt = getopt(argc, argv, "W:U:R:d:P:l:hL:")) != EOF) { -- cgit From b4096748dd5613f7c6f7d8c6d73c5ff0fba0c346 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 Feb 2001 06:35:54 +0000 Subject: don't crash on null acl sort (This used to be commit 59341377413fcbf30c090a3763608d23ac2bff95) --- source3/utils/smbcacls.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index bef16d349c..5ea595c4ea 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -544,6 +544,8 @@ static void sort_acl(SEC_ACL *the_acl) int i, ace_ndx = 0; BOOL do_denied = True; + if (!the_acl) return; + tmp_ace = (SEC_ACE *)malloc(sizeof(SEC_ACE) * the_acl->num_aces); if (!tmp_ace) return; -- cgit From 8d070c60fc99e27d7e58f6d45aa64657c462b875 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 23 Feb 2001 07:20:11 +0000 Subject: - fixed the sort_acl bug, sorting now works right - don't allow setting of duplicate ACEs - fixed a ACE delete bug (This used to be commit 61293979ce2aded58a5ef2a54b3b05d1d278f7cf) --- source3/utils/smbcacls.c | 77 ++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 45 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 5ea595c4ea..3e71f39077 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -175,7 +175,7 @@ static void print_ace(FILE *f, SEC_ACE *ace) fprintf(f, "%s:", sidstr); if (numeric) { - fprintf(f, "%d/%d/0x%08x\n", + fprintf(f, "%d/%d/0x%08x", ace->type, ace->flags, ace->info.mask); return; } @@ -198,7 +198,7 @@ static void print_ace(FILE *f, SEC_ACE *ace) for (v = standard_values; v->perm; v++) { if (ace->info.mask == v->mask) { - fprintf(f, "%s\n", v->perm); + fprintf(f, "%s", v->perm); return; } } @@ -226,8 +226,6 @@ static void print_ace(FILE *f, SEC_ACE *ace) goto again; } } - - fprintf(f, "\n"); } @@ -441,6 +439,7 @@ static void sec_desc_print(FILE *f, SEC_DESC *sd) SEC_ACE *ace = &sd->dacl->ace[i]; fprintf(f, "ACL:"); print_ace(f, ace); + fprintf(f, "\n"); } } @@ -533,51 +532,41 @@ static int owner_set(struct cli_state *cli, enum chown_mode change_mode, return EXIT_OK; } + /* The MSDN is contradictory over the ordering of ACE entries in an ACL. However NT4 gives a "The information may have been modified by a computer running Windows NT 5.0" if denied ACEs do not appear before allowed ACEs. */ -static void sort_acl(SEC_ACL *the_acl) +static int ace_compare(SEC_ACE *ace1, SEC_ACE *ace2) { - SEC_ACE *tmp_ace; - int i, ace_ndx = 0; - BOOL do_denied = True; + if (sec_ace_equal(ace1, ace2)) return 0; + if (ace1->type != ace2->type) return ace1->type - ace2->type; + if (sid_compare(&ace1->sid, &ace2->sid)) return sid_compare(&ace1->sid, &ace2->sid); + if (ace1->flags != ace2->flags) return ace1->flags - ace2->flags; + if (ace1->info.mask != ace2->info.mask) return ace1->info.mask - ace2->info.mask; + if (ace1->size != ace2->size) return ace1->size - ace2->size; + return memcmp(ace1, ace2, sizeof(SEC_ACE)); +} +static void sort_acl(SEC_ACL *the_acl) +{ + int i; if (!the_acl) return; - tmp_ace = (SEC_ACE *)malloc(sizeof(SEC_ACE) * the_acl->num_aces); - - if (!tmp_ace) return; - - copy_aces: - - for (i = 0; i < the_acl->num_aces; i++) { - - /* Copy denied ACEs */ - - if (do_denied && - the_acl->ace[i].type == SEC_ACE_TYPE_ACCESS_DENIED) { - tmp_ace[ace_ndx] = the_acl->ace[i]; - ace_ndx++; - } + qsort(the_acl->ace, the_acl->num_aces, sizeof(the_acl->ace[0]), ace_compare); - /* Copy other ACEs */ - - if (!do_denied && - the_acl->ace[i].type != SEC_ACE_TYPE_ACCESS_DENIED) { - tmp_ace[ace_ndx] = the_acl->ace[i]; - ace_ndx++; + for (i=1;inum_aces;) { + if (sec_ace_equal(&the_acl->ace[i-1], &the_acl->ace[i])) { + int j; + for (j=i; jnum_aces-1; j++) { + the_acl->ace[j] = the_acl->ace[j+1]; + } + the_acl->num_aces--; + } else { + i++; } } - - if (do_denied) { - do_denied = False; - goto copy_aces; - } - - free(the_acl->ace); - the_acl->ace = tmp_ace; } /***************************************************** @@ -625,8 +614,9 @@ static int cacl_set(struct cli_state *cli, char *filename, for (j=0;old->dacl && jdacl->num_aces;j++) { if (sec_ace_equal(&sd->dacl->ace[i], &old->dacl->ace[j])) { - if (j != old->dacl->num_aces-1) { - old->dacl->ace[j] = old->dacl->ace[j+1]; + int k; + for (k=j; kdacl->num_aces-1;k++) { + old->dacl->ace[k] = old->dacl->ace[k+1]; } old->dacl->num_aces--; if (old->dacl->num_aces == 0) { @@ -642,10 +632,9 @@ static int cacl_set(struct cli_state *cli, char *filename, } if (!found) { - fstring str; - - SidToString(str, &sd->dacl->ace[i].sid); - printf("ACL for SID %s not found\n", str); + printf("ACL for ACE:"); + print_ace(stdout, &sd->dacl->ace[i]); + printf(" not found\n"); } } break; @@ -689,11 +678,9 @@ static int cacl_set(struct cli_state *cli, char *filename, } /* Denied ACE entries must come before allowed ones */ - sort_acl(old->dacl); /* Create new security descriptor and set it */ - sd = make_sec_desc(old->revision, old->owner_sid, old->grp_sid, NULL, old->dacl, &sd_size); -- cgit From 46807bd1870e8136f752841814086edd19f4c1f1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 23 Feb 2001 07:21:50 +0000 Subject: cast the qsort (This used to be commit 703d9f5cb32ca4131051c50646fd833fb1ae7d76) --- source3/utils/smbcacls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 3e71f39077..9d806bbd9b 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -554,7 +554,7 @@ static void sort_acl(SEC_ACL *the_acl) int i; if (!the_acl) return; - qsort(the_acl->ace, the_acl->num_aces, sizeof(the_acl->ace[0]), ace_compare); + qsort(the_acl->ace, the_acl->num_aces, sizeof(the_acl->ace[0]), QSORT_CAST ace_compare); for (i=1;inum_aces;) { if (sec_ace_equal(&the_acl->ace[i-1], &the_acl->ace[i])) { -- cgit From 7082b61c4b06a9c5b4a6fe89a0f3e1ac5945066c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 23 Feb 2001 07:25:49 +0000 Subject: make sure denied aces are first (This used to be commit b0b49a4b28891f3e2ec8e8e221af713250cc8e17) --- source3/utils/smbcacls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 9d806bbd9b..b050139aa5 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -541,7 +541,7 @@ static int owner_set(struct cli_state *cli, enum chown_mode change_mode, static int ace_compare(SEC_ACE *ace1, SEC_ACE *ace2) { if (sec_ace_equal(ace1, ace2)) return 0; - if (ace1->type != ace2->type) return ace1->type - ace2->type; + if (ace1->type != ace2->type) return ace2->type - ace1->type; if (sid_compare(&ace1->sid, &ace2->sid)) return sid_compare(&ace1->sid, &ace2->sid); if (ace1->flags != ace2->flags) return ace1->flags - ace2->flags; if (ace1->info.mask != ace2->info.mask) return ace1->info.mask - ace2->info.mask; -- cgit From f7602aaaa6d03fc50299def73293912a2ab1f997 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 25 Feb 2001 23:47:27 +0000 Subject: a snapshot of my attempts to get wildcard matching right for LANMAN1 clients. This is not complete and not correct - expect some more work on this soon (This used to be commit 06d158d5e91a222e6bf8d22f02107c60da383f82) --- source3/utils/masktest.c | 118 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 108 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index 981a508f0a..864962d79a 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -27,20 +27,110 @@ extern int DEBUGLEVEL; static fstring password; static fstring username; static int got_pass; - +static int max_protocol = PROTOCOL_NT1; static BOOL showall = False; static BOOL old_list = False; static char *maskchars = "<>\"?*abc."; static char *filechars = "abcdefghijklm."; -static BOOL reg_match_one(char *pattern, char *file) +/* a test fn for LANMAN mask support */ +int ms_fnmatch_lanman_core(char *pattern, char *string) { - if (strcmp(file,"..") == 0) file = "."; - if (strcmp(pattern,".") == 0) return False; + char *p = pattern, *n = string; + char c; + + // printf("ms_fnmatch_lanman_core(%s, %s)\n", pattern, string); + + while ((c = *p++)) { + switch (c) { + case '?': + if (*n == 0 && ms_fnmatch_lanman_core(p, n) == 0) return 0; + if (! *n && !*p) return 0; + n++; + break; + + case '>': + if (n[0] == '.') { + if (! n[1] && ms_fnmatch_lanman_core(p, n+1) == 0) return 0; + if (ms_fnmatch_lanman_core(p, n) == 0) return 0; + return -1; + } + if (! *n) return ms_fnmatch_lanman_core(p, n); + n++; + break; + case '*': + for (; *n; n++) { + if (ms_fnmatch_lanman_core(p, n) == 0) return 0; + } + break; + + case '<': + for (; *n; n++) { + if (ms_fnmatch_lanman_core(p, n) == 0) return 0; + if (*n == '.' && !strchr(n+1,'.')) { + n++; + break; + } + } + break; + + case '"': + if (*n == 0 && ms_fnmatch_lanman_core(p, n) == 0) return 0; + if (*n != '.') return -1; + n++; + break; + + default: + if (c != *n) return -1; + n++; + } + } + + if (! *n) return 0; + + return -1; +} + +int ms_fnmatch_lanman(char *pattern, char *string) +{ + pstring p_base, p_ext="", s_base, s_ext=""; + char *p; + + pstrcpy(p_base, pattern); + pstrcpy(s_base, string); + + p = strrchr(p_base,'.'); + if (p) { + *p = 0; + pstrcpy(p_ext, p+1); + } + + p = strrchr(s_base,'.'); + if (p) { + *p = 0; + pstrcpy(s_ext, p+1); + } + + //printf("[%s/%s] [%s/%s] [%s/%s]\n", + // pattern, string, p_base, s_base, p_ext, s_ext); + + return ms_fnmatch_lanman_core(p_base, s_base) || + ms_fnmatch_lanman_core(p_ext, s_ext); +} + +static BOOL reg_match_one(char *pattern, char *file) +{ /* oh what a weird world this is */ if (old_list && strcmp(pattern, "*.*") == 0) return True; + if (max_protocol <= PROTOCOL_LANMAN2) { + return ms_fnmatch_lanman(pattern, file)==0; + } + + if (strcmp(file,"..") == 0) file = "."; + if (strcmp(pattern,".") == 0) return False; + return ms_fnmatch(pattern, file)==0; } @@ -50,7 +140,7 @@ static char *reg_test(char *pattern, char *file, char *short_name) fstrcpy(ret, "---"); pattern = 1+strrchr(pattern,'\\'); - file = 1+strrchr(file,'\\'); + // file = 1+strrchr(file,'\\'); if (reg_match_one(pattern, ".")) ret[0] = '+'; if (reg_match_one(pattern, "..")) ret[1] = '+'; @@ -95,6 +185,8 @@ struct cli_state *connect_one(char *share) return NULL; } + c->protocol = max_protocol; + if (!cli_session_request(c, &calling, &called)) { DEBUG(0,("session request to %s failed\n", called.name)); cli_shutdown(c); @@ -170,12 +262,14 @@ void listfn(file_info *f, const char *s, void *state) } static void get_short_name(struct cli_state *cli, - char *name, fstring short_name) + char *name, pstring long_name, fstring short_name) { - cli_list(cli, name, aHIDDEN | aDIR, listfn, NULL); + cli_list(cli, "\\masktest\\*.*", aHIDDEN | aDIR, listfn, NULL); if (finfo) { fstrcpy(short_name, finfo->short_name); strlower(short_name); + pstrcpy(long_name, finfo->name); + strlower(long_name); } } @@ -186,6 +280,7 @@ static void testpair(struct cli_state *cli, char *mask, char *file) char *res2; static int count; fstring short_name; + pstring long_name; count++; @@ -204,13 +299,13 @@ static void testpair(struct cli_state *cli, char *mask, char *file) if (old_list) { cli_list_old(cli, mask, aHIDDEN | aDIR, listfn, NULL); } else { - get_short_name(cli, file, short_name); + get_short_name(cli, file, long_name, short_name); finfo = NULL; fstrcpy(res1, "---"); cli_list(cli, mask, aHIDDEN | aDIR, listfn, NULL); } - res2 = reg_test(mask, file, short_name); + res2 = reg_test(mask, long_name, short_name); if (showall || strcmp(res1, res2)) { DEBUG(0,("%s %s %d mask=[%s] file=[%s] mfile=[%s]\n", @@ -341,8 +436,11 @@ static void usage(void) seed = time(NULL); - while ((opt = getopt(argc, argv, "U:s:hm:f:aoW:")) != EOF) { + while ((opt = getopt(argc, argv, "U:s:hm:f:aoW:M:")) != EOF) { switch (opt) { + case 'M': + max_protocol = interpret_protocol(optarg, max_protocol); + break; case 'U': pstrcpy(username,optarg); p = strchr(username,'%'); -- cgit From 571a04613b739bbfcea8a55d5ec55569b7a7b319 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 26 Feb 2001 05:13:19 +0000 Subject: made some progress in masktest it now handles the server renaming files on create (This used to be commit 85ce14f36da4f5a3fb3029634279bb473873bbd5) --- source3/utils/masktest.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index 864962d79a..9a4d7156b4 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -134,17 +134,16 @@ static BOOL reg_match_one(char *pattern, char *file) return ms_fnmatch(pattern, file)==0; } -static char *reg_test(char *pattern, char *file, char *short_name) +static char *reg_test(char *pattern, char *long_name, char *short_name) { 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) || + if (reg_match_one(pattern, long_name) || (*short_name && reg_match_one(pattern, short_name))) ret[2] = '+'; return ret; } @@ -261,10 +260,14 @@ void listfn(file_info *f, const char *s, void *state) finfo = f; } -static void get_short_name(struct cli_state *cli, - char *name, pstring long_name, fstring short_name) +static void get_real_name(struct cli_state *cli, + pstring long_name, fstring short_name) { - cli_list(cli, "\\masktest\\*.*", aHIDDEN | aDIR, listfn, NULL); + if (max_protocol <= PROTOCOL_LANMAN1) { + cli_list_new(cli, "\\masktest\\*.*", aHIDDEN | aDIR, listfn, NULL); + } else { + cli_list_new(cli, "\\masktest\\*", aHIDDEN | aDIR, listfn, NULL); + } if (finfo) { fstrcpy(short_name, finfo->short_name); strlower(short_name); @@ -296,20 +299,16 @@ static void testpair(struct cli_state *cli, char *mask, char *file) resultp = res1; fstrcpy(short_name, ""); finfo = NULL; - if (old_list) { - cli_list_old(cli, mask, aHIDDEN | aDIR, listfn, NULL); - } else { - get_short_name(cli, file, long_name, short_name); - finfo = NULL; - fstrcpy(res1, "---"); - cli_list(cli, mask, aHIDDEN | aDIR, listfn, NULL); - } + get_real_name(cli, long_name, short_name); + finfo = NULL; + fstrcpy(res1, "---"); + cli_list(cli, mask, aHIDDEN | aDIR, listfn, NULL); res2 = reg_test(mask, long_name, short_name); if (showall || strcmp(res1, res2)) { - DEBUG(0,("%s %s %d mask=[%s] file=[%s] mfile=[%s]\n", - res1, res2, count, mask, file, short_name)); + DEBUG(0,("%s %s %d mask=[%s] file=[%s] rfile=[%s/%s]\n", + res1, res2, count, mask, file, long_name, short_name)); } cli_unlink(cli, file); -- cgit From 0d54de536c03f941739359a121a337aa33a2dc84 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 26 Feb 2001 06:53:42 +0000 Subject: made some LANMAN1 wildcard progress it now handles -M LANMAN1 -f '.x' -m '?x' nicely (This used to be commit e7ccb9be6da9b1426eb136b4a0a1171232471768) --- source3/utils/masktest.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index 9a4d7156b4..c1e27c564c 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -39,13 +39,12 @@ int ms_fnmatch_lanman_core(char *pattern, char *string) char *p = pattern, *n = string; char c; - // printf("ms_fnmatch_lanman_core(%s, %s)\n", pattern, string); + // printf("ms_fnmatch_lanman_core(%s, %s)\n", pattern, string); while ((c = *p++)) { switch (c) { case '?': - if (*n == 0 && ms_fnmatch_lanman_core(p, n) == 0) return 0; - if (! *n && !*p) return 0; + if (! *n) return ms_fnmatch_lanman_core(p, n); n++; break; @@ -124,13 +123,13 @@ static BOOL reg_match_one(char *pattern, char *file) /* oh what a weird world this is */ if (old_list && strcmp(pattern, "*.*") == 0) return True; + if (strcmp(file,"..") == 0) file = "."; + if (strcmp(pattern,".") == 0) return False; + if (max_protocol <= PROTOCOL_LANMAN2) { return ms_fnmatch_lanman(pattern, file)==0; } - if (strcmp(file,"..") == 0) file = "."; - if (strcmp(pattern,".") == 0) return False; - return ms_fnmatch(pattern, file)==0; } @@ -263,6 +262,8 @@ void listfn(file_info *f, const char *s, void *state) static void get_real_name(struct cli_state *cli, pstring long_name, fstring short_name) { + /* nasty hack to force level 260 listings - tridge */ + cli->capabilities |= CAP_NT_SMBS; if (max_protocol <= PROTOCOL_LANMAN1) { cli_list_new(cli, "\\masktest\\*.*", aHIDDEN | aDIR, listfn, NULL); } else { -- cgit From 54f5661b439af0ab86cce0d5bf8dc79faec7d7ac Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 Feb 2001 04:18:12 +0000 Subject: I have now found that despite initial appearences the lanman1 wildcard algorithm does *not* match separately on base and extension. I also added a -v option to masktest for verbose output (This used to be commit 76c8fa5cd1ce9095583f818d100cd0f2116ddc62) --- source3/utils/masktest.c | 59 ++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 35 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index c1e27c564c..a5b4888b0e 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -32,6 +32,7 @@ static BOOL showall = False; static BOOL old_list = False; static char *maskchars = "<>\"?*abc."; static char *filechars = "abcdefghijklm."; +static int verbose; /* a test fn for LANMAN mask support */ int ms_fnmatch_lanman_core(char *pattern, char *string) @@ -39,34 +40,34 @@ int ms_fnmatch_lanman_core(char *pattern, char *string) char *p = pattern, *n = string; char c; - // printf("ms_fnmatch_lanman_core(%s, %s)\n", pattern, string); - while ((c = *p++)) { switch (c) { case '?': + //if (! *n) return -1; if (! *n) return ms_fnmatch_lanman_core(p, n); n++; break; case '>': if (n[0] == '.') { - if (! n[1] && ms_fnmatch_lanman_core(p, n+1) == 0) return 0; - if (ms_fnmatch_lanman_core(p, n) == 0) return 0; - return -1; + if (! n[1] && ms_fnmatch_lanman_core(p, n+1) == 0) goto match; + if (ms_fnmatch_lanman_core(p, n) == 0) goto match; + goto nomatch; } if (! *n) return ms_fnmatch_lanman_core(p, n); n++; break; case '*': + if (! *p) goto match; for (; *n; n++) { - if (ms_fnmatch_lanman_core(p, n) == 0) return 0; + if (ms_fnmatch_lanman_core(p, n) == 0) goto match; } break; case '<': for (; *n; n++) { - if (ms_fnmatch_lanman_core(p, n) == 0) return 0; + if (ms_fnmatch_lanman_core(p, n) == 0) goto match; if (*n == '.' && !strchr(n+1,'.')) { n++; break; @@ -75,47 +76,32 @@ int ms_fnmatch_lanman_core(char *pattern, char *string) break; case '"': - if (*n == 0 && ms_fnmatch_lanman_core(p, n) == 0) return 0; - if (*n != '.') return -1; + if (*n == 0 && ms_fnmatch_lanman_core(p, n) == 0) goto match; + if (*n != '.') goto nomatch; n++; break; default: - if (c != *n) return -1; + if (c != *n) goto nomatch; n++; } } - if (! *n) return 0; + if (! *n) goto match; + + nomatch: + if (verbose) printf("NOMATCH pattern=[%s] string=[%s]\n", pattern, string); return -1; + + match: + if (verbose) printf("MATCH pattern=[%s] string=[%s]\n", pattern, string); + return 0; } int ms_fnmatch_lanman(char *pattern, char *string) { - pstring p_base, p_ext="", s_base, s_ext=""; - char *p; - - pstrcpy(p_base, pattern); - pstrcpy(s_base, string); - - p = strrchr(p_base,'.'); - if (p) { - *p = 0; - pstrcpy(p_ext, p+1); - } - - p = strrchr(s_base,'.'); - if (p) { - *p = 0; - pstrcpy(s_ext, p+1); - } - - //printf("[%s/%s] [%s/%s] [%s/%s]\n", - // pattern, string, p_base, s_base, p_ext, s_ext); - - return ms_fnmatch_lanman_core(p_base, s_base) || - ms_fnmatch_lanman_core(p_ext, s_ext); + return ms_fnmatch_lanman_core(pattern, string); } static BOOL reg_match_one(char *pattern, char *file) @@ -436,8 +422,11 @@ static void usage(void) seed = time(NULL); - while ((opt = getopt(argc, argv, "U:s:hm:f:aoW:M:")) != EOF) { + while ((opt = getopt(argc, argv, "U:s:hm:f:aoW:M:v")) != EOF) { switch (opt) { + case 'v': + verbose++; + break; case 'M': max_protocol = interpret_protocol(optarg, max_protocol); break; -- cgit From dccf44d752604d877a379290bda10644e0844682 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 Feb 2001 06:11:59 +0000 Subject: almost there with lanman1 wildcards. We now seem to correctly handle '<', '>', '"' and '?' when combined with '.'. The '*' character is proving troublesome. (This used to be commit 0a55d9a17b5d98c7e151bb2ee014cfb0b3660400) --- source3/utils/masktest.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index a5b4888b0e..072f9eb16f 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -40,11 +40,12 @@ int ms_fnmatch_lanman_core(char *pattern, char *string) char *p = pattern, *n = string; char c; + if (strcmp(p,"?")==0 && strcmp(n,".")==0) return 0; + while ((c = *p++)) { switch (c) { case '?': - //if (! *n) return -1; - if (! *n) return ms_fnmatch_lanman_core(p, n); + if (*n == '.' || ! *n) return ms_fnmatch_lanman_core(p, n); n++; break; @@ -101,7 +102,19 @@ int ms_fnmatch_lanman_core(char *pattern, char *string) int ms_fnmatch_lanman(char *pattern, char *string) { - return ms_fnmatch_lanman_core(pattern, string); + int ret; + pattern = strdup(pattern); + + /* it appears that '.' at the end of a pattern is stripped if the + pattern contains any wildcard characters. Bizarre */ + if (strpbrk(pattern, "?*<>\"")) { + int len = strlen(pattern); + if (len > 0 && pattern[len-1] == '.') pattern[len-1] = 0; + } + + ret = ms_fnmatch_lanman_core(pattern, string); + free(pattern); + return ret; } static BOOL reg_match_one(char *pattern, char *file) @@ -293,7 +306,7 @@ static void testpair(struct cli_state *cli, char *mask, char *file) res2 = reg_test(mask, long_name, short_name); - if (showall || strcmp(res1, res2)) { + if (showall || strcmp(res1+2, res2+2)) { DEBUG(0,("%s %s %d mask=[%s] file=[%s] rfile=[%s/%s]\n", res1, res2, count, mask, file, long_name, short_name)); } -- cgit From acaf04b7cc831b06128c64e15dc35308a61e18a0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 Feb 2001 06:13:32 +0000 Subject: remove some test code (This used to be commit 2c509c9860fdcf4d2b3bb35e12f9fedbb77bd17e) --- source3/utils/masktest.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index 072f9eb16f..7e0757e32a 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -306,9 +306,10 @@ static void testpair(struct cli_state *cli, char *mask, char *file) res2 = reg_test(mask, long_name, short_name); - if (showall || strcmp(res1+2, res2+2)) { + if (showall || strcmp(res1, res2)) { DEBUG(0,("%s %s %d mask=[%s] file=[%s] rfile=[%s/%s]\n", res1, res2, count, mask, file, long_name, short_name)); + // exit(1); } cli_unlink(cli, file); -- cgit From 1d67fe4dbee99ec1113abbc5ebb19d4e8c67e414 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 Feb 2001 12:04:49 +0000 Subject: better handling of '.' better verbose print (This used to be commit 1f8b8a7189fb8c142801d679cf53c586aee74740) --- source3/utils/masktest.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index 7e0757e32a..4dd8f3ef06 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -40,12 +40,19 @@ int ms_fnmatch_lanman_core(char *pattern, char *string) char *p = pattern, *n = string; char c; - if (strcmp(p,"?")==0 && strcmp(n,".")==0) return 0; + if (strcmp(p,"?")==0 && strcmp(n,".")==0) goto match; while ((c = *p++)) { switch (c) { + case '.': + if (!strchr(p,'.') && !*n && ms_fnmatch_lanman_core(p, n)==0) + goto match; + if (*n != '.') goto nomatch; + n++; + break; + case '?': - if (*n == '.' || ! *n) return ms_fnmatch_lanman_core(p, n); + if ((*n == '.' && n[1] != '.') || ! *n) goto next; n++; break; @@ -55,7 +62,7 @@ int ms_fnmatch_lanman_core(char *pattern, char *string) if (ms_fnmatch_lanman_core(p, n) == 0) goto match; goto nomatch; } - if (! *n) return ms_fnmatch_lanman_core(p, n); + if (! *n) goto next; n++; break; @@ -90,11 +97,14 @@ int ms_fnmatch_lanman_core(char *pattern, char *string) if (! *n) goto match; - nomatch: if (verbose) printf("NOMATCH pattern=[%s] string=[%s]\n", pattern, string); return -1; +next: + if (ms_fnmatch_lanman_core(p, n) == 0) goto match; + goto nomatch; + match: if (verbose) printf("MATCH pattern=[%s] string=[%s]\n", pattern, string); return 0; @@ -102,19 +112,11 @@ int ms_fnmatch_lanman_core(char *pattern, char *string) int ms_fnmatch_lanman(char *pattern, char *string) { - int ret; - pattern = strdup(pattern); - - /* it appears that '.' at the end of a pattern is stripped if the - pattern contains any wildcard characters. Bizarre */ - if (strpbrk(pattern, "?*<>\"")) { - int len = strlen(pattern); - if (len > 0 && pattern[len-1] == '.') pattern[len-1] = 0; + if (!strpbrk(pattern, "?*<>\"")) { + return strcmp(pattern, string); } - ret = ms_fnmatch_lanman_core(pattern, string); - free(pattern); - return ret; + return ms_fnmatch_lanman_core(pattern, string); } static BOOL reg_match_one(char *pattern, char *file) -- cgit From 6ed9b52862fa076c26a267ab48df5a097f17edd6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Feb 2001 01:38:12 +0000 Subject: Ooops - forgot to check the rpcclient and smbcacls compile with the new code :-(. Jeremy. (This used to be commit 70beabf73bdaad7b6a60e24b7a11798a411bed02) --- source3/utils/smbcacls.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index b050139aa5..ea4191988a 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -30,6 +30,7 @@ static pstring owner_username; static fstring server; static int got_pass; static int test_args; +TALLOC_CTX *ctx; #define CREATE_ACCESS_READ READ_CONTROL_ACCESS #define CREATE_ACCESS_WRITE (WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS) @@ -327,15 +328,14 @@ static BOOL add_ace(SEC_ACL **the_acl, SEC_ACE *ace) SEC_ACL *new; SEC_ACE *aces; if (! *the_acl) { - (*the_acl) = make_sec_acl(3, 1, ace); + (*the_acl) = make_sec_acl(ctx, 3, 1, ace); return True; } aces = calloc(1+(*the_acl)->num_aces,sizeof(SEC_ACE)); memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE)); memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE)); - new = make_sec_acl((*the_acl)->revision,1+(*the_acl)->num_aces, aces); - free_sec_acl(the_acl); + new = make_sec_acl(ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces); free(aces); (*the_acl) = new; return True; @@ -396,11 +396,9 @@ static SEC_DESC *sec_desc_parse(char *str) return NULL; } - ret = make_sec_desc(revision, owner_sid, grp_sid, + ret = make_sec_desc(ctx,revision, owner_sid, grp_sid, NULL, dacl, &sd_size); - free_sec_acl(&dacl); - if (grp_sid) free(grp_sid); if (owner_sid) free(owner_sid); @@ -469,8 +467,6 @@ static int cacl_dump(struct cli_state *cli, char *filename) sec_desc_print(stdout, sd); - free_sec_desc(&sd); - cli_close(cli, fnum); return EXIT_OK; @@ -508,7 +504,7 @@ static int owner_set(struct cli_state *cli, enum chown_mode change_mode, return EXIT_FAILED; } - sd = make_sec_desc(old->revision, + sd = make_sec_desc(ctx,old->revision, (change_mode == REQUEST_CHOWN) ? &sid : old->owner_sid, (change_mode == REQUEST_CHGRP) ? &sid : old->grp_sid, NULL, old->dacl, &sd_size); @@ -524,9 +520,6 @@ static int owner_set(struct cli_state *cli, enum chown_mode change_mode, printf("ERROR: secdesc set failed: %s\n", cli_errstr(cli)); } - free_sec_desc(&sd); - free_sec_desc(&old); - cli_close(cli, fnum); return EXIT_OK; @@ -668,20 +661,15 @@ static int cacl_set(struct cli_state *cli, char *filename, break; case ACL_SET: - free_sec_desc(&old); old = sd; break; } - if (sd != old) { - free_sec_desc(&sd); - } - /* Denied ACE entries must come before allowed ones */ sort_acl(old->dacl); /* Create new security descriptor and set it */ - sd = make_sec_desc(old->revision, old->owner_sid, old->grp_sid, + sd = make_sec_desc(ctx,old->revision, old->owner_sid, old->grp_sid, NULL, old->dacl, &sd_size); fnum = cli_nt_create(cli, filename, CREATE_ACCESS_WRITE); @@ -698,9 +686,6 @@ static int cacl_set(struct cli_state *cli, char *filename, /* Clean up */ - free_sec_desc(&sd); - free_sec_desc(&old); - cli_close(cli, fnum); return result; @@ -838,12 +823,15 @@ You can string acls together with spaces, commas or newlines\n\ enum chown_mode change_mode = REQUEST_NONE; int result; + ctx=talloc_init(); + setlinebuf(stdout); dbf = stderr; if (argc < 3 || argv[1][0] == '-') { usage(); + talloc_destroy(ctx); exit(EXIT_PARSE_ERROR); } @@ -929,10 +917,12 @@ You can string acls together with spaces, commas or newlines\n\ case 'h': usage(); + talloc_destroy(ctx); exit(EXIT_PARSE_ERROR); default: printf("Unknown option %c (%d)\n", (char)opt, opt); + talloc_destroy(ctx); exit(EXIT_PARSE_ERROR); } } @@ -942,6 +932,7 @@ You can string acls together with spaces, commas or newlines\n\ if (argc > 0) { usage(); + talloc_destroy(ctx); exit(EXIT_PARSE_ERROR); } @@ -949,7 +940,10 @@ You can string acls together with spaces, commas or newlines\n\ if (!test_args) { cli = connect_one(share); - if (!cli) exit(EXIT_FAILED); + if (!cli) { + talloc_destroy(ctx); + exit(EXIT_FAILED); + } } all_string_sub(filename, "/", "\\", 0); @@ -970,5 +964,7 @@ You can string acls together with spaces, commas or newlines\n\ result = cacl_dump(cli, filename); } + talloc_destroy(ctx); + return result; } -- cgit From da3053048c3d224a20d6383ac6682d31059cd46c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 11 Mar 2001 00:32:10 +0000 Subject: Merge of new 2.2 code into HEAD (Gerald I hate you :-) :-). Allows new SAMR RPC code to merge with new passdb code. Currently rpcclient doesn't compile. I'm working on it... Jeremy. (This used to be commit 0be41d5158ea4e645e93e8cd30617c038416e549) --- source3/utils/smbpasswd.c | 19 +++++++------------ source3/utils/status.c | 4 ++-- 2 files changed, 9 insertions(+), 14 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index d20760bee1..94bfe464e4 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -221,13 +221,12 @@ static BOOL password_change(const char *remote_machine, char *user_name, if (remote_machine != NULL) { if (local_flags & (LOCAL_ADD_USER|LOCAL_DELETE_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER| - LOCAL_TRUST_ACCOUNT|LOCAL_SET_NO_PASSWORD)) - { + LOCAL_TRUST_ACCOUNT|LOCAL_SET_NO_PASSWORD)) { /* these things can't be done remotely yet */ return False; } - ret = remote_password_change(remote_machine, user_name, old_passwd, - new_passwd, err_str, sizeof(err_str)); + ret = remote_password_change(remote_machine, user_name, + old_passwd, new_passwd, err_str, sizeof(err_str)); if(*err_str) fprintf(stderr, err_str); return ret; @@ -409,11 +408,9 @@ static int process_root(int argc, char *argv[]) * smbpasswd file) then we need to prompt for a new password. */ - if(local_flags & LOCAL_ENABLE_USER) - { + if(local_flags & LOCAL_ENABLE_USER) { SAM_ACCOUNT *sampass = pdb_getsampwnam(user_name); - if((sampass != NULL) && (pdb_get_lanman_passwd(sampass) != NULL)) - { + if((sampass != NULL) && (pdb_get_lanman_passwd(sampass) != NULL)) { new_passwd = xstrdup("XXXX"); /* Don't care. */ } } @@ -427,15 +424,13 @@ static int process_root(int argc, char *argv[]) } } - if (!password_change(remote_machine, user_name, old_passwd, new_passwd, local_flags)) - { + if (!password_change(remote_machine, user_name, old_passwd, new_passwd, local_flags)) { fprintf(stderr,"Failed to modify password entry for user %s\n", user_name); result = 1; goto done; } - if(!(local_flags & (LOCAL_ADD_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER|LOCAL_DELETE_USER|LOCAL_SET_NO_PASSWORD))) - { + if(!(local_flags & (LOCAL_ADD_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER|LOCAL_DELETE_USER|LOCAL_SET_NO_PASSWORD))) { SAM_ACCOUNT *sampass = pdb_getsampwnam(user_name); printf("Password changed for user %s.", user_name ); if( (sampass != NULL) && (pdb_get_acct_ctrl(sampass)&ACB_DISABLED) ) diff --git a/source3/utils/status.c b/source3/utils/status.c index edc861d267..06abd09d92 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -58,8 +58,8 @@ static BOOL processes_only=False; static int show_brl; /* we need these because we link to locking*.o */ - void become_root(BOOL save_dir) {} - void unbecome_root(BOOL restore_dir) {} + void become_root(void) {} + void unbecome_root(void) {} /* added by OH */ -- cgit From c4a84783a672734f695defbac25733e5cbf29430 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 11 Mar 2001 00:45:07 +0000 Subject: Added JF's new util. Jeremy. (This used to be commit 96bcfdcded7202a7bced58fae6534f1fcd4c4e36) --- source3/utils/rpccheck.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 source3/utils/rpccheck.c (limited to 'source3/utils') diff --git a/source3/utils/rpccheck.c b/source3/utils/rpccheck.c new file mode 100644 index 0000000000..f504463027 --- /dev/null +++ b/source3/utils/rpccheck.c @@ -0,0 +1,64 @@ +/* + Unix SMB/Netbios implementation. + Version 2.2. + + Copyright (C) Jean François Micouleau 2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +main() +{ + char filter[]="0123456789ABCDEF"; + + char s[128]; + char d=0; + int x=0; + prs_struct ps; + TALLOC_CTX *ctx; + + /* change that struct */ + SAMR_R_QUERY_USERINFO rpc_stub; + + ZERO_STRUCT(rpc_stub); + + setup_logging("", True); + DEBUGLEVEL=10; + + ctx=talloc_init(); + + prs_init(&ps, 1600, 4, ctx, MARSHALL); + + while (scanf("%s", s)!=-1) { + if (strlen(s)==2 && strchr(filter, *s)!=NULL && strchr(filter, *(s+1))!=NULL) { + d=strtol(s, NULL, 16); + if(!prs_append_data(&ps, &d, 1)) + printf("error while reading data\n"); + } + } + + prs_switch_type(&ps, UNMARSHALL); + prs_set_offset(&ps, 0); + + /* change that call */ + if(!samr_io_r_query_userinfo("", &rpc_stub, &ps, 0)) + printf("error while UNMARSHALLING the data\n"); + + printf("\n"); +} -- cgit From 762c6e3f84141a1c7ef697f1b0a3339d655c86ad Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 14 Mar 2001 20:17:27 +0000 Subject: patches from Simo. Couple of snity things (This used to be commit af3f2a30c657fc42171bbf7da2354bc4cc7b088d) --- source3/utils/pdbedit.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index cd77cbc436..a86ea2ef5f 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -50,8 +50,8 @@ static void usage(void) printf("(actually to add a user you need to use smbpasswd)\n"); printf("options:\n"); printf(" -l list usernames\n"); - printf(" -v verbose output\n"); - printf(" -w smbpasswd file style\n"); + printf(" -v verbose output\n"); + printf(" -w smbpasswd file style\n"); printf(" -u username print user's info\n"); printf(" -f fullname set Full Name\n"); printf(" -h homedir set home directory\n"); @@ -89,8 +89,8 @@ static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdst { char lm_passwd[33]; char nt_passwd[33]; - pdb_gethexpwd(pdb_get_lanman_passwd(sam_pwent), lm_passwd); - pdb_gethexpwd(pdb_get_nt_passwd(sam_pwent), nt_passwd); + pdb_sethexpwd(lm_passwd, pdb_get_lanman_passwd(sam_pwent), pdb_get_acct_ctrl(sam_pwent)); + pdb_sethexpwd(nt_passwd, pdb_get_nt_passwd(sam_pwent), pdb_get_acct_ctrl(sam_pwent)); printf ("%s:%d:%s:%s:%s:LCT-%08x:\n", pdb_get_username(sam_pwent), -- cgit From 85a18b2c0cbccf8fa774ac5fb56e3c569ba4834c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 21 Mar 2001 05:54:09 +0000 Subject: latest attempt at lanman1 wildcard matching (This used to be commit 32361fc53e11a71f133a1727c6234a2bf01a5ccf) --- source3/utils/masktest.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index 4dd8f3ef06..8ee590d077 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -45,8 +45,7 @@ int ms_fnmatch_lanman_core(char *pattern, char *string) while ((c = *p++)) { switch (c) { case '.': - if (!strchr(p,'.') && !*n && ms_fnmatch_lanman_core(p, n)==0) - goto match; + /* if (! *n && ! *p) goto match; */ if (*n != '.') goto nomatch; n++; break; @@ -113,9 +112,15 @@ next: int ms_fnmatch_lanman(char *pattern, char *string) { if (!strpbrk(pattern, "?*<>\"")) { + if (strcmp(string,"..") == 0) string = "."; return strcmp(pattern, string); } + if (strcmp(string,"..") == 0 || strcmp(string,".") == 0) { + return ms_fnmatch_lanman_core(pattern, "..") && + ms_fnmatch_lanman_core(pattern, "."); + } + return ms_fnmatch_lanman_core(pattern, string); } @@ -124,13 +129,14 @@ static BOOL reg_match_one(char *pattern, char *file) /* oh what a weird world this is */ if (old_list && strcmp(pattern, "*.*") == 0) return True; - if (strcmp(file,"..") == 0) file = "."; if (strcmp(pattern,".") == 0) return False; if (max_protocol <= PROTOCOL_LANMAN2) { return ms_fnmatch_lanman(pattern, file)==0; } + if (strcmp(file,"..") == 0) file = "."; + return ms_fnmatch(pattern, file)==0; } @@ -276,6 +282,16 @@ static void get_real_name(struct cli_state *cli, pstrcpy(long_name, finfo->name); strlower(long_name); } + + if (*short_name == 0) { + fstrcpy(short_name, long_name); + } + +#if 0 + if (!strchr(short_name,'.')) { + fstrcat(short_name,"."); + } +#endif } static void testpair(struct cli_state *cli, char *mask, char *file) @@ -311,7 +327,7 @@ static void testpair(struct cli_state *cli, char *mask, char *file) if (showall || strcmp(res1, res2)) { DEBUG(0,("%s %s %d mask=[%s] file=[%s] rfile=[%s/%s]\n", res1, res2, count, mask, file, long_name, short_name)); - // exit(1); + /* exit(1); */ } cli_unlink(cli, file); -- cgit From 90890ef9fc2e0e1de389f6bc8137f7db7c8f9621 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 21 Mar 2001 06:44:49 +0000 Subject: added -E option (for exit on errors) forced exclusion of filenames containing only '.' as NT rejects those (This used to be commit a83ff172f271aa74148016f0e2ac62c868c140fb) --- source3/utils/masktest.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index 8ee590d077..a654b5bfd1 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -33,6 +33,7 @@ static BOOL old_list = False; static char *maskchars = "<>\"?*abc."; static char *filechars = "abcdefghijklm."; static int verbose; +static int die_on_error; /* a test fn for LANMAN mask support */ int ms_fnmatch_lanman_core(char *pattern, char *string) @@ -327,7 +328,7 @@ static void testpair(struct cli_state *cli, char *mask, char *file) if (showall || strcmp(res1, res2)) { DEBUG(0,("%s %s %d mask=[%s] file=[%s] rfile=[%s/%s]\n", res1, res2, count, mask, file, long_name, short_name)); - /* exit(1); */ + if (die_on_error) exit(1); } cli_unlink(cli, file); @@ -380,6 +381,8 @@ static void test_mask(int argc, char *argv[], strcmp(file+l,"..") == 0 || strcmp(mask+l,"..") == 0) continue; + if (strspn(file+l, ".") == strlen(file+l)) continue; + testpair(cli, mask, file); } @@ -454,8 +457,11 @@ static void usage(void) seed = time(NULL); - while ((opt = getopt(argc, argv, "U:s:hm:f:aoW:M:v")) != EOF) { + while ((opt = getopt(argc, argv, "U:s:hm:f:aoW:M:vE")) != EOF) { switch (opt) { + case 'E': + die_on_error = 1; + break; case 'v': verbose++; break; -- cgit From 0053bd8b80cc08d65948c97f8ab0b4e2b829f083 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Fri, 23 Mar 2001 00:50:31 +0000 Subject: first pass of the new group mapping code J.F. (This used to be commit 7154deb026d53cb0cd503562174c3332a372be63) --- source3/utils/smbgroupedit.c | 341 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 341 insertions(+) create mode 100644 source3/utils/smbgroupedit.c (limited to 'source3/utils') diff --git a/source3/utils/smbgroupedit.c b/source3/utils/smbgroupedit.c new file mode 100644 index 0000000000..d36e982b51 --- /dev/null +++ b/source3/utils/smbgroupedit.c @@ -0,0 +1,341 @@ +/* + * Unix SMB/Netbios implementation. + * Version 1.9. + * RPC Pipe client / server routines + * Copyright (C) Andrew Tridgell 1992-2000, + * Copyright (C) Jean François Micouleau 1998-2001. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +extern pstring global_myname; +extern int DEBUGLEVEL; +extern DOM_SID global_sam_sid; + +/* + * Next two lines needed for SunOS and don't + * hurt anything else... + */ +extern char *optarg; +extern int optind; + +/********************************************************* + Print command usage on stderr and die. +**********************************************************/ +static void usage(void) +{ + if (getuid() == 0) { + printf("groupedit options\n"); + } else { + printf("You need to be root to use this tool!\n"); + } + printf("options:\n"); + printf(" -a group create new group\n"); + printf(" -n group NT group name\n"); + printf(" -p privilege only local\n"); + printf(" -v list groups\n"); + printf(" -c SID change group\n"); + printf(" -x group delete this group\n"); + printf("\n"); + printf(" -t[b|d|l] type: builtin, domain, local \n"); + exit(1); +} + +/********************************************************* + add a group. +**********************************************************/ +int addgroup(char *group, enum SID_NAME_USE sid_type, char *ntgroup, char *ntcomment, char *privilege) +{ + uint32 se_priv; + gid_t gid; + DOM_SID sid; + fstring string_sid; + fstring name, comment; + +/* convert_priv_from_text(&se_priv, privilege);*/ + + se_priv=0xff; + + gid=nametogid(group); + if (gid==-1) + return -1; + + local_gid_to_sid(&sid, gid); + sid_to_string(string_sid, &sid); + + if (ntgroup==NULL) + fstrcpy(name, group); + else + fstrcpy(name, ntgroup); + + if (ntcomment==NULL) + fstrcpy(comment, "Local Unix group"); + else + fstrcpy(comment, ntcomment); + + if(add_initial_entry(gid, string_sid, sid_type, group, comment, se_priv)) + return 0; + +} + +/********************************************************* + Change a group. +**********************************************************/ +int changegroup(char *sid_string, char *group, enum SID_NAME_USE sid_type, char *groupdesc, char *privilege) +{ + DOM_SID sid; + GROUP_MAP map; + gid_t gid; + uint32 se_priv; + + string_to_sid(&sid, sid_string); + + /* Get the current mapping from the database */ + if(!get_group_map_from_sid(sid, &map)) { + printf("This SID does not exist in the database\n"); + return -1; + } + + /* If a new Unix group is specified, check and change */ + if (group!=NULL) { + gid=nametogid(group); + if (gid==-1) { + printf("The UNIX group does not exist\n"); + return -1; + } else + map.gid=gid; + } + + /* + * Allow changing of group type only between domain and local + * We disallow changing Builtin groups !!! (SID problem) + */ + if (sid_type==SID_NAME_ALIAS || sid_type==SID_NAME_DOM_GRP) + if (map.sid_name_use==SID_NAME_ALIAS || map.sid_name_use==SID_NAME_DOM_GRP) + map.sid_name_use=sid_type; + + + /* Change comment if new one */ + if (groupdesc!=NULL) + fstrcpy(map.comment, groupdesc); + + /* Change the privilege if new one */ + if (privilege!=NULL) { + convert_priv_from_text(&se_priv, privilege); + map.privilege=se_priv; + } + + if (!add_mapping_entry(&map, TDB_REPLACE)) { + printf("Count not update group database\n"); + return -1; + } + +} + +/********************************************************* + List the groups. +**********************************************************/ +int deletegroup(char *group) +{ + uint32 se_priv; + +/* convert_priv(&se_priv, privilege);*/ + +/* if(add_initial_entry(gid, sid, type, ntgroup, "", se_priv)) + return 0; +*/ +} + +/********************************************************* + List the groups. +**********************************************************/ +int listgroup(enum SID_NAME_USE sid_type) +{ + int entries,i; + GROUP_MAP *map=NULL; + fstring string_sid; + fstring group_type; + fstring priv_text; + + printf("Unix\tSID\ttype\tnt name\tnt comment\tprivilege\n"); + + if (enum_group_mapping(sid_type, &map, &entries)==False) + return 0; + + for (i=0; i 1) { + fprintf (stderr, "Incompatible options on command line!\n"); + usage(); + exit(1); + } + + /* no option on command line -> list groups */ + if (((add_group?1:0) + (view_group?1:0) + (change_group?1:0) + (delete_group?1:0)) == 0) + view_group = True; + + + if (group_type==False) + sid_type=SID_NAME_UNKNOWN; + else { + switch (groupt[0]) { + case 'l': + case 'L': + sid_type=SID_NAME_ALIAS; + break; + case 'd': + case 'D': + sid_type=SID_NAME_DOM_GRP; + break; + case 'b': + case 'B': + sid_type=SID_NAME_WKN_GRP; + break; + default: + sid_type=SID_NAME_UNKNOWN; + break; + } + } + + if (init_group_mapping()==False) { + printf("Could not open tdb mapping file.\n"); + return 0; + } + + if(pdb_generate_sam_sid()==False) { + printf("Can not read machine SID\n"); + return 0; + } + + default_group_mapping(); + + if (add_group) + return addgroup(group, sid_type, ntgroup, group_desc, privilege); + + if (view_group) + return listgroup(sid_type); + + if (delete_group) + return deletegroup(group); + + if (change_group) { + return changegroup(sid, group, sid_type, group_desc, privilege); + } + + usage(); + + return 0; +} + + -- cgit From 810ea03f9b1960ca7e9a775cd3582ca6bc080597 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Fri, 23 Mar 2001 01:19:21 +0000 Subject: can delete mapping from command line now. J.F. (This used to be commit 287d9fb06899fe7721fdfcd5ccaa566935d31c4d) --- source3/utils/smbgroupedit.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbgroupedit.c b/source3/utils/smbgroupedit.c index d36e982b51..01ae7091b3 100644 --- a/source3/utils/smbgroupedit.c +++ b/source3/utils/smbgroupedit.c @@ -87,9 +87,10 @@ int addgroup(char *group, enum SID_NAME_USE sid_type, char *ntgroup, char *ntcom else fstrcpy(comment, ntcomment); - if(add_initial_entry(gid, string_sid, sid_type, group, comment, se_priv)) - return 0; + if(!add_initial_entry(gid, string_sid, sid_type, group, comment, se_priv)) + return -1; + return 0; } /********************************************************* @@ -144,20 +145,22 @@ int changegroup(char *sid_string, char *group, enum SID_NAME_USE sid_type, char return -1; } + return 0; } /********************************************************* - List the groups. + Delete the group. **********************************************************/ -int deletegroup(char *group) +BOOL deletegroup(char *group) { - uint32 se_priv; + DOM_SID sid; -/* convert_priv(&se_priv, privilege);*/ + string_to_sid(&sid, group); -/* if(add_initial_entry(gid, sid, type, ntgroup, "", se_priv)) - return 0; -*/ + if(!group_map_remove(sid)) + return False; + + return True; } /********************************************************* @@ -173,8 +176,8 @@ int listgroup(enum SID_NAME_USE sid_type) printf("Unix\tSID\ttype\tnt name\tnt comment\tprivilege\n"); - if (enum_group_mapping(sid_type, &map, &entries)==False) - return 0; + if (!enum_group_mapping(sid_type, &map, &entries)) + return -1; for (i=0; i Date: Fri, 23 Mar 2001 02:14:08 +0000 Subject: groupdb/mapping.c: include/proto.h: Fix missing (void) in proto. rpc_server/srv_samr_nt.c: Fix user private group problem by filtering out groups that clash with users. smbd/posix_acls.c: Ensure default ACE's are sensible. utils/pdbedit.c: Fix from Simo Sorce. Jeremy. (This used to be commit 29414fe0d6665642d9b5f88a35e712426376c47f) --- source3/utils/pdbedit.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index a86ea2ef5f..6022f9aef2 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -185,6 +185,8 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, uchar new_nt_p16[16]; char *password1, *password2; + ZERO_STRUCT(sam_pwent); + if (pdb_getsampwnam (username)) { fprintf (stderr, "Username already exist in database!\n"); -- cgit From 1452c2d8c4a2124e4c97bb51a1e58bcfda620ef0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 26 Mar 2001 23:13:02 +0000 Subject: Fix from Ryo Kawahara to make SWAT correctly write and smb.conf file in utf8. Jeremy. (This used to be commit 42052d6079479452aa43eb37ad3d679d28337779) --- source3/utils/testparm.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index dcf114bc91..20f36fcffe 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -146,6 +146,7 @@ static void usage(char *pname) printf("\t-s Suppress prompt for enter\n"); printf("\t-h Print usage\n"); printf("\t-L servername Set %%L macro to servername\n"); + printf("\t-t encoding Print parameters with encoding\n"); printf("\tconfigfilename Configuration file to test\n"); printf("\thostname hostIP. Hostname and Host IP address to test\n"); printf("\t against \"host allow\" and \"host deny\"\n"); @@ -163,6 +164,9 @@ int main(int argc, char *argv[]) int s; BOOL silent_mode = False; int ret = 0; + pstring term_code; + + *term_code = 0; TimeInit(); @@ -170,7 +174,7 @@ int main(int argc, char *argv[]) charset_initialise(); - while ((opt = getopt(argc, argv,"shL:")) != EOF) { + while ((opt = getopt(argc, argv,"shL:t:")) != EOF) { switch (opt) { case 's': silent_mode = True; @@ -182,6 +186,9 @@ int main(int argc, char *argv[]) usage(argv[0]); exit(0); break; + case 't': + pstrcpy(term_code,optarg); + break; default: printf("Incorrect program usage\n"); usage(argv[0]); @@ -250,13 +257,16 @@ Level II oplocks can only be set if oplocks are also set.\n", } } + if (*term_code) + interpret_coding_system(term_code); + if (argc < 3) { if (!silent_mode) { printf("Press enter to see a dump of your service definitions\n"); fflush(stdout); getc(stdin); } - lp_dump(stdout,True, lp_numservices()); + lp_dump(stdout,True, lp_numservices(), _dos_to_unix); } if (argc >= 3) { -- cgit From de368e09cb310d4625995f1f47cc992f482d76fa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Mar 2001 00:28:01 +0000 Subject: Fix for ENOSPC from DCB. Jeremy. (This used to be commit 55fcd71eecf4477c56fc4a01bda6d452d3b0caa4) --- source3/utils/nbio.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nbio.c b/source3/utils/nbio.c index 973f7d0628..4866e52d4e 100644 --- a/source3/utils/nbio.c +++ b/source3/utils/nbio.c @@ -128,8 +128,14 @@ void nb_write(int handle, int size, int offset) return; } if (cli_smbwrite(c, ftable[i].fd, buf, offset, size) != size) { - printf("(%d) write failed on handle %d\n", - line_count, handle); + printf("(%d) write failed on handle %d, fd %d \ +errno %d (%s)\n", line_count, handle, ftable[i].fd, errno, strerror(errno)); + if (errno == ENOSPC) { + printf("Halting.\n"); + fflush(stdout); + fflush(stderr); + exit(3); + } } } @@ -147,8 +153,8 @@ void nb_read(int handle, int size, int offset) } 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); + printf("(%d) read failed on handle %d ofs=%d size=%d res=%d fd %d errno %d (%s)\n", + line_count, handle, offset, size, ret, ftable[i].fd, errno, strerror(errno)); #endif } } -- cgit From 74c81cd628076da460128cb9a84cd90647a37edd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 30 Mar 2001 00:35:47 +0000 Subject: Added delete on close test that has allowed me to determine how w2k behaves in this situation. Jeremy. (This used to be commit b0266fe0a8c707cb7e818269dc7fe52da709fdab) --- source3/utils/torture.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 40b4b123e9..0c6ba40607 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -2045,6 +2045,152 @@ static void run_oplock2(int dummy) printf("finished oplock test 2\n"); } +/* + Test delete on close semantics. + */ +static void run_deletetest(int dummy) +{ + static struct cli_state cli1; + char *fname = "\\delete.file"; + int fnum1, fnum2; + + printf("starting delete test\n"); + + if (!open_connection(&cli1)) { + return; + } + + cli_sockopt(&cli1, sockops); + + /* Test 1 - this should *NOT* delete the file on close. */ + + cli_setatr(&cli1, fname, 0, 0); + cli_unlink(&cli1, fname); + + fnum1 = cli_nt_create_full(&cli1, fname, 0x30196, FILE_ATTRIBUTE_NORMAL, + FILE_SHARE_DELETE, FILE_OVERWRITE_IF, DELETE_ON_CLOSE_FLAG); + + if (fnum1 == -1) { + printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + if (!cli_close(&cli1, fnum1)) { + printf("[1] close failed (%s)\n", cli_errstr(&cli1)); + return; + } + + fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE); + if (fnum1 == -1) { + printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + if (!cli_close(&cli1, fnum1)) { + printf("[1] close failed (%s)\n", cli_errstr(&cli1)); + return; + } + + printf("first delete on close test succeeded.\n"); + + /* Test 2 - this should delete the file on close. */ + + cli_setatr(&cli1, fname, 0, 0); + cli_unlink(&cli1, fname); + + fnum1 = cli_nt_create_full(&cli1, fname, 0x30196, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0); + + if (fnum1 == -1) { + printf("[2] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + if (!cli_nt_delete_on_close(&cli1, fnum1, True)) { + printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(&cli1)); + return; + } + + if (!cli_close(&cli1, fnum1)) { + printf("[2] close failed (%s)\n", cli_errstr(&cli1)); + return; + } + + fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE); + if (fnum1 != -1) { + printf("[2] open of %s succeeded should have been deleted on close !\n", fname); + if (!cli_close(&cli1, fnum1)) { + printf("[2] close failed (%s)\n", cli_errstr(&cli1)); + } + cli_unlink(&cli1, fname); + } else + printf("second delete on close test succeeded.\n"); + + + /* Test 3 - ... */ + cli_setatr(&cli1, fname, 0, 0); + cli_unlink(&cli1, fname); + + fnum1 = cli_nt_create_full(&cli1, fname, 0x30196, FILE_ATTRIBUTE_NORMAL, + FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0); + + if (fnum1 == -1) { + printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + /* This should fail with a sharing violation. */ + + fnum2 = cli_nt_create_full(&cli1, fname, 0x30196, FILE_ATTRIBUTE_NORMAL, + FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0); + + if (fnum2 != -1) { + printf("[3] open - 2 of %s succeeded - should have failed.\n", fname); + return; + } + + /* This should succeed. */ + + fnum2 = cli_nt_create_full(&cli1, fname, 0x30196, FILE_ATTRIBUTE_NORMAL, + FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0); + + if (fnum2 == -1) { + printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + if (!cli_nt_delete_on_close(&cli1, fnum1, True)) { + printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(&cli1)); + return; + } + + if (!cli_close(&cli1, fnum1)) { + printf("[3] close 1 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + if (!cli_close(&cli1, fnum2)) { + printf("[3] close 2 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE); + if (fnum1 != -1) { + printf("[3] open of %s succeeded should have been deleted on close !\n", fname); + if (!cli_close(&cli1, fnum1)) { + printf("[3] close failed (%s)\n", cli_errstr(&cli1)); + } + cli_unlink(&cli1, fname); + } else + printf("third delete on close test succeeded.\n"); + + cli_setatr(&cli1, fname, 0, 0); + cli_unlink(&cli1, fname); + + close_connection(&cli1); + + printf("finished delete test 1\n"); +} + /* Test open mode returns on read-only files. */ @@ -2279,6 +2425,7 @@ static struct { {"RW1", run_readwritetest, 0}, {"RW2", run_readwritemulti, FLAG_MULTIPROC}, {"OPEN", run_opentest, 0}, + {"DELETE", run_deletetest, 0}, {NULL, NULL, 0}}; -- cgit From e51ffc811137825e32603f7330869e4ecdf18ba1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 30 Mar 2001 02:48:06 +0000 Subject: Changed to using GENERIC_XX constants instead of hex values to make delete test explicit. Jeremy. (This used to be commit cb5963af0ecabab928aafacd27714e337b9bb37e) --- source3/utils/torture.c | 66 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 9 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 0c6ba40607..76d431c64f 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -2067,9 +2067,9 @@ static void run_deletetest(int dummy) cli_setatr(&cli1, fname, 0, 0); cli_unlink(&cli1, fname); - fnum1 = cli_nt_create_full(&cli1, fname, 0x30196, FILE_ATTRIBUTE_NORMAL, + fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE, FILE_OVERWRITE_IF, DELETE_ON_CLOSE_FLAG); - + if (fnum1 == -1) { printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); return; @@ -2098,8 +2098,9 @@ static void run_deletetest(int dummy) cli_setatr(&cli1, fname, 0, 0); cli_unlink(&cli1, fname); - fnum1 = cli_nt_create_full(&cli1, fname, 0x30196, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0); - + fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, + FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0); + if (fnum1 == -1) { printf("[2] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); return; @@ -2130,7 +2131,7 @@ static void run_deletetest(int dummy) cli_setatr(&cli1, fname, 0, 0); cli_unlink(&cli1, fname); - fnum1 = cli_nt_create_full(&cli1, fname, 0x30196, FILE_ATTRIBUTE_NORMAL, + fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0); if (fnum1 == -1) { @@ -2138,9 +2139,10 @@ static void run_deletetest(int dummy) return; } - /* This should fail with a sharing violation. */ + /* This should fail with a sharing violation - SHARE_DELETE is only compatible + with SHARE_DELETE. */ - fnum2 = cli_nt_create_full(&cli1, fname, 0x30196, FILE_ATTRIBUTE_NORMAL, + fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0); if (fnum2 != -1) { @@ -2150,7 +2152,7 @@ static void run_deletetest(int dummy) /* This should succeed. */ - fnum2 = cli_nt_create_full(&cli1, fname, 0x30196, FILE_ATTRIBUTE_NORMAL, + fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0); if (fnum2 == -1) { @@ -2173,6 +2175,8 @@ static void run_deletetest(int dummy) return; } + /* This should fail - file should no longer be there. */ + fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE); if (fnum1 != -1) { printf("[3] open of %s succeeded should have been deleted on close !\n", fname); @@ -2183,12 +2187,56 @@ static void run_deletetest(int dummy) } else printf("third delete on close test succeeded.\n"); + /* Test 4 ... */ cli_setatr(&cli1, fname, 0, 0); cli_unlink(&cli1, fname); - close_connection(&cli1); + fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, + FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0); + + if (fnum1 == -1) { + printf("[4] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + /* This should succeed. */ + fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, + FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0); + if (fnum2 == -1) { + printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + if (!cli_close(&cli1, fnum2)) { + printf("[4] close - 1 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + if (!cli_nt_delete_on_close(&cli1, fnum1, True)) { + printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(&cli1)); + return; + } + + /* This should fail - no more opens once delete on close set. */ + fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, + FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0); + if (fnum2 != -1) { + printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname ); + return; + } else + printf("fourth delete on close test succeeded.\n"); + + if (!cli_close(&cli1, fnum1)) { + printf("[4] close - 2 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + cli_setatr(&cli1, fname, 0, 0); + cli_unlink(&cli1, fname); printf("finished delete test 1\n"); + + close_connection(&cli1); } /* -- cgit From 0be5f29179440e3c9035c0b898af2f0856b2541f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 30 Mar 2001 06:22:14 +0000 Subject: Expanded delete on close test to 6 cases. I now understand the semantics of this and the FILE_SHARE_DELETE flag exactly. The bad news is it means our share mode handling is broken (again :-). Jeremy. (This used to be commit a55ed1a91d91beafb2f199d1da530169715dbe0e) --- source3/utils/torture.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 76d431c64f..0869e5e019 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -2132,14 +2132,14 @@ static void run_deletetest(int dummy) cli_unlink(&cli1, fname); fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL, - FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0); + FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0); if (fnum1 == -1) { printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(&cli1)); return; } - /* This should fail with a sharing violation - SHARE_DELETE is only compatible + /* This should fail with a sharing violation - open for delete is only compatible with SHARE_DELETE. */ fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL, @@ -2231,6 +2231,57 @@ static void run_deletetest(int dummy) return; } + /* Test 5 ... */ + cli_setatr(&cli1, fname, 0, 0); + cli_unlink(&cli1, fname); + + fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + /* This should fail - only allowed on NT opens with DELETE access. */ + + if (cli_nt_delete_on_close(&cli1, fnum1, True)) { + printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n"); + return; + } + + if (!cli_close(&cli1, fnum1)) { + printf("[5] close - 2 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + printf("fifth delete on close test succeeded.\n"); + + /* Test 6 ... */ + cli_setatr(&cli1, fname, 0, 0); + cli_unlink(&cli1, fname); + + fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA, + FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, + FILE_OVERWRITE_IF, 0); + + if (fnum1 == -1) { + printf("[6] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + /* This should fail - only allowed on NT opens with DELETE access. */ + + if (cli_nt_delete_on_close(&cli1, fnum1, True)) { + printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n"); + return; + } + + if (!cli_close(&cli1, fnum1)) { + printf("[6] close - 2 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + printf("sixth delete on close test succeeded.\n"); + cli_setatr(&cli1, fname, 0, 0); cli_unlink(&cli1, fname); -- cgit From 9874ebc3d3355465f884f3aad4d69914a4e1f0c5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 30 Mar 2001 06:31:22 +0000 Subject: Added one more test - just to make sure flag can be unset. Jeremy. (This used to be commit 54960b9c8d6be6646a0c0e8ef9ee6c61a4b69cf8) --- source3/utils/torture.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 0869e5e019..8588aa9610 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -2282,10 +2282,52 @@ static void run_deletetest(int dummy) printf("sixth delete on close test succeeded.\n"); + /* Test 7 ... */ cli_setatr(&cli1, fname, 0, 0); cli_unlink(&cli1, fname); - printf("finished delete test 1\n"); + fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, + FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0); + + if (fnum1 == -1) { + printf("[7] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + if (!cli_nt_delete_on_close(&cli1, fnum1, True)) { + printf("[7] setting delete_on_close on file failed !\n"); + return; + } + + if (!cli_nt_delete_on_close(&cli1, fnum1, False)) { + printf("[7] unsetting delete_on_close on file failed !\n"); + return; + } + + if (!cli_close(&cli1, fnum1)) { + printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + /* This next open should succeed - we reset the flag. */ + + fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE); + if (fnum1 == -1) { + printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + if (!cli_close(&cli1, fnum1)) { + printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + printf("seventh delete on close test succeeded.\n"); + + cli_setatr(&cli1, fname, 0, 0); + cli_unlink(&cli1, fname); + + printf("finished delete test\n"); close_connection(&cli1); } -- cgit From fd6e9d6db98086e47650e5679064172fd5454f40 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 30 Mar 2001 21:53:33 +0000 Subject: utils/torture.c: Added one more delete on close test. smbd/notify_kernel.c: This code was wrong I believe. It was structured to only return a changenotify event on being called from timeout processing (t != 0). The kernel changenotify events should fire on *asynchronous* processing (EINTR return from select caused by the realtime signal delivery) with t == 0. Reported by Juergen Hasch (Hasch@t-online.de). ANDREW PLEASE CHECK THIS ! Currently the hash style changenotify is done on async processing as well as timeout processing. As this is expensive we may want to revisit doing this and maybe set it to fire only on timeout processing. Jeremy. (This used to be commit f952380c5d0cfbbec1e7de98b712952f302cddfd) --- source3/utils/torture.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 8588aa9610..ac922eed61 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -2051,6 +2051,7 @@ static void run_oplock2(int dummy) static void run_deletetest(int dummy) { static struct cli_state cli1; + static struct cli_state cli2; char *fname = "\\delete.file"; int fnum1, fnum2; @@ -2324,12 +2325,66 @@ static void run_deletetest(int dummy) printf("seventh delete on close test succeeded.\n"); + /* Test 7 ... */ cli_setatr(&cli1, fname, 0, 0); cli_unlink(&cli1, fname); + if (!open_connection(&cli2)) { + printf("[8] failed to open second connection.\n"); + return; + } + + cli_sockopt(&cli1, sockops); + + fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, + FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0); + + if (fnum1 == -1) { + printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + fnum2 = cli_nt_create_full(&cli2, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, + FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0); + + if (fnum2 == -1) { + printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + if (!cli_nt_delete_on_close(&cli1, fnum1, True)) { + printf("[8] setting delete_on_close on file failed !\n"); + return; + } + + if (!cli_close(&cli1, fnum1)) { + printf("[8] close - 1 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + if (!cli_close(&cli2, fnum2)) { + printf("[8] close - 2 failed (%s)\n", cli_errstr(&cli2)); + return; + } + + /* This should fail.. */ + fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE); + if (fnum1 != -1) { + printf("[8] open of %s succeeded should have been deleted on close !\n", fname); + if (!cli_close(&cli1, fnum1)) { + printf("[8] close failed (%s)\n", cli_errstr(&cli1)); + } + cli_unlink(&cli1, fname); + } else + printf("eighth delete on close test succeeded.\n"); + printf("finished delete test\n"); + cli_setatr(&cli1, fname, 0, 0); + cli_unlink(&cli1, fname); + close_connection(&cli1); + close_connection(&cli2); } /* -- cgit From 3a38f122d9bf747ae31d630da1ce6762aefa47ce Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Apr 2001 01:34:37 +0000 Subject: Added SMB_ prefix to enums that clash with Solaris ACL definitions. Jeremy. (This used to be commit 493d2c316a9e80de0239ef3a6f0b3f4ec9ac6e13) --- source3/utils/smbcacls.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index ea4191988a..6f5bcc4476 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -39,7 +39,7 @@ TALLOC_CTX *ctx; than going via LSA calls to resolve them */ static int numeric; -enum acl_mode {ACL_SET, ACL_DELETE, ACL_MODIFY, ACL_ADD }; +enum acl_mode {SMB_ACL_SET, SMB_ACL_DELETE, SMB_ACL_MODIFY, SMB_ACL_ADD }; enum chown_mode {REQUEST_NONE, REQUEST_CHOWN, REQUEST_CHGRP}; enum exit_values {EXIT_OK, EXIT_FAILED, EXIT_PARSE_ERROR}; @@ -600,7 +600,7 @@ static int cacl_set(struct cli_state *cli, char *filename, /* the logic here is rather more complex than I would like */ switch (mode) { - case ACL_DELETE: + case SMB_ACL_DELETE: for (i=0;sd->dacl && idacl->num_aces;i++) { BOOL found = False; @@ -632,7 +632,7 @@ static int cacl_set(struct cli_state *cli, char *filename, } break; - case ACL_MODIFY: + case SMB_ACL_MODIFY: for (i=0;sd->dacl && idacl->num_aces;i++) { BOOL found = False; @@ -654,13 +654,13 @@ static int cacl_set(struct cli_state *cli, char *filename, break; - case ACL_ADD: + case SMB_ACL_ADD: for (i=0;sd->dacl && idacl->num_aces;i++) { add_ace(&old->dacl, &sd->dacl->ace[i]); } break; - case ACL_SET: + case SMB_ACL_SET: old = sd; break; } @@ -879,22 +879,22 @@ You can string acls together with spaces, commas or newlines\n\ case 'S': the_acl = optarg; - mode = ACL_SET; + mode = SMB_ACL_SET; break; case 'D': the_acl = optarg; - mode = ACL_DELETE; + mode = SMB_ACL_DELETE; break; case 'M': the_acl = optarg; - mode = ACL_MODIFY; + mode = SMB_ACL_MODIFY; break; case 'A': the_acl = optarg; - mode = ACL_ADD; + mode = SMB_ACL_ADD; break; case 'C': -- cgit From 2ef68c7e92d4661664f0410509f7cb551e74a198 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 13 Apr 2001 19:12:06 +0000 Subject: Merge of Andrew's changes in 2.2. Jeremy. (This used to be commit fc76681812b1469208ad6c8847afdfc68bc6db49) --- source3/utils/smbcacls.c | 11 ++++------- source3/utils/smbcontrol.c | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 6f5bcc4476..4803da9f33 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -74,7 +74,7 @@ BOOL got_policy_hnd; /* Open cli connection and policy handle */ -static BOOL open_policy_hnd(void) +static BOOL cacls_open_policy_hnd(void) { creds.pwd.null_pwd = 1; @@ -117,7 +117,7 @@ static void SidToString(fstring str, DOM_SID *sid) /* Ask LSA to convert the sid to a name */ - if (!open_policy_hnd() || + if (!cacls_open_policy_hnd() || cli_lsa_lookup_sids(&lsa_cli, &pol, 1, sid, &names, &types, &num_names) != NT_STATUS_NOPROBLEMO || !names || !names[0]) { @@ -145,7 +145,7 @@ static BOOL StringToSid(DOM_SID *sid, char *str) return string_to_sid(sid, str); } - if (!open_policy_hnd() || + if (!cacls_open_policy_hnd() || cli_lsa_lookup_names(&lsa_cli, &pol, 1, &str, &sids, &types, &num_sids) != NT_STATUS_NOPROBLEMO) { result = False; @@ -815,9 +815,8 @@ You can string acls together with spaces, commas or newlines\n\ extern FILE *dbf; int opt; char *p; - int seed; static pstring servicesf = CONFIGFILE; - struct cli_state *cli; + struct cli_state *cli=NULL; enum acl_mode mode; char *the_acl = NULL; enum chown_mode change_mode = REQUEST_NONE; @@ -863,8 +862,6 @@ You can string acls together with spaces, commas or newlines\n\ } } - seed = time(NULL); - while ((opt = getopt(argc, argv, "U:nhS:D:A:M:C:G:t")) != EOF) { switch (opt) { case 'U': diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 26c01ced9e..c5462ea1fb 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -97,7 +97,7 @@ Prints out the current Profile level returned by MSG_PROFILELEVEL void profilelevel_function(int msg_type, pid_t src, void *buf, size_t len) { int level; - char *s; + char *s=NULL; memcpy(&level, buf, sizeof(int)); if (level) { @@ -175,7 +175,7 @@ static BOOL do_command(char *dest, char *msg_name, char *params[]) { int i, n, v; int mtype; - BOOL retval; + BOOL retval=False; int debuglevel_class[DBGC_LAST]; mtype = parse_type(msg_name); -- cgit From 819482c07137937ee0c063437d2b2eade2895b99 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 13 Apr 2001 20:49:11 +0000 Subject: Fixed potential file descriptor leak with MS-Access fix. Jeremy. (This used to be commit 192887fe72157a141b8df1977085f479e5204782) --- source3/utils/torture.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index ac922eed61..446bf7eaf2 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -2431,7 +2431,7 @@ static void run_opentest(int dummy) return; } - /* This will fail - but the error should be ERRnoaccess, not ERRshare. */ + /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */ fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL); cli_error( &cli1, &eclass, &errnum, NULL); @@ -2444,14 +2444,37 @@ static void run_opentest(int dummy) } + printf("finished open test 1\n"); + cli_close(&cli1, fnum1); + /* Now try not readonly and ensure ERRbadshare is returned. */ + cli_setatr(&cli1, fname, 0, 0); + + fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + /* This will fail - but the error should be ERRshare. */ + fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL); + + cli_error( &cli1, &eclass, &errnum, NULL); + + if (eclass != ERRDOS || errnum != ERRbadshare) { + printf("wrong error code (%x,%x) = %s\n", (unsigned int)eclass, + (unsigned int)errnum, cli_errstr(&cli1) ); + } else { + printf("correct error code ERRDOS/ERRbadshare returned\n"); + } + cli_unlink(&cli1, fname); close_connection(&cli1); - printf("finished open test 1\n"); + printf("finished open test 2\n"); } static void list_fn(file_info *finfo, const char *name, void *state) -- cgit From 2df39394fe01de6fb19cd919554272f407ecee4a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 14 Apr 2001 20:47:30 +0000 Subject: This little piece of insanity is inspired by the fact that an NT client can open a file for O_RDONLY, but set the create disposition to FILE_EXISTS_TRUNCATE. If the client *can* write to the file, then it expects to truncate the file, even though it is opening for readonly. Quicken uses this stupid trick in backup file creation... Thanks *greatly* to "David W. Chapman Jr." for helping track this one down. It didn't bite us in 2.0.x as we always opened files read-write in that release. Jeremy. (This used to be commit 5baef56831f9bc4fa10a851abd5f9305b974fb3b) --- source3/utils/torture.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 446bf7eaf2..871e2adfc3 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -2397,6 +2397,8 @@ static void run_opentest(int dummy) int fnum1, fnum2; uint8 eclass; uint32 errnum; + char buf[20]; + size_t fsize; printf("starting open test\n"); @@ -2470,11 +2472,76 @@ static void run_opentest(int dummy) printf("correct error code ERRDOS/ERRbadshare returned\n"); } + if (!cli_close(&cli1, fnum1)) { + printf("close2 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + cli_unlink(&cli1, fname); + + printf("finished open test 2\n"); + + /* Test truncate open disposition on file opened for read. */ + + fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + /* write 20 bytes. */ + + memset(buf, '\0', 20); + + if (cli_write(&cli1, fnum1, 0, buf, 0, 20) != 20) { + printf("write failed (%s)\n", cli_errstr(&cli1)); + } + + if (!cli_close(&cli1, fnum1)) { + printf("(3) close1 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + /* Ensure size == 20. */ + if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) { + printf("(3) getatr failed (%s)\n", cli_errstr(&cli1)); + return; + } + + if (fsize != 20) { + printf("(3) file size != 20\n"); + return; + } + + /* Now test if we can truncate a file opened for readonly. */ + + fnum1 = cli_open(&cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE); + if (fnum1 == -1) { + printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + if (!cli_close(&cli1, fnum1)) { + printf("close2 failed (%s)\n", cli_errstr(&cli1)); + return; + } + + /* Ensure size == 0. */ + if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) { + printf("(3) getatr failed (%s)\n", cli_errstr(&cli1)); + return; + } + + if (fsize != 0) { + printf("(3) file size != 0\n"); + return; + } + printf("finished open test 3\n"); + cli_unlink(&cli1, fname); close_connection(&cli1); - printf("finished open test 2\n"); } static void list_fn(file_info *finfo, const char *name, void *state) -- cgit From 57007050da6e45cc0f42b12c4b17812bfb423bcd Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Tue, 24 Apr 2001 16:44:28 +0000 Subject: don't allow both add and delete user to be set at the same time (This used to be commit 9db84de46a3823878c2a9356ac4ae4fd179d5847) --- source3/utils/smbpasswd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 94bfe464e4..411d89f3f1 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -319,10 +319,13 @@ static int process_root(int argc, char *argv[]) argv += optind; /* + * Ensure both add/delete user are not set * Ensure add/delete user and either remote machine or join domain are * not both set. */ - if((local_flags & (LOCAL_ADD_USER|LOCAL_DELETE_USER)) && ((remote_machine != NULL) || joining_domain)) { + if(((local__flags & (LOCAL_ADD_USER|LOCAL_DELETE_USER)) == (LOCAL_ADD_USER|LOCAL_DELETE_USER)) || + ((local_flags & (LOCAL_ADD_USER|LOCAL_DELETE_USER)) && + ((remote_machine != NULL) || joining_domain))) { usage(); } -- cgit From 55d0bdbf4a656fe457d180940ad0e700375ffc15 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Tue, 24 Apr 2001 18:53:15 +0000 Subject: fix typo (This used to be commit ed2dfae0e503367671c54ad8f1f49ac3af0b1c6a) --- source3/utils/smbpasswd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 411d89f3f1..8ddd07a4c5 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -323,7 +323,7 @@ static int process_root(int argc, char *argv[]) * Ensure add/delete user and either remote machine or join domain are * not both set. */ - if(((local__flags & (LOCAL_ADD_USER|LOCAL_DELETE_USER)) == (LOCAL_ADD_USER|LOCAL_DELETE_USER)) || + if(((local_flags & (LOCAL_ADD_USER|LOCAL_DELETE_USER)) == (LOCAL_ADD_USER|LOCAL_DELETE_USER)) || ((local_flags & (LOCAL_ADD_USER|LOCAL_DELETE_USER)) && ((remote_machine != NULL) || joining_domain))) { usage(); -- cgit From 8f11c24b74ff943e67a456c17c1ac139fa801c6d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 27 Apr 2001 22:42:10 +0000 Subject: More gcc compile on solaris tidyups. Jeremy. (This used to be commit 956201c4fb6e604407911b9709574f0c24dcb84f) --- source3/utils/smbcontrol.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index c5462ea1fb..09f0e3090b 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -69,7 +69,7 @@ a useful function for testing the message system void pong_function(int msg_type, pid_t src, void *buf, size_t len) { pong_count++; - printf("PONG from PID %d\n",src); + printf("PONG from PID %u\n",(unsigned int)src); } /**************************************************************************** @@ -82,7 +82,7 @@ void debuglevel_function(int msg_type, pid_t src, void *buf, size_t len) memcpy(debuglevel_class, buf, len); - printf("Current debug level of PID %d is %d ",src, debuglevel_class[0]); + printf("Current debug level of PID %u is %d ",(unsigned int)src, debuglevel_class[0]); for (i=1;i Date: Sat, 28 Apr 2001 00:05:11 +0000 Subject: rpcclient/rpcclient.c: Non-void return in void function. smbd/sec_ctx.c: Fixed potential memory leak spotted by Kenichi Okuyama@Tokyo Research Lab, IBM-Japan, Co. utils/nmblookup.c: gcc warning on Solaris fix. Jeremy. (This used to be commit 1be60597cd62af2b30a1496d06ea5704e87d3b7d) --- source3/utils/nmblookup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 4e85f6ac45..0f978a6cf3 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -118,7 +118,7 @@ static void do_node_status(int fd, char *name, int type, struct in_addr ip) for (i=0;i - %s\n", cleanname,status[i].type, -- cgit From e40449fa720d0934abd06cd0b0b05d0ca0f4e257 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 28 Apr 2001 00:32:56 +0000 Subject: rpcclient merge from 2.2 (including Jeremy's non-void return fix) (This used to be commit 0a6ceed279cc8111008b21f75c6791efbd993f4b) --- source3/utils/smbcacls.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 4803da9f33..3566ccb28c 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -92,7 +92,7 @@ static BOOL cacls_open_policy_hnd(void) /* Some systems don't support SEC_RIGHTS_MAXIMUM_ALLOWED, but NT sends 0x2000000 so we might as well do it too. */ - if (cli_lsa_open_policy(&lsa_cli, True, + if (cli_lsa_open_policy(&lsa_cli, lsa_cli.mem_ctx, True, GENERIC_EXECUTE_ACCESS, &pol) != NT_STATUS_NOPROBLEMO) { return False; @@ -118,7 +118,7 @@ static void SidToString(fstring str, DOM_SID *sid) /* Ask LSA to convert the sid to a name */ if (!cacls_open_policy_hnd() || - cli_lsa_lookup_sids(&lsa_cli, &pol, 1, sid, &names, &types, + cli_lsa_lookup_sids(&lsa_cli, lsa_cli.mem_ctx, &pol, 1, sid, &names, &types, &num_names) != NT_STATUS_NOPROBLEMO || !names || !names[0]) { return; @@ -146,7 +146,7 @@ static BOOL StringToSid(DOM_SID *sid, char *str) } if (!cacls_open_policy_hnd() || - cli_lsa_lookup_names(&lsa_cli, &pol, 1, &str, &sids, &types, + cli_lsa_lookup_names(&lsa_cli, lsa_cli.mem_ctx, &pol, 1, &str, &sids, &types, &num_sids) != NT_STATUS_NOPROBLEMO) { result = False; goto done; -- cgit From 7e82811d2d1b9ed06767625fff12755ced83bcad Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 1 May 2001 04:05:53 +0000 Subject: fixed some uninitialised variables (This used to be commit 5d899e51a4fc4e872da550b88ef603dbd2d8391f) --- source3/utils/smbcacls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 3566ccb28c..66b15ea1ac 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -817,7 +817,7 @@ You can string acls together with spaces, commas or newlines\n\ char *p; static pstring servicesf = CONFIGFILE; struct cli_state *cli=NULL; - enum acl_mode mode; + enum acl_mode mode = 0; char *the_acl = NULL; enum chown_mode change_mode = REQUEST_NONE; int result; -- cgit From f5eab4421c0fcda6907259cb91ba091e9cca5eae Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 1 May 2001 23:07:30 +0000 Subject: Fixup smbcacls. Don't return memory already freed, don't free memory allocated with talloc. Jeremy. (This used to be commit 0ae0d024f5898f7e47e4b1d4487b15447096780c) --- source3/utils/smbcacls.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 66b15ea1ac..7b459a32ed 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -127,10 +127,6 @@ static void SidToString(fstring str, DOM_SID *sid) /* Converted OK */ fstrcpy(str, names[0]); - - safe_free(names[0]); - safe_free(names); - safe_free(types); } /* convert a string to a SID, either numeric or username/group */ @@ -154,9 +150,6 @@ static BOOL StringToSid(DOM_SID *sid, char *str) sid_copy(sid, &sids[0]); - safe_free(sids); - safe_free(types); - done: return result; @@ -458,7 +451,7 @@ static int cacl_dump(struct cli_state *cli, char *filename) return EXIT_FAILED; } - sd = cli_query_secdesc(cli, fnum); + sd = cli_query_secdesc(cli, fnum, ctx); if (!sd) { printf("ERROR: secdesc query failed: %s\n", cli_errstr(cli)); @@ -495,7 +488,7 @@ static int owner_set(struct cli_state *cli, enum chown_mode change_mode, if (!StringToSid(&sid, new_username)) return EXIT_PARSE_ERROR; - old = cli_query_secdesc(cli, fnum); + old = cli_query_secdesc(cli, fnum, ctx); cli_close(cli, fnum); @@ -589,7 +582,7 @@ static int cacl_set(struct cli_state *cli, char *filename, return EXIT_FAILED; } - old = cli_query_secdesc(cli, fnum); + old = cli_query_secdesc(cli, fnum, ctx); if (!old) { printf("calc_set: Failed to query old descriptor\n"); -- cgit From 548d16869acffdec899121906a7bcd88f58d9b6f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 3 May 2001 19:47:30 +0000 Subject: Fixed SHM_R/SHM_W warnings by moving sys/ipc.h and sys/shm.h into includes.h and using autoconf tests. Added "restrict acl with mask" parameter. Jeremy. (This used to be commit 7792e32ba7fd734cc68b354f31c382ac11521fe8) --- source3/utils/torture.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 871e2adfc3..fe22b60a89 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -22,8 +22,6 @@ #define NO_SYSLOG #include "includes.h" -#include -#include static fstring host, workgroup, share, password, username, myname; static int max_protocol = PROTOCOL_NT1; -- cgit From f35157f39293f9fa240a28642c41708b55d301c8 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Fri, 4 May 2001 15:44:27 +0000 Subject: Big cleanup of passdb and backends. I did some basic tests but I have probably broken something. Notably the password changing. So don't cry ;-) J.F. (This used to be commit a4a4c02b12f030a3b9e6225b999c90689dfc4719) --- source3/utils/pdbedit.c | 93 ++++++++++++++++++++++++++++---------------- source3/utils/smbgroupedit.c | 9 +++-- source3/utils/smbpasswd.c | 21 +++++++--- 3 files changed, 81 insertions(+), 42 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index 6022f9aef2..9a545fbb45 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -113,12 +113,23 @@ static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdst **********************************************************/ static int print_user_info (char *username, BOOL verbosity, BOOL smbpwdstyle) { - SAM_ACCOUNT *sam_pwent; + SAM_ACCOUNT *sam_pwent=NULL; + BOOL ret; + + pdb_init_sam(&sam_pwent); - sam_pwent = pdb_getsampwnam (username); - if (sam_pwent) return print_sam_info (sam_pwent, verbosity, smbpwdstyle); - else fprintf (stderr, "Username not found!\n"); - return -1; + ret = pdb_getsampwnam (sam_pwent, username); + + if (ret==False) { + fprintf (stderr, "Username not found!\n"); + pdb_clear_sam(sam_pwent); + return -1; + } + + ret=print_sam_info (sam_pwent, verbosity, smbpwdstyle); + pdb_clear_sam(sam_pwent); + + return ret; } /********************************************************* @@ -126,22 +137,26 @@ static int print_user_info (char *username, BOOL verbosity, BOOL smbpwdstyle) **********************************************************/ static int print_users_list (BOOL verbosity, BOOL smbpwdstyle) { - SAM_ACCOUNT *sam_pwent; + SAM_ACCOUNT *sam_pwent=NULL; BOOL ret; + pdb_init_sam(&sam_pwent); + ret = pdb_setsampwent(False); if (ret && errno == ENOENT) { fprintf (stderr,"Password database not found!\n"); + pdb_clear_sam(sam_pwent); exit(1); } - while ((sam_pwent = pdb_getsampwent ())) + while ((ret = pdb_getsampwent (sam_pwent))) { if (verbosity) printf ("---------------\n"); print_sam_info (sam_pwent, verbosity, smbpwdstyle); } pdb_endsampwent (); + pdb_clear_sam(sam_pwent); return 0; } @@ -150,27 +165,33 @@ static int print_users_list (BOOL verbosity, BOOL smbpwdstyle) **********************************************************/ static int set_user_info (char *username, char *fullname, char *homedir, char *drive, char *script, char *profile) { - SAM_ACCOUNT *sam_pwent; + SAM_ACCOUNT *sam_pwent=NULL; + BOOL ret; + + pdb_init_sam(&sam_pwent); - sam_pwent = pdb_getsampwnam (username); - if (!sam_pwent) + ret = pdb_getsampwnam (sam_pwent, username); + if (ret==False) { fprintf (stderr, "Username not found!\n"); + pdb_clear_sam(sam_pwent); return -1; } - if (fullname) sam_pwent->full_name = fullname; - if (homedir) sam_pwent->home_dir = homedir; - if (drive) sam_pwent->dir_drive = drive; - if (script) sam_pwent->logon_script = script; - if (profile) sam_pwent->profile_path = profile; + if (fullname) pdb_set_fullname(sam_pwent, fullname); + if (homedir) pdb_set_homedir(sam_pwent, homedir); + if (drive) pdb_set_dir_drive(sam_pwent,drive); + if (script) pdb_set_logon_script(sam_pwent, script); + if (profile) pdb_set_profile_path (sam_pwent, profile); if (pdb_update_sam_account (sam_pwent, TRUE)) print_user_info (username, TRUE, FALSE); else { fprintf (stderr, "Unable to modify entry!\n"); + pdb_clear_sam(sam_pwent); return -1; } + pdb_clear_sam(sam_pwent); return 0; } @@ -180,6 +201,7 @@ static int set_user_info (char *username, char *fullname, char *homedir, char *d static int new_user (char *username, char *fullname, char *homedir, char *drive, char *script, char *profile) { SAM_ACCOUNT sam_pwent; + BOOL ret; struct passwd *pwd = NULL; uchar new_p16[16]; uchar new_nt_p16[16]; @@ -187,7 +209,7 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, ZERO_STRUCT(sam_pwent); - if (pdb_getsampwnam (username)) + if (pdb_getsampwnam (&sam_pwent, username)) { fprintf (stderr, "Username already exist in database!\n"); return -1; @@ -208,12 +230,12 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, } nt_lm_owf_gen (password1, new_nt_p16, new_p16); - sam_pwent.username = username; - if (fullname) sam_pwent.full_name = fullname; - if (homedir) sam_pwent.home_dir = homedir; - if (drive) sam_pwent.dir_drive = drive; - if (script) sam_pwent.logon_script = script; - if (profile) sam_pwent.profile_path = profile; + pdb_set_username(&sam_pwent, username); + if (fullname) pdb_set_fullname(&sam_pwent, fullname); + if (homedir) pdb_set_homedir (&sam_pwent, homedir); + if (drive) pdb_set_dir_drive (&sam_pwent, drive); + if (script) pdb_set_logon_script(&sam_pwent, script); + if (profile) pdb_set_profile_path (&sam_pwent, profile); /* TODO: Check uid not being in MACHINE UID range!! */ sam_pwent.uid = pwd->pw_uid; @@ -239,6 +261,7 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, static int new_machine (char *machinename) { SAM_ACCOUNT sam_pwent; + SAM_ACCOUNT sam_trust; uchar new_p16[16]; uchar new_nt_p16[16]; char name[16]; @@ -254,14 +277,17 @@ static int new_machine (char *machinename) strlower(password); nt_lm_owf_gen (password, new_nt_p16, new_p16); - sam_pwent.username = name; + pdb_set_username(&sam_pwent, name); + + for (uid=BASE_MACHINE_UID; uid<=MAX_MACHINE_UID; uid++) + if (!(pdb_getsampwuid (&sam_trust, uid))) + break; - for (uid=BASE_MACHINE_UID; uid<=MAX_MACHINE_UID; uid++) if (!(pdb_getsampwuid (uid))) break; - if (uid>MAX_MACHINE_UID) - { + if (uid>MAX_MACHINE_UID) { fprintf (stderr, "No more free UIDs available to Machine accounts!\n"); return -1; } + sam_pwent.uid = uid; sam_pwent.gid = BASE_MACHINE_UID; /* TODO: set there more appropriate value!! */ sam_pwent.user_rid = pdb_uid_to_user_rid (uid); @@ -270,9 +296,9 @@ static int new_machine (char *machinename) sam_pwent.nt_pw = new_nt_p16; sam_pwent.acct_ctrl = ACB_WSTRUST; - if (pdb_add_sam_account (&sam_pwent)) print_user_info (name, TRUE, FALSE); - else - { + if (pdb_add_sam_account (&sam_pwent)) + print_user_info (name, TRUE, FALSE); + else { fprintf (stderr, "Unable to add machine!\n"); return -1; } @@ -309,6 +335,7 @@ static int import_users (char *filename) { FILE *fp = NULL; SAM_ACCOUNT sam_pwent; + SAM_ACCOUNT sam_test; static pstring user_name; static unsigned char smbpwd[16]; static unsigned char smbntpwd[16]; @@ -360,7 +387,7 @@ static int import_users (char *filename) line++; if (linebuf[0] == '#' || linebuf[0] == '\0') continue; - pdb_init_sam (&sam_pwent); + /*pdb_init_sam (&sam_pwent);*/ sam_pwent.acct_ctrl = ACB_NORMAL; /* Get user name */ @@ -393,8 +420,8 @@ static int import_users (char *filename) continue; } - sam_pwent.username = user_name; - sam_pwent.uid = uidval; + pdb_set_username(&sam_pwent, user_name); + pdb_set_uid (&sam_pwent, uidval); /* Get passwords */ p++; @@ -503,7 +530,7 @@ static int import_users (char *filename) { struct passwd *pwd = NULL; - if (pdb_getsampwnam (user_name)) + if (pdb_getsampwnam (&sam_test,user_name)) { fprintf (stderr, "Error: Username already exist in database!\n"); continue; diff --git a/source3/utils/smbgroupedit.c b/source3/utils/smbgroupedit.c index 01ae7091b3..76624312d5 100644 --- a/source3/utils/smbgroupedit.c +++ b/source3/utils/smbgroupedit.c @@ -48,7 +48,8 @@ static void usage(void) printf(" -n group NT group name\n"); printf(" -p privilege only local\n"); printf(" -v list groups\n"); - printf(" -c SID change group\n"); + printf(" -c SID change group\n"); + printf(" -u unix group\n"); printf(" -x group delete this group\n"); printf("\n"); printf(" -t[b|d|l] type: builtin, domain, local \n"); @@ -68,7 +69,7 @@ int addgroup(char *group, enum SID_NAME_USE sid_type, char *ntgroup, char *ntcom /* convert_priv_from_text(&se_priv, privilege);*/ - se_priv=0xff; + se_priv=0x0; gid=nametogid(group); if (gid==-1) @@ -87,7 +88,7 @@ int addgroup(char *group, enum SID_NAME_USE sid_type, char *ntgroup, char *ntcom else fstrcpy(comment, ntcomment); - if(!add_initial_entry(gid, string_sid, sid_type, group, comment, se_priv)) + if(!add_initial_entry(gid, string_sid, sid_type, name, comment, se_priv)) return -1; return 0; @@ -176,7 +177,7 @@ int listgroup(enum SID_NAME_USE sid_type) printf("Unix\tSID\ttype\tnt name\tnt comment\tprivilege\n"); - if (!enum_group_mapping(sid_type, &map, &entries)) + if (!enum_group_mapping(sid_type, &map, &entries, ENUM_ALL_MAPPED)) return -1; for (i=0; i Date: Mon, 7 May 2001 03:55:54 +0000 Subject: merge some fixes from 2.2 (This used to be commit 7e57adf2a039cb5b6458496f9190c9c642645600) --- source3/utils/smbrun.c | 74 ------------------------------------------------- source3/utils/torture.c | 14 ++++++++++ 2 files changed, 14 insertions(+), 74 deletions(-) delete mode 100644 source3/utils/smbrun.c (limited to 'source3/utils') diff --git a/source3/utils/smbrun.c b/source3/utils/smbrun.c deleted file mode 100644 index b7c678411c..0000000000 --- a/source3/utils/smbrun.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - Unix SMB/Netbios implementation. - Version 1.9. - external program running routine - Copyright (C) Andrew Tridgell 1992-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. -*/ - -#include "includes.h" - - -/******************************************************************* -close the low 3 fd's and open dev/null in their place -********************************************************************/ -static void close_fds(void) -{ - int fd; - int i; - close(0); close(1); close(2); - /* try and use up these file descriptors, so silly - library routines writing to stdout etc won't cause havoc */ - for (i=0;i<3;i++) { - fd = open("/dev/null",O_RDWR,0); - if (fd < 0) fd = open("/dev/null",O_WRONLY,0); - if (fd != i) return; - } -} - - -/* -This is a wrapper around the system() call to allow commands to run correctly -as non root from a program which is switching between root and non-root - -It takes 3 arguments as uid,gid,command and runs command after -becoming a non-root user */ - int main(int argc,char *argv[]) -{ - uid_t uid; - gid_t gid; - - close_fds(); - - if (argc != 4) exit(2); - - uid = (uid_t)atoi(argv[1]); - gid = (gid_t)atoi(argv[2]); - - become_user_permanently( uid, gid); - - /* paranoia :-) */ - if (getuid() != uid) - return(3); - - if (geteuid() != getuid()) - return(4); - - /* this is to make sure that the system() call doesn't run forever */ - alarm(30); - - return(system(argv[3])); -} diff --git a/source3/utils/torture.c b/source3/utils/torture.c index fe22b60a89..4e6789e6ae 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -2538,6 +2538,20 @@ static void run_opentest(int dummy) cli_unlink(&cli1, fname); + + printf("testing ctemp\n"); + { + char *tmp_path; + fnum1 = cli_ctemp(&cli1, "\\", &tmp_path); + if (fnum1 == -1) { + printf("ctemp failed (%s)\n", cli_errstr(&cli1)); + return; + } + printf("ctemp gave path %s\n", tmp_path); + cli_close(&cli1, fnum1); + cli_unlink(&cli1, tmp_path); + } + close_connection(&cli1); } -- cgit From 050b0307f086037ec9c21d7125fd2a86cf218339 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 7 May 2001 06:05:30 +0000 Subject: Removed unused variable. (This used to be commit 6bd197714a6f51e43efb8fb72bb51e83c6991c79) --- source3/utils/pdbedit.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index 9a545fbb45..da57dbd8c8 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -201,7 +201,6 @@ static int set_user_info (char *username, char *fullname, char *homedir, char *d static int new_user (char *username, char *fullname, char *homedir, char *drive, char *script, char *profile) { SAM_ACCOUNT sam_pwent; - BOOL ret; struct passwd *pwd = NULL; uchar new_p16[16]; uchar new_nt_p16[16]; -- cgit From 30c4c04c2f584857633ce7605555dcfb37a3e1af Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 7 May 2001 14:04:46 +0000 Subject: Patch from Simo: o sed 's/pdb_clear_sam/pdb_free_sam/g' o add pdb_reset_sam() o password changing should be ok now as well. (This used to be commit 96d0e7c3301ad990f6c83b9c216720cb32661fb5) --- source3/utils/pdbedit.c | 15 ++++++++------- source3/utils/smbpasswd.c | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index da57dbd8c8..ef62fe32df 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -122,12 +122,12 @@ static int print_user_info (char *username, BOOL verbosity, BOOL smbpwdstyle) if (ret==False) { fprintf (stderr, "Username not found!\n"); - pdb_clear_sam(sam_pwent); + pdb_free_sam(sam_pwent); return -1; } ret=print_sam_info (sam_pwent, verbosity, smbpwdstyle); - pdb_clear_sam(sam_pwent); + pdb_free_sam(sam_pwent); return ret; } @@ -145,7 +145,7 @@ static int print_users_list (BOOL verbosity, BOOL smbpwdstyle) ret = pdb_setsampwent(False); if (ret && errno == ENOENT) { fprintf (stderr,"Password database not found!\n"); - pdb_clear_sam(sam_pwent); + pdb_free_sam(sam_pwent); exit(1); } @@ -153,10 +153,11 @@ static int print_users_list (BOOL verbosity, BOOL smbpwdstyle) { if (verbosity) printf ("---------------\n"); print_sam_info (sam_pwent, verbosity, smbpwdstyle); + pdb_reset_sam(sam_pwent); } pdb_endsampwent (); - pdb_clear_sam(sam_pwent); + pdb_free_sam(sam_pwent); return 0; } @@ -174,7 +175,7 @@ static int set_user_info (char *username, char *fullname, char *homedir, char *d if (ret==False) { fprintf (stderr, "Username not found!\n"); - pdb_clear_sam(sam_pwent); + pdb_free_sam(sam_pwent); return -1; } @@ -188,10 +189,10 @@ static int set_user_info (char *username, char *fullname, char *homedir, char *d else { fprintf (stderr, "Unable to modify entry!\n"); - pdb_clear_sam(sam_pwent); + pdb_free_sam(sam_pwent); return -1; } - pdb_clear_sam(sam_pwent); + pdb_free_sam(sam_pwent); return 0; } diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 2131ea0d8f..00a7d3c1c1 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -420,7 +420,7 @@ static int process_root(int argc, char *argv[]) if((sampass != False) && (pdb_get_lanman_passwd(sampass) != NULL)) { new_passwd = xstrdup("XXXX"); /* Don't care. */ } - pdb_clear_sam(sampass); + pdb_free_sam(sampass); } if(!new_passwd) @@ -451,7 +451,7 @@ static int process_root(int argc, char *argv[]) if((ret != False) && (pdb_get_acct_ctrl(sampass) & ACB_PWNOTREQ) ) printf(" User has no password flag set."); printf("\n"); - pdb_clear_sam(sampass); + pdb_free_sam(sampass); } done: -- cgit From 9de17c5c3892930d6d1d349df63e2c4206787ceb Mon Sep 17 00:00:00 2001 From: Anton Blanchard Date: Wed, 9 May 2001 01:58:12 +0000 Subject: need to do codepage_initialise() for smbtorture to work. (This used to be commit 7a619ab81c07b4b50e865635eee22efd8c5656b4) --- source3/utils/torture.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 4e6789e6ae..7298cd9b9a 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -2809,6 +2809,8 @@ static void usage(void) charset_initialise(); + codepage_initialise(lp_client_code_page()); + lp_load(servicesf,True,False,False); load_interfaces(); -- cgit From 47cd09ee57d8f24022d60c1c52677a0e236b6853 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 10 May 2001 06:53:19 +0000 Subject: Don't check for passwd program if using pam change password. Original patch from Andrew Bartlett. Jeremy. (This used to be commit aae779d0a3d3c80e6fa010fdb397af3aff360551) --- source3/utils/testparm.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 20f36fcffe..ae4a12a882 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -93,29 +93,37 @@ to a valid password server.\n", sec_setting ); if(lp_security() == SEC_USER && lp_unix_password_sync()) { /* - * Check that we have a valid lp_passwd_program(). + * Check that we have a valid lp_passwd_program() if not using pam. */ - if(lp_passwd_program() == NULL) { - printf("ERROR: the 'unix password sync' parameter is set and there is no valid 'passwd program' \ +#ifdef WITH_PAM + if (!lp_pam_password_change()) { +#endif + + if(lp_passwd_program() == NULL) { + printf("ERROR: the 'unix password sync' parameter is set and there is no valid 'passwd program' \ parameter.\n" ); - ret = 1; - } else { - pstring passwd_prog; - pstring truncated_prog; - char *p; - - pstrcpy( passwd_prog, lp_passwd_program()); - p = passwd_prog; - *truncated_prog = '\0'; - next_token(&p, truncated_prog, NULL, sizeof(pstring)); - - if(access(truncated_prog, F_OK) == -1) { - printf("ERROR: the 'unix password sync' parameter is set and the 'passwd program' (%s) \ -cannot be executed (error was %s).\n", truncated_prog, strerror(errno) ); ret = 1; + } else { + pstring passwd_prog; + pstring truncated_prog; + char *p; + + pstrcpy( passwd_prog, lp_passwd_program()); + p = passwd_prog; + *truncated_prog = '\0'; + next_token(&p, truncated_prog, NULL, sizeof(pstring)); + + if(access(truncated_prog, F_OK) == -1) { + printf("ERROR: the 'unix password sync' parameter is set and the 'passwd program' (%s) \ +cannot be executed (error was %s).\n", truncated_prog, strerror(errno) ); + ret = 1; + } } + +#ifdef WITH_PAM } +#endif if(lp_passwd_chat() == NULL) { printf("ERROR: the 'unix password sync' parameter is set and there is no valid 'passwd chat' \ -- cgit From bc51512aadc705cbe5c4d666b7d45271e60d3f00 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 14 May 2001 22:37:01 +0000 Subject: Fix crash in smbcontrol Gerald pointed out when no parameter given to debug. Jeremy. (This used to be commit ef687a2f6ba8143dcc041b2b629542c3ea9e3966) --- source3/utils/smbcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 09f0e3090b..5bb4e602f0 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -171,7 +171,7 @@ static int parse_type(char *mtype) /**************************************************************************** do command ****************************************************************************/ -static BOOL do_command(char *dest, char *msg_name, char *params[]) +static BOOL do_command(char *dest, char *msg_name, char **params) { int i, n, v; int mtype; @@ -186,7 +186,7 @@ static BOOL do_command(char *dest, char *msg_name, char *params[]) switch (mtype) { case MSG_DEBUG: - if (!params[0]) { + if (!params || !params[0]) { fprintf(stderr,"MSG_DEBUG needs a parameter\n"); return(False); } -- cgit From 98da4768df0939611bdfe7fb919c111013bc960a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 15 May 2001 01:28:34 +0000 Subject: remember to close tdb after use (This used to be commit 8f8d7202cf6e12cdb2f4445ddcac83a7ac9e33a2) --- source3/utils/smbcontrol.c | 22 +++++++++++++--------- source3/utils/status.c | 1 + 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 5bb4e602f0..30861030d8 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -125,17 +125,21 @@ send a message to a named destination static BOOL send_message(char *dest, int msg_type, void *buf, int len, BOOL duplicates) { pid_t pid; - TDB_CONTEXT *the_tdb; - - the_tdb = tdb_open(lock_path("connections.tdb"), 0, 0, O_RDONLY, 0); - if (!the_tdb) { - fprintf(stderr,"Failed to open connections database in send_message.\n"); - return False; - } - /* "smbd" is the only broadcast operation */ if (strequal(dest,"smbd")) { - return message_send_all(the_tdb,msg_type, buf, len, duplicates); + TDB_CONTEXT *tdb; + BOOL ret; + + tdb = tdb_open(lock_path("connections.tdb"), 0, 0, O_RDONLY, 0); + if (!tdb) { + fprintf(stderr,"Failed to open connections database in send_message.\n"); + return False; + } + + ret = message_send_all(tdb,msg_type, buf, len, duplicates); + tdb_close(tdb); + + return ret; } else if (strequal(dest,"nmbd")) { pid = pidfile_pid(dest); if (pid == 0) { diff --git a/source3/utils/status.c b/source3/utils/status.c index 06abd09d92..243ccdd755 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -327,6 +327,7 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st printf("----------------------------------------------\n"); } tdb_traverse(tdb, traverse_fn1, NULL); + tdb_close(tdb); locks: if (processes_only) exit(0); -- cgit From 10211f53f9fa9e21a6ededf892b8be27bad9643e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 15 May 2001 18:12:02 +0000 Subject: Check sizes of data entries in connections.tdb before deciding they're crecs... We will need this when we use finer grained locking for max connections. Jeremy. (This used to be commit c6cd42a6791e26174eb795fd08ddbbd797e5a9cf) --- source3/utils/status.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 243ccdd755..55c3c1bad1 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -186,9 +186,13 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st struct session_record *ptr; struct connections_data crec; + if (dbuf.dsize != sizeof(crec)) + return 0; + memcpy(&crec, dbuf.dptr, sizeof(crec)); - if (crec.cnum == -1) return 0; + if (crec.cnum == -1) + return 0; if (!process_exists(crec.pid) || !Ucrit_checkUsername(uidtoname(crec.uid))) { return 0; -- cgit From 6dce5c47c62d6ad3d74489bde3824fbfb02d8616 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 1 Jun 2001 12:04:44 +0000 Subject: If a debug class was explicitly set to zero the debug system would not recognise it as there was no distinction made between zeroing a debug class and just not setting it to anything. I've added a debuglevel_isset array in parallel with the debuglevel_class array to fix this. Added a couple of new debug classes which I might start filling out to get smb, rpc header and rpc marshall/unmarshalling debugs tidied up. Fixed a bunch of cut&paste bugs in include/debug.h Modified smbcontrol and the messaging system debug handler to like the debuglevel_isset stuff. (This used to be commit 391e7caf76cbc22021629ef0ec5e0c32806edfd7) --- source3/utils/smbcontrol.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 30861030d8..b940b4006a 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -180,7 +180,6 @@ static BOOL do_command(char *dest, char *msg_name, char **params) int i, n, v; int mtype; BOOL retval=False; - int debuglevel_class[DBGC_LAST]; mtype = parse_type(msg_name); if (mtype == -1) { @@ -189,19 +188,22 @@ static BOOL do_command(char *dest, char *msg_name, char **params) } switch (mtype) { - case MSG_DEBUG: + case MSG_DEBUG: { + struct debuglevel_message dm; + if (!params || !params[0]) { fprintf(stderr,"MSG_DEBUG needs a parameter\n"); return(False); } - ZERO_ARRAY(debuglevel_class); - if (!debug_parse_params(params, debuglevel_class)) { + ZERO_STRUCT(dm); + if (!debug_parse_params(params, dm.debuglevel_class, dm.debuglevel_class_isset)) { fprintf(stderr, "MSG_DEBUG error. Expected :level\n"); return(False); } else - send_message(dest, MSG_DEBUG, debuglevel_class, sizeof(debuglevel_class), False); + send_message(dest, MSG_DEBUG, &dm, sizeof(dm), False); break; + } case MSG_PROFILE: if (!params[0]) { -- cgit From 05fc3e578c895f632b351969d09cd00feb7599c7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Jun 2001 05:13:59 +0000 Subject: use LDSHFLAGS not -shared in several places (This used to be commit 8ec9c87b5d1a7dae17d5b1a30f58effaf5e69e4b) --- source3/utils/smbcontrol.c | 2 +- source3/utils/status.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index b940b4006a..843d56234b 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -130,7 +130,7 @@ static BOOL send_message(char *dest, int msg_type, void *buf, int len, BOOL dupl TDB_CONTEXT *tdb; BOOL ret; - tdb = tdb_open(lock_path("connections.tdb"), 0, 0, O_RDONLY, 0); + tdb = tdb_open_log(lock_path("connections.tdb"), 0, 0, O_RDONLY, 0); if (!tdb) { fprintf(stderr,"Failed to open connections database in send_message.\n"); return False; diff --git a/source3/utils/status.c b/source3/utils/status.c index 55c3c1bad1..e695e7572f 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -310,7 +310,7 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st return profile_dump(); } - tdb = tdb_open(lock_path("connections.tdb"), 0, 0, O_RDONLY, 0); + tdb = tdb_open_log(lock_path("connections.tdb"), 0, 0, O_RDONLY, 0); if (!tdb) { printf("connections.tdb not initialised\n"); if (!lp_status(-1)) -- cgit From 5264e9a2a737d6498be0f346bcbc3b583609abf5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 5 Jun 2001 08:17:16 +0000 Subject: Set correct reply word in large writeX (greater than 64k) replies. Also added smbtorture test for this. Jeremy. (This used to be commit 6d65556ae8bea45a203defaded8436cbb56965e1) --- source3/utils/torture.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 7298cd9b9a..982be77151 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -483,6 +483,54 @@ static void run_readwritemulti(int dummy) close_connection(&cli); } +static void run_readwritelarge(int dummy) +{ + static struct cli_state cli1; + int fnum1; + char *lockfname = "\\large.dat"; + size_t fsize; + char buf[0x10000]; + + if (!open_connection(&cli1)) { + return; + } + cli_sockopt(&cli1, sockops); + memset(buf,'\0',sizeof(buf)); + + cli1.max_xmit = 0x11000; + + printf("starting readwritelarge\n"); + + cli_unlink(&cli1, lockfname); + + fnum1 = cli_open(&cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(&cli1)); + return; + } + + cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)); + + if (!cli_close(&cli1, fnum1)) { + printf("close failed (%s)\n", cli_errstr(&cli1)); + } + + if (!cli_qpathinfo(&cli1, lockfname, NULL, NULL, NULL, &fsize, NULL)) { + printf("qpathinfo failed (%s)\n", cli_errstr(&cli1)); + } + + if (fsize == sizeof(buf)) + printf("readwritelarge test succeeded (size = %x)\n", fsize); + else + printf("readwritelarge test failed (size = %x)\n", fsize); + + if (!cli_unlink(&cli1, lockfname)) { + printf("unlink failed (%s)\n", cli_errstr(&cli1)); + } + + close_connection(&cli1); +} + int line_count = 0; /* run a test that simulates an approximate netbench client load */ @@ -2722,6 +2770,7 @@ static struct { {"TCON", run_tcon_test, 0}, {"RW1", run_readwritetest, 0}, {"RW2", run_readwritemulti, FLAG_MULTIPROC}, + {"RW3", run_readwritelarge, 0}, {"OPEN", run_opentest, 0}, {"DELETE", run_deletetest, 0}, {NULL, NULL, 0}}; @@ -2811,6 +2860,8 @@ static void usage(void) codepage_initialise(lp_client_code_page()); + codepage_initialise(lp_client_code_page()); + lp_load(servicesf,True,False,False); load_interfaces(); -- cgit From df8713fdb97eb7b0fee8b92f792c430c398851f3 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 13 Jun 2001 05:36:28 +0000 Subject: Renamed -d option (make verbose) on smbstatus to -v. Added -d option. (This used to be commit bdb9714380503d5bbe12a8bfa4ec723e1f5070ca) --- source3/utils/status.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index e695e7572f..448239baba 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -245,7 +245,7 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st int c; static pstring servicesf = CONFIGFILE; extern char *optarg; - int profile_only = 0; + int profile_only = 0, new_debuglevel = -1; TDB_CONTEXT *tdb; struct session_record *ptr; @@ -262,7 +262,7 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st return(1); } - while ((c = getopt(argc, argv, "pdLSs:u:bPB")) != EOF) { + while ((c = getopt(argc, argv, "pvLSs:u:bPBd:")) != EOF) { switch (c) { case 'b': brief = 1; @@ -271,6 +271,10 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st show_brl = 1; break; case 'd': + new_debuglevel = atoi(optarg); + break; + + case 'v': verbose = 1; break; case 'L': @@ -292,7 +296,7 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st Ucrit_addUsername(optarg); break; default: - fprintf(stderr, "Usage: %s [-P] [-d] [-L] [-p] [-S] [-s configfile] [-u username]\n", *argv); + fprintf(stderr, "Usage: %s [-P] [-v] [-L] [-p] [-S] [-s configfile] [-u username] [-d debuglevel]\n", *argv); return (-1); } } @@ -302,6 +306,10 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st return (-1); } + if (new_debuglevel != -1) { + DEBUGLEVEL = new_debuglevel; + } + if (verbose) { printf("using configfile = %s\n", servicesf); } -- cgit From e324e21457b232acb13a06fa5a4b8f363b3dec7c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 18 Jun 2001 08:26:15 +0000 Subject: added a oplock break handler hook to the client code, this allows for more complete testing of oplocks from smbtorture and would also be essential if a client app ever really did want to use oplocks properly (This used to be commit 3d4a3bfacd9ef225aeaab801e5a216d12814b60a) --- source3/utils/torture.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 982be77151..5f08887a60 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -2091,6 +2091,49 @@ static void run_oplock2(int dummy) printf("finished oplock test 2\n"); } +/* handler for oplock 3 tests */ +static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level) +{ + printf("got oplock break fnum=%d level=%d\n", + fnum, level); + return cli_oplock_ack(cli, fnum, level); +} + +static void run_oplock3(int dummy) +{ + static struct cli_state cli; + char *fname = "\\oplockt3.dat"; + int fnum; + char buf[4] = "abcd"; + + printf("starting oplock test 3\n"); + + if (fork() == 0) { + /* Child code */ + if (!open_connection(&cli)) return; + sleep(2); + /* try to trigger a oplock break in parent */ + fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE); + cli_write(&cli, fnum, 0, buf, 0, 4); + exit(0); + } + + /* parent code */ + use_oplocks = True; + use_level_II_oplocks = True; + if (!open_connection(&cli)) return; + cli_oplock_handler(&cli, oplock3_handler); + fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE); + cli_write(&cli, fnum, 0, buf, 0, 4); + cli_close(&cli, fnum); + fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE); + cli.timeout = 20000; + cli_receive_smb(&cli); + printf("finished oplock test 3\n"); +} + + + /* Test delete on close semantics. */ @@ -2764,6 +2807,7 @@ static struct { {"NBWNT", run_nbwnt, 0}, {"OPLOCK1", run_oplock1, 0}, {"OPLOCK2", run_oplock2, 0}, + {"OPLOCK3", run_oplock3, 0}, {"DIR", run_dirtest, 0}, {"DENY1", run_denytest1, 0}, {"DENY2", run_denytest2, 0}, @@ -2790,8 +2834,8 @@ static void run_test(char *name) } for (i=0;torture_ops[i].name;i++) { - fstrcpy(randomfname, "\\XXXXXXX"); - mktemp(randomfname); + snprintf(randomfname, sizeof(randomfname), "\\XX%x", + (unsigned)random()); if (strequal(name, torture_ops[i].name)) { start_timer(); -- cgit From 0c69d176532ea4ee2fa4c7809db37b00ecfbeeb6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 18 Jun 2001 23:31:22 +0000 Subject: New info level tester. Jeremy. (This used to be commit 9297ae69a7dde878bb4c696f90fbaceb46e18720) --- source3/utils/torture.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 5f08887a60..6f4076cecb 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -1929,6 +1929,52 @@ static void run_trans2test(int dummy) printf("trans2 test finished\n"); } +/* + This checks new W2K calls. +*/ + +void new_trans(struct cli_state *pcli, int fnum, int level) +{ + char buf[4096]; + + memset(buf, 0xff, sizeof(buf)); + + if (!cli_qfileinfo_test(pcli, fnum, level, buf)) { + printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli)); + } else { + printf("qfileinfo: level %d\n", level); + dump_data(0, buf, 256); + printf("\n"); + } +} + +static void run_w2ktest(int dummy) +{ + static struct cli_state cli; + int fnum; + char *fname = "\\w2ktest\\w2k.tst"; + int level; + + printf("starting w2k test\n"); + + if (!open_connection(&cli)) { + return; + } + + fnum = cli_open(&cli, fname, + O_RDWR | O_CREAT , DENY_NONE); + + for (level = 1004; level < 1040; level++) + new_trans(&cli, fnum, level); + + cli_close(&cli, fnum); + + + close_connection(&cli); + + printf("w2k test finished\n"); +} + /* this is a harness for some oplock tests @@ -2817,6 +2863,7 @@ static struct { {"RW3", run_readwritelarge, 0}, {"OPEN", run_opentest, 0}, {"DELETE", run_deletetest, 0}, + {"W2K", run_w2ktest, 0}, {NULL, NULL, 0}}; -- cgit From c1fbf761ce819a4da9f26758129e0923bfc1e6ff Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 19 Jun 2001 00:44:23 +0000 Subject: rpc_server/srv_srvsvc_nt.c: Don't test an uint32 for < 0. utils/smbcacls.c: Set enum correctly. Jeremy. (This used to be commit 66f959e0ffb0cd385167a34c7db3f4959eaf1d7f) --- source3/utils/smbcacls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 7b459a32ed..4893eb4202 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -810,7 +810,7 @@ You can string acls together with spaces, commas or newlines\n\ char *p; static pstring servicesf = CONFIGFILE; struct cli_state *cli=NULL; - enum acl_mode mode = 0; + enum acl_mode mode = SMB_ACL_SET; char *the_acl = NULL; enum chown_mode change_mode = REQUEST_NONE; int result; -- cgit From 90b757f6bf6c27c4bfc1fb745981c56a21da3488 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 19 Jun 2001 01:54:42 +0000 Subject: torture code is moving to its own directory (This used to be commit a4ef84e1a031042ca24fc3bea6d7311ab5976ac6) --- source3/utils/torture.c | 3053 ----------------------------------------------- 1 file changed, 3053 deletions(-) delete mode 100644 source3/utils/torture.c (limited to 'source3/utils') diff --git a/source3/utils/torture.c b/source3/utils/torture.c deleted file mode 100644 index 6f4076cecb..0000000000 --- a/source3/utils/torture.c +++ /dev/null @@ -1,3053 +0,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" - -static fstring host, workgroup, share, password, username, myname; -static int max_protocol = PROTOCOL_NT1; -static char *sockops="TCP_NODELAY"; -static int nprocs=1, numops=100; -static int procnum; /* records process count number when forking */ -static struct cli_state current_cli; -static fstring randomfname; -static BOOL use_oplocks; -static BOOL use_level_II_oplocks; - -static double create_procs(void (*fn)(int)); - - -static struct timeval tp1,tp2; - -static void start_timer(void) -{ - gettimeofday(&tp1,NULL); -} - -static double end_timer(void) -{ - gettimeofday(&tp2,NULL); - return((tp2.tv_sec - tp1.tv_sec) + - (tp2.tv_usec - tp1.tv_usec)*1.0e-6); -} - - -/* return a pointer to a anonymous shared memory segment of size "size" - which will persist across fork() but will disappear when all processes - exit - - The memory is not zeroed - - This function uses system5 shared memory. It takes advantage of a property - that the memory is not destroyed if it is attached when the id is removed - */ -static void *shm_setup(int size) -{ - int shmid; - void *ret; - - shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W); - if (shmid == -1) { - printf("can't get shared memory\n"); - exit(1); - } - ret = (void *)shmat(shmid, 0, 0); - if (!ret || ret == (void *)-1) { - printf("can't attach to shared memory\n"); - return NULL; - } - /* the following releases the ipc, but note that this process - and all its children will still have access to the memory, its - just that the shmid is no longer valid for other shm calls. This - means we don't leave behind lots of shm segments after we exit - - See Stevens "advanced programming in unix env" for details - */ - shmctl(shmid, IPC_RMID, 0); - - return ret; -} - - -static BOOL open_nbt_connection(struct cli_state *c) -{ - struct nmb_name called, calling; - struct in_addr ip; - extern struct in_addr ipzero; - - ZERO_STRUCTP(c); - - make_nmb_name(&calling, myname, 0x0); - make_nmb_name(&called , host, 0x20); - - ip = ipzero; - - if (!cli_initialise(c) || !cli_connect(c, host, &ip)) { - printf("Failed to connect with %s\n", host); - return False; - } - - c->timeout = 120000; /* set a really long timeout (2 minutes) */ - if (use_oplocks) c->use_oplocks = True; - if (use_level_II_oplocks) c->use_level_II_oplocks = True; - - if (!cli_session_request(c, &calling, &called)) { - printf("%s rejected the session\n",host); - cli_shutdown(c); - return False; - } - - return True; -} - -static BOOL open_connection(struct cli_state *c) -{ - ZERO_STRUCTP(c); - - if (!open_nbt_connection(c)) { - return False; - } - - if (!cli_negprot(c)) { - printf("%s rejected the negprot (%s)\n",host, cli_errstr(c)); - cli_shutdown(c); - return False; - } - - if (!cli_session_setup(c, username, - password, strlen(password), - password, strlen(password), - workgroup)) { - printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c)); - cli_shutdown(c); - return False; - } - - if (!cli_send_tconX(c, share, "?????", - password, strlen(password)+1)) { - printf("%s refused tree connect (%s)\n", host, cli_errstr(c)); - cli_shutdown(c); - return False; - } - - return True; -} - - -static void close_connection(struct cli_state *c) -{ - if (!cli_tdis(c)) { - printf("tdis failed (%s)\n", cli_errstr(c)); - } - - cli_shutdown(c); -} - - -/* check if the server produced the expected error code */ -static BOOL check_error(struct cli_state *c, - uint8 eclass, uint32 ecode, uint32 nterr) -{ - uint8 class; - uint32 num; - (void)cli_error(c, &class, &num, NULL); - if ((eclass != class || ecode != num) && - num != (nterr&0xFFFFFF)) { - printf("unexpected error code class=%d code=%d\n", - (int)class, (int)num); - printf(" expected %d/%d %d\n", - (int)eclass, (int)ecode, (int)nterr); - return False; - } - return True; -} - - -static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len) -{ - while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) { - if (!check_error(c, ERRDOS, ERRlock, 0)) return False; - } - return True; -} - - -static BOOL rw_torture(struct cli_state *c) -{ - char *lockfname = "\\torture.lck"; - fstring fname; - int fnum; - int fnum2; - pid_t pid2, pid = getpid(); - int i, j; - char buf[1024]; - - fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL, - DENY_NONE); - if (fnum2 == -1) - fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE); - if (fnum2 == -1) { - printf("open of %s failed (%s)\n", lockfname, cli_errstr(c)); - return False; - } - - - for (i=0;i= countprev) { - printf("%d %8d\r", i, count); - fflush(stdout); - i++; - countprev += (sizeof(buf) / 20); - } - - if (procnum == 0) - { - sent = ((unsigned)sys_random()%(20))+ 1; - if (sent > sizeof(buf) - count) - { - sent = sizeof(buf) - count; - } - - if (cli_write(c, fnum, 0, buf+count, count, sent) != sent) { - printf("write failed (%s)\n", cli_errstr(c)); - } - } - else - { - sent = cli_read(c, fnum, buf_rd+count, count, - sizeof(buf)-count); - if (sent < 0) - { - printf("read failed offset:%d size:%d (%s)\n", - count, sizeof(buf)-count, - cli_errstr(c)); - sent = 0; - } - if (sent > 0) - { - if (memcmp(buf_rd+count, buf+count, sent) != 0) - { - printf("read/write compare failed\n"); - printf("offset: %d req %d recvd %d\n", - count, sizeof(buf)-count, sent); - break; - } - } - } - - } - - if (!cli_close(c, fnum)) { - printf("close failed (%s)\n", cli_errstr(c)); - } - - return True; -} - -static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2) -{ - char *lockfname = "\\torture.lck"; - int fnum1; - int fnum2; - int i; - char buf[131072]; - char buf_rd[131072]; - - if (!cli_unlink(c1, lockfname)) { - printf("unlink failed (%s)\n", cli_errstr(c1)); - } - - fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL, - DENY_NONE); - if (fnum1 == -1) { - printf("first open read/write of %s failed (%s)\n", - lockfname, cli_errstr(c1)); - return False; - } - fnum2 = cli_open(c2, lockfname, O_RDONLY, - DENY_NONE); - if (fnum2 == -1) { - printf("second open read-only of %s failed (%s)\n", - lockfname, cli_errstr(c2)); - cli_close(c1, fnum1); - return False; - } - - for (i=0;i 0) { - fnum--; - slprintf(fname,sizeof(fname)-1,template, fnum,(int)getpid()); - cli_close(&cli, fnum); - if (!cli_unlink(&cli, fname)) { - printf("unlink of %s failed (%s)\n", - fname, cli_errstr(&cli)); - } - } - - printf("maxfid test finished\n"); - close_connection(&cli); -} - -/* generate a random buffer */ -static void rand_buf(char *buf, int len) -{ - while (len--) { - *buf = (char)sys_random(); - buf++; - } -} - -/* send smb negprot commands, not reading the response */ -static void run_negprot_nowait(int dummy) -{ - int i; - static struct cli_state cli; - - printf("starting negprot nowait test\n"); - - if (!open_nbt_connection(&cli)) { - return; - } - - for (i=0;i<50000;i++) { - cli_negprot_send(&cli); - } - - close_connection(&cli); - - printf("finished negprot nowait test\n"); -} - - -/* send random IPC commands */ -static void run_randomipc(int dummy) -{ - char *rparam = NULL; - char *rdata = NULL; - int rdrcnt,rprcnt; - pstring param; - int api, param_len, i; - static struct cli_state cli; - - printf("starting random ipc test\n"); - - if (!open_connection(&cli)) { - return; - } - - for (i=0;i<50000;i++) { - api = sys_random() % 500; - param_len = (sys_random() % 64); - - rand_buf(param, param_len); - - SSVAL(param,0,api); - - cli_api(&cli, - param, param_len, 8, - NULL, 0, BUFFER_SIZE, - &rparam, &rprcnt, - &rdata, &rdrcnt); - } - - close_connection(&cli); - - printf("finished random ipc test\n"); -} - - - -static void browse_callback(const char *sname, uint32 stype, - const char *comment, void *state) -{ - printf("\t%20.20s %08x %s\n", sname, stype, comment); -} - - - -/* - This test checks the browse list code - -*/ -static void run_browsetest(int dummy) -{ - static struct cli_state cli; - - printf("starting browse test\n"); - - if (!open_connection(&cli)) { - return; - } - - printf("domain list:\n"); - cli_NetServerEnum(&cli, cli.server_domain, - SV_TYPE_DOMAIN_ENUM, - browse_callback, NULL); - - printf("machine list:\n"); - cli_NetServerEnum(&cli, cli.server_domain, - SV_TYPE_ALL, - browse_callback, NULL); - - close_connection(&cli); - - printf("browse test finished\n"); -} - - -/* - This checks how the getatr calls works -*/ -static void run_attrtest(int dummy) -{ - static struct cli_state cli; - int fnum; - time_t t, t2; - char *fname = "\\attrib.tst"; - - printf("starting attrib test\n"); - - if (!open_connection(&cli)) { - return; - } - - cli_unlink(&cli, fname); - fnum = cli_open(&cli, fname, - O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); - cli_close(&cli, fnum); - if (!cli_getatr(&cli, fname, NULL, NULL, &t)) { - printf("getatr failed (%s)\n", cli_errstr(&cli)); - } - - if (abs(t - time(NULL)) > 2) { - printf("ERROR: SMBgetatr bug. time is %s", - ctime(&t)); - t = time(NULL); - } - - t2 = t-60*60*24; /* 1 day ago */ - - if (!cli_setatr(&cli, fname, 0, t2)) { - printf("setatr failed (%s)\n", cli_errstr(&cli)); - } - - if (!cli_getatr(&cli, fname, NULL, NULL, &t)) { - printf("getatr failed (%s)\n", cli_errstr(&cli)); - } - - if (t != t2) { - printf("ERROR: getatr/setatr bug. times are\n%s", - ctime(&t)); - printf("%s", ctime(&t2)); - } - - cli_unlink(&cli, fname); - - close_connection(&cli); - - printf("attrib test finished\n"); -} - - -/* - This checks a couple of trans2 calls -*/ -static void run_trans2test(int dummy) -{ - static struct cli_state cli; - int fnum; - size_t size; - time_t c_time, a_time, m_time, w_time, m_time2; - char *fname = "\\trans2.tst"; - char *dname = "\\trans2"; - char *fname2 = "\\trans2\\trans2.tst"; - - printf("starting trans2 test\n"); - - if (!open_connection(&cli)) { - return; - } - - cli_unlink(&cli, fname); - fnum = cli_open(&cli, fname, - O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); - if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time, - NULL, NULL)) { - printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli)); - } - cli_close(&cli, fnum); - - sleep(2); - - cli_unlink(&cli, fname); - fnum = cli_open(&cli, fname, - O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); - cli_close(&cli, fnum); - - if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) { - printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli)); - } else { - if (c_time != m_time) { - printf("create time=%s", ctime(&c_time)); - printf("modify time=%s", ctime(&m_time)); - printf("This system appears to have sticky create times\n"); - } - if (a_time % (60*60) == 0) { - printf("access time=%s", ctime(&a_time)); - printf("This system appears to set a midnight access time\n"); - } - - if (abs(m_time - time(NULL)) > 60*60*24*7) { - printf("ERROR: totally incorrect times - maybe word reversed?\n"); - } - } - - - cli_unlink(&cli, fname); - fnum = cli_open(&cli, fname, - O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); - cli_close(&cli, fnum); - if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time, - &w_time, &size, NULL, NULL)) { - printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); - } else { - if (w_time < 60*60*24*2) { - printf("write time=%s", ctime(&w_time)); - printf("This system appears to set a initial 0 write time\n"); - } - } - - cli_unlink(&cli, fname); - - - /* check if the server updates the directory modification time - when creating a new file */ - if (!cli_mkdir(&cli, dname)) { - printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli)); - } - sleep(3); - if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time, - &w_time, &size, NULL, NULL)) { - printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); - } - - fnum = cli_open(&cli, fname2, - O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); - cli_write(&cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum)); - cli_close(&cli, fnum); - if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2, - &w_time, &size, NULL, NULL)) { - printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); - } else { - if (m_time2 == m_time) - printf("This system does not update directory modification times\n"); - } - cli_unlink(&cli, fname2); - cli_rmdir(&cli, dname); - - - close_connection(&cli); - - printf("trans2 test finished\n"); -} - -/* - This checks new W2K calls. -*/ - -void new_trans(struct cli_state *pcli, int fnum, int level) -{ - char buf[4096]; - - memset(buf, 0xff, sizeof(buf)); - - if (!cli_qfileinfo_test(pcli, fnum, level, buf)) { - printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli)); - } else { - printf("qfileinfo: level %d\n", level); - dump_data(0, buf, 256); - printf("\n"); - } -} - -static void run_w2ktest(int dummy) -{ - static struct cli_state cli; - int fnum; - char *fname = "\\w2ktest\\w2k.tst"; - int level; - - printf("starting w2k test\n"); - - if (!open_connection(&cli)) { - return; - } - - fnum = cli_open(&cli, fname, - O_RDWR | O_CREAT , DENY_NONE); - - for (level = 1004; level < 1040; level++) - new_trans(&cli, fnum, level); - - cli_close(&cli, fnum); - - - close_connection(&cli); - - printf("w2k test finished\n"); -} - - -/* - this is a harness for some oplock tests - */ -static void run_oplock1(int dummy) -{ - static struct cli_state cli1; - char *fname = "\\lockt1.lck"; - int fnum1; - - printf("starting oplock test 1\n"); - - if (!open_connection(&cli1)) { - return; - } - - cli_unlink(&cli1, fname); - - cli_sockopt(&cli1, sockops); - - cli1.use_oplocks = True; - - fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); - if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - cli1.use_oplocks = False; - - cli_unlink(&cli1, fname); - cli_unlink(&cli1, fname); - - if (!cli_close(&cli1, fnum1)) { - printf("close2 failed (%s)\n", cli_errstr(&cli1)); - return; - } - - if (!cli_unlink(&cli1, fname)) { - printf("unlink failed (%s)\n", cli_errstr(&cli1)); - return; - } - - - close_connection(&cli1); - - printf("finished oplock test 1\n"); -} - -static void run_oplock2(int dummy) -{ - static struct cli_state cli1, cli2; - char *fname = "\\lockt2.lck"; - int fnum1, fnum2; - int saved_use_oplocks = use_oplocks; - char buf[4]; - - use_level_II_oplocks = True; - use_oplocks = True; - - printf("starting oplock test 2\n"); - - if (!open_connection(&cli1)) { - use_level_II_oplocks = False; - use_oplocks = saved_use_oplocks; - return; - } - - cli1.use_oplocks = True; - cli1.use_level_II_oplocks = True; - - if (!open_connection(&cli2)) { - use_level_II_oplocks = False; - use_oplocks = saved_use_oplocks; - return; - } - - cli2.use_oplocks = True; - cli2.use_level_II_oplocks = True; - - cli_unlink(&cli1, fname); - - cli_sockopt(&cli1, sockops); - cli_sockopt(&cli2, sockops); - - fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); - if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - /* Don't need the globals any more. */ - use_level_II_oplocks = False; - use_oplocks = saved_use_oplocks; - - if (fork() == 0) { - /* Child code */ - fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE); - if (fnum2 == -1) { - printf("second open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - exit(0); - } - - sleep(2); - - if (!cli_close(&cli2, fnum2)) { - printf("close2 failed (%s)\n", cli_errstr(&cli1)); - } - - exit(0); - } - - sleep(2); - - /* Ensure cli1 processes the break. */ - - if (cli_read(&cli1, fnum1, buf, 0, 4) != 4) { - printf("read on fnum1 failed (%s)\n", cli_errstr(&cli1)); - } - - /* Should now be at level II. */ - /* Test if sending a write locks causes a break to none. */ - - if (!cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK)) { - printf("lock failed (%s)\n", cli_errstr(&cli1)); - } - - cli_unlock(&cli1, fnum1, 0, 4); - - sleep(2); - - if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) { - printf("lock failed (%s)\n", cli_errstr(&cli1)); - } - - cli_unlock(&cli1, fnum1, 0, 4); - - sleep(2); - - cli_read(&cli1, fnum1, buf, 0, 4); - -#if 0 - if (cli_write(&cli1, fnum1, 0, buf, 0, 4) != 4) { - printf("write on fnum1 failed (%s)\n", cli_errstr(&cli1)); - } -#endif - - if (!cli_close(&cli1, fnum1)) { - printf("close1 failed (%s)\n", cli_errstr(&cli1)); - } - - sleep(4); - - if (!cli_unlink(&cli1, fname)) { - printf("unlink failed (%s)\n", cli_errstr(&cli1)); - } - - close_connection(&cli1); - - printf("finished oplock test 2\n"); -} - -/* handler for oplock 3 tests */ -static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level) -{ - printf("got oplock break fnum=%d level=%d\n", - fnum, level); - return cli_oplock_ack(cli, fnum, level); -} - -static void run_oplock3(int dummy) -{ - static struct cli_state cli; - char *fname = "\\oplockt3.dat"; - int fnum; - char buf[4] = "abcd"; - - printf("starting oplock test 3\n"); - - if (fork() == 0) { - /* Child code */ - if (!open_connection(&cli)) return; - sleep(2); - /* try to trigger a oplock break in parent */ - fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE); - cli_write(&cli, fnum, 0, buf, 0, 4); - exit(0); - } - - /* parent code */ - use_oplocks = True; - use_level_II_oplocks = True; - if (!open_connection(&cli)) return; - cli_oplock_handler(&cli, oplock3_handler); - fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE); - cli_write(&cli, fnum, 0, buf, 0, 4); - cli_close(&cli, fnum); - fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE); - cli.timeout = 20000; - cli_receive_smb(&cli); - printf("finished oplock test 3\n"); -} - - - -/* - Test delete on close semantics. - */ -static void run_deletetest(int dummy) -{ - static struct cli_state cli1; - static struct cli_state cli2; - char *fname = "\\delete.file"; - int fnum1, fnum2; - - printf("starting delete test\n"); - - if (!open_connection(&cli1)) { - return; - } - - cli_sockopt(&cli1, sockops); - - /* Test 1 - this should *NOT* delete the file on close. */ - - cli_setatr(&cli1, fname, 0, 0); - cli_unlink(&cli1, fname); - - fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL, - FILE_SHARE_DELETE, FILE_OVERWRITE_IF, DELETE_ON_CLOSE_FLAG); - - if (fnum1 == -1) { - printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - if (!cli_close(&cli1, fnum1)) { - printf("[1] close failed (%s)\n", cli_errstr(&cli1)); - return; - } - - fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE); - if (fnum1 == -1) { - printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - if (!cli_close(&cli1, fnum1)) { - printf("[1] close failed (%s)\n", cli_errstr(&cli1)); - return; - } - - printf("first delete on close test succeeded.\n"); - - /* Test 2 - this should delete the file on close. */ - - cli_setatr(&cli1, fname, 0, 0); - cli_unlink(&cli1, fname); - - fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, - FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0); - - if (fnum1 == -1) { - printf("[2] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - if (!cli_nt_delete_on_close(&cli1, fnum1, True)) { - printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(&cli1)); - return; - } - - if (!cli_close(&cli1, fnum1)) { - printf("[2] close failed (%s)\n", cli_errstr(&cli1)); - return; - } - - fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE); - if (fnum1 != -1) { - printf("[2] open of %s succeeded should have been deleted on close !\n", fname); - if (!cli_close(&cli1, fnum1)) { - printf("[2] close failed (%s)\n", cli_errstr(&cli1)); - } - cli_unlink(&cli1, fname); - } else - printf("second delete on close test succeeded.\n"); - - - /* Test 3 - ... */ - cli_setatr(&cli1, fname, 0, 0); - cli_unlink(&cli1, fname); - - fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL, - FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0); - - if (fnum1 == -1) { - printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - /* This should fail with a sharing violation - open for delete is only compatible - with SHARE_DELETE. */ - - fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL, - FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0); - - if (fnum2 != -1) { - printf("[3] open - 2 of %s succeeded - should have failed.\n", fname); - return; - } - - /* This should succeed. */ - - fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL, - FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0); - - if (fnum2 == -1) { - printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - if (!cli_nt_delete_on_close(&cli1, fnum1, True)) { - printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(&cli1)); - return; - } - - if (!cli_close(&cli1, fnum1)) { - printf("[3] close 1 failed (%s)\n", cli_errstr(&cli1)); - return; - } - - if (!cli_close(&cli1, fnum2)) { - printf("[3] close 2 failed (%s)\n", cli_errstr(&cli1)); - return; - } - - /* This should fail - file should no longer be there. */ - - fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE); - if (fnum1 != -1) { - printf("[3] open of %s succeeded should have been deleted on close !\n", fname); - if (!cli_close(&cli1, fnum1)) { - printf("[3] close failed (%s)\n", cli_errstr(&cli1)); - } - cli_unlink(&cli1, fname); - } else - printf("third delete on close test succeeded.\n"); - - /* Test 4 ... */ - cli_setatr(&cli1, fname, 0, 0); - cli_unlink(&cli1, fname); - - fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, - FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0); - - if (fnum1 == -1) { - printf("[4] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - /* This should succeed. */ - fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, - FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0); - if (fnum2 == -1) { - printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - if (!cli_close(&cli1, fnum2)) { - printf("[4] close - 1 failed (%s)\n", cli_errstr(&cli1)); - return; - } - - if (!cli_nt_delete_on_close(&cli1, fnum1, True)) { - printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(&cli1)); - return; - } - - /* This should fail - no more opens once delete on close set. */ - fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, - FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0); - if (fnum2 != -1) { - printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname ); - return; - } else - printf("fourth delete on close test succeeded.\n"); - - if (!cli_close(&cli1, fnum1)) { - printf("[4] close - 2 failed (%s)\n", cli_errstr(&cli1)); - return; - } - - /* Test 5 ... */ - cli_setatr(&cli1, fname, 0, 0); - cli_unlink(&cli1, fname); - - fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT, DENY_NONE); - if (fnum1 == -1) { - printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - /* This should fail - only allowed on NT opens with DELETE access. */ - - if (cli_nt_delete_on_close(&cli1, fnum1, True)) { - printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n"); - return; - } - - if (!cli_close(&cli1, fnum1)) { - printf("[5] close - 2 failed (%s)\n", cli_errstr(&cli1)); - return; - } - - printf("fifth delete on close test succeeded.\n"); - - /* Test 6 ... */ - cli_setatr(&cli1, fname, 0, 0); - cli_unlink(&cli1, fname); - - fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA, - FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, - FILE_OVERWRITE_IF, 0); - - if (fnum1 == -1) { - printf("[6] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - /* This should fail - only allowed on NT opens with DELETE access. */ - - if (cli_nt_delete_on_close(&cli1, fnum1, True)) { - printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n"); - return; - } - - if (!cli_close(&cli1, fnum1)) { - printf("[6] close - 2 failed (%s)\n", cli_errstr(&cli1)); - return; - } - - printf("sixth delete on close test succeeded.\n"); - - /* Test 7 ... */ - cli_setatr(&cli1, fname, 0, 0); - cli_unlink(&cli1, fname); - - fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, - FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0); - - if (fnum1 == -1) { - printf("[7] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - if (!cli_nt_delete_on_close(&cli1, fnum1, True)) { - printf("[7] setting delete_on_close on file failed !\n"); - return; - } - - if (!cli_nt_delete_on_close(&cli1, fnum1, False)) { - printf("[7] unsetting delete_on_close on file failed !\n"); - return; - } - - if (!cli_close(&cli1, fnum1)) { - printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1)); - return; - } - - /* This next open should succeed - we reset the flag. */ - - fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE); - if (fnum1 == -1) { - printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - if (!cli_close(&cli1, fnum1)) { - printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1)); - return; - } - - printf("seventh delete on close test succeeded.\n"); - - /* Test 7 ... */ - cli_setatr(&cli1, fname, 0, 0); - cli_unlink(&cli1, fname); - - if (!open_connection(&cli2)) { - printf("[8] failed to open second connection.\n"); - return; - } - - cli_sockopt(&cli1, sockops); - - fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, - FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0); - - if (fnum1 == -1) { - printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - fnum2 = cli_nt_create_full(&cli2, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, - FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0); - - if (fnum2 == -1) { - printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - if (!cli_nt_delete_on_close(&cli1, fnum1, True)) { - printf("[8] setting delete_on_close on file failed !\n"); - return; - } - - if (!cli_close(&cli1, fnum1)) { - printf("[8] close - 1 failed (%s)\n", cli_errstr(&cli1)); - return; - } - - if (!cli_close(&cli2, fnum2)) { - printf("[8] close - 2 failed (%s)\n", cli_errstr(&cli2)); - return; - } - - /* This should fail.. */ - fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE); - if (fnum1 != -1) { - printf("[8] open of %s succeeded should have been deleted on close !\n", fname); - if (!cli_close(&cli1, fnum1)) { - printf("[8] close failed (%s)\n", cli_errstr(&cli1)); - } - cli_unlink(&cli1, fname); - } else - printf("eighth delete on close test succeeded.\n"); - - printf("finished delete test\n"); - - cli_setatr(&cli1, fname, 0, 0); - cli_unlink(&cli1, fname); - - close_connection(&cli1); - close_connection(&cli2); -} - -/* - Test open mode returns on read-only files. - */ -static void run_opentest(int dummy) -{ - static struct cli_state cli1; - char *fname = "\\readonly.file"; - int fnum1, fnum2; - uint8 eclass; - uint32 errnum; - char buf[20]; - size_t fsize; - - printf("starting open test\n"); - - if (!open_connection(&cli1)) { - return; - } - - cli_setatr(&cli1, fname, 0, 0); - cli_unlink(&cli1, fname); - - cli_sockopt(&cli1, sockops); - - fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); - if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - if (!cli_close(&cli1, fnum1)) { - printf("close2 failed (%s)\n", cli_errstr(&cli1)); - return; - } - - if (!cli_setatr(&cli1, fname, aRONLY, 0)) { - printf("cli_setatr failed (%s)\n", cli_errstr(&cli1)); - return; - } - - fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE); - if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */ - fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL); - - cli_error( &cli1, &eclass, &errnum, NULL); - - if (eclass != ERRDOS || errnum != ERRnoaccess) { - printf("wrong error code (%x,%x) = %s\n", (unsigned int)eclass, - (unsigned int)errnum, cli_errstr(&cli1) ); - } else { - printf("correct error code ERRDOS/ERRnoaccess returned\n"); - } - - - printf("finished open test 1\n"); - - cli_close(&cli1, fnum1); - - /* Now try not readonly and ensure ERRbadshare is returned. */ - - cli_setatr(&cli1, fname, 0, 0); - - fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE); - if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - /* This will fail - but the error should be ERRshare. */ - fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL); - - cli_error( &cli1, &eclass, &errnum, NULL); - - if (eclass != ERRDOS || errnum != ERRbadshare) { - printf("wrong error code (%x,%x) = %s\n", (unsigned int)eclass, - (unsigned int)errnum, cli_errstr(&cli1) ); - } else { - printf("correct error code ERRDOS/ERRbadshare returned\n"); - } - - if (!cli_close(&cli1, fnum1)) { - printf("close2 failed (%s)\n", cli_errstr(&cli1)); - return; - } - - cli_unlink(&cli1, fname); - - printf("finished open test 2\n"); - - /* Test truncate open disposition on file opened for read. */ - - fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); - if (fnum1 == -1) { - printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - /* write 20 bytes. */ - - memset(buf, '\0', 20); - - if (cli_write(&cli1, fnum1, 0, buf, 0, 20) != 20) { - printf("write failed (%s)\n", cli_errstr(&cli1)); - } - - if (!cli_close(&cli1, fnum1)) { - printf("(3) close1 failed (%s)\n", cli_errstr(&cli1)); - return; - } - - /* Ensure size == 20. */ - if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) { - printf("(3) getatr failed (%s)\n", cli_errstr(&cli1)); - return; - } - - if (fsize != 20) { - printf("(3) file size != 20\n"); - return; - } - - /* Now test if we can truncate a file opened for readonly. */ - - fnum1 = cli_open(&cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE); - if (fnum1 == -1) { - printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(&cli1)); - return; - } - - if (!cli_close(&cli1, fnum1)) { - printf("close2 failed (%s)\n", cli_errstr(&cli1)); - return; - } - - /* Ensure size == 0. */ - if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) { - printf("(3) getatr failed (%s)\n", cli_errstr(&cli1)); - return; - } - - if (fsize != 0) { - printf("(3) file size != 0\n"); - return; - } - printf("finished open test 3\n"); - - cli_unlink(&cli1, fname); - - - printf("testing ctemp\n"); - { - char *tmp_path; - fnum1 = cli_ctemp(&cli1, "\\", &tmp_path); - if (fnum1 == -1) { - printf("ctemp failed (%s)\n", cli_errstr(&cli1)); - return; - } - printf("ctemp gave path %s\n", tmp_path); - cli_close(&cli1, fnum1); - cli_unlink(&cli1, tmp_path); - } - - close_connection(&cli1); - -} - -static void list_fn(file_info *finfo, const char *name, void *state) -{ - -} - -/* - test directory listing speed - */ -static void run_dirtest(int dummy) -{ - int i; - static struct cli_state cli; - int fnum; - double t1; - - printf("starting directory test\n"); - - if (!open_connection(&cli)) { - return; - } - - cli_sockopt(&cli, sockops); - - srandom(0); - for (i=0;i TEST1 TEST2 ...\n"); - - printf("\t-d debuglevel\n"); - printf("\t-U user%%pass\n"); - printf("\t-N numprocs\n"); - printf("\t-n my_netbios_name\n"); - printf("\t-W workgroup\n"); - printf("\t-o num_operations\n"); - printf("\t-O socket_options\n"); - printf("\t-m maximum protocol\n"); - printf("\t-L use oplocks\n"); - printf("\n\n"); - - printf("tests are:"); - for (i=0;torture_ops[i].name;i++) { - printf(" %s", torture_ops[i].name); - } - printf("\n"); - - printf("default test is ALL\n"); - - exit(1); -} - - - - - -/**************************************************************************** - main program -****************************************************************************/ - int main(int argc,char *argv[]) -{ - int opt, i; - char *p; - int gotpass = 0; - extern char *optarg; - extern int optind; - extern FILE *dbf; - static pstring servicesf = CONFIGFILE; - - dbf = stdout; - - setbuffer(stdout, NULL, 0); - - charset_initialise(); - - codepage_initialise(lp_client_code_page()); - - codepage_initialise(lp_client_code_page()); - - lp_load(servicesf,True,False,False); - load_interfaces(); - - if (argc < 2) { - usage(); - } - - for(p = argv[1]; *p; p++) - if(*p == '\\') - *p = '/'; - - if (strncmp(argv[1], "//", 2)) { - usage(); - } - - fstrcpy(host, &argv[1][2]); - p = strchr(&host[2],'/'); - if (!p) { - usage(); - } - *p = 0; - fstrcpy(share, p+1); - - get_myname(myname); - - if (*username == 0 && getenv("LOGNAME")) { - pstrcpy(username,getenv("LOGNAME")); - } - - argc--; - argv++; - - - fstrcpy(workgroup, lp_workgroup()); - - while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:Ld:")) != EOF) { - switch (opt) { - case 'W': - fstrcpy(workgroup,optarg); - break; - case 'm': - max_protocol = interpret_protocol(optarg, max_protocol); - break; - case 'N': - nprocs = atoi(optarg); - break; - case 'o': - numops = atoi(optarg); - break; - case 'd': - DEBUGLEVEL = atoi(optarg); - break; - case 'O': - sockops = optarg; - break; - case 'L': - use_oplocks = True; - break; - case 'n': - fstrcpy(myname, optarg); - break; - case 'U': - pstrcpy(username,optarg); - p = strchr(username,'%'); - if (p) { - *p = 0; - pstrcpy(password, p+1); - gotpass = 1; - } - break; - default: - printf("Unknown option %c (%d)\n", (char)opt, opt); - usage(); - } - } - - - while (!gotpass) { - p = getpass("Password:"); - if (p) { - pstrcpy(password, p); - gotpass = 1; - } - } - - printf("host=%s share=%s user=%s myname=%s\n", - host, share, username, myname); - - if (argc == 1) { - run_test("ALL"); - } else { - for (i=1;i Date: Tue, 19 Jun 2001 02:02:19 +0000 Subject: moved all our torture code to a separate directory (This used to be commit dd12c47645e2d0e832bc555492a6a8725a4495ee) --- source3/utils/locktest.c | 567 ---------------------------------------- source3/utils/locktest2.c | 626 --------------------------------------------- source3/utils/masktest.c | 521 ------------------------------------- source3/utils/msgtest.c | 96 ------- source3/utils/nbio.c | 240 ----------------- source3/utils/rpctorture.c | 559 ---------------------------------------- 6 files changed, 2609 deletions(-) delete mode 100644 source3/utils/locktest.c delete mode 100644 source3/utils/locktest2.c delete mode 100644 source3/utils/masktest.c delete mode 100644 source3/utils/msgtest.c delete mode 100644 source3/utils/nbio.c delete mode 100644 source3/utils/rpctorture.c (limited to 'source3/utils') diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c deleted file mode 100644 index 80dbba1e37..0000000000 --- a/source3/utils/locktest.c +++ /dev/null @@ -1,567 +0,0 @@ -/* - Unix SMB/Netbios implementation. - Version 2.0 - randomised byte range lock 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" - -static fstring password; -static fstring username; -static int got_pass; -static int numops = 1000; -static BOOL showall; -static BOOL analyze; -static BOOL hide_unlock_fails; -static BOOL use_oplocks; - -#define FILENAME "\\locktest.dat" -#define LOCKRANGE 1000 -#define LOCKBASE 0; - -/* -#define LOCKBASE (0x40000000 - 50) -*/ - -#define READ_PCT 50 -#define LOCK_PCT 35 -#define UNLOCK_PCT 55 -#define RANGE_MULTIPLE 1 -#define NSERVERS 2 -#define NCONNECTIONS 2 -#define NFILES 2 -#define LOCK_TIMEOUT 0 - -#define NASTY_POSIX_LOCK_HACK 0 - - -struct record { - char r1, r2; - char conn, f; - SMB_BIG_UINT start, len; - char needed; -}; - -static struct record preset[] = { -#if 0 -{36, 5, 0, 0, 0, 8, 1}, -{ 2, 6, 0, 1, 0, 1, 1}, -{53, 92, 0, 0, 0, 0, 1}, -{99, 11, 0, 0, 7, 1, 1}, -#endif -}; - -static struct record *recorded; - -static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, - enum brl_type lock_type, - br_off start, br_off size) -{ -#if NASTY_POSIX_LOCK_HACK - { - pstring cmd; - static SMB_INO_T lastino; - - if (lastino != ino) { - slprintf(cmd, sizeof(cmd), - "egrep POSIX.*%u /proc/locks", (int)ino); - system(cmd); - } - lastino = ino; - } -#endif - - printf("%6d %05x:%05x %s %.0f:%.0f(%.0f)\n", - (int)pid, (int)dev, (int)ino, - lock_type==READ_LOCK?"R":"W", - (double)start, (double)start+size-1,(double)size); - -} - - -static void show_locks(void) -{ - brl_forall(print_brl); - /* system("cat /proc/locks"); */ -} - - -/***************************************************** -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; - fstring server; - struct in_addr ip; - extern struct in_addr ipzero; - fstring myname; - static int count; - - fstrcpy(server,share+2); - share = strchr(server,'\\'); - if (!share) return NULL; - *share = 0; - share++; - - server_n = server; - - ip = ipzero; - - slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++); - - make_nmb_name(&calling, myname, 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), - lp_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")); - - c->use_oplocks = use_oplocks; - - return c; -} - - -static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NSERVERS][NCONNECTIONS][NFILES], - char *share[NSERVERS]) -{ - int server, conn, f; - - for (server=0;serverconn; - unsigned f = rec->f; - SMB_BIG_UINT start = rec->start; - SMB_BIG_UINT len = rec->len; - unsigned r1 = rec->r1; - unsigned r2 = rec->r2; - unsigned op; - int server; - BOOL ret[NSERVERS]; - - if (r1 < READ_PCT) { - op = READ_LOCK; - } else { - op = WRITE_LOCK; - } - - if (r2 < LOCK_PCT) { - /* set a lock */ - for (server=0;server %u:%u\n", - conn, f, - (double)start, (double)start+len-1, (double)len, - op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", - ret[0], ret[1]); - } - if (showall || ret[0] != ret[1]) show_locks(); - if (ret[0] != ret[1]) return False; - } else if (r2 < LOCK_PCT+UNLOCK_PCT) { - /* unset a lock */ - for (server=0;server %u:%u\n", - conn, f, - (double)start, (double)start+len-1, (double)len, - ret[0], ret[1]); - } - if (showall || ret[0] != ret[1]) show_locks(); - if (!hide_unlock_fails && ret[0] != ret[1]) return False; - } else { - /* reopen the file */ - for (server=0;serverserver_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")); - - c->use_oplocks = use_oplocks; - - return c; -} - - -static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], - char *nfs[NSERVERS], - int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES], - char *share1, char *share2) -{ - int server, conn, f, fstype; - char *share[2]; - share[0] = share1; - share[1] = share2; - - fstype = FSTYPE_SMB; - - for (server=0;serverconn; - unsigned f = rec->f; - unsigned fstype = rec->fstype; - unsigned start = rec->start; - unsigned len = rec->len; - unsigned r1 = rec->r1; - unsigned r2 = rec->r2; - unsigned op; - int server; - BOOL ret[NSERVERS]; - - if (r1 < READ_PCT) { - op = READ_LOCK; - } else { - op = WRITE_LOCK; - } - - if (r2 < LOCK_PCT) { - /* set a lock */ - for (server=0;server %u:%u\n", - conn, fstype, f, - start, start+len-1, len, - op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", - ret[0], ret[1]); - } - if (showall) brl_forall(print_brl); - if (ret[0] != ret[1]) return False; - } else if (r2 < LOCK_PCT+UNLOCK_PCT) { - /* unset a lock */ - for (server=0;server %u:%u\n", - conn, fstype, f, - start, start+len-1, len, - ret[0], ret[1]); - } - if (showall) brl_forall(print_brl); - if (!hide_unlock_fails && ret[0] != ret[1]) return False; - } else { - /* reopen the file */ - for (server=0;server': - if (n[0] == '.') { - if (! n[1] && ms_fnmatch_lanman_core(p, n+1) == 0) goto match; - if (ms_fnmatch_lanman_core(p, n) == 0) goto match; - goto nomatch; - } - if (! *n) goto next; - n++; - break; - - case '*': - if (! *p) goto match; - for (; *n; n++) { - if (ms_fnmatch_lanman_core(p, n) == 0) goto match; - } - break; - - case '<': - for (; *n; n++) { - if (ms_fnmatch_lanman_core(p, n) == 0) goto match; - if (*n == '.' && !strchr(n+1,'.')) { - n++; - break; - } - } - break; - - case '"': - if (*n == 0 && ms_fnmatch_lanman_core(p, n) == 0) goto match; - if (*n != '.') goto nomatch; - n++; - break; - - default: - if (c != *n) goto nomatch; - n++; - } - } - - if (! *n) goto match; - - nomatch: - if (verbose) printf("NOMATCH pattern=[%s] string=[%s]\n", pattern, string); - return -1; - -next: - if (ms_fnmatch_lanman_core(p, n) == 0) goto match; - goto nomatch; - - match: - if (verbose) printf("MATCH pattern=[%s] string=[%s]\n", pattern, string); - return 0; -} - -int ms_fnmatch_lanman(char *pattern, char *string) -{ - if (!strpbrk(pattern, "?*<>\"")) { - if (strcmp(string,"..") == 0) string = "."; - return strcmp(pattern, string); - } - - if (strcmp(string,"..") == 0 || strcmp(string,".") == 0) { - return ms_fnmatch_lanman_core(pattern, "..") && - ms_fnmatch_lanman_core(pattern, "."); - } - - return ms_fnmatch_lanman_core(pattern, string); -} - -static BOOL reg_match_one(char *pattern, char *file) -{ - /* oh what a weird world this is */ - if (old_list && strcmp(pattern, "*.*") == 0) return True; - - if (strcmp(pattern,".") == 0) return False; - - if (max_protocol <= PROTOCOL_LANMAN2) { - return ms_fnmatch_lanman(pattern, file)==0; - } - - if (strcmp(file,"..") == 0) file = "."; - - return ms_fnmatch(pattern, file)==0; -} - -static char *reg_test(char *pattern, char *long_name, char *short_name) -{ - static fstring ret; - fstrcpy(ret, "---"); - - pattern = 1+strrchr(pattern,'\\'); - - if (reg_match_one(pattern, ".")) ret[0] = '+'; - if (reg_match_one(pattern, "..")) ret[1] = '+'; - if (reg_match_one(pattern, long_name) || - (*short_name && reg_match_one(pattern, short_name))) 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; - } - - c->protocol = max_protocol; - - 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), - lp_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; -static file_info *finfo; - -void listfn(file_info *f, const char *s, void *state) -{ - if (strcmp(f->name,".") == 0) { - resultp[0] = '+'; - } else if (strcmp(f->name,"..") == 0) { - resultp[1] = '+'; - } else { - resultp[2] = '+'; - } - finfo = f; -} - -static void get_real_name(struct cli_state *cli, - pstring long_name, fstring short_name) -{ - /* nasty hack to force level 260 listings - tridge */ - cli->capabilities |= CAP_NT_SMBS; - if (max_protocol <= PROTOCOL_LANMAN1) { - cli_list_new(cli, "\\masktest\\*.*", aHIDDEN | aDIR, listfn, NULL); - } else { - cli_list_new(cli, "\\masktest\\*", aHIDDEN | aDIR, listfn, NULL); - } - if (finfo) { - fstrcpy(short_name, finfo->short_name); - strlower(short_name); - pstrcpy(long_name, finfo->name); - strlower(long_name); - } - - if (*short_name == 0) { - fstrcpy(short_name, long_name); - } - -#if 0 - if (!strchr(short_name,'.')) { - fstrcat(short_name,"."); - } -#endif -} - -static void testpair(struct cli_state *cli, char *mask, char *file) -{ - int fnum; - fstring res1; - char *res2; - static int count; - fstring short_name; - pstring long_name; - - count++; - - fstrcpy(res1, "---"); - - fnum = cli_open(cli, file, O_CREAT|O_TRUNC|O_RDWR, 0); - if (fnum == -1) { - DEBUG(0,("Can't create %s\n", file)); - return; - } - cli_close(cli, fnum); - - resultp = res1; - fstrcpy(short_name, ""); - finfo = NULL; - get_real_name(cli, long_name, short_name); - finfo = NULL; - fstrcpy(res1, "---"); - cli_list(cli, mask, aHIDDEN | aDIR, listfn, NULL); - - res2 = reg_test(mask, long_name, short_name); - - if (showall || strcmp(res1, res2)) { - DEBUG(0,("%s %s %d mask=[%s] file=[%s] rfile=[%s/%s]\n", - res1, res2, count, mask, file, long_name, short_name)); - if (die_on_error) exit(1); - } - - cli_unlink(cli, file); - - if (count % 100 == 0) DEBUG(0,("%d\n", count)); -} - -static void test_mask(int argc, char *argv[], - struct cli_state *cli) -{ - pstring mask, file; - int l1, l2, i, l; - int mc_len = strlen(maskchars); - int fc_len = strlen(filechars); - - cli_mkdir(cli, "\\masktest"); - - cli_unlink(cli, "\\masktest\\*"); - - if (argc >= 2) { - while (argc >= 2) { - pstrcpy(mask,"\\masktest\\"); - pstrcpy(file,"\\masktest\\"); - pstrcat(mask, argv[0]); - pstrcat(file, argv[1]); - testpair(cli, mask, file); - argv += 2; - argc -= 2; - } - goto finished; - } - - while (1) { - l1 = 1 + random() % 20; - l2 = 1 + random() % 20; - pstrcpy(mask,"\\masktest\\"); - pstrcpy(file,"\\masktest\\"); - l = strlen(mask); - for (i=0;i 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;icapabilities |= CAP_NT_SMBS; -} - -/**************************************************************************** -make smb client connection -****************************************************************************/ -static BOOL rpcclient_connect(struct client_info *info) -{ - struct nmb_name calling; - struct nmb_name called; - - make_nmb_name(&called , dns_to_netbios_name(info->dest_host ), info->name_type); - make_nmb_name(&calling, dns_to_netbios_name(info->myhostname), 0x0); - - if (!cli_establish_connection(smb_cli, - info->dest_host, &info->dest_ip, - &calling, &called, - info->share, info->svc_type, - False, True)) - { - DEBUG(0,("rpcclient_connect: connection failed\n")); - cli_shutdown(smb_cli); - return False; - } - - return True; -} - -/**************************************************************************** -stop the smb connection(s?) -****************************************************************************/ -static void rpcclient_stop(void) -{ - cli_shutdown(smb_cli); -} - -/**************************************************************************** - log in as an nt user, log out again. -****************************************************************************/ -void run_enums_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) -{ - pstring cmd; - int i; - - /* establish connections. nothing to stop these being re-established. */ - rpcclient_connect(cli_info); - - DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd)); - if (cli->fd <= 0) - { - fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n", - cli_info->dest_host, cli_info->name_type); - return; - } - - for (i = 0; i < num_ops; i++) - { - set_first_token(""); - cmd_srv_enum_sess(cli_info); - set_first_token(""); - cmd_srv_enum_shares(cli_info); - set_first_token(""); - cmd_srv_enum_files(cli_info); - - if (password[0] != 0) - { - slprintf(cmd, sizeof(cmd)-1, "1"); - set_first_token(cmd); - } - else - { - set_first_token(""); - } - cmd_srv_enum_conn(cli_info); - } - - rpcclient_stop(); - -} - -/**************************************************************************** - log in as an nt user, log out again. -****************************************************************************/ -void run_ntlogin_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) -{ - pstring cmd; - int i; - - /* establish connections. nothing to stop these being re-established. */ - rpcclient_connect(cli_info); - - DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd)); - if (cli->fd <= 0) - { - fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n", - cli_info->dest_host, cli_info->name_type); - return; - } - - for (i = 0; i < num_ops; i++) - { - slprintf(cmd, sizeof(cmd)-1, "%s %s", cli->user_name, password); - set_first_token(cmd); - - cmd_netlogon_login_test(cli_info); - } - - rpcclient_stop(); - -} - -/**************************************************************************** - runs n simultaneous functions. -****************************************************************************/ -static void create_procs(int nprocs, int numops, - struct client_info *cli_info, struct cli_state *cli, - void (*fn)(int, struct client_info *, struct cli_state *)) -{ - int i, status; - - for (i=0;i [-d debuglevel] [-l log] ", - pname); - - fprintf(out_hnd, "\nVersion %s\n",VERSION); - fprintf(out_hnd, "\t-d debuglevel set the debuglevel\n"); - fprintf(out_hnd, "\t-l log basename. Basename for log/debug files\n"); - fprintf(out_hnd, "\t-n netbios name. Use this name as my netbios name\n"); - fprintf(out_hnd, "\t-m max protocol set the max protocol level\n"); - fprintf(out_hnd, "\t-I dest IP use this IP to connect to\n"); - fprintf(out_hnd, "\t-E write messages to stderr instead of stdout\n"); - fprintf(out_hnd, "\t-U username set the network username\n"); - fprintf(out_hnd, "\t-W workgroup set the workgroup name\n"); - fprintf(out_hnd, "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n"); - fprintf(out_hnd, "\n"); -} - -enum client_action -{ - CLIENT_NONE, - CLIENT_IPC, - CLIENT_SVC -}; - -/**************************************************************************** - main program -****************************************************************************/ - int main(int argc,char *argv[]) -{ - char *pname = argv[0]; - int opt; - extern FILE *dbf; - extern char *optarg; - extern int optind; - static pstring servicesf = CONFIGFILE; - pstring term_code; - BOOL got_pass = False; - char *cmd_str=""; - mode_t myumask = 0755; - enum client_action cli_action = CLIENT_NONE; - int nprocs = 1; - int numops = 100; - - struct client_info cli_info; - - out_hnd = stdout; - - rpcclient_init(); - -#ifdef KANJI - pstrcpy(term_code, KANJI); -#else /* KANJI */ - *term_code = 0; -#endif /* KANJI */ - - if (!lp_load(servicesf,True, False, False)) - { - fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); - } - - codepage_initialise(lp_client_code_page()); - - DEBUGLEVEL = 0; - - cli_info.put_total_size = 0; - cli_info.put_total_time_ms = 0; - cli_info.get_total_size = 0; - cli_info.get_total_time_ms = 0; - - cli_info.dir_total = 0; - cli_info.newer_than = 0; - cli_info.archive_level = 0; - cli_info.print_mode = 1; - - cli_info.translation = False; - cli_info.recurse_dir = False; - cli_info.lowercase = False; - cli_info.prompt = True; - cli_info.abort_mget = True; - - cli_info.dest_ip.s_addr = 0; - cli_info.name_type = 0x20; - - pstrcpy(cli_info.cur_dir , "\\"); - pstrcpy(cli_info.file_sel, ""); - pstrcpy(cli_info.base_dir, ""); - pstrcpy(smb_cli->domain, ""); - pstrcpy(smb_cli->user_name, ""); - pstrcpy(cli_info.myhostname, ""); - pstrcpy(cli_info.dest_host, ""); - - pstrcpy(cli_info.svc_type, "A:"); - pstrcpy(cli_info.share, ""); - pstrcpy(cli_info.service, ""); - - ZERO_STRUCT(cli_info.dom.level3_sid); - pstrcpy(cli_info.dom.level3_dom, ""); - ZERO_STRUCT(cli_info.dom.level5_sid); - pstrcpy(cli_info.dom.level5_dom, ""); - - smb_cli->nt_pipe_fnum = 0xffff; - - setup_logging(pname, True); - - TimeInit(); - charset_initialise(); - - myumask = umask(0); - umask(myumask); - - if (!get_myname(global_myname)) - { - fprintf(stderr, "Failed to get my hostname.\n"); - } - - password[0] = 0; - - if (argc < 2) - { - usage(pname); - exit(1); - } - - if (*argv[1] != '-') - { - pstrcpy(cli_info.service, argv[1]); - /* Convert any '/' characters in the service name to '\' characters */ - string_replace( cli_info.service, '/','\\'); - argc--; - argv++; - - DEBUG(1,("service: %s\n", cli_info.service)); - - if (count_chars(cli_info.service,'\\') < 3) - { - usage(pname); - printf("\n%s: Not enough '\\' characters in service\n", cli_info.service); - exit(1); - } - - /* - if (count_chars(cli_info.service,'\\') > 3) - { - usage(pname); - printf("\n%s: Too many '\\' characters in service\n", cli_info.service); - exit(1); - } - */ - - if (argc > 1 && (*argv[1] != '-')) - { - got_pass = True; - pstrcpy(password,argv[1]); - memset(argv[1],'X',strlen(argv[1])); - argc--; - argv++; - } - - cli_action = CLIENT_SVC; - } - - while ((opt = getopt(argc, argv,"s:O:M:S:i:N:o:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF) - { - switch (opt) - { - case 'm': - { - /* FIXME ... max_protocol seems to be funny here */ - - int max_protocol = 0; - max_protocol = interpret_protocol(optarg,max_protocol); - fprintf(stderr, "max protocol not currently supported\n"); - break; - } - - case 'O': - { - pstrcpy(user_socket_options,optarg); - break; - } - - case 'S': - { - pstrcpy(cli_info.dest_host,optarg); - strupper(cli_info.dest_host); - cli_action = CLIENT_IPC; - break; - } - - case 'i': - { - pstrcpy(scope, optarg); - break; - } - - case 'U': - { - char *lp; - pstrcpy(smb_cli->user_name,optarg); - if ((lp=strchr(smb_cli->user_name,'%'))) - { - *lp = 0; - pstrcpy(password,lp+1); - got_pass = True; - memset(strchr(optarg,'%')+1,'X',strlen(password)); - } - break; - } - - case 'W': - { - pstrcpy(smb_cli->domain,optarg); - break; - } - - case 'E': - { - dbf = stderr; - break; - } - - case 'I': - { - cli_info.dest_ip = *interpret_addr2(optarg); - if (zero_ip(cli_info.dest_ip)) - { - exit(1); - } - break; - } - - case 'N': - { - nprocs = atoi(optarg); - break; - } - - case 'o': - { - numops = atoi(optarg); - break; - } - - case 'n': - { - fstrcpy(global_myname, optarg); - break; - } - - case 'd': - { - if (*optarg == 'A') - DEBUGLEVEL = 10000; - else - DEBUGLEVEL = atoi(optarg); - break; - } - - case 'l': - { - slprintf(debugf, sizeof(debugf)-1, - "%s.client",optarg); - break; - } - - case 'c': - { - cmd_str = optarg; - got_pass = True; - break; - } - - case 'h': - { - usage(pname); - exit(0); - break; - } - - case 's': - { - pstrcpy(servicesf, optarg); - break; - } - - case 't': - { - pstrcpy(term_code, optarg); - break; - } - - default: - { - usage(pname); - exit(1); - break; - } - } - } - - if (cli_action == CLIENT_NONE) - { - usage(pname); - exit(1); - } - - strupper(global_myname); - fstrcpy(cli_info.myhostname, global_myname); - - DEBUG(3,("%s client started (version %s)\n",timestring(False),VERSION)); - - if (*smb_cli->domain == 0) - { - pstrcpy(smb_cli->domain,lp_workgroup()); - } - strupper(smb_cli->domain); - - load_interfaces(); - - if (cli_action == CLIENT_IPC) - { - pstrcpy(cli_info.share, "IPC$"); - pstrcpy(cli_info.svc_type, "IPC"); - } - - fstrcpy(cli_info.mach_acct, cli_info.myhostname); - strupper(cli_info.mach_acct); - fstrcat(cli_info.mach_acct, "$"); - - /* set the password cache info */ - if (got_pass) - { - if (password[0] == 0) - { - pwd_set_nullpwd(&(smb_cli->pwd)); - } - else - { - pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ - } - } - else - { - char *pwd = getpass("Enter Password:"); - safe_strcpy(password, pwd, sizeof(password)); - pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ - } - - create_procs(nprocs, numops, &cli_info, smb_cli, run_enums_test); - - if (password[0] != 0) - { - create_procs(nprocs, numops, &cli_info, smb_cli, run_ntlogin_test); - } - - fflush(out_hnd); - - return(0); -} -- cgit From fcda2645f099e5d356361ec3de4f45d97285f0b5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 20 Jun 2001 03:05:09 +0000 Subject: added a close-share smbcontrol message that forcibly closes a share in smbd (to allow unmount) (This used to be commit 15b17a80db605a55f667c95fb7e316877a441887) --- source3/utils/smbcontrol.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 843d56234b..27a3b61170 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -32,6 +32,7 @@ static struct { {"profilelevel", MSG_REQ_PROFILELEVEL}, {"debuglevel", MSG_REQ_DEBUGLEVEL}, {"printer-notify", MSG_PRINTER_NOTIFY}, + {"close-share", MSG_SMB_FORCE_TDIS}, {NULL, -1} }; @@ -206,7 +207,7 @@ static BOOL do_command(char *dest, char *msg_name, char **params) } case MSG_PROFILE: - if (!params[0]) { + if (!params || !params[0]) { fprintf(stderr,"MSG_PROFILE needs a parameter\n"); return(False); } @@ -277,7 +278,7 @@ static BOOL do_command(char *dest, char *msg_name, char **params) fprintf(stderr,"printer-notify can only be sent to smbd\n"); return(False); } - if (!params[0]) { + if (!params || !params[0]) { fprintf(stderr, "printer-notify needs a printer name\n"); return (False); } @@ -285,12 +286,25 @@ static BOOL do_command(char *dest, char *msg_name, char **params) strlen(params[0]) + 1, False); break; + case MSG_SMB_FORCE_TDIS: + if (!strequal(dest, "smbd")) { + fprintf(stderr,"close-share can only be sent to smbd\n"); + return(False); + } + if (!params || !params[0]) { + fprintf(stderr, "close-share needs a share name or '*'\n"); + return (False); + } + retval = send_message(dest, MSG_SMB_FORCE_TDIS, params[0], + strlen(params[0]) + 1, False); + break; + case MSG_PING: if (!pong_registered) { message_register(MSG_PONG, pong_function); pong_registered = True; } - if (!params[0]) { + if (!params || !params[0]) { fprintf(stderr,"MSG_PING needs a parameter\n"); return(False); } -- cgit From 82970b833cca505fcb5013c0264edde5a79cbd2e Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 20 Jun 2001 16:54:32 +0000 Subject: initial support for paramter type P_LIST it will avoid problems with lists being longer than 1024 bytes just now only ip list parameters have been converted to the new type (hosts allow, hosts deny, ssl hosts, ssl hosts resign) (This used to be commit e1572f85d6247b760db10825b2fa688d7ed50bd3) --- source3/utils/testparm.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index ae4a12a882..b8536d4b9d 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -237,23 +237,28 @@ int main(int argc, char *argv[]) for (s=0;s<1000;s++) { if (VALID_SNUM(s)) { - char *deny_list = lp_hostsdeny(s); - char *allow_list = lp_hostsallow(s); + char **deny_list = lp_hostsdeny(s); + char **allow_list = lp_hostsallow(s); + int i; if(deny_list) { - char *hasstar = strchr(deny_list, '*'); - char *hasquery = strchr(deny_list, '?'); - if(hasstar || hasquery) { - printf("Invalid character %c in hosts deny list %s for service %s.\n", - hasstar ? *hasstar : *hasquery, deny_list, lp_servicename(s) ); + for (i=0; deny_list[i]; i++) { + char *hasstar = strchr(deny_list[i], '*'); + char *hasquery = strchr(deny_list[i], '?'); + if(hasstar || hasquery) { + printf("Invalid character %c in hosts deny list (%s) for service %s.\n", + hasstar ? *hasstar : *hasquery, deny_list[i], lp_servicename(s) ); + } } } if(allow_list) { - char *hasstar = strchr(allow_list, '*'); - char *hasquery = strchr(allow_list, '?'); - if(hasstar || hasquery) { - printf("Invalid character %c in hosts allow list %s for service %s.\n", - hasstar ? *hasstar : *hasquery, allow_list, lp_servicename(s) ); + for (i=0; allow_list[i]; i++) { + char *hasstar = strchr(allow_list[i], '*'); + char *hasquery = strchr(allow_list[i], '?'); + if(hasstar || hasquery) { + printf("Invalid character %c in hosts allow list (%s) for service %s.\n", + hasstar ? *hasstar : *hasquery, allow_list[i], lp_servicename(s) ); + } } } -- cgit From 6fb063b4d5dfb1b201cb4531855662997ca02dbf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 20 Jun 2001 17:49:38 +0000 Subject: Warning fix from Andrew Bartlett. Jeremy. (This used to be commit 87f647715d9fba9f8d25da0bde005a8d8858c2ae) --- source3/utils/smbcacls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 4893eb4202..028eb481a6 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -340,7 +340,7 @@ static SEC_DESC *sec_desc_parse(char *str) char *p = str; fstring tok; SEC_DESC *ret; - unsigned sd_size; + size_t sd_size; DOM_SID *grp_sid=NULL, *owner_sid=NULL; SEC_ACL *dacl=NULL; int revision=1; -- cgit From 91b8a8d1d21b810b6aca44ce647837669efd6dcf Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 21 Jun 2001 09:10:42 +0000 Subject: next_token() was supposed to be a reentrant replacement for strtok(), but the code suffered from bitrot and is not now reentrant. That means we can get bizarre behaviour i've fixed this by making next_token() reentrant and creating a next_token_nr() that is a small non-reentrant wrapper for those lumps of code (mostly smbclient) that have come to rely on the non-reentrant behaviour (This used to be commit 674ee2f1d12b0afc164a9e9072758fd1c5e54df7) --- source3/utils/smbcacls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 028eb481a6..08c3fecbb9 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -266,12 +266,12 @@ static BOOL parse_ace(SEC_ACE *ace, char *str) /* Only numeric form accepted for flags at present */ - if (!(next_token(NULL, tok, "/", sizeof(fstring)) && + if (!(next_token(&p, tok, "/", sizeof(fstring)) && sscanf(tok, "%i", &aflags))) { return False; } - if (!next_token(NULL, tok, "/", sizeof(fstring))) { + if (!next_token(&p, tok, "/", sizeof(fstring))) { return False; } -- cgit From 53ca6d33ce46f29afdf3fa82ba0669ef88dd97e4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 25 Jun 2001 01:15:17 +0000 Subject: added a -L option to smbpasswd to force it to run locally so we can test smbpasswd as non-root (This used to be commit ab635202655712a05b812ff40550d00d00552853) --- source3/utils/smbpasswd.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 00a7d3c1c1..b4576a603c 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -29,6 +29,9 @@ extern int DEBUGLEVEL; extern char *optarg; extern int optind; +/* forced running in root-mode */ +static BOOL local_mode; + /********************************************************* a strdup with exit **********************************************************/ @@ -59,7 +62,8 @@ static void usage(void) printf(" -U USER remote username\n"); printf(" -r MACHINE remote machine\n"); - if (getuid() == 0) { + if (getuid() == 0 || local_mode) { + printf(" -L local mode (must be first option)\n"); printf(" -R ORDER name resolve order\n"); printf(" -j DOMAIN join domain name\n"); printf(" -a add user\n"); @@ -261,8 +265,11 @@ static int process_root(int argc, char *argv[]) char *old_passwd = NULL; char *remote_machine = NULL; - while ((ch = getopt(argc, argv, "ax:d:e:mnj:r:sR:D:U:")) != EOF) { + while ((ch = getopt(argc, argv, "ax:d:e:mnj:r:sR:D:U:L")) != EOF) { switch(ch) { + case 'L': + local_mode = True; + break; case 'a': local_flags |= LOCAL_ADD_USER; break; @@ -609,7 +616,14 @@ int main(int argc, char **argv) exit(1); } - if (getuid() == 0) { + /* pre-check for local mode option as first option. We can't + do this via normal getopt as getopt can't be called + twice. */ + if (argc > 1 && strcmp(argv[1], "-L") == 0) { + local_mode = True; + } + + if (local_mode || getuid() == 0) { return process_root(argc, argv); } -- cgit From b95a294a0879e800e816281a80d0074224cd8cd4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 25 Jun 2001 02:53:13 +0000 Subject: fixed usage of socklen_t and also tidied up SIG_ATOMIC_T, using a typedef instead of a define (This used to be commit e2ecff419fdc0a0dc7551b33b377dc11061ef2a3) --- source3/utils/smbfilter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c index 833221b10b..db83873e69 100644 --- a/source3/utils/smbfilter.c +++ b/source3/utils/smbfilter.c @@ -179,7 +179,7 @@ static void start_filter(char *desthost) fd_set fds; int num; struct sockaddr addr; - int in_addrlen = sizeof(addr); + socklen_t in_addrlen = sizeof(addr); FD_ZERO(&fds); FD_SET(s, &fds); -- cgit From 39a265ae20a7ffcc264db6ab2838f40e90db5bf4 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 27 Jun 2001 04:43:55 +0000 Subject: Added some missing entries to usage(). Added -d option to set debug level. (This used to be commit 9874df0c2242ee46182744eabae14829c3b5f21e) --- source3/utils/smbcacls.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 08c3fecbb9..f07bdb0dd8 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -788,6 +788,8 @@ static void usage(void) \t-G username change group ownership of a file\n\ \t-n don't resolve sids or masks to names\n\ \t-h print help\n\ +\t-d debuglevel set debug output level\n\ +\t-U username user to autheticate as\n\ \n\ The username can be of the form username%%password or\n\ workgroup\\username%%password.\n\n\ @@ -855,7 +857,7 @@ You can string acls together with spaces, commas or newlines\n\ } } - while ((opt = getopt(argc, argv, "U:nhS:D:A:M:C:G:t")) != EOF) { + while ((opt = getopt(argc, argv, "U:nhS:D:A:M:C:G:td:")) != EOF) { switch (opt) { case 'U': pstrcpy(username,optarg); @@ -910,6 +912,10 @@ You can string acls together with spaces, commas or newlines\n\ talloc_destroy(ctx); exit(EXIT_PARSE_ERROR); + case 'd': + DEBUGLEVEL = atoi(optarg); + break; + default: printf("Unknown option %c (%d)\n", (char)opt, opt); talloc_destroy(ctx); -- cgit From d90f7ef5eae4cf1475c915e3675e8d138de8d96a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 29 Jun 2001 08:04:12 +0000 Subject: Experimental support for joining a domain without creating an account in server manager first. Just use the -U parameter to smbpasswd when joining the domain: smbpasswd -r PDC -j DOMAIN -U administrator%password Should also work with domain users with the 'add workstation to domain' user right. (This used to be commit 937b96feaa276f8dd626f2d640f03dc4c55f48c6) --- source3/utils/smbpasswd.c | 367 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 344 insertions(+), 23 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index b4576a603c..3442efc3a8 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -1,11 +1,14 @@ /* - * Unix SMB/Netbios implementation. Version 1.9. smbpasswd module. Copyright - * (C) Jeremy Allison 1995-1998 + * Unix SMB/Netbios implementation. + * Version 1.9. + * smbpasswd module. + * Copyright (C) Jeremy Allison 1995-1998 + * Copyright (C) Tim Potter 2001 * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. + * This program is 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 @@ -14,8 +17,7 @@ * * 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. - */ + * Mass Ave, Cambridge, MA 02139, USA. */ #include "includes.h" @@ -136,6 +138,288 @@ unable to join domain.\n"); return (int)ret; } +/* Initialise client credentials for authenticated pipe access */ + +void init_rpcclient_creds(struct ntuser_creds *creds, char* username, + char* domain, char* password) +{ + ZERO_STRUCTP(creds); + + if (lp_encrypted_passwords()) { + pwd_make_lm_nt_16(&creds->pwd, password); + } else { + pwd_set_cleartext(&creds->pwd, password); + } + + fstrcpy(creds->user_name, username); + fstrcpy(creds->domain, domain); +} + +/********************************************************* +Join a domain using the administrator username and password +**********************************************************/ + +/* Macro for checking RPC error codes to make things more readable */ + +#define CHECK_RPC_ERR(rpc, msg) \ + if ((result = rpc) != NT_STATUS_NO_PROBLEMO) { \ + DEBUG(0, (msg ": %s\n", get_nt_error_msg(result))); \ + goto done; \ + } + +#define CHECK_RPC_ERR_DEBUG(rpc, debug_args) \ + if ((result = rpc) != NT_STATUS_NO_PROBLEMO) { \ + DEBUG(0, debug_args); \ + goto done; \ + } + +static int join_domain_byuser(char *domain, char *remote_machine, + char *username, char *password) +{ + /* libsmb variables */ + + struct nmb_name calling, called; + struct ntuser_creds creds; + struct cli_state cli; + fstring dest_host, acct_name; + struct in_addr dest_ip; + TALLOC_CTX *mem_ctx; + + /* rpc variables */ + + POLICY_HND lsa_pol, sam_pol, domain_pol, user_pol; + DOM_SID domain_sid; + uint32 user_rid; + + /* Password stuff */ + + char *machine_pwd; + int plen = 0; + uchar pwbuf[516], ntpw[16], sess_key[16]; + SAM_USERINFO_CTR ctr; + SAM_USER_INFO_24 p24; + SAM_USER_INFO_10 p10; + + /* Misc */ + + uint32 result; + int retval = 1; + + /* Connect to remote machine */ + + ZERO_STRUCT(cli); + ZERO_STRUCT(creds); + + if (!(mem_ctx = talloc_init())) { + DEBUG(0, ("Could not initialise talloc context\n")); + goto done; + } + + if (!cli_initialise(&cli)) { + DEBUG(0, ("Could not initialise client structure\n")); + goto done; + } + + init_rpcclient_creds(&creds, username, domain, password); + cli_init_creds(&cli, &creds); + + if (!resolve_srv_name(remote_machine, dest_host, &dest_ip)) { + DEBUG(0, ("Could not resolve name %s\n", remote_machine)); + goto done; + } + + make_nmb_name(&called, dns_to_netbios_name(dest_host), 0x20); + make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0); + + if (!cli_establish_connection(&cli, dest_host, &dest_ip, &calling, + &called, "IPC$", "IPC", False, True)) { + DEBUG(0, ("Error connecting to %s\n", dest_host)); + goto done; + } + + /* Fetch domain sid */ + + if (!cli_nt_session_open(&cli, PIPE_LSARPC)) { + DEBUG(0, ("Error connecting to SAM pipe\n")); + goto done; + } + + + CHECK_RPC_ERR(cli_lsa_open_policy(&cli, mem_ctx, True, + SEC_RIGHTS_MAXIMUM_ALLOWED, + &lsa_pol), + "error opening lsa policy handle"); + + CHECK_RPC_ERR(cli_lsa_query_info_policy(&cli, mem_ctx, &lsa_pol, + 5, domain, &domain_sid), + "error querying info policy"); + + cli_lsa_close(&cli, mem_ctx, &lsa_pol); + + cli_nt_session_close(&cli); /* Done with this pipe */ + + /* Create domain user */ + + if (!cli_nt_session_open(&cli, PIPE_SAMR)) { + DEBUG(0, ("Error connecting to SAM pipe\n")); + goto done; + } + + CHECK_RPC_ERR(cli_samr_connect(&cli, mem_ctx, + SEC_RIGHTS_MAXIMUM_ALLOWED, + &sam_pol), + "could not connect to SAM database"); + + + CHECK_RPC_ERR(cli_samr_open_domain(&cli, mem_ctx, &sam_pol, + SEC_RIGHTS_MAXIMUM_ALLOWED, + &domain_sid, &domain_pol), + "could not open domain"); + + /* Create domain user */ + + fstrcpy(acct_name, global_myname); + fstrcat(acct_name, "$"); + + strlower(acct_name); + + { + uint32 unknown = 0xe005000b; + + result = cli_samr_create_dom_user(&cli, mem_ctx, &domain_pol, + acct_name, ACB_WSTRUST, + unknown, &user_pol, + &user_rid); + } + + if (result == NT_STATUS_USER_EXISTS) { + uint32 num_rids, *name_types, *user_rids; + uint32 flags = 0x3e8; + char *names; + + /* Look up existing rid */ + + names = (char *)&acct_name[0]; + + CHECK_RPC_ERR_DEBUG( + cli_samr_lookup_names(&cli, mem_ctx, + &domain_pol, flags, + 1, &names, &num_rids, + &user_rids, &name_types), + ("error looking up rid for user %s: %s\n", + acct_name, get_nt_error_msg(result))); + + if (name_types[0] != SID_NAME_USER) { + DEBUG(0, ("%s is not a user account\n", acct_name)); + goto done; + } + + user_rid = user_rids[0]; + + /* Open handle on user */ + + CHECK_RPC_ERR_DEBUG( + cli_samr_open_user(&cli, mem_ctx, &domain_pol, + SEC_RIGHTS_MAXIMUM_ALLOWED, + user_rid, &user_pol), + ("could not re-open existing user %s: %s\n", + acct_name, get_nt_error_msg(result))); + + } else if (result != NT_STATUS_NOPROBLEMO) { + DEBUG(0, ("error creating domain user: %s\n", + get_nt_error_msg(result))); + goto done; + } + + /* Create a random machine account password */ + + { + UNISTR2 upw; /* Unicode password */ + + upw.buffer = (uint16 *)talloc_zero(mem_ctx, 0xc * + sizeof(uint16)); + + upw.uni_str_len = 0xc; + upw.uni_max_len = 0xc; + + machine_pwd = (char *)upw.buffer; + plen = upw.uni_str_len * 2; + generate_random_buffer(machine_pwd, plen, True); + + encode_pw_buffer(pwbuf, machine_pwd, plen, False); + + nt_owf_genW(&upw, ntpw); + } + + /* Set password on machine account */ + + ZERO_STRUCT(ctr); + ZERO_STRUCT(p24); + + init_sam_user_info24(&p24, pwbuf); + + ctr.switch_value = 24; + ctr.info.id24 = &p24; + + /* I don't think this is quite the right place for this + calculation. It should be moved somewhere where the credentials + are calculated. )-: */ + + mdfour(sess_key, cli.pwd.smb_nt_pwd, 16); + + CHECK_RPC_ERR(cli_samr_set_userinfo(&cli, mem_ctx, &user_pol, 24, + sess_key, &ctr), + "error setting trust account password"); + + /* Why do we have to try to (re-)set the ACB to be the same as what + we passed in the samr_create_dom_user() call? When a NT + workstation is joined to a domain by an administrator the + acb_info is set to 0x80. For a normal user with "Add + workstations to the domain" rights the acb_info is 0x84. I'm + not sure whether it is supposed to make a difference or not. NT + seems to cope with either value so don't bomb out if the set + userinfo2 level 0x10 fails. -tpot */ + + ctr.switch_value = 0x10; + ctr.info.id10 = &p10; + + init_sam_user_info10(&p10, ACB_WSTRUST); + + /* Ignoring the return value is necessary for joining a domain + as a normal user with "Add workstation to domain" privilege. */ + + result = cli_samr_set_userinfo2(&cli, mem_ctx, &user_pol, 0x10, + sess_key, &ctr); + + /* Now store the secret in the secrets database */ + + strupper(domain); + + if (!secrets_store_domain_sid(domain, &domain_sid) || + !secrets_store_trust_account_password(domain, ntpw)) { + DEBUG(0, ("error storing domain secrets\n")); + goto done; + } + + retval = 0; /* Success! */ + + done: + /* Close down pipe - this will clean up open policy handles */ + + if (cli.nt_pipe_fnum) + cli_nt_session_close(&cli); + + /* Display success or failure */ + + if (retval != 0) { + trust_password_delete(domain); + fprintf(stderr,"Unable to join domain %s.\n",domain); + } else { + printf("Joined domain %s.\n",domain); + } + + return retval; +} static void set_line_buffering(FILE *f) { @@ -256,10 +540,10 @@ static int process_root(int argc, char *argv[]) { struct passwd *pwd; int result = 0, ch; - BOOL joining_domain = False; + BOOL joining_domain = False, got_pass = False; int local_flags = 0; BOOL stdin_passwd_get = False; - char *user_name = NULL; + fstring user_name, user_password; char *new_domain = NULL; char *new_passwd = NULL; char *old_passwd = NULL; @@ -275,17 +559,17 @@ static int process_root(int argc, char *argv[]) break; case 'x': local_flags |= LOCAL_DELETE_USER; - user_name = optarg; + fstrcpy(user_name, optarg); new_passwd = xstrdup("XXXXXX"); break; case 'd': local_flags |= LOCAL_DISABLE_USER; - user_name = optarg; + fstrcpy(user_name, optarg); new_passwd = xstrdup("XXXXXX"); break; case 'e': local_flags |= LOCAL_ENABLE_USER; - user_name = optarg; + fstrcpy(user_name, optarg); break; case 'm': local_flags |= LOCAL_TRUST_ACCOUNT; @@ -314,9 +598,21 @@ static int process_root(int argc, char *argv[]) case 'D': DEBUGLEVEL = atoi(optarg); break; - case 'U': - user_name = optarg; + case 'U': { + char *lp; + + fstrcpy(user_name, optarg); + + if ((lp = strchr(user_name, '%'))) { + *lp = 0; + fstrcpy(user_password, lp + 1); + got_pass = True; + memset(strchr(optarg, '%') + 1, 'X', + strlen(user_password)); + } + break; + } default: usage(); } @@ -342,10 +638,35 @@ static int process_root(int argc, char *argv[]) load_interfaces(); } - if(joining_domain) { + /* Join a domain */ + + if (joining_domain) { + if (argc != 0) usage(); - return join_domain(new_domain, remote_machine); + + /* Are we joining by specifing an admin username and + password? */ + + if (user_name[0]) { + + /* Get administrator password if not specified */ + + if (!got_pass) { + char *pass = getpass("Password: "); + + if (pass) + pstrcpy(user_password, pass); + } + + return join_domain_byuser(new_domain, remote_machine, + user_name, user_password); + } else { + + /* Or just with the server manager? */ + + return join_domain(new_domain, remote_machine); + } } /* @@ -356,21 +677,21 @@ static int process_root(int argc, char *argv[]) case 0: break; case 1: - user_name = argv[0]; + fstrcpy(user_name, argv[0]); break; case 2: - user_name = argv[0]; + fstrcpy(user_name, argv[0]); new_passwd = xstrdup(argv[1]); break; default: usage(); } - if (!user_name && (pwd = sys_getpwuid(0))) { - user_name = xstrdup(pwd->pw_name); + if (!user_name[0] && (pwd = sys_getpwuid(0))) { + fstrcpy(user_name, pwd->pw_name); } - if (!user_name) { + if (!user_name[0]) { fprintf(stderr,"You must specify a username\n"); exit(1); } @@ -400,7 +721,7 @@ static int process_root(int argc, char *argv[]) */ slprintf(buf, sizeof(buf)-1, "%s$", user_name); - user_name = buf; + fstrcpy(user_name, buf); } if (remote_machine != NULL) { -- cgit From 4a6ef39261a91e03f9bb6a18dcbfce0742d98702 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 3 Jul 2001 22:00:11 +0000 Subject: Small warning removal tidyup. Jeremy. (This used to be commit 5cf7bc582bc2dc4fa7be43d87c81e94f6dd00573) --- source3/utils/make_unicodemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/make_unicodemap.c b/source3/utils/make_unicodemap.c index ff9bb19b6f..3584facbf6 100644 --- a/source3/utils/make_unicodemap.c +++ b/source3/utils/make_unicodemap.c @@ -149,7 +149,7 @@ static int do_compile(const char *codepage, const char *input_file, const char * 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) { + if(sys_stat(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); -- cgit From d972dc06a189fc433c822d1e5eee650a02a79550 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 4 Jul 2001 04:04:17 +0000 Subject: Removed bogus server_n local variable in connect_one() function. (This used to be commit 69d90a8af167d53ebdb6d7aeef41b28b672288d1) --- source3/utils/smbcacls.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index f07bdb0dd8..51ae05b52a 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -692,7 +692,6 @@ struct cli_state *connect_one(char *share) { struct cli_state *c; struct nmb_name called, calling; - char *server_n; struct in_addr ip; extern struct in_addr ipzero; extern pstring global_myname; @@ -703,8 +702,6 @@ struct cli_state *connect_one(char *share) *share = 0; share++; - server_n = server; - ip = ipzero; make_nmb_name(&calling, global_myname, 0x0); @@ -715,8 +712,8 @@ struct cli_state *connect_one(char *share) /* 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)); + !cli_connect(c, server, &ip)) { + DEBUG(0,("Connection to %s failed\n", server)); cli_shutdown(c); safe_free(c); return NULL; -- cgit From 87fbb7092b8f8b2f0db0f361c3d625e19de57cd9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 07:15:53 +0000 Subject: The big character set handling changeover! This commit gets rid of all our old codepage handling and replaces it with iconv. All internal strings in Samba are now in "unix" charset, which may be multi-byte. See internals.doc and my posting to samba-technical for a more complete explanation. (This used to be commit debb471267960e56005a741817ebd227ecfc512a) --- source3/utils/make_smbcodepage.c | 476 --------------------------------------- source3/utils/make_unicodemap.c | 313 ------------------------- source3/utils/nmblookup.c | 2 - source3/utils/pdbedit.c | 2 - source3/utils/smbcacls.c | 2 - source3/utils/smbcontrol.c | 1 - source3/utils/smbfilter.c | 2 - source3/utils/smbgroupedit.c | 2 - source3/utils/smbpasswd.c | 4 - source3/utils/smbw_sample.c | 2 - source3/utils/status.c | 4 +- source3/utils/testparm.c | 7 +- source3/utils/testprns.c | 2 - 13 files changed, 2 insertions(+), 817 deletions(-) delete mode 100644 source3/utils/make_smbcodepage.c delete mode 100644 source3/utils/make_unicodemap.c (limited to 'source3/utils') diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c deleted file mode 100644 index 1bd3edc263..0000000000 --- a/source3/utils/make_smbcodepage.c +++ /dev/null @@ -1,476 +0,0 @@ -/* - Unix SMB/Netbios implementation. - Version 1.9. - Create codepage files from codepage_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 codepage_usage(char *progname) -{ - fprintf(stderr, "Usage is : %s [c|d] \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, int size) -{ - char *p = *buf; - int num = 0; - - for(; *p && (*p != '\n'); 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 int clean_data( char **buf, size_t *size) -{ - pstring linebuf; - char *p = *buf; - int num_lines = 0; - char *newbuf = (char *)malloc( *size + 1); - char *newbuf_p = NULL; - - if(newbuf == NULL) - { - fprintf(stderr, "%s: malloc fail for size %d.\n", prog_name, *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 byte from a codepage file. - */ - -static BOOL parse_byte(char *buf, unsigned char *bp) -{ - unsigned int b; - char *endptr = NULL; - - b = (unsigned int)strtol(buf, &endptr, 0); - if(endptr == buf || b > 255) - return False; - - *bp = (unsigned char)b; - return True; -} - -/* - * Parse a bool from a codepage file. - */ - -static BOOL parse_bool(char *buf, unsigned char *bp) -{ - if(isdigit((int)*buf)) - { - char *endptr = NULL; - - *bp = (unsigned char)strtol(buf, &endptr, 0); - if(endptr == buf ) - return False; - if(*bp != 0) - *bp = 1; - } else { - if(strcasecmp(buf, "True") && strcasecmp(buf, "False")) - return False; - if(strcasecmp(buf, "True")==0) - *bp = 1; - else - *bp = 0; - } - return True; -} - -/* - * Print a parse error and exit. - */ - -static void parse_error(char *buf, char *msg) -{ - fprintf(stderr, "%s: %s whilst parsing line \n%s\n", prog_name, - msg, buf); - exit(1); -} - -/* - * Create a compiled codepage file from a codepage definition file. - */ - -static int do_compile(int codepage, char *input_file, char *output_file) -{ - FILE *fp = NULL; - size_t size = 0; - char *buf = NULL; - char *orig_buf = NULL; - char output_buf[CODEPAGE_HEADER_SIZE + 4 * MAXCODEPAGELINES]; - 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 = (uint32)st.st_size; - - /* I don't believe these things should be bigger than 100k :-) */ - if(size > 100*1024) - { - fprintf(stderr, "%s: filesize %d is too large for a codepage definition file. \ -The maximum size I will believe is 100k.\n", prog_name, size); - exit(1); - } - - 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); - - orig_buf = buf; /* Save for free(). */ - - /* There can be a maximum of MAXCODEPAGELINES lines. */ - if(num_lines > MAXCODEPAGELINES) - { - fprintf(stderr, "%s: There can be a maximum %d lines of data in a codepage \ -definition file. File %s has %d.\n", prog_name, MAXCODEPAGELINES, input_file, num_lines); - exit(1); - } - - /* Setup the output file header. */ - SSVAL(output_buf,CODEPAGE_VERSION_OFFSET,CODEPAGE_FILE_VERSION_ID); - SSVAL(output_buf,CODEPAGE_CLIENT_CODEPAGE_OFFSET,(uint16)codepage); - SIVAL(output_buf,CODEPAGE_LENGTH_OFFSET,(num_lines * 4)); - - /* Now convert the lines into the compiled form. */ - for(i = 0; i < num_lines; i++) - { - char token_buf[512]; - char *p = buf; - unsigned char b = 0; - - /* Get the 'lower' value. */ - if(!next_token(&p, token_buf, NULL, sizeof(token_buf))) - parse_error(buf, "cannot parse first value"); - if(!parse_byte( token_buf, &b)) - parse_error(buf, "first value doesn't resolve to a byte"); - - /* Add this to the output buffer. */ - SCVAL(output_buf,CODEPAGE_HEADER_SIZE+(i*4),b); - - /* Get the 'upper' value. */ - if(!next_token(&p, token_buf, NULL, sizeof(token_buf))) - parse_error(buf, "cannot parse second value"); - if(!parse_byte( token_buf, &b)) - parse_error(buf, "second value doesn't resolve to a byte"); - - /* Add this to the output buffer. */ - SCVAL(output_buf,CODEPAGE_HEADER_SIZE+(i*4) + 1,b); - - /* Get the 'upper to lower' value. */ - if(!next_token(&p, token_buf, NULL, sizeof(token_buf))) - parse_error(buf, "cannot parse third value"); - if(!parse_bool( token_buf, &b)) - parse_error(buf, "third value doesn't resolve to a boolean"); - - /* Add this to the output buffer. */ - SCVAL(output_buf,CODEPAGE_HEADER_SIZE+(i*4) + 2,b); - - /* Get the 'lower to upper' value. */ - if(!next_token(&p, token_buf, NULL, sizeof(token_buf))) - parse_error(buf, "cannot parse fourth value"); - if(!parse_bool( token_buf, &b)) - parse_error(buf, "fourth value doesn't resolve to a boolean"); - - /* Add this to the output buffer. */ - SCVAL(output_buf,CODEPAGE_HEADER_SIZE+(i*4) + 3,b); - - buf += (strlen(buf) + 1); - } - - /* 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, CODEPAGE_HEADER_SIZE + (num_lines*4), fp) != - CODEPAGE_HEADER_SIZE + (num_lines*4)) - { - fprintf(stderr, "%s: Cannot write output file %s. Error was %s.\n", - prog_name, output_file, strerror(errno)); - exit(1); - } - - fclose(fp); - - free(orig_buf); - return 0; -} - -/* - * Placeholder for now. - */ - -static int do_decompile( int codepage, char *input_file, char *output_file) -{ - size_t size = 0; - SMB_STRUCT_STAT st; - char header_buf[CODEPAGE_HEADER_SIZE]; - char *buf = NULL; - FILE *fp = NULL; - int num_lines = 0; - int i = 0; - - /* 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( size < CODEPAGE_HEADER_SIZE || size > (CODEPAGE_HEADER_SIZE + 256)) - { - fprintf(stderr, "%s: file %s is an incorrect size for a \ -code page file.\n", prog_name, input_file); - exit(1); - } - - /* 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 = sys_fopen( input_file, "r")) == NULL) - { - fprintf(stderr, "%s: cannot open file %s. Error was %s\n", - prog_name, input_file, strerror(errno)); - exit(1); - } - - if(fread( header_buf, 1, CODEPAGE_HEADER_SIZE, fp)!=CODEPAGE_HEADER_SIZE) - { - fprintf(stderr, "%s: cannot read header from file %s. Error was %s\n", - prog_name, input_file, strerror(errno)); - exit(1); - } - - /* Check the version value */ - if(SVAL(header_buf,CODEPAGE_VERSION_OFFSET) != CODEPAGE_FILE_VERSION_ID) - { - fprintf(stderr, "%s: filename %s has incorrect version id. \ -Needed %hu, got %hu.\n", - prog_name, input_file, (uint16)CODEPAGE_FILE_VERSION_ID, - SVAL(header_buf,CODEPAGE_VERSION_OFFSET)); - exit(1); - } - - /* Check the codepage matches */ - if(SVAL(header_buf,CODEPAGE_CLIENT_CODEPAGE_OFFSET) != (uint16)codepage) - { - fprintf(stderr, "%s: filename %s has incorrect codepage. \ -Needed %hu, got %hu.\n", - prog_name, input_file, (uint16)codepage, - SVAL(header_buf,CODEPAGE_CLIENT_CODEPAGE_OFFSET)); - exit(1); - } - - /* Check the length is correct. */ - if(IVAL(header_buf,CODEPAGE_LENGTH_OFFSET) != - (unsigned int)(size - CODEPAGE_HEADER_SIZE)) - { - fprintf(stderr, "%s: filename %s has incorrect size headers. \ -Needed %u, got %u.\n", prog_name, input_file, size - CODEPAGE_HEADER_SIZE, - IVAL(header_buf,CODEPAGE_LENGTH_OFFSET)); - exit(1); - } - - size -= CODEPAGE_HEADER_SIZE; /* Remove header */ - - /* Make sure the size is a multiple of 4. */ - if((size % 4 ) != 0) - { - fprintf(stderr, "%s: filename %s has a codepage size not a \ -multiple of 4.\n", prog_name, input_file); - exit(1); - } - - /* Allocate space for the code page file and read it all in. */ - if((buf = (char *)malloc( size )) == NULL) - { - fprintf (stderr, "%s: malloc fail for size %d.\n", - prog_name, size ); - exit(1); - } - - if(fread( buf, 1, size, fp)!=size) - { - fprintf(stderr, "%s: read fail on file %s. Error was %s.\n", - prog_name, input_file, strerror(errno)); - exit(1); - } - - fclose(fp); - - /* Now dump the codepage into an ascii file. */ - if((fp = sys_fopen(output_file, "w")) == NULL) - { - fprintf(stderr, "%s: cannot open file %s. Error was %s\n", - prog_name, output_file, strerror(errno)); - exit(1); - } - - fprintf(fp, "#\n# Codepage definition file for IBM Code Page %d.\n#\n", - codepage); - fprintf(fp, "# This file was automatically generated.\n#\n"); - fprintf(fp, "# defines lower->upper mapping.\n"); - fprintf(fp, "#\n#The columns are :\n# lower\tupper\tu-t-l\tl-t-u\n#\n"); - - num_lines = size / 4; - for( i = 0; i < num_lines; i++) - { - fprintf(fp, "0x%02X\t0x%02X\t%s\t%s\n", CVAL(buf, (i*4)), CVAL(buf, (i*4)+1), - CVAL(buf, (i*4)+2) ? "True" : "False", - CVAL(buf, (i*4)+3) ? "True" : "False"); - } - fclose(fp); - return 0; -} - -int main(int argc, char **argv) -{ - int codepage = 0; - char *input_file = NULL; - char *output_file = NULL; - BOOL compile = False; - - prog_name = argv[0]; - - if(argc != 5) - codepage_usage(prog_name); - - if(argv[1][0] != 'c' && argv[1][0] != 'C' && argv[1][0] != 'd' && - argv[1][0] != 'D') - codepage_usage(prog_name); - - input_file = argv[3]; - output_file = argv[4]; - - /* Are we compiling or decompiling. */ - if(argv[1][0] == 'c' || argv[1][0] == 'C') - compile = True; - - /* Convert the second argument into a client codepage value. */ - if((codepage = atoi(argv[2])) == 0) - { - fprintf(stderr, "%s: %s is not a valid codepage.\n", prog_name, argv[2]); - exit(1); - } - - if(compile) - return do_compile( codepage, input_file, output_file); - else - return do_decompile( codepage, input_file, output_file); -} diff --git a/source3/utils/make_unicodemap.c b/source3/utils/make_unicodemap.c deleted file mode 100644 index 3584facbf6..0000000000 --- a/source3/utils/make_unicodemap.c +++ /dev/null @@ -1,313 +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 \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 *orig_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(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); - - orig_buf = buf; /* Store for free(). */ - - /* - * 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); - - free(orig_buf); - free(output_buf); - 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/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 0f978a6cf3..adb75e6104 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -206,8 +206,6 @@ int main(int argc,char *argv[]) setup_logging(argv[0],True); - charset_initialise(); - while ((opt = getopt(argc, argv, "d:B:U:i:s:SMrhART")) != EOF) switch (opt) { diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index ef62fe32df..2b1dfe9f92 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -592,8 +592,6 @@ int main (int argc, char **argv) setup_logging("tdbedit", True); - charset_initialise(); - if (argc < 2) { diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 51ae05b52a..9edc35f800 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -836,10 +836,8 @@ You can string acls together with spaces, commas or newlines\n\ argv += 2; TimeInit(); - charset_initialise(); lp_load(servicesf,True,False,False); - codepage_initialise(lp_client_code_page()); load_interfaces(); if (getenv("USER")) { diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 27a3b61170..fef4ded218 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -342,7 +342,6 @@ static BOOL do_command(char *dest, char *msg_name, char **params) TimeInit(); setup_logging(argv[0],True); - charset_initialise(); lp_load(servicesf,False,False,False); if (!message_init()) exit(1); diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c index db83873e69..8550159955 100644 --- a/source3/utils/smbfilter.c +++ b/source3/utils/smbfilter.c @@ -210,8 +210,6 @@ int main(int argc, char *argv[]) setup_logging(argv[0],True); - charset_initialise(); - pstrcpy(configfile,CONFIGFILE); if (argc < 2) { diff --git a/source3/utils/smbgroupedit.c b/source3/utils/smbgroupedit.c index 76624312d5..ffaacca102 100644 --- a/source3/utils/smbgroupedit.c +++ b/source3/utils/smbgroupedit.c @@ -220,8 +220,6 @@ int main (int argc, char **argv) setup_logging("groupedit", True); - charset_initialise(); - if (argc < 2) { usage(); return 0; diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 3442efc3a8..ebc588eb64 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -901,8 +901,6 @@ int main(int argc, char **argv) setup_logging("smbpasswd", True); - charset_initialise(); - if(!initialize_password_db(True)) { fprintf(stderr, "Can't setup password database vectors.\n"); exit(1); @@ -927,8 +925,6 @@ int main(int argc, char **argv) } strupper(global_myname); - codepage_initialise(lp_client_code_page()); - secrets_init(); /* Check the effective uid - make sure we are not setuid */ diff --git a/source3/utils/smbw_sample.c b/source3/utils/smbw_sample.c index db92af9510..7d6eb7f353 100644 --- a/source3/utils/smbw_sample.c +++ b/source3/utils/smbw_sample.c @@ -33,9 +33,7 @@ int main(int argc, char *argv[]) extern int optind; char *path; - charset_initialise(); lp_load(CONFIGFILE,1,0,0); - codepage_initialise(lp_client_code_page()); smbw_setup_shared(); while ((opt = getopt(argc, argv, "W:U:R:d:P:l:hL:")) != EOF) { diff --git a/source3/utils/status.c b/source3/utils/status.c index 448239baba..ea683ad19c 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -135,7 +135,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) else printf("NONE "); - printf(" %s %s",dos_to_unix(fname,False), + printf(" %s %s",fname, asctime(LocalTime((time_t *)&e->time.tv_sec))); } } @@ -252,8 +252,6 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st TimeInit(); setup_logging(argv[0],True); - charset_initialise(); - DEBUGLEVEL = 0; dbf = stderr; diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index b8536d4b9d..c9080e1994 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -180,8 +180,6 @@ int main(int argc, char *argv[]) setup_logging(argv[0],True); - charset_initialise(); - while ((opt = getopt(argc, argv,"shL:t:")) != EOF) { switch (opt) { case 's': @@ -270,16 +268,13 @@ Level II oplocks can only be set if oplocks are also set.\n", } } - if (*term_code) - interpret_coding_system(term_code); - if (argc < 3) { if (!silent_mode) { printf("Press enter to see a dump of your service definitions\n"); fflush(stdout); getc(stdin); } - lp_dump(stdout,True, lp_numservices(), _dos_to_unix); + lp_dump(stdout,True, lp_numservices()); } if (argc >= 3) { diff --git a/source3/utils/testprns.c b/source3/utils/testprns.c index c03fa0436a..f8fdcd63a1 100644 --- a/source3/utils/testprns.c +++ b/source3/utils/testprns.c @@ -46,8 +46,6 @@ int main(int argc, char *argv[]) setup_logging(argv[0],True); - charset_initialise(); - if (argc < 2 || argc > 3) printf("Usage: testprns printername [printcapfile]\n"); else -- cgit From 527e824293ee934ca5da0ef5424efe5ab7757248 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 07:36:09 +0000 Subject: strchr and strrchr are macros when compiling with optimisation in gcc, so we can't redefine them. damn. (This used to be commit c41fc06376d1a2b83690612304e85010b5e5f3cf) --- source3/utils/make_printerdef.c | 14 +++++++------- source3/utils/nmblookup.c | 2 +- source3/utils/pdbedit.c | 4 ++-- source3/utils/rpccheck.c | 2 +- source3/utils/smbcacls.c | 10 +++++----- source3/utils/smbpasswd.c | 6 +++--- source3/utils/smbw_sample.c | 2 +- source3/utils/testparm.c | 8 ++++---- 8 files changed, 24 insertions(+), 24 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index f403ee79bb..5107b124a7 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -47,8 +47,8 @@ static char *myfgets(char *s, int n, FILE *stream) int i; fgets(s,n,stream); - while ((LString1 = strchr(s,'%')) != NULL) { - if (!(LString2 = strchr(LString1+1,'%'))) break; + while ((LString1 = strchr_m(s,'%')) != NULL) { + if (!(LString2 = strchr_m(LString1+1,'%'))) break; *LString2 = '\0'; pstrcpy(String,LString1+1); i = 0; @@ -56,7 +56,7 @@ static char *myfgets(char *s, int n, FILE *stream) if (strncmp(sbuffer[i],String,strlen(String))==0) { pstrcpy(String,sbuffer[i]); - if ((temp = strchr(String,'=')) != NULL) ++temp; + if ((temp = strchr_m(String,'=')) != NULL) ++temp; pstrcpy(String,temp); break; } @@ -360,7 +360,7 @@ static void scan_copyfiles(FILE *fichier, char *chaine) * This may still be wrong but at least I get the same list * of files as seen on a printer test page. */ - part = strchr(buffer[i],'='); + part = strchr_m(buffer[i],'='); if (part) { /* * Case (1) eg. pscript.hlp = pscript.hl_ - chop after the first name. @@ -379,13 +379,13 @@ static void scan_copyfiles(FILE *fichier, char *chaine) break; } } else { - part = strchr(buffer[i],','); + part = strchr_m(buffer[i],','); if (part) { /* * Cases (2-4) */ - if ((mpart = strrchr(part+1,','))!=NULL) { + if ((mpart = strrchr_m(part+1,','))!=NULL) { /* * Second ',' - case 3 or 4. * Check if the last part is just a number, @@ -507,7 +507,7 @@ static void scan_short_desc(FILE *fichier, char *short_desc) temp = strtok(languagemonitor,","); if (*temp == '"') ++temp; pstrcpy(languagemonitor,temp); - if ((temp = strchr(languagemonitor,'"'))!=NULL) *temp = '\0'; + if ((temp = strchr_m(languagemonitor,'"'))!=NULL) *temp = '\0'; } if (i) fprintf(stderr,"End of section found\n"); diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index adb75e6104..3e2f0610e6 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -303,7 +303,7 @@ int main(int argc,char *argv[]) } } - p = strchr(lookup,'#'); + p = strchr_m(lookup,'#'); if (p) { *p = '\0'; sscanf(++p,"%x",&lookup_type); diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index 2b1dfe9f92..ec90e7ff1d 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -391,7 +391,7 @@ static int import_users (char *filename) sam_pwent.acct_ctrl = ACB_NORMAL; /* Get user name */ - p = (unsigned char *) strchr(linebuf, ':'); + p = (unsigned char *) strchr_m(linebuf, ':'); if (p == NULL) { fprintf (stderr, "Error: malformed password entry at line %d !!\n", line); @@ -478,7 +478,7 @@ static int import_users (char *filename) /* Get ACCT_CTRL field if any */ if (*p == '[') { - unsigned char *end_p = (unsigned char *)strchr((char *)p, ']'); + unsigned char *end_p = (unsigned char *)strchr_m((char *)p, ']'); sam_pwent.acct_ctrl = pdb_decode_acct_ctrl((char*)p); if(sam_pwent.acct_ctrl == 0) sam_pwent.acct_ctrl = ACB_NORMAL; diff --git a/source3/utils/rpccheck.c b/source3/utils/rpccheck.c index f504463027..1b00d528ac 100644 --- a/source3/utils/rpccheck.c +++ b/source3/utils/rpccheck.c @@ -46,7 +46,7 @@ main() prs_init(&ps, 1600, 4, ctx, MARSHALL); while (scanf("%s", s)!=-1) { - if (strlen(s)==2 && strchr(filter, *s)!=NULL && strchr(filter, *(s+1))!=NULL) { + if (strlen(s)==2 && strchr_m(filter, *s)!=NULL && strchr_m(filter, *(s+1))!=NULL) { d=strtol(s, NULL, 16); if(!prs_append_data(&ps, &d, 1)) printf("error while reading data\n"); diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 9edc35f800..20333f772b 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -234,7 +234,7 @@ static BOOL parse_ace(SEC_ACE *ace, char *str) struct perm_value *v; ZERO_STRUCTP(ace); - p = strchr(str,':'); + p = strchr_m(str,':'); if (!p) return False; *p = '\0'; p++; @@ -697,7 +697,7 @@ struct cli_state *connect_one(char *share) extern pstring global_myname; fstrcpy(server,share+2); - share = strchr(server,'\\'); + share = strchr_m(server,'\\'); if (!share) return NULL; *share = 0; share++; @@ -843,11 +843,11 @@ You can string acls together with spaces, commas or newlines\n\ if (getenv("USER")) { pstrcpy(username,getenv("USER")); - if ((p=strchr(username,'%'))) { + if ((p=strchr_m(username,'%'))) { *p = 0; pstrcpy(password,p+1); got_pass = True; - memset(strchr(getenv("USER"), '%') + 1, 'X', + memset(strchr_m(getenv("USER"), '%') + 1, 'X', strlen(password)); } } @@ -856,7 +856,7 @@ You can string acls together with spaces, commas or newlines\n\ switch (opt) { case 'U': pstrcpy(username,optarg); - p = strchr(username,'%'); + p = strchr_m(username,'%'); if (p) { *p = 0; pstrcpy(password, p+1); diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index ebc588eb64..a10e757910 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -603,11 +603,11 @@ static int process_root(int argc, char *argv[]) fstrcpy(user_name, optarg); - if ((lp = strchr(user_name, '%'))) { + if ((lp = strchr_m(user_name, '%'))) { *lp = 0; fstrcpy(user_password, lp + 1); got_pass = True; - memset(strchr(optarg, '%') + 1, 'X', + memset(strchr_m(optarg, '%') + 1, 'X', strlen(user_password)); } @@ -920,7 +920,7 @@ int main(int argc, char **argv) if (!*global_myname) { char *p; fstrcpy(global_myname, myhostname()); - p = strchr(global_myname, '.' ); + p = strchr_m(global_myname, '.' ); if (p) *p = 0; } strupper(global_myname); diff --git a/source3/utils/smbw_sample.c b/source3/utils/smbw_sample.c index 7d6eb7f353..6a8fbf116b 100644 --- a/source3/utils/smbw_sample.c +++ b/source3/utils/smbw_sample.c @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) smbw_setshared("DEBUG", optarg); break; case 'U': - p = strchr(optarg,'%'); + p = strchr_m(optarg,'%'); if (p) { *p=0; smbw_setshared("PASSWORD",p+1); diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index c9080e1994..9b19a6c0fd 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -240,8 +240,8 @@ int main(int argc, char *argv[]) int i; if(deny_list) { for (i=0; deny_list[i]; i++) { - char *hasstar = strchr(deny_list[i], '*'); - char *hasquery = strchr(deny_list[i], '?'); + char *hasstar = strchr_m(deny_list[i], '*'); + char *hasquery = strchr_m(deny_list[i], '?'); if(hasstar || hasquery) { printf("Invalid character %c in hosts deny list (%s) for service %s.\n", hasstar ? *hasstar : *hasquery, deny_list[i], lp_servicename(s) ); @@ -251,8 +251,8 @@ int main(int argc, char *argv[]) if(allow_list) { for (i=0; allow_list[i]; i++) { - char *hasstar = strchr(allow_list[i], '*'); - char *hasquery = strchr(allow_list[i], '?'); + char *hasstar = strchr_m(allow_list[i], '*'); + char *hasquery = strchr_m(allow_list[i], '?'); if(hasstar || hasquery) { printf("Invalid character %c in hosts allow list (%s) for service %s.\n", hasstar ? *hasstar : *hasquery, allow_list[i], lp_servicename(s) ); -- cgit From 2036ce8a5d72f8e14f59d1c41b129f2787df2c66 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 6 Jul 2001 10:49:34 +0000 Subject: A program to display a tree of domains, servers and shares similar to the network neighbourhood graph. Still needs a bit of work. (This used to be commit 6b4559506d1434e6114d9707dd11fdc8ee8d54be) --- source3/utils/smbtree.c | 419 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 419 insertions(+) create mode 100644 source3/utils/smbtree.c (limited to 'source3/utils') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c new file mode 100644 index 0000000000..26db717668 --- /dev/null +++ b/source3/utils/smbtree.c @@ -0,0 +1,419 @@ +/* + Unix SMB/Netbios implementation. + Network neighbourhood browser. + Version 3.0 + + Copyright (C) Tim Potter 2000 + + 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" + +struct user_auth_info { + pstring username; + pstring password; + pstring workgroup; +}; + +/* How low can we go? */ + +enum tree_level {LEV_WORKGROUP, LEV_SERVER, LEV_SHARE}; +enum tree_level level = LEV_SHARE; + +static void usage(void) +{ + printf( +"Usage: smbtree [options]\n\ +\n\ +\t-d debuglevel set debug output level\n\ +\t-U username user to autheticate as\n\ +\t-W workgroup workgroup of user to authenticate as\n\ +\t-D list only domains (workgroups) of tree\n\ +\t-S list domains and servers of tree\n\ +\n\ +The username can be of the form username%%password or\n\ +workgroup\\username%%password.\n\n\ +"); +} + +/* Holds a list of workgroups or servers */ + +struct name_list { + struct name_list *prev, *next; + pstring name, comment; + uint32 server_type; +}; + +static struct name_list *workgroups, *servers, *shares; + +static void free_name_list(struct name_list *list) +{ + while(list) + DLIST_REMOVE(list, list); +} + +static void add_name(const char *machine_name, uint32 server_type, + const char *comment, void *state) +{ + struct name_list **name_list = (struct name_list **)state; + struct name_list *new_name; + + new_name = (struct name_list *)malloc(sizeof(struct name_list)); + + if (!new_name) + return; + + ZERO_STRUCTP(new_name); + + pstrcpy(new_name->name, machine_name); + pstrcpy(new_name->comment, comment); + new_name->server_type = server_type; + + DLIST_ADD(*name_list, new_name); +} + +/* Return a cli_state pointing at the IPC$ share for the given workgroup */ + +static struct cli_state *get_ipc_connect(char *server, + struct user_auth_info *user_info) +{ + struct nmb_name calling, called; + extern struct in_addr ipzero; + struct in_addr server_ip = ipzero; + struct cli_state *cli; + pstring myname; + + get_myname(myname); + + make_nmb_name(&called, myname, 0x0); + make_nmb_name(&calling, server, 0x20); + + if (is_ipaddress(server)) + if (!resolve_name(server, &server_ip, 0x20)) + return False; + + again: + if (!(cli = cli_initialise(NULL))) { + DEBUG(4, ("Unable to initialise cli structure\n")); + goto error; + } + + if (!cli_connect(cli, server, &server_ip)) { + DEBUG(4, ("Unable to connect to %s\n", server)); + goto error; + } + + if (!cli_session_request(cli, &calling, &called)) { + cli_shutdown(cli); + if (!strequal(called.name, "*SMBSERVER")) { + make_nmb_name(&called , "*SMBSERVER", 0x20); + goto again; + } + DEBUG(4, ("Session request failed to %s\n", called.name)); + goto error; + } + + if (!cli_negprot(cli)) { + DEBUG(4, ("Negprot failed\n")); + goto error; + } + + if (!cli_session_setup(cli, user_info->username, user_info->password, + strlen(user_info->password), + user_info->password, + strlen(user_info->password), server) && + /* try an anonymous login if it failed */ + !cli_session_setup(cli, "", "", 1,"", 0, server)) { + DEBUG(4, ("Session setup failed\n")); + goto error; + } + + DEBUG(4,(" session setup ok\n")); + + if (!cli_send_tconX(cli, "IPC$", "?????", + user_info->password, + strlen(user_info->password)+1)) { + DEBUG(4, ("Tconx failed\n")); + goto error; + } + + return cli; + + /* Clean up after error */ + + error: + if (cli && cli->initialised) + cli_shutdown(cli); + + free(cli); + return NULL; +} + +/* Return the IP address and workgroup of a master browser on the + network. */ + +static BOOL find_master_ip_bcast(pstring workgroup, struct in_addr *server_ip) +{ + struct in_addr *ip_list; + int i, count; + + /* Go looking for workgroups by broadcasting on the local network */ + + if (!name_resolve_bcast(MSBROWSE, 1, &ip_list, &count)) { + return False; + } + + for (i = 0; i < count; i++) { + static fstring name; + + if (!name_status_find(0x1d, ip_list[i], name)) + return False; + + if (!find_master_ip(name, server_ip)) + return False; + + pstrcpy(workgroup, name); + + DEBUG(4, ("found master browser %s, %s\n", + name, inet_ntoa(ip_list[i]))); + + return True; + } + + return False; +} + +/**************************************************************************** + display tree of smb workgroups, servers and shares +****************************************************************************/ +static BOOL get_workgroups(struct user_auth_info *user_info) +{ + struct cli_state *cli; + struct in_addr server_ip; + pstring master_workgroup; + + /* Try to connect to a #1d name of our current workgroup. If that + doesn't work broadcast for a master browser and then jump off + that workgroup. */ + + pstrcpy(master_workgroup, lp_workgroup()); + + if (!find_master_ip(lp_workgroup(), &server_ip)) { + DEBUG(4, ("Unable to find master browser for workgroup %s\n", + master_workgroup)); + if (!find_master_ip_bcast(master_workgroup, &server_ip)) { + DEBUG(4, ("Unable to find master browser by " + "broadcast\n")); + return False; + } + } + + if (!(cli = get_ipc_connect(inet_ntoa(server_ip), user_info))) + return False; + + if (!cli_NetServerEnum(cli, master_workgroup, + SV_TYPE_DOMAIN_ENUM, add_name, &workgroups)) + return False; + + return True; +} + +/* Retrieve the list of servers for a given workgroup */ + +static BOOL get_servers(char *workgroup, struct user_auth_info *user_info) +{ + struct cli_state *cli; + struct in_addr server_ip; + + /* Open an IPC$ connection to the master browser for the workgroup */ + + if (!find_master_ip(workgroup, &server_ip)) { + DEBUG(4, ("Cannot find master browser for workgroup %s\n", + workgroup)); + return False; + } + + if (!(cli = get_ipc_connect(inet_ntoa(server_ip), user_info))) + return False; + + if (!cli_NetServerEnum(cli, workgroup, SV_TYPE_ALL, add_name, + &servers)) + return False; + + return True; +} + +static BOOL get_shares(char *server_name, struct user_auth_info *user_info) +{ + struct cli_state *cli; + + if (!(cli = get_ipc_connect(server_name, user_info))) + return False; + + if (!cli_RNetShareEnum(cli, add_name, &shares)) + return False; + + return True; +} + +static BOOL print_tree(struct user_auth_info *user_info) +{ + struct name_list *wg, *sv, *sh; + + /* List workgroups */ + + if (!get_workgroups(user_info)) + return False; + + for (wg = workgroups; wg; wg = wg->next) { + + printf("%s\n", wg->name); + + /* List servers */ + + free_name_list(servers); + servers = NULL; + + if (level == LEV_WORKGROUP || + !get_servers(wg->name, user_info)) + continue; + + for (sv = servers; sv; sv = sv->next) { + + printf("\t%s\n", sv->name); + + /* List shares */ + + free_name_list(shares); + shares = NULL; + + if (level == LEV_SERVER || + !get_shares(sv->name, user_info)) + continue; + + for (sh = shares; sh; sh = sh->next) { + printf("\t\t%s\n", sh->name); + } + } + } + + return True; +} + +/**************************************************************************** + main program +****************************************************************************/ + int main(int argc,char *argv[]) +{ + extern char *optarg; + extern int optind; + extern FILE *dbf; + int opt; + char *p; + pstring servicesf = CONFIGFILE; + struct user_auth_info user_info; + BOOL got_pass = False; + + /* Initialise samba stuff */ + + setlinebuf(stdout); + + dbf = stderr; + + setup_logging(argv[0],True); + + TimeInit(); + + lp_load(servicesf,True,False,False); + load_interfaces(); + + if (getenv("USER")) { + pstrcpy(user_info.username, getenv("USER")); + + if ((p=strchr(user_info.username, '%'))) { + *p = 0; + pstrcpy(user_info.password, p+1); + got_pass = True; + memset(strchr(getenv("USER"), '%') + 1, 'X', + strlen(user_info.password)); + } + } + + pstrcpy(user_info.workgroup, lp_workgroup()); + + /* Parse command line args */ + + while ((opt = getopt(argc, argv, "U:hd:W:DS")) != EOF) { + switch (opt) { + case 'U': + pstrcpy(user_info.username,optarg); + p = strchr(user_info.username,'%'); + if (p) { + *p = 0; + pstrcpy(user_info.password, p+1); + got_pass = 1; + } + break; + + case 'h': + usage(); + exit(1); + + case 'd': + DEBUGLEVEL = atoi(optarg); + break; + + case 'W': + pstrcpy(user_info.workgroup, optarg); + break; + + case 'D': + level = LEV_WORKGROUP; + break; + + case 'S': + level = LEV_SERVER; + break; + + default: + printf("Unknown option %c (%d)\n", (char)opt, opt); + exit(1); + } + } + + argc -= optind; + argv += optind; + + if (argc > 0) { + usage(); + exit(1); + } + + if (!got_pass) { + char *pass = getpass("Password: "); + if (pass) { + pstrcpy(user_info.password, pass); + } + got_pass = True; + } + + /* Now do our stuff */ + + if (!print_tree(&user_info)) + return 1; + + return 0; +} -- cgit From da9fb5ba388a16f7adeb7403fee74e1981735d1e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 6 Jul 2001 21:53:32 +0000 Subject: Don't try and open tdb secrets file in non-root/local mode. Jeremy. (This used to be commit e78a114425129d980f79db812dbea368123913ed) --- source3/utils/smbpasswd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index a10e757910..cfc8ac6aa1 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -925,8 +925,6 @@ int main(int argc, char **argv) } strupper(global_myname); - secrets_init(); - /* Check the effective uid - make sure we are not setuid */ if ((geteuid() == (uid_t)0) && (getuid() != (uid_t)0)) { fprintf(stderr, "smbpasswd must *NOT* be setuid root.\n"); @@ -941,6 +939,7 @@ int main(int argc, char **argv) } if (local_mode || getuid() == 0) { + secrets_init(); return process_root(argc, argv); } -- cgit From 647a680b00f8fc36a2282d774c4a6104fef8a01b Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Mon, 9 Jul 2001 18:15:28 +0000 Subject: allow to rename an NT group (This used to be commit 42fc4f4154ccf2e93322da6b0b234f8f846991dc) --- source3/utils/smbgroupedit.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbgroupedit.c b/source3/utils/smbgroupedit.c index ffaacca102..4e192ed43d 100644 --- a/source3/utils/smbgroupedit.c +++ b/source3/utils/smbgroupedit.c @@ -97,7 +97,7 @@ int addgroup(char *group, enum SID_NAME_USE sid_type, char *ntgroup, char *ntcom /********************************************************* Change a group. **********************************************************/ -int changegroup(char *sid_string, char *group, enum SID_NAME_USE sid_type, char *groupdesc, char *privilege) +int changegroup(char *sid_string, char *group, enum SID_NAME_USE sid_type, char *ntgroup, char *groupdesc, char *privilege) { DOM_SID sid; GROUP_MAP map; @@ -131,6 +131,9 @@ int changegroup(char *sid_string, char *group, enum SID_NAME_USE sid_type, char map.sid_name_use=sid_type; + if (ntgroup!=NULL) + fstrcpy(map.nt_name, ntgroup); + /* Change comment if new one */ if (groupdesc!=NULL) fstrcpy(map.comment, groupdesc); @@ -332,7 +335,7 @@ int main (int argc, char **argv) return deletegroup(group); if (change_group) { - return changegroup(sid, group, sid_type, group_desc, privilege); + return changegroup(sid, group, sid_type, ntgroup, group_desc, privilege); } usage(); -- cgit From afa73000063d7c3eb94ccc7b423c8a7bea28f9a5 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 12 Jul 2001 22:27:00 +0000 Subject: Changed instances of TRUE, FALSE to True, False as some compilers don't have the first set of symbols. (This used to be commit ad0cbfbd790bc5d6003ffcff2835d82fb0140625) --- source3/utils/pdbedit.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index ec90e7ff1d..a31f83956d 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -185,7 +185,7 @@ static int set_user_info (char *username, char *fullname, char *homedir, char *d if (script) pdb_set_logon_script(sam_pwent, script); if (profile) pdb_set_profile_path (sam_pwent, profile); - if (pdb_update_sam_account (sam_pwent, TRUE)) print_user_info (username, TRUE, FALSE); + if (pdb_update_sam_account (sam_pwent, True)) print_user_info (username, True, False); else { fprintf (stderr, "Unable to modify entry!\n"); @@ -246,7 +246,7 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, sam_pwent.nt_pw = new_nt_p16; sam_pwent.acct_ctrl = ACB_NORMAL; - if (pdb_add_sam_account (&sam_pwent)) print_user_info (username, TRUE, FALSE); + if (pdb_add_sam_account (&sam_pwent)) print_user_info (username, True, False); else { fprintf (stderr, "Unable to add user!\n"); @@ -297,7 +297,7 @@ static int new_machine (char *machinename) sam_pwent.acct_ctrl = ACB_WSTRUST; if (pdb_add_sam_account (&sam_pwent)) - print_user_info (name, TRUE, FALSE); + print_user_info (name, True, False); else { fprintf (stderr, "Unable to add machine!\n"); return -1; @@ -572,14 +572,14 @@ int main (int argc, char **argv) { int ch; static pstring servicesf = CONFIGFILE; - BOOL list_users = FALSE; - BOOL verbose = FALSE; - BOOL spstyle = FALSE; - BOOL setparms = FALSE; - BOOL machine = FALSE; - BOOL add_user = FALSE; - BOOL delete_user = FALSE; - BOOL import = FALSE; + BOOL list_users = False; + BOOL verbose = False; + BOOL spstyle = False; + BOOL setparms = False; + BOOL machine = False; + BOOL add_user = False; + BOOL delete_user = False; + BOOL import = False; char *user_name = NULL; char *full_name = NULL; char *home_dir = NULL; @@ -613,48 +613,48 @@ int main (int argc, char **argv) while ((ch = getopt(argc, argv, "ad:f:h:i:lmp:s:u:vwx")) != EOF) { switch(ch) { case 'a': - add_user = TRUE; + add_user = True; break; case 'm': - machine = TRUE; + machine = True; break; case 'l': - list_users = TRUE; + list_users = True; break; case 'v': - verbose = TRUE; + verbose = True; break; case 'w': - spstyle = TRUE; + spstyle = True; break; case 'u': user_name = optarg; break; case 'f': - setparms = TRUE; + setparms = True; full_name = optarg; break; case 'h': - setparms = TRUE; + setparms = True; home_dir = optarg; break; case 'd': - setparms = TRUE; + setparms = True; home_drive = optarg; break; case 's': - setparms = TRUE; + setparms = True; logon_script = optarg; break; case 'p': - setparms = TRUE; + setparms = True; profile_path = optarg; break; case 'x': - delete_user = TRUE; + delete_user = True; break; case 'i': - import = TRUE; + import = True; smbpasswd = optarg; break; default: -- cgit From e3bbe5d5915d6947ce85c4473b2eebb2ba321fea Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 25 Jul 2001 04:09:44 +0000 Subject: nicer smbtree output (This used to be commit b840d7d65e0e8e437e016318d7ee702db2fa561b) --- source3/utils/smbtree.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 26db717668..f3d3d2ae31 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -293,7 +293,8 @@ static BOOL print_tree(struct user_auth_info *user_info) for (sv = servers; sv; sv = sv->next) { - printf("\t%s\n", sv->name); + printf("\t\\\\%-15s\t\t%s\n", + sv->name, sv->comment); /* List shares */ @@ -305,7 +306,8 @@ static BOOL print_tree(struct user_auth_info *user_info) continue; for (sh = shares; sh; sh = sh->next) { - printf("\t\t%s\n", sh->name); + printf("\t\t\\\\%s\\%-15s\t%s\n", + sv->name, sh->name, sh->comment); } } } -- cgit From 648528196ca136469d82b83cd2ba89b1b30290ae Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 25 Jul 2001 06:42:05 +0000 Subject: Held a shoot-out between NT_STATUS_NO_PROBLEMO and NT_STATUS_NOPROBLEMO. According to the incorruptible judges find and grep, the latter won. Mmm - procrastination. (-: (This used to be commit 2e339403605177b15d5185a8fdd1b06f3f043168) --- source3/utils/smbpasswd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index cfc8ac6aa1..aa369e61b4 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -162,13 +162,13 @@ Join a domain using the administrator username and password /* Macro for checking RPC error codes to make things more readable */ #define CHECK_RPC_ERR(rpc, msg) \ - if ((result = rpc) != NT_STATUS_NO_PROBLEMO) { \ + if ((result = rpc) != NT_STATUS_NOPROBLEMO) { \ DEBUG(0, (msg ": %s\n", get_nt_error_msg(result))); \ goto done; \ } #define CHECK_RPC_ERR_DEBUG(rpc, debug_args) \ - if ((result = rpc) != NT_STATUS_NO_PROBLEMO) { \ + if ((result = rpc) != NT_STATUS_NOPROBLEMO) { \ DEBUG(0, debug_args); \ goto done; \ } -- cgit From 996719cce26700c68ff0e456e6a25d20085d091f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 30 Jul 2001 22:21:31 +0000 Subject: Added "use mmap" for HPUX. Jeremy. (This used to be commit 840802f10677cb0009cb4df4c37c7d01aa5edacd) --- source3/utils/smbcontrol.c | 2 +- source3/utils/status.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index fef4ded218..088ce0c08e 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -131,7 +131,7 @@ static BOOL send_message(char *dest, int msg_type, void *buf, int len, BOOL dupl TDB_CONTEXT *tdb; BOOL ret; - tdb = tdb_open_log(lock_path("connections.tdb"), 0, 0, O_RDONLY, 0); + tdb = tdb_open_log(lock_path("connections.tdb"), 0, USE_TDB_MMAP_FLAG, O_RDONLY, 0); if (!tdb) { fprintf(stderr,"Failed to open connections database in send_message.\n"); return False; diff --git a/source3/utils/status.c b/source3/utils/status.c index ea683ad19c..e5beb6403c 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -316,7 +316,7 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st return profile_dump(); } - tdb = tdb_open_log(lock_path("connections.tdb"), 0, 0, O_RDONLY, 0); + tdb = tdb_open_log(lock_path("connections.tdb"), 0, USE_TDB_MMAP_FLAG, O_RDONLY, 0); if (!tdb) { printf("connections.tdb not initialised\n"); if (!lp_status(-1)) -- cgit From 65bf96ed06845ea0ba78600d86751def7c3b4068 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 2 Aug 2001 23:48:51 +0000 Subject: Allow smbpasswd to join a W2K hosted AD domain. Jeremy. (This used to be commit c51cfc7f0d3ad1614ca1e0330c8707f7b263b8e6) --- source3/utils/smbpasswd.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index aa369e61b4..27a00e2e2b 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -290,7 +290,12 @@ static int join_domain_byuser(char *domain, char *remote_machine, acct_name, ACB_WSTRUST, unknown, &user_pol, &user_rid); - } + + /* We *must* do this.... don't ask... */ + + CHECK_RPC_ERR_DEBUG(cli_samr_close(&cli, mem_ctx, &user_pol), ("error closing user policy")); + result = NT_STATUS_USER_EXISTS; + } if (result == NT_STATUS_USER_EXISTS) { uint32 num_rids, *name_types, *user_rids; @@ -356,7 +361,7 @@ static int join_domain_byuser(char *domain, char *remote_machine, ZERO_STRUCT(ctr); ZERO_STRUCT(p24); - init_sam_user_info24(&p24, pwbuf); + init_sam_user_info24(&p24, pwbuf,24); ctr.switch_value = 24; ctr.info.id24 = &p24; @@ -380,6 +385,7 @@ static int join_domain_byuser(char *domain, char *remote_machine, seems to cope with either value so don't bomb out if the set userinfo2 level 0x10 fails. -tpot */ + ZERO_STRUCT(ctr); ctr.switch_value = 0x10; ctr.info.id10 = &p10; @@ -549,7 +555,7 @@ static int process_root(int argc, char *argv[]) char *old_passwd = NULL; char *remote_machine = NULL; - while ((ch = getopt(argc, argv, "ax:d:e:mnj:r:sR:D:U:L")) != EOF) { + while ((ch = getopt(argc, argv, "ax:d:e:hmnj:r:sR:D:U:L")) != EOF) { switch(ch) { case 'L': local_mode = True; @@ -613,6 +619,7 @@ static int process_root(int argc, char *argv[]) break; } + case 'h': default: usage(); } -- cgit From 5eccc9061bcaa1e225dea189ec99e9f53df66bca Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 20 Aug 2001 17:38:37 +0000 Subject: added -b option (This used to be commit 1c2618df450ddde7e52ab8784fcdd2b64a85771e) --- source3/utils/smbtree.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index f3d3d2ae31..0f824f7ecf 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -22,6 +22,8 @@ #include "includes.h" +static BOOL use_bcast; + struct user_auth_info { pstring username; pstring password; @@ -43,6 +45,7 @@ static void usage(void) \t-W workgroup workgroup of user to authenticate as\n\ \t-D list only domains (workgroups) of tree\n\ \t-S list domains and servers of tree\n\ +\t-b use bcast instead of using the master browser\n\ \n\ The username can be of the form username%%password or\n\ workgroup\\username%%password.\n\n\ @@ -211,7 +214,7 @@ static BOOL get_workgroups(struct user_auth_info *user_info) pstrcpy(master_workgroup, lp_workgroup()); - if (!find_master_ip(lp_workgroup(), &server_ip)) { + if (use_bcast || !find_master_ip(lp_workgroup(), &server_ip)) { DEBUG(4, ("Unable to find master browser for workgroup %s\n", master_workgroup)); if (!find_master_ip_bcast(master_workgroup, &server_ip)) { @@ -358,7 +361,7 @@ static BOOL print_tree(struct user_auth_info *user_info) /* Parse command line args */ - while ((opt = getopt(argc, argv, "U:hd:W:DS")) != EOF) { + while ((opt = getopt(argc, argv, "U:hd:W:DSb")) != EOF) { switch (opt) { case 'U': pstrcpy(user_info.username,optarg); @@ -370,6 +373,10 @@ static BOOL print_tree(struct user_auth_info *user_info) } break; + case 'b': + use_bcast = True; + break; + case 'h': usage(); exit(1); -- cgit From 2051bb7d0366e07c5ecda5e5f7cfedc4153d6228 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 22 Aug 2001 19:11:55 +0000 Subject: A few changes: drop paramaters: status utmp hostname change session code to always record each vuid current on the server. The sessionid struct is no longer packed, as I couldn't get that to work ;-) change smbstatus to show this info and less of the connections.tdb info (its not actualy that accurate). I'll get swat doing some of this shortly. (This used to be commit b068ad300527c44673bbee0aede7849199c89de7) --- source3/utils/status.c | 104 +++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 60 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index e5beb6403c..36de6858f1 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -198,41 +198,33 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st return 0; } - if (brief) { - ptr=srecs; - while (ptr!=NULL) { - if ((ptr->pid==crec.pid)&&(strncmp(ptr->machine,crec.machine,30)==0)) { - if (ptr->start > crec.start) - ptr->start=crec.start; - break; - } - ptr=ptr->next; - } - if (ptr==NULL) { - ptr=(struct session_record *) malloc(sizeof(struct session_record)); - ptr->uid=crec.uid; - ptr->pid=crec.pid; - ptr->start=crec.start; - strncpy(ptr->machine,crec.machine,30); - ptr->machine[30]='\0'; - ptr->next=srecs; - srecs=ptr; - } - } else { - Ucrit_addPid(crec.pid); - if (processes_only) { - if (last_pid != crec.pid) - printf("%d\n",(int)crec.pid); - last_pid = crec.pid; /* XXXX we can still get repeats, have to - add a sort at some time */ - } else { - printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", - crec.name,uidtoname(crec.uid),gidtoname(crec.gid),(int)crec.pid, - crec.machine,crec.addr, - asctime(LocalTime(&crec.start))); - } + printf("%-10.10s %5d %-12s %s", + crec.name,(int)crec.pid, + crec.machine, + asctime(LocalTime(&crec.start))); + + return 0; +} + +static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) +{ + static pid_t last_pid; + struct session_record *ptr; + struct sessionid sessionid; + + if (dbuf.dsize != sizeof(sessionid)) + return 0; + + memcpy(&sessionid, dbuf.dptr, sizeof(sessionid)); + + if (!process_exists(sessionid.pid) || !Ucrit_checkUsername(uidtoname(sessionid.uid))) { + return 0; } + printf("%5d %-12s %-12s %-12s (%s)\n", + (int)sessionid.pid, uidtoname(sessionid.uid), gidtoname(sessionid.gid), + sessionid.remote_machine, sessionid.hostname); + return 0; } @@ -316,46 +308,38 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st return profile_dump(); } + tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, USE_TDB_MMAP_FLAG, O_RDONLY, 0); + if (!tdb) { + printf("sessionid.tdb not initialised\n"); + } + + if (locks_only) goto locks; + + printf("\nSamba version %s\n",VERSION); + printf("PID Username Group Machine \n"); + printf("-------------------------------------------------------------------\n"); + + tdb_traverse(tdb, traverse_sessionid, NULL); + tdb_close(tdb); + tdb = tdb_open_log(lock_path("connections.tdb"), 0, USE_TDB_MMAP_FLAG, O_RDONLY, 0); if (!tdb) { printf("connections.tdb not initialised\n"); - if (!lp_status(-1)) - printf("You need to have status=yes in your smb config file\n"); - return(0); } else if (verbose) { printf("Opened status file %s\n", fname); } - if (locks_only) goto locks; + if (brief) + exit(0); + + printf("\nService pid machine Connected at\n"); + printf("-------------------------------------------------------\n"); - printf("\nSamba version %s\n",VERSION); - if (brief) { - printf("PID Username Machine Time logged in\n"); - printf("-------------------------------------------------------------------\n"); - } else { - printf("Service uid gid pid machine\n"); - printf("----------------------------------------------\n"); - } tdb_traverse(tdb, traverse_fn1, NULL); tdb_close(tdb); locks: if (processes_only) exit(0); - - if (brief) { - ptr=srecs; - while (ptr!=NULL) { - printf("%-8d%-10.10s%-30.30s%s", - (int)ptr->pid,uidtoname(ptr->uid), - ptr->machine, - asctime(LocalTime(&(ptr->start)))); - ptr=ptr->next; - } - printf("\n"); - exit(0); - } - - printf("\n"); if (!shares_only) { int ret; -- cgit From 2f6486b55f05947205c380e071b16cd40af4d057 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 23 Aug 2001 18:13:56 +0000 Subject: Fix up some unused variables and functions, fix up formatting (This used to be commit bfce4ba7b6db261d981a60a7e262f2f690355f5c) --- source3/utils/status.c | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 36de6858f1..c41551b7ec 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -77,15 +77,6 @@ static unsigned int Ucrit_checkUsername(char *username) return 0; } -static void Ucrit_addPid(pid_t pid) -{ - int i; - if ( !Ucrit_IsActive) return; - for (i=0;i Date: Fri, 24 Aug 2001 20:11:09 +0000 Subject: fixed handling of 139/445 in clients (This used to be commit 22b372f8a7996a19bebb8cdb411df999cffa32a4) --- source3/utils/smbcacls.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 20333f772b..9e8cbb1ddd 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -711,8 +711,7 @@ struct cli_state *connect_one(char *share) ip = ipzero; /* have to open a new connection */ - if (!(c=cli_initialise(NULL)) || (cli_set_port(c, 139) == 0) || - !cli_connect(c, server, &ip)) { + if (!(c=cli_initialise(NULL)) || !cli_connect(c, server, &ip)) { DEBUG(0,("Connection to %s failed\n", server)); cli_shutdown(c); safe_free(c); -- cgit From 717533483b41ef975953f58e0c6be04828a3d467 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Fri, 24 Aug 2001 20:32:01 +0000 Subject: get rid of compiler warnings (This used to be commit 0768991d04ea03e774ca8662c9cae5e1951b88e0) --- source3/utils/smbpasswd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 27a00e2e2b..5cfe1152c8 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -349,9 +349,9 @@ static int join_domain_byuser(char *domain, char *remote_machine, machine_pwd = (char *)upw.buffer; plen = upw.uni_str_len * 2; - generate_random_buffer(machine_pwd, plen, True); + generate_random_buffer((unsigned char *)machine_pwd, plen, True); - encode_pw_buffer(pwbuf, machine_pwd, plen, False); + encode_pw_buffer((char *)pwbuf, machine_pwd, plen, False); nt_owf_genW(&upw, ntpw); } @@ -361,7 +361,7 @@ static int join_domain_byuser(char *domain, char *remote_machine, ZERO_STRUCT(ctr); ZERO_STRUCT(p24); - init_sam_user_info24(&p24, pwbuf,24); + init_sam_user_info24(&p24, (char *)pwbuf,24); ctr.switch_value = 24; ctr.info.id24 = &p24; -- cgit From 7c09aa553da2f0b855e96396c13d854968537c30 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Sun, 26 Aug 2001 06:43:39 +0000 Subject: Same as nmbd.c. These now test wins_srv_count() instead of lp_wins_server to determine whether the 'wins server' parameter is set. (This used to be commit 5b975d3a9cea39e9992a9b556b8a6d9d3ec14807) --- source3/utils/testparm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 9b19a6c0fd..28870fb272 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -54,7 +54,7 @@ static int do_global_checks(void) ret = 1; } - if (lp_wins_support() && *lp_wins_server()) { + if (lp_wins_support() && wins_srv_count()) { printf("ERROR: both 'wins support = true' and 'wins server = ' \ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); ret = 1; -- cgit From b031af348c7dcc8c74bf49945211c466b8eca079 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 27 Aug 2001 19:46:22 +0000 Subject: converted another bunch of stuff to NTSTATUS (This used to be commit 1d36250e338ae0ff9fbbf86019809205dd97d05e) --- source3/utils/smbcacls.c | 6 +++--- source3/utils/smbpasswd.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 9e8cbb1ddd..53f9db1a6c 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -94,7 +94,7 @@ static BOOL cacls_open_policy_hnd(void) if (cli_lsa_open_policy(&lsa_cli, lsa_cli.mem_ctx, True, GENERIC_EXECUTE_ACCESS, &pol) - != NT_STATUS_NOPROBLEMO) { + != NT_STATUS_OK) { return False; } @@ -119,7 +119,7 @@ static void SidToString(fstring str, DOM_SID *sid) if (!cacls_open_policy_hnd() || cli_lsa_lookup_sids(&lsa_cli, lsa_cli.mem_ctx, &pol, 1, sid, &names, &types, - &num_names) != NT_STATUS_NOPROBLEMO || + &num_names) != NT_STATUS_OK || !names || !names[0]) { return; } @@ -143,7 +143,7 @@ static BOOL StringToSid(DOM_SID *sid, char *str) if (!cacls_open_policy_hnd() || cli_lsa_lookup_names(&lsa_cli, lsa_cli.mem_ctx, &pol, 1, &str, &sids, &types, - &num_sids) != NT_STATUS_NOPROBLEMO) { + &num_sids) != NT_STATUS_OK) { result = False; goto done; } diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 5cfe1152c8..3911987991 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -162,13 +162,13 @@ Join a domain using the administrator username and password /* Macro for checking RPC error codes to make things more readable */ #define CHECK_RPC_ERR(rpc, msg) \ - if ((result = rpc) != NT_STATUS_NOPROBLEMO) { \ + if ((result = rpc) != NT_STATUS_OK) { \ DEBUG(0, (msg ": %s\n", get_nt_error_msg(result))); \ goto done; \ } #define CHECK_RPC_ERR_DEBUG(rpc, debug_args) \ - if ((result = rpc) != NT_STATUS_NOPROBLEMO) { \ + if ((result = rpc) != NT_STATUS_OK) { \ DEBUG(0, debug_args); \ goto done; \ } @@ -330,7 +330,7 @@ static int join_domain_byuser(char *domain, char *remote_machine, ("could not re-open existing user %s: %s\n", acct_name, get_nt_error_msg(result))); - } else if (result != NT_STATUS_NOPROBLEMO) { + } else if (result != NT_STATUS_OK) { DEBUG(0, ("error creating domain user: %s\n", get_nt_error_msg(result))); goto done; -- cgit From 5021be2f24c3a1414d834a16f89a3a671aee444c Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 28 Aug 2001 06:02:51 +0000 Subject: Fixed typo in comment. (This used to be commit b10ad789d6d412ef1d2e0d8b47fc233225861bf9) --- source3/utils/pdbedit.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index a31f83956d..1068446905 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -23,7 +23,7 @@ */ #define BASE_MACHINE_UID 60000 -#define MAX_MACHINE_UID 65500 /* 5500 trust acconts aren't enough? */ +#define MAX_MACHINE_UID 65500 /* 5500 trust accounts aren't enough? */ #include "includes.h" @@ -715,5 +715,3 @@ int main (int argc, char **argv) return 0; } - - -- cgit From 49dff249fc3f9155037016dd131cbaa41e5306bc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 28 Aug 2001 06:38:11 +0000 Subject: Added samsync and samrepl (untested) message types to smbcontrol. (This used to be commit b0c8090396ca02d06669d6e20a1c715fc83ff887) --- source3/utils/smbcontrol.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 088ce0c08e..112c707412 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -33,6 +33,8 @@ static struct { {"debuglevel", MSG_REQ_DEBUGLEVEL}, {"printer-notify", MSG_PRINTER_NOTIFY}, {"close-share", MSG_SMB_FORCE_TDIS}, + {"samsync", MSG_SMB_SAM_SYNC}, + {"samrepl", MSG_SMB_SAM_REPL}, {NULL, -1} }; @@ -299,6 +301,42 @@ static BOOL do_command(char *dest, char *msg_name, char **params) strlen(params[0]) + 1, False); break; + case MSG_SMB_SAM_SYNC: + if (!strequal(dest, "smbd")) { + fprintf(stderr, "samsync can only be sent to smbd\n"); + return False; + } + + if (params) { + fprintf(stderr, "samsync does not take any parameters\n"); + return False; + } + + retval = send_message(dest, MSG_SMB_SAM_SYNC, NULL, 0, False); + + break; + + case MSG_SMB_SAM_REPL: { + uint32 seqnum; + + if (!strequal(dest, "smbd")) { + fprintf(stderr, "sam repl can only be sent to smbd\n"); + return False; + } + + if (!params || !params[0]) { + fprintf(stderr, "SAM_REPL needs a parameter\n"); + return False; + } + + seqnum = atoi(params[0]); + + retval = send_message(dest, MSG_SMB_SAM_SYNC, + (char *)&seqnum, sizeof(uint32), False); + + break; + } + case MSG_PING: if (!pong_registered) { message_register(MSG_PONG, pong_function); -- cgit From 6c38114f57bebec95ce8252e675e8699f683ff5e Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 29 Aug 2001 04:26:27 +0000 Subject: Fuss, fuss, fuss... Function name_status_query() performs a node status query, so it really should be called "node_status_query()" just to be consistent. Yeah, minor... but it's looking as though an overhaul of namequery.c is in order and I am trying to do the tiny changes that impact other stuff first. Chris -)----- (This used to be commit 3af2de7ed26e5a26a273be2dcd9c5565c586fe47) --- source3/utils/nmblookup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 3e2f0610e6..5acdf62735 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -113,7 +113,7 @@ static void do_node_status(int fd, char *name, int type, struct in_addr ip) printf("Looking up status of %s\n",inet_ntoa(ip)); make_nmb_name(&nname, name, type); - status = name_status_query(fd,&nname,ip, &count); + status = node_status_query(fd,&nname,ip, &count); if (status) { for (i=0;i Date: Wed, 29 Aug 2001 22:47:59 +0000 Subject: Fix uninitialised variables. Spotted by "Esh, Andrew" (This used to be commit 9081af4fe584d222c00587d6d3c81e12d6611222) --- source3/utils/smbpasswd.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 3911987991..e02a8115a1 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -555,6 +555,9 @@ static int process_root(int argc, char *argv[]) char *old_passwd = NULL; char *remote_machine = NULL; + ZERO_STRUCT(user_name); + ZERO_STRUCT(user_password); + while ((ch = getopt(argc, argv, "ax:d:e:hmnj:r:sR:D:U:L")) != EOF) { switch(ch) { case 'L': -- cgit From aca0710066fc4517eac7bbcee9b21a68d45496fd Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 30 Aug 2001 05:54:41 +0000 Subject: merge from 2.2 (This used to be commit d31e1b63b5a13ec585da18971e85c9eaa941ed33) --- source3/utils/smbpasswd.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index e02a8115a1..7ca9c37f28 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -558,6 +558,8 @@ static int process_root(int argc, char *argv[]) ZERO_STRUCT(user_name); ZERO_STRUCT(user_password); + user_name[0] = '\0'; + while ((ch = getopt(argc, argv, "ax:d:e:hmnj:r:sR:D:U:L")) != EOF) { switch(ch) { case 'L': @@ -685,6 +687,7 @@ static int process_root(int argc, char *argv[]) switch(argc) { case 0: + fstrcpy(user_name, ""); break; case 1: fstrcpy(user_name, argv[0]); -- cgit From d01c23680a7cbd0a4bdc60c82131df5c8cd19f1d Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 31 Aug 2001 05:48:37 +0000 Subject: Set acb_info to ACB_SVRTRUST if we are joining the domain as a BDC without going through the server manager. (This used to be commit 52f5abae4667d841be7ca8f5ff0f25ba6d027067) --- source3/utils/smbpasswd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 7ca9c37f28..74b9916d93 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -184,6 +184,7 @@ static int join_domain_byuser(char *domain, char *remote_machine, fstring dest_host, acct_name; struct in_addr dest_ip; TALLOC_CTX *mem_ctx; + uint32 acb_info; /* rpc variables */ @@ -283,11 +284,14 @@ static int join_domain_byuser(char *domain, char *remote_machine, strlower(acct_name); + acb_info = (lp_server_role() == ROLE_DOMAIN_BDC) ? ACB_SVRTRUST : + ACB_WSTRUST; + { uint32 unknown = 0xe005000b; result = cli_samr_create_dom_user(&cli, mem_ctx, &domain_pol, - acct_name, ACB_WSTRUST, + acct_name, acb_info, unknown, &user_pol, &user_rid); @@ -389,7 +393,7 @@ static int join_domain_byuser(char *domain, char *remote_machine, ctr.switch_value = 0x10; ctr.info.id10 = &p10; - init_sam_user_info10(&p10, ACB_WSTRUST); + init_sam_user_info10(&p10, acb_info); /* Ignoring the return value is necessary for joining a domain as a normal user with "Add workstation to domain" privilege. */ -- cgit From 19fea3242cf6234786b6cbb60631e0071f31ff9f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Sep 2001 07:13:01 +0000 Subject: the next stage in the NTSTATUS/WERROR change. smbd and nmbd now compile, but the client code still needs some work (This used to be commit dcd6e735f709a9231860ceb9682db40ff26c9a66) --- source3/utils/smbpasswd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 74b9916d93..74f4e8833a 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -162,13 +162,13 @@ Join a domain using the administrator username and password /* Macro for checking RPC error codes to make things more readable */ #define CHECK_RPC_ERR(rpc, msg) \ - if ((result = rpc) != NT_STATUS_OK) { \ + if (!NT_STATUS_IS_OK(result = rpc)) { \ DEBUG(0, (msg ": %s\n", get_nt_error_msg(result))); \ goto done; \ } #define CHECK_RPC_ERR_DEBUG(rpc, debug_args) \ - if ((result = rpc) != NT_STATUS_OK) { \ + if (!NT_STATUS_IS_OK(result = rpc)) { \ DEBUG(0, debug_args); \ goto done; \ } @@ -203,7 +203,7 @@ static int join_domain_byuser(char *domain, char *remote_machine, /* Misc */ - uint32 result; + NTSTATUS result; int retval = 1; /* Connect to remote machine */ @@ -301,7 +301,7 @@ static int join_domain_byuser(char *domain, char *remote_machine, result = NT_STATUS_USER_EXISTS; } - if (result == NT_STATUS_USER_EXISTS) { + if (NT_STATUS_V(result) == NT_STATUS_V(NT_STATUS_USER_EXISTS)) { uint32 num_rids, *name_types, *user_rids; uint32 flags = 0x3e8; char *names; @@ -334,7 +334,7 @@ static int join_domain_byuser(char *domain, char *remote_machine, ("could not re-open existing user %s: %s\n", acct_name, get_nt_error_msg(result))); - } else if (result != NT_STATUS_OK) { + } else if (!NT_STATUS_IS_OK(result)) { DEBUG(0, ("error creating domain user: %s\n", get_nt_error_msg(result))); goto done; -- cgit From c76dd1404041f42d3a398339cefbeb60f22d2910 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Sep 2001 10:57:29 +0000 Subject: it now all compiles - so try enabling it by default and see what explodes on the build farm (This used to be commit 5bb7e4f0f65edf1db20245f403cbe81833134240) --- source3/utils/smbcacls.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 53f9db1a6c..b26dbae417 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -92,9 +92,8 @@ static BOOL cacls_open_policy_hnd(void) /* Some systems don't support SEC_RIGHTS_MAXIMUM_ALLOWED, but NT sends 0x2000000 so we might as well do it too. */ - if (cli_lsa_open_policy(&lsa_cli, lsa_cli.mem_ctx, True, - GENERIC_EXECUTE_ACCESS, &pol) - != NT_STATUS_OK) { + if (!NT_STATUS_IS_OK(cli_lsa_open_policy(&lsa_cli, lsa_cli.mem_ctx, True, + GENERIC_EXECUTE_ACCESS, &pol))) { return False; } @@ -118,8 +117,8 @@ static void SidToString(fstring str, DOM_SID *sid) /* Ask LSA to convert the sid to a name */ if (!cacls_open_policy_hnd() || - cli_lsa_lookup_sids(&lsa_cli, lsa_cli.mem_ctx, &pol, 1, sid, &names, &types, - &num_names) != NT_STATUS_OK || + !NT_STATUS_IS_OK(cli_lsa_lookup_sids(&lsa_cli, lsa_cli.mem_ctx, &pol, 1, sid, &names, + &types, &num_names)) || !names || !names[0]) { return; } @@ -142,8 +141,8 @@ static BOOL StringToSid(DOM_SID *sid, char *str) } if (!cacls_open_policy_hnd() || - cli_lsa_lookup_names(&lsa_cli, lsa_cli.mem_ctx, &pol, 1, &str, &sids, &types, - &num_sids) != NT_STATUS_OK) { + !NT_STATUS_IS_OK(cli_lsa_lookup_names(&lsa_cli, lsa_cli.mem_ctx, &pol, 1, &str, + &sids, &types, &num_sids))) { result = False; goto done; } -- cgit From 7844aa868b02f99c013f336ee03ef05adbd11a7b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 5 Sep 2001 08:11:17 +0000 Subject: more warning fixes on solaris (This used to be commit c04c67fec85b1c81ef0b3cebacde304a1de0d854) --- source3/utils/smbtree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 0f824f7ecf..41940d9a6c 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -183,10 +183,10 @@ static BOOL find_master_ip_bcast(pstring workgroup, struct in_addr *server_ip) static fstring name; if (!name_status_find(0x1d, ip_list[i], name)) - return False; + continue; if (!find_master_ip(name, server_ip)) - return False; + continue; pstrcpy(workgroup, name); -- cgit From 00973eb50ea846b31266ab6ad62759c22bef2bbb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 5 Sep 2001 17:23:51 +0000 Subject: When sending a message via a tdb, it must be open read/write. Jeremy. (This used to be commit f35887c7d40ced750596b87bf37f7aae1df68c7a) --- source3/utils/smbcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 112c707412..377f7a148b 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -133,7 +133,7 @@ static BOOL send_message(char *dest, int msg_type, void *buf, int len, BOOL dupl TDB_CONTEXT *tdb; BOOL ret; - tdb = tdb_open_log(lock_path("connections.tdb"), 0, USE_TDB_MMAP_FLAG, O_RDONLY, 0); + tdb = tdb_open_log(lock_path("connections.tdb"), 0, USE_TDB_MMAP_FLAG, O_RDWR, 0); if (!tdb) { fprintf(stderr,"Failed to open connections database in send_message.\n"); return False; -- cgit From 283b15bcd727186848ffa4dff3aa864221f4d97e Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 5 Sep 2001 17:58:24 +0000 Subject: add profiling stats from 2.2 (This used to be commit 6c333e9d922b3a7443db829277b8a209cce2d350) --- source3/utils/status.c | 334 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 332 insertions(+), 2 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index c41551b7ec..1137898e34 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -164,8 +164,338 @@ static int profile_dump(void) return -1; } - printf("smb_count:\t%u\n", profile_p->smb_count); - printf("uid_changes:\t%u\n", profile_p->uid_changes); + printf("smb_count: %u\n", profile_p->smb_count); + printf("uid_changes: %u\n", profile_p->uid_changes); + printf("************************ System Calls ****************************\n"); + printf("opendir_count: %u\n", profile_p->syscall_opendir_count); + printf("opendir_time: %u\n", profile_p->syscall_opendir_time); + printf("readdir_count: %u\n", profile_p->syscall_readdir_count); + printf("readdir_time: %u\n", profile_p->syscall_readdir_time); + printf("mkdir_count: %u\n", profile_p->syscall_mkdir_count); + printf("mkdir_time: %u\n", profile_p->syscall_mkdir_time); + printf("rmdir_count: %u\n", profile_p->syscall_rmdir_count); + printf("rmdir_time: %u\n", profile_p->syscall_rmdir_time); + printf("closedir_count: %u\n", profile_p->syscall_closedir_count); + printf("closedir_time: %u\n", profile_p->syscall_closedir_time); + printf("open_count: %u\n", profile_p->syscall_open_count); + printf("open_time: %u\n", profile_p->syscall_open_time); + printf("close_count: %u\n", profile_p->syscall_close_count); + printf("close_time: %u\n", profile_p->syscall_close_time); + printf("read_count: %u\n", profile_p->syscall_read_count); + printf("read_time: %u\n", profile_p->syscall_read_time); + printf("read_bytes: %u\n", profile_p->syscall_read_bytes); + printf("write_count: %u\n", profile_p->syscall_write_count); + printf("write_time: %u\n", profile_p->syscall_write_time); + printf("write_bytes: %u\n", profile_p->syscall_write_bytes); + printf("lseek_count: %u\n", profile_p->syscall_lseek_count); + printf("lseek_time: %u\n", profile_p->syscall_lseek_time); + printf("rename_count: %u\n", profile_p->syscall_rename_count); + printf("rename_time: %u\n", profile_p->syscall_rename_time); + printf("fsync_count: %u\n", profile_p->syscall_fsync_count); + printf("fsync_time: %u\n", profile_p->syscall_fsync_time); + printf("stat_count: %u\n", profile_p->syscall_stat_count); + printf("stat_time: %u\n", profile_p->syscall_stat_time); + printf("fstat_count: %u\n", profile_p->syscall_fstat_count); + printf("fstat_time: %u\n", profile_p->syscall_fstat_time); + printf("lstat_count: %u\n", profile_p->syscall_lstat_count); + printf("lstat_time: %u\n", profile_p->syscall_lstat_time); + printf("unlink_count: %u\n", profile_p->syscall_unlink_count); + printf("unlink_time: %u\n", profile_p->syscall_unlink_time); + printf("chmod_count: %u\n", profile_p->syscall_chmod_count); + printf("chmod_time: %u\n", profile_p->syscall_chmod_time); + printf("fchmod_count: %u\n", profile_p->syscall_fchmod_count); + printf("fchmod_time: %u\n", profile_p->syscall_fchmod_time); + printf("chown_count: %u\n", profile_p->syscall_chown_count); + printf("chown_time: %u\n", profile_p->syscall_chown_time); + printf("fchown_count: %u\n", profile_p->syscall_fchown_count); + printf("fchown_time: %u\n", profile_p->syscall_fchown_time); + printf("chdir_count: %u\n", profile_p->syscall_chdir_count); + printf("chdir_time: %u\n", profile_p->syscall_chdir_time); + printf("getwd_count: %u\n", profile_p->syscall_getwd_count); + printf("getwd_time: %u\n", profile_p->syscall_getwd_time); + printf("utime_count: %u\n", profile_p->syscall_utime_count); + printf("utime_time: %u\n", profile_p->syscall_utime_time); + printf("ftruncate_count: %u\n", profile_p->syscall_ftruncate_count); + printf("ftruncate_time: %u\n", profile_p->syscall_ftruncate_time); + printf("fcntl_lock_count: %u\n", profile_p->syscall_fcntl_lock_count); + printf("fcntl_lock_time: %u\n", profile_p->syscall_fcntl_lock_time); + printf("readlink_count: %u\n", profile_p->syscall_readlink_count); + printf("readlink_time: %u\n", profile_p->syscall_readlink_time); + printf("symlink_count: %u\n", profile_p->syscall_symlink_count); + printf("symlink_time: %u\n", profile_p->syscall_symlink_time); + printf("************************ Statcache *******************************\n"); + printf("lookups: %u\n", profile_p->statcache_lookups); + printf("misses: %u\n", profile_p->statcache_misses); + printf("hits: %u\n", profile_p->statcache_hits); + printf("************************ Writecache ******************************\n"); + printf("read_hits: %u\n", profile_p->writecache_read_hits); + printf("abutted_writes: %u\n", profile_p->writecache_abutted_writes); + printf("total_writes: %u\n", profile_p->writecache_total_writes); + printf("non_oplock_writes: %u\n", profile_p->writecache_non_oplock_writes); + printf("direct_writes: %u\n", profile_p->writecache_direct_writes); + printf("init_writes: %u\n", profile_p->writecache_init_writes); + printf("flushed_writes[SEEK]: %u\n", profile_p->writecache_flushed_writes[SEEK_FLUSH]); + printf("flushed_writes[READ]: %u\n", profile_p->writecache_flushed_writes[READ_FLUSH]); + printf("flushed_writes[WRITE]: %u\n", profile_p->writecache_flushed_writes[WRITE_FLUSH]); + printf("flushed_writes[READRAW]: %u\n", profile_p->writecache_flushed_writes[READRAW_FLUSH]); + printf("flushed_writes[OPLOCK_RELEASE]: %u\n", profile_p->writecache_flushed_writes[OPLOCK_RELEASE_FLUSH]); + printf("flushed_writes[CLOSE]: %u\n", profile_p->writecache_flushed_writes[CLOSE_FLUSH]); + printf("flushed_writes[SYNC]: %u\n", profile_p->writecache_flushed_writes[SYNC_FLUSH]); + printf("flushed_writes[SIZECHANGE]: %u\n", profile_p->writecache_flushed_writes[SIZECHANGE_FLUSH]); + printf("num_perfect_writes: %u\n", profile_p->writecache_num_perfect_writes); + printf("num_write_caches: %u\n", profile_p->writecache_num_write_caches); + printf("allocated_write_caches: %u\n", profile_p->writecache_allocated_write_caches); + printf("************************ SMB Calls *******************************\n"); + printf("mkdir_count: %u\n", profile_p->SMBmkdir_count); + printf("mkdir_time: %u\n", profile_p->SMBmkdir_time); + printf("rmdir_count: %u\n", profile_p->SMBrmdir_count); + printf("rmdir_time: %u\n", profile_p->SMBrmdir_time); + printf("open_count: %u\n", profile_p->SMBopen_count); + printf("open_time: %u\n", profile_p->SMBopen_time); + printf("create_count: %u\n", profile_p->SMBcreate_count); + printf("create_time: %u\n", profile_p->SMBcreate_time); + printf("close_count: %u\n", profile_p->SMBclose_count); + printf("close_time: %u\n", profile_p->SMBclose_time); + printf("flush_count: %u\n", profile_p->SMBflush_count); + printf("flush_time: %u\n", profile_p->SMBflush_time); + printf("unlink_count: %u\n", profile_p->SMBunlink_count); + printf("unlink_time: %u\n", profile_p->SMBunlink_time); + printf("mv_count: %u\n", profile_p->SMBmv_count); + printf("mv_time: %u\n", profile_p->SMBmv_time); + printf("getatr_count: %u\n", profile_p->SMBgetatr_count); + printf("getatr_time: %u\n", profile_p->SMBgetatr_time); + printf("setatr_count: %u\n", profile_p->SMBsetatr_count); + printf("setatr_time: %u\n", profile_p->SMBsetatr_time); + printf("read_count: %u\n", profile_p->SMBread_count); + printf("read_time: %u\n", profile_p->SMBread_time); + printf("write_count: %u\n", profile_p->SMBwrite_count); + printf("write_time: %u\n", profile_p->SMBwrite_time); + printf("lock_count: %u\n", profile_p->SMBlock_count); + printf("lock_time: %u\n", profile_p->SMBlock_time); + printf("unlock_count: %u\n", profile_p->SMBunlock_count); + printf("unlock_time: %u\n", profile_p->SMBunlock_time); + printf("ctemp_count: %u\n", profile_p->SMBctemp_count); + printf("ctemp_time: %u\n", profile_p->SMBctemp_time); + printf("mknew_count: %u\n", profile_p->SMBmknew_count); + printf("mknew_time: %u\n", profile_p->SMBmknew_time); + printf("chkpth_count: %u\n", profile_p->SMBchkpth_count); + printf("chkpth_time: %u\n", profile_p->SMBchkpth_time); + printf("exit_count: %u\n", profile_p->SMBexit_count); + printf("exit_time: %u\n", profile_p->SMBexit_time); + printf("lseek_count: %u\n", profile_p->SMBlseek_count); + printf("lseek_time: %u\n", profile_p->SMBlseek_time); + printf("lockread_count: %u\n", profile_p->SMBlockread_count); + printf("lockread_time: %u\n", profile_p->SMBlockread_time); + printf("writeunlock_count: %u\n", profile_p->SMBwriteunlock_count); + printf("writeunlock_time: %u\n", profile_p->SMBwriteunlock_time); + printf("readbraw_count: %u\n", profile_p->SMBreadbraw_count); + printf("readbraw_time: %u\n", profile_p->SMBreadbraw_time); + printf("readBmpx_count: %u\n", profile_p->SMBreadBmpx_count); + printf("readBmpx_time: %u\n", profile_p->SMBreadBmpx_time); + printf("readBs_count: %u\n", profile_p->SMBreadBs_count); + printf("readBs_time: %u\n", profile_p->SMBreadBs_time); + printf("writebraw_count: %u\n", profile_p->SMBwritebraw_count); + printf("writebraw_time: %u\n", profile_p->SMBwritebraw_time); + printf("writeBmpx_count: %u\n", profile_p->SMBwriteBmpx_count); + printf("writeBmpx_time: %u\n", profile_p->SMBwriteBmpx_time); + printf("writeBs_count: %u\n", profile_p->SMBwriteBs_count); + printf("writeBs_time: %u\n", profile_p->SMBwriteBs_time); + printf("writec_count: %u\n", profile_p->SMBwritec_count); + printf("writec_time: %u\n", profile_p->SMBwritec_time); + printf("setattrE_count: %u\n", profile_p->SMBsetattrE_count); + printf("setattrE_time: %u\n", profile_p->SMBsetattrE_time); + printf("getattrE_count: %u\n", profile_p->SMBgetattrE_count); + printf("getattrE_time: %u\n", profile_p->SMBgetattrE_time); + printf("lockingX_count: %u\n", profile_p->SMBlockingX_count); + printf("lockingX_time: %u\n", profile_p->SMBlockingX_time); + printf("trans_count: %u\n", profile_p->SMBtrans_count); + printf("trans_time: %u\n", profile_p->SMBtrans_time); + printf("transs_count: %u\n", profile_p->SMBtranss_count); + printf("transs_time: %u\n", profile_p->SMBtranss_time); + printf("ioctl_count: %u\n", profile_p->SMBioctl_count); + printf("ioctl_time: %u\n", profile_p->SMBioctl_time); + printf("ioctls_count: %u\n", profile_p->SMBioctls_count); + printf("ioctls_time: %u\n", profile_p->SMBioctls_time); + printf("copy_count: %u\n", profile_p->SMBcopy_count); + printf("copy_time: %u\n", profile_p->SMBcopy_time); + printf("move_count: %u\n", profile_p->SMBmove_count); + printf("move_time: %u\n", profile_p->SMBmove_time); + printf("echo_count: %u\n", profile_p->SMBecho_count); + printf("echo_time: %u\n", profile_p->SMBecho_time); + printf("writeclose_count: %u\n", profile_p->SMBwriteclose_count); + printf("writeclose_time: %u\n", profile_p->SMBwriteclose_time); + printf("openX_count: %u\n", profile_p->SMBopenX_count); + printf("openX_time: %u\n", profile_p->SMBopenX_time); + printf("readX_count: %u\n", profile_p->SMBreadX_count); + printf("readX_time: %u\n", profile_p->SMBreadX_time); + printf("writeX_count: %u\n", profile_p->SMBwriteX_count); + printf("writeX_time: %u\n", profile_p->SMBwriteX_time); + printf("trans2_count: %u\n", profile_p->SMBtrans2_count); + printf("trans2_time: %u\n", profile_p->SMBtrans2_time); + printf("transs2_count: %u\n", profile_p->SMBtranss2_count); + printf("transs2_time: %u\n", profile_p->SMBtranss2_time); + printf("findclose_count: %u\n", profile_p->SMBfindclose_count); + printf("findclose_time: %u\n", profile_p->SMBfindclose_time); + printf("findnclose_count: %u\n", profile_p->SMBfindnclose_count); + printf("findnclose_time: %u\n", profile_p->SMBfindnclose_time); + printf("tcon_count: %u\n", profile_p->SMBtcon_count); + printf("tcon_time: %u\n", profile_p->SMBtcon_time); + printf("tdis_count: %u\n", profile_p->SMBtdis_count); + printf("tdis_time: %u\n", profile_p->SMBtdis_time); + printf("negprot_count: %u\n", profile_p->SMBnegprot_count); + printf("negprot_time: %u\n", profile_p->SMBnegprot_time); + printf("sesssetupX_count: %u\n", profile_p->SMBsesssetupX_count); + printf("sesssetupX_time: %u\n", profile_p->SMBsesssetupX_time); + printf("ulogoffX_count: %u\n", profile_p->SMBulogoffX_count); + printf("ulogoffX_time: %u\n", profile_p->SMBulogoffX_time); + printf("tconX_count: %u\n", profile_p->SMBtconX_count); + printf("tconX_time: %u\n", profile_p->SMBtconX_time); + printf("dskattr_count: %u\n", profile_p->SMBdskattr_count); + printf("dskattr_time: %u\n", profile_p->SMBdskattr_time); + printf("search_count: %u\n", profile_p->SMBsearch_count); + printf("search_time: %u\n", profile_p->SMBsearch_time); + printf("ffirst_count: %u\n", profile_p->SMBffirst_count); + printf("ffirst_time: %u\n", profile_p->SMBffirst_time); + printf("funique_count: %u\n", profile_p->SMBfunique_count); + printf("funique_time: %u\n", profile_p->SMBfunique_time); + printf("fclose_count: %u\n", profile_p->SMBfclose_count); + printf("fclose_time: %u\n", profile_p->SMBfclose_time); + printf("nttrans_count: %u\n", profile_p->SMBnttrans_count); + printf("nttrans_time: %u\n", profile_p->SMBnttrans_time); + printf("nttranss_count: %u\n", profile_p->SMBnttranss_count); + printf("nttranss_time: %u\n", profile_p->SMBnttranss_time); + printf("ntcreateX_count: %u\n", profile_p->SMBntcreateX_count); + printf("ntcreateX_time: %u\n", profile_p->SMBntcreateX_time); + printf("ntcancel_count: %u\n", profile_p->SMBntcancel_count); + printf("ntcancel_time: %u\n", profile_p->SMBntcancel_time); + printf("splopen_count: %u\n", profile_p->SMBsplopen_count); + printf("splopen_time: %u\n", profile_p->SMBsplopen_time); + printf("splwr_count: %u\n", profile_p->SMBsplwr_count); + printf("splwr_time: %u\n", profile_p->SMBsplwr_time); + printf("splclose_count: %u\n", profile_p->SMBsplclose_count); + printf("splclose_time: %u\n", profile_p->SMBsplclose_time); + printf("splretq_count: %u\n", profile_p->SMBsplretq_count); + printf("splretq_time: %u\n", profile_p->SMBsplretq_time); + printf("sends_count: %u\n", profile_p->SMBsends_count); + printf("sends_time: %u\n", profile_p->SMBsends_time); + printf("sendb_count: %u\n", profile_p->SMBsendb_count); + printf("sendb_time: %u\n", profile_p->SMBsendb_time); + printf("fwdname_count: %u\n", profile_p->SMBfwdname_count); + printf("fwdname_time: %u\n", profile_p->SMBfwdname_time); + printf("cancelf_count: %u\n", profile_p->SMBcancelf_count); + printf("cancelf_time: %u\n", profile_p->SMBcancelf_time); + printf("getmac_count: %u\n", profile_p->SMBgetmac_count); + printf("getmac_time: %u\n", profile_p->SMBgetmac_time); + printf("sendstrt_count: %u\n", profile_p->SMBsendstrt_count); + printf("sendstrt_time: %u\n", profile_p->SMBsendstrt_time); + printf("sendend_count: %u\n", profile_p->SMBsendend_count); + printf("sendend_time: %u\n", profile_p->SMBsendend_time); + printf("sendtxt_count: %u\n", profile_p->SMBsendtxt_count); + printf("sendtxt_time: %u\n", profile_p->SMBsendtxt_time); + printf("invalid_count: %u\n", profile_p->SMBinvalid_count); + printf("invalid_time: %u\n", profile_p->SMBinvalid_time); + printf("************************ Pathworks Calls *************************\n"); + printf("setdir_count: %u\n", profile_p->pathworks_setdir_count); + printf("setdir_time: %u\n", profile_p->pathworks_setdir_time); + printf("************************ Trans2 Calls ****************************\n"); + printf("open_count: %u\n", profile_p->Trans2_open_count); + printf("open_time: %u\n", profile_p->Trans2_open_time); + printf("findfirst_count: %u\n", profile_p->Trans2_findfirst_count); + printf("findfirst_time: %u\n", profile_p->Trans2_findfirst_time); + printf("findnext_count: %u\n", profile_p->Trans2_findnext_count); + printf("findnext_time: %u\n", profile_p->Trans2_findnext_time); + printf("qfsinfo_count: %u\n", profile_p->Trans2_qfsinfo_count); + printf("qfsinfo_time: %u\n", profile_p->Trans2_qfsinfo_time); + printf("setfsinfo_count: %u\n", profile_p->Trans2_setfsinfo_count); + printf("setfsinfo_time: %u\n", profile_p->Trans2_setfsinfo_time); + printf("qpathinfo_count: %u\n", profile_p->Trans2_qpathinfo_count); + printf("qpathinfo_time: %u\n", profile_p->Trans2_qpathinfo_time); + printf("setpathinfo_count: %u\n", profile_p->Trans2_setpathinfo_count); + printf("setpathinfo_time: %u\n", profile_p->Trans2_setpathinfo_time); + printf("qfileinfo_count: %u\n", profile_p->Trans2_qfileinfo_count); + printf("qfileinfo_time: %u\n", profile_p->Trans2_qfileinfo_time); + printf("setfileinfo_count: %u\n", profile_p->Trans2_setfileinfo_count); + printf("setfileinfo_time: %u\n", profile_p->Trans2_setfileinfo_time); + printf("fsctl_count: %u\n", profile_p->Trans2_fsctl_count); + printf("fsctl_time: %u\n", profile_p->Trans2_fsctl_time); + printf("ioctl_count: %u\n", profile_p->Trans2_ioctl_count); + printf("ioctl_time: %u\n", profile_p->Trans2_ioctl_time); + printf("findnotifyfirst_count: %u\n", profile_p->Trans2_findnotifyfirst_count); + printf("findnotifyfirst_time: %u\n", profile_p->Trans2_findnotifyfirst_time); + printf("findnotifynext_count: %u\n", profile_p->Trans2_findnotifynext_count); + printf("findnotifynext_time: %u\n", profile_p->Trans2_findnotifynext_time); + printf("mkdir_count: %u\n", profile_p->Trans2_mkdir_count); + printf("mkdir_time: %u\n", profile_p->Trans2_mkdir_time); + printf("session_setup_count: %u\n", profile_p->Trans2_session_setup_count); + printf("session_setup_time: %u\n", profile_p->Trans2_session_setup_time); + printf("get_dfs_referral_count: %u\n", profile_p->Trans2_get_dfs_referral_count); + printf("get_dfs_referral_time: %u\n", profile_p->Trans2_get_dfs_referral_time); + printf("report_dfs_inconsistancy_count: %u\n", profile_p->Trans2_report_dfs_inconsistancy_count); + printf("report_dfs_inconsistancy_time: %u\n", profile_p->Trans2_report_dfs_inconsistancy_time); + printf("************************ NT Transact Calls ***********************\n"); + printf("create_count: %u\n", profile_p->NT_transact_create_count); + printf("create_time: %u\n", profile_p->NT_transact_create_time); + printf("ioctl_count: %u\n", profile_p->NT_transact_ioctl_count); + printf("ioctl_time: %u\n", profile_p->NT_transact_ioctl_time); + printf("set_security_desc_count: %u\n", profile_p->NT_transact_set_security_desc_count); + printf("set_security_desc_time: %u\n", profile_p->NT_transact_set_security_desc_time); + printf("notify_change_count: %u\n", profile_p->NT_transact_notify_change_count); + printf("notify_change_time: %u\n", profile_p->NT_transact_notify_change_time); + printf("rename_count: %u\n", profile_p->NT_transact_rename_count); + printf("rename_time: %u\n", profile_p->NT_transact_rename_time); + printf("query_security_desc_count: %u\n", profile_p->NT_transact_query_security_desc_count); + printf("query_security_desc_time: %u\n", profile_p->NT_transact_query_security_desc_time); + printf("************************ ACL Calls *******************************\n"); + printf("get_nt_acl_count: %u\n", profile_p->get_nt_acl_count); + printf("get_nt_acl_time: %u\n", profile_p->get_nt_acl_time); + printf("fget_nt_acl_count: %u\n", profile_p->fget_nt_acl_count); + printf("fget_nt_acl_time: %u\n", profile_p->fget_nt_acl_time); + printf("set_nt_acl_count: %u\n", profile_p->set_nt_acl_count); + printf("set_nt_acl_time: %u\n", profile_p->set_nt_acl_time); + printf("fset_nt_acl_count: %u\n", profile_p->fset_nt_acl_count); + printf("fset_nt_acl_time: %u\n", profile_p->fset_nt_acl_time); + printf("chmod_acl_count: %u\n", profile_p->chmod_acl_count); + printf("chmod_acl_time: %u\n", profile_p->chmod_acl_time); + printf("fchmod_acl_count: %u\n", profile_p->fchmod_acl_count); + printf("fchmod_acl_time: %u\n", profile_p->fchmod_acl_time); + printf("************************ NMBD Calls ****************************\n"); + printf("name_release_count: %u\n", profile_p->name_release_count); + printf("name_release_time: %u\n", profile_p->name_release_time); + printf("name_refresh_count: %u\n", profile_p->name_refresh_count); + printf("name_refresh_time: %u\n", profile_p->name_refresh_time); + printf("name_registration_count: %u\n", profile_p->name_registration_count); + printf("name_registration_time: %u\n", profile_p->name_registration_time); + printf("node_status_count: %u\n", profile_p->node_status_count); + printf("node_status_time: %u\n", profile_p->node_status_time); + printf("name_query_count: %u\n", profile_p->name_query_count); + printf("name_query_time: %u\n", profile_p->name_query_time); + printf("host_announce_count: %u\n", profile_p->host_announce_count); + printf("host_announce_time: %u\n", profile_p->host_announce_time); + printf("workgroup_announce_count: %u\n", profile_p->workgroup_announce_count); + printf("workgroup_announce_time: %u\n", profile_p->workgroup_announce_time); + printf("local_master_announce_count: %u\n", profile_p->local_master_announce_count); + printf("local_master_announce_time: %u\n", profile_p->local_master_announce_time); + printf("master_browser_announce_count: %u\n", profile_p->master_browser_announce_count); + printf("master_browser_announce_time: %u\n", profile_p->master_browser_announce_time); + printf("lm_host_announce_count: %u\n", profile_p->lm_host_announce_count); + printf("lm_host_announce_time: %u\n", profile_p->lm_host_announce_time); + printf("get_backup_list_count: %u\n", profile_p->get_backup_list_count); + printf("get_backup_list_time: %u\n", profile_p->get_backup_list_time); + printf("reset_browser_count: %u\n", profile_p->reset_browser_count); + printf("reset_browser_time: %u\n", profile_p->reset_browser_time); + printf("announce_request_count: %u\n", profile_p->announce_request_count); + printf("announce_request_time: %u\n", profile_p->announce_request_time); + printf("lm_announce_request_count: %u\n", profile_p->lm_announce_request_count); + printf("lm_announce_request_time: %u\n", profile_p->lm_announce_request_time); + printf("domain_logon_count: %u\n", profile_p->domain_logon_count); + printf("domain_logon_time: %u\n", profile_p->domain_logon_time); + printf("sync_browse_lists_count: %u\n", profile_p->sync_browse_lists_count); + printf("sync_browse_lists_time: %u\n", profile_p->sync_browse_lists_time); + printf("run_elections_count: %u\n", profile_p->run_elections_count); + printf("run_elections_time: %u\n", profile_p->run_elections_time); + printf("election_count: %u\n", profile_p->election_count); + printf("election_time: %u\n", profile_p->election_time); + return 0; #endif } -- cgit From dff3c815e2837ee0421298e3da7698bd3e01e0a6 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 5 Sep 2001 18:01:48 +0000 Subject: always include profile support so you do not need a different binary of smbstatus to dump profile stats. (This used to be commit fc048955b8af05779992bc111f9bd690b8a8faf2) --- source3/utils/status.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 1137898e34..77e76a34e8 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -155,10 +155,6 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, ******************************************************************/ static int profile_dump(void) { -#ifndef WITH_PROFILE - fprintf(stderr,"ERROR: not compiled with profile support\n"); - return -1; -#else if (!profile_setup(True)) { fprintf(stderr,"Failed to initialise profile memory\n"); return -1; @@ -497,7 +493,6 @@ static int profile_dump(void) printf("election_time: %u\n", profile_p->election_time); return 0; -#endif } -- cgit From 65e35d5d4bf2a35fde52d1fb795c84764009acad Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 6 Sep 2001 09:10:26 +0000 Subject: Started a cleanup of smbpasswd related stuff. I've created a new file lib/smbpasswd.c which will contain routines related to manipulating smbpasswd entries. - renamed and moved pdb_{get,set}hexpwd() functions - renamed and moved pdb_{decode,encode}acct_ctrl() functions - started hiding references to the cruftalicious NEW_PW_FORMAT_SPACE_PADDED_LEN constant - started gradual rename of references to acct_ctrl to acb_info which is the nomenclature used in MSDN and header files There's still more work to be done. Currently there are several places where smbpasswd entries are iterated etc. Ideally this should all happen through the passdb system. (This used to be commit 4a01e240305fb6fead973beef4937a016b15d744) --- source3/utils/pdbedit.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index 1068446905..f09fd4f773 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -89,16 +89,20 @@ static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdst { char lm_passwd[33]; char nt_passwd[33]; - pdb_sethexpwd(lm_passwd, pdb_get_lanman_passwd(sam_pwent), pdb_get_acct_ctrl(sam_pwent)); - pdb_sethexpwd(nt_passwd, pdb_get_nt_passwd(sam_pwent), pdb_get_acct_ctrl(sam_pwent)); + smbpasswd_sethexpwd(lm_passwd, + pdb_get_lanman_passwd(sam_pwent), + pdb_get_acct_ctrl(sam_pwent)); + smbpasswd_sethexpwd(nt_passwd, + pdb_get_nt_passwd(sam_pwent), + pdb_get_acct_ctrl(sam_pwent)); - printf ("%s:%d:%s:%s:%s:LCT-%08x:\n", - pdb_get_username(sam_pwent), - pdb_get_uid(sam_pwent), - lm_passwd, - nt_passwd, - pdb_encode_acct_ctrl(pdb_get_acct_ctrl(sam_pwent),NEW_PW_FORMAT_SPACE_PADDED_LEN), - (uint32)pdb_get_pass_last_set_time(sam_pwent)); + printf("%s:%d:%s:%s:%s:LCT-%08x:\n", + pdb_get_username(sam_pwent), + pdb_get_uid(sam_pwent), + lm_passwd, + nt_passwd, + smbpasswd_encode_acb_info(pdb_get_acct_ctrl(sam_pwent)), + (uint32)pdb_get_pass_last_set_time(sam_pwent)); } else { @@ -452,7 +456,7 @@ static int import_users (char *filename) } else { - if (!pdb_gethexpwd((char *)p, smbpwd)) + if (!smbpasswd_gethexpwd((char *)p, smbpwd)) { fprintf (stderr, "Error: malformed Lanman password entry at line %d (non hex chars)\n", line); continue; @@ -466,7 +470,7 @@ static int import_users (char *filename) { if (*p != '*' && *p != 'X') { - if (pdb_gethexpwd((char *)p,smbntpwd)) + if (smbpasswd_gethexpwd((char *)p,smbntpwd)) { sam_pwent.nt_pw = smbntpwd; } @@ -480,7 +484,7 @@ static int import_users (char *filename) { unsigned char *end_p = (unsigned char *)strchr_m((char *)p, ']'); - sam_pwent.acct_ctrl = pdb_decode_acct_ctrl((char*)p); + sam_pwent.acct_ctrl = smbpasswd_decode_acb_info((char*)p); if(sam_pwent.acct_ctrl == 0) sam_pwent.acct_ctrl = ACB_NORMAL; /* Get last change time */ -- cgit From 9a9ac2739bbdc993ecdfa78298bdd9c059328378 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Sep 2001 22:08:19 +0000 Subject: got rid of USE_TDB_MMAP_FLAG as its not needed any more (This used to be commit c26e0d3f27a05ecc8bd2390f9aab7f9451524e47) --- source3/utils/smbcontrol.c | 2 +- source3/utils/status.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 377f7a148b..40892ba1c0 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -133,7 +133,7 @@ static BOOL send_message(char *dest, int msg_type, void *buf, int len, BOOL dupl TDB_CONTEXT *tdb; BOOL ret; - tdb = tdb_open_log(lock_path("connections.tdb"), 0, USE_TDB_MMAP_FLAG, O_RDWR, 0); + tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDWR, 0); if (!tdb) { fprintf(stderr,"Failed to open connections database in send_message.\n"); return False; diff --git a/source3/utils/status.c b/source3/utils/status.c index 77e76a34e8..27c6d9b51b 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -619,7 +619,7 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo return profile_dump(); } - tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, USE_TDB_MMAP_FLAG, O_RDONLY, 0); + tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); if (!tdb) { printf("sessionid.tdb not initialised\n"); } @@ -633,7 +633,7 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo tdb_traverse(tdb, traverse_sessionid, NULL); tdb_close(tdb); - tdb = tdb_open_log(lock_path("connections.tdb"), 0, USE_TDB_MMAP_FLAG, O_RDONLY, 0); + tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); if (!tdb) { printf("connections.tdb not initialised\n"); } else if (verbose) { -- cgit From 65c5a1c0ba2cc3dc8e45a499c42191016e658b20 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Sep 2001 02:59:23 +0000 Subject: convert more code to using d_printf (This used to be commit 60d297303488ed583537ca2853828fccd6da2ade) --- source3/utils/nmblookup.c | 52 ++-- source3/utils/status.c | 738 +++++++++++++++++++++++----------------------- 2 files changed, 395 insertions(+), 395 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 5acdf62735..2d86cc0a35 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -62,22 +62,22 @@ usage on the program ****************************************************************************/ static void usage(void) { - printf("Usage: nmblookup [-M] [-B bcast address] [-d debuglevel] name\n"); - printf("Version %s\n",VERSION); - printf("\t-d debuglevel set the debuglevel\n"); - printf("\t-B broadcast address the address to use for broadcasts\n"); - printf("\t-U unicast address the address to use for unicast\n"); - printf("\t-M searches for a master browser\n"); - printf("\t-R set recursion desired in packet\n"); - printf("\t-S lookup node status as well\n"); - printf("\t-T translate IP addresses into names\n"); - printf("\t-r Use root port 137 (Win95 only replies to this)\n"); - printf("\t-A Do a node status on as an IP Address\n"); - printf("\t-i NetBIOS scope Use the given NetBIOS scope for name queries\n"); - printf("\t-s smb.conf file Use the given path to the smb.conf file\n"); - printf("\t-h Print this help message.\n"); - printf("\n If you specify -M and name is \"-\", nmblookup looks up __MSBROWSE__<01>\n"); - printf("\n"); + d_printf("Usage: nmblookup [-M] [-B bcast address] [-d debuglevel] name\n"); + d_printf("Version %s\n",VERSION); + d_printf("\t-d debuglevel set the debuglevel\n"); + d_printf("\t-B broadcast address the address to use for broadcasts\n"); + d_printf("\t-U unicast address the address to use for unicast\n"); + d_printf("\t-M searches for a master browser\n"); + d_printf("\t-R set recursion desired in packet\n"); + d_printf("\t-S lookup node status as well\n"); + d_printf("\t-T translate IP addresses into names\n"); + d_printf("\t-r Use root port 137 (Win95 only replies to this)\n"); + d_printf("\t-A Do a node status on as an IP Address\n"); + d_printf("\t-i NetBIOS scope Use the given NetBIOS scope for name queries\n"); + d_printf("\t-s smb.conf file Use the given path to the smb.conf file\n"); + d_printf("\t-h Print this help message.\n"); + d_printf("\n If you specify -M and name is \"-\", nmblookup looks up __MSBROWSE__<01>\n"); + d_printf("\n"); } /**************************************************************************** @@ -111,7 +111,7 @@ static void do_node_status(int fd, char *name, int type, struct in_addr ip) struct node_status *status; fstring cleanname; - printf("Looking up status of %s\n",inet_ntoa(ip)); + d_printf("Looking up status of %s\n",inet_ntoa(ip)); make_nmb_name(&nname, name, type); status = node_status_query(fd,&nname,ip, &count); if (status) { @@ -120,13 +120,13 @@ static void do_node_status(int fd, char *name, int type, struct in_addr ip) for (j=0;cleanname[j];j++) { if (!isprint((int)cleanname[j])) cleanname[j] = '.'; } - printf("\t%-15s <%02x> - %s\n", + d_printf("\t%-15s <%02x> - %s\n", cleanname,status[i].type, node_status_flags(status[i].flags)); } free(status); } - printf("\n"); + d_printf("\n"); } @@ -139,7 +139,7 @@ static BOOL query_one(char *lookup, unsigned int lookup_type) struct in_addr *ip_list=NULL; if (got_bcast) { - printf("querying %s on %s\n", lookup, inet_ntoa(bcast_addr)); + d_printf("querying %s on %s\n", lookup, inet_ntoa(bcast_addr)); ip_list = name_query(ServerFD,lookup,lookup_type,use_bcast, use_bcast?True:recursion_desired, bcast_addr,&count); @@ -149,7 +149,7 @@ static BOOL query_one(char *lookup, unsigned int lookup_type) !ip_list && j >= 0; j--) { bcast = iface_n_bcast(j); - printf("querying %s on %s\n", + d_printf("querying %s on %s\n", lookup, inet_ntoa(*bcast)); ip_list = name_query(ServerFD,lookup,lookup_type, use_bcast, @@ -164,10 +164,10 @@ static BOOL query_one(char *lookup, unsigned int lookup_type) if (translate_addresses) { struct hostent *host = gethostbyaddr((char *)&ip_list[j], sizeof(ip_list[j]), AF_INET); if (host) { - printf("%s, ", host -> h_name); + d_printf("%s, ", host -> h_name); } } - printf("%s %s<%02x>\n",inet_ntoa(ip_list[j]),lookup, lookup_type); + d_printf("%s %s<%02x>\n",inet_ntoa(ip_list[j]),lookup, lookup_type); } /* We can only do find_status if the ip address returned @@ -310,10 +310,10 @@ int main(int argc,char *argv[]) } if (!query_one(lookup, lookup_type)) { - printf( "name_query failed to find name %s", lookup ); + d_printf( "name_query failed to find name %s", lookup ); if( 0 != lookup_type ) - printf( "#%02x", lookup_type ); - printf( "\n" ); + d_printf( "#%02x", lookup_type ); + d_printf( "\n" ); } } diff --git a/source3/utils/status.c b/source3/utils/status.c index 27c6d9b51b..91eca9f88f 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -91,42 +91,42 @@ static void print_share_mode(share_mode_entry *e, char *fname) { static int count; if (count==0) { - printf("Locked files:\n"); - printf("Pid DenyMode R/W Oplock Name\n"); - printf("--------------------------------------------------\n"); + d_printf("Locked files:\n"); + d_printf("Pid DenyMode R/W Oplock Name\n"); + d_printf("--------------------------------------------------\n"); } count++; if (Ucrit_checkPid(e->pid)) { - printf("%-5d ",(int)e->pid); + d_printf("%-5d ",(int)e->pid); switch (GET_DENY_MODE(e->share_mode)) { - case DENY_NONE: printf("DENY_NONE "); break; - case DENY_ALL: printf("DENY_ALL "); break; - case DENY_DOS: printf("DENY_DOS "); break; - case DENY_READ: printf("DENY_READ "); break; + case DENY_NONE: d_printf("DENY_NONE "); break; + case DENY_ALL: d_printf("DENY_ALL "); break; + case DENY_DOS: d_printf("DENY_DOS "); break; + case DENY_READ: d_printf("DENY_READ "); break; case DENY_WRITE:printf("DENY_WRITE "); break; - case DENY_FCB: printf("DENY_FCB "); break; + case DENY_FCB: d_printf("DENY_FCB "); break; } switch (e->share_mode&0xF) { - case 0: printf("RDONLY "); break; - case 1: printf("WRONLY "); break; - case 2: printf("RDWR "); break; + case 0: d_printf("RDONLY "); break; + case 1: d_printf("WRONLY "); break; + case 2: d_printf("RDWR "); break; } if((e->op_type & (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) - printf("EXCLUSIVE+BATCH "); + d_printf("EXCLUSIVE+BATCH "); else if (e->op_type & EXCLUSIVE_OPLOCK) - printf("EXCLUSIVE "); + d_printf("EXCLUSIVE "); else if (e->op_type & BATCH_OPLOCK) - printf("BATCH "); + d_printf("BATCH "); else if (e->op_type & LEVEL_II_OPLOCK) - printf("LEVEL_II "); + d_printf("LEVEL_II "); else - printf("NONE "); + d_printf("NONE "); - printf(" %s %s",fname, + d_printf(" %s %s",fname, asctime(LocalTime((time_t *)&e->time.tv_sec))); } } @@ -137,13 +137,13 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, { static int count; if (count==0) { - printf("Byte range locks:\n"); - printf(" Pid dev:inode R/W start size\n"); - printf("------------------------------------------------\n"); + d_printf("Byte range locks:\n"); + d_printf(" Pid dev:inode R/W start size\n"); + d_printf("------------------------------------------------\n"); } count++; - printf("%6d %05x:%05x %s %9.0f %9.0f\n", + d_printf("%6d %05x:%05x %s %9.0f %9.0f\n", (int)pid, (int)dev, (int)ino, lock_type==READ_LOCK?"R":"W", (double)start, (double)size); @@ -160,337 +160,337 @@ static int profile_dump(void) return -1; } - printf("smb_count: %u\n", profile_p->smb_count); - printf("uid_changes: %u\n", profile_p->uid_changes); - printf("************************ System Calls ****************************\n"); - printf("opendir_count: %u\n", profile_p->syscall_opendir_count); - printf("opendir_time: %u\n", profile_p->syscall_opendir_time); - printf("readdir_count: %u\n", profile_p->syscall_readdir_count); - printf("readdir_time: %u\n", profile_p->syscall_readdir_time); - printf("mkdir_count: %u\n", profile_p->syscall_mkdir_count); - printf("mkdir_time: %u\n", profile_p->syscall_mkdir_time); - printf("rmdir_count: %u\n", profile_p->syscall_rmdir_count); - printf("rmdir_time: %u\n", profile_p->syscall_rmdir_time); - printf("closedir_count: %u\n", profile_p->syscall_closedir_count); - printf("closedir_time: %u\n", profile_p->syscall_closedir_time); - printf("open_count: %u\n", profile_p->syscall_open_count); - printf("open_time: %u\n", profile_p->syscall_open_time); - printf("close_count: %u\n", profile_p->syscall_close_count); - printf("close_time: %u\n", profile_p->syscall_close_time); - printf("read_count: %u\n", profile_p->syscall_read_count); - printf("read_time: %u\n", profile_p->syscall_read_time); - printf("read_bytes: %u\n", profile_p->syscall_read_bytes); - printf("write_count: %u\n", profile_p->syscall_write_count); - printf("write_time: %u\n", profile_p->syscall_write_time); - printf("write_bytes: %u\n", profile_p->syscall_write_bytes); - printf("lseek_count: %u\n", profile_p->syscall_lseek_count); - printf("lseek_time: %u\n", profile_p->syscall_lseek_time); - printf("rename_count: %u\n", profile_p->syscall_rename_count); - printf("rename_time: %u\n", profile_p->syscall_rename_time); - printf("fsync_count: %u\n", profile_p->syscall_fsync_count); - printf("fsync_time: %u\n", profile_p->syscall_fsync_time); - printf("stat_count: %u\n", profile_p->syscall_stat_count); - printf("stat_time: %u\n", profile_p->syscall_stat_time); - printf("fstat_count: %u\n", profile_p->syscall_fstat_count); - printf("fstat_time: %u\n", profile_p->syscall_fstat_time); - printf("lstat_count: %u\n", profile_p->syscall_lstat_count); - printf("lstat_time: %u\n", profile_p->syscall_lstat_time); - printf("unlink_count: %u\n", profile_p->syscall_unlink_count); - printf("unlink_time: %u\n", profile_p->syscall_unlink_time); - printf("chmod_count: %u\n", profile_p->syscall_chmod_count); - printf("chmod_time: %u\n", profile_p->syscall_chmod_time); - printf("fchmod_count: %u\n", profile_p->syscall_fchmod_count); - printf("fchmod_time: %u\n", profile_p->syscall_fchmod_time); - printf("chown_count: %u\n", profile_p->syscall_chown_count); - printf("chown_time: %u\n", profile_p->syscall_chown_time); - printf("fchown_count: %u\n", profile_p->syscall_fchown_count); - printf("fchown_time: %u\n", profile_p->syscall_fchown_time); - printf("chdir_count: %u\n", profile_p->syscall_chdir_count); - printf("chdir_time: %u\n", profile_p->syscall_chdir_time); - printf("getwd_count: %u\n", profile_p->syscall_getwd_count); - printf("getwd_time: %u\n", profile_p->syscall_getwd_time); - printf("utime_count: %u\n", profile_p->syscall_utime_count); - printf("utime_time: %u\n", profile_p->syscall_utime_time); - printf("ftruncate_count: %u\n", profile_p->syscall_ftruncate_count); - printf("ftruncate_time: %u\n", profile_p->syscall_ftruncate_time); - printf("fcntl_lock_count: %u\n", profile_p->syscall_fcntl_lock_count); - printf("fcntl_lock_time: %u\n", profile_p->syscall_fcntl_lock_time); - printf("readlink_count: %u\n", profile_p->syscall_readlink_count); - printf("readlink_time: %u\n", profile_p->syscall_readlink_time); - printf("symlink_count: %u\n", profile_p->syscall_symlink_count); - printf("symlink_time: %u\n", profile_p->syscall_symlink_time); - printf("************************ Statcache *******************************\n"); - printf("lookups: %u\n", profile_p->statcache_lookups); - printf("misses: %u\n", profile_p->statcache_misses); - printf("hits: %u\n", profile_p->statcache_hits); - printf("************************ Writecache ******************************\n"); - printf("read_hits: %u\n", profile_p->writecache_read_hits); - printf("abutted_writes: %u\n", profile_p->writecache_abutted_writes); - printf("total_writes: %u\n", profile_p->writecache_total_writes); - printf("non_oplock_writes: %u\n", profile_p->writecache_non_oplock_writes); - printf("direct_writes: %u\n", profile_p->writecache_direct_writes); - printf("init_writes: %u\n", profile_p->writecache_init_writes); - printf("flushed_writes[SEEK]: %u\n", profile_p->writecache_flushed_writes[SEEK_FLUSH]); - printf("flushed_writes[READ]: %u\n", profile_p->writecache_flushed_writes[READ_FLUSH]); - printf("flushed_writes[WRITE]: %u\n", profile_p->writecache_flushed_writes[WRITE_FLUSH]); - printf("flushed_writes[READRAW]: %u\n", profile_p->writecache_flushed_writes[READRAW_FLUSH]); - printf("flushed_writes[OPLOCK_RELEASE]: %u\n", profile_p->writecache_flushed_writes[OPLOCK_RELEASE_FLUSH]); - printf("flushed_writes[CLOSE]: %u\n", profile_p->writecache_flushed_writes[CLOSE_FLUSH]); - printf("flushed_writes[SYNC]: %u\n", profile_p->writecache_flushed_writes[SYNC_FLUSH]); - printf("flushed_writes[SIZECHANGE]: %u\n", profile_p->writecache_flushed_writes[SIZECHANGE_FLUSH]); - printf("num_perfect_writes: %u\n", profile_p->writecache_num_perfect_writes); - printf("num_write_caches: %u\n", profile_p->writecache_num_write_caches); - printf("allocated_write_caches: %u\n", profile_p->writecache_allocated_write_caches); - printf("************************ SMB Calls *******************************\n"); - printf("mkdir_count: %u\n", profile_p->SMBmkdir_count); - printf("mkdir_time: %u\n", profile_p->SMBmkdir_time); - printf("rmdir_count: %u\n", profile_p->SMBrmdir_count); - printf("rmdir_time: %u\n", profile_p->SMBrmdir_time); - printf("open_count: %u\n", profile_p->SMBopen_count); - printf("open_time: %u\n", profile_p->SMBopen_time); - printf("create_count: %u\n", profile_p->SMBcreate_count); - printf("create_time: %u\n", profile_p->SMBcreate_time); - printf("close_count: %u\n", profile_p->SMBclose_count); - printf("close_time: %u\n", profile_p->SMBclose_time); - printf("flush_count: %u\n", profile_p->SMBflush_count); - printf("flush_time: %u\n", profile_p->SMBflush_time); - printf("unlink_count: %u\n", profile_p->SMBunlink_count); - printf("unlink_time: %u\n", profile_p->SMBunlink_time); - printf("mv_count: %u\n", profile_p->SMBmv_count); - printf("mv_time: %u\n", profile_p->SMBmv_time); - printf("getatr_count: %u\n", profile_p->SMBgetatr_count); - printf("getatr_time: %u\n", profile_p->SMBgetatr_time); - printf("setatr_count: %u\n", profile_p->SMBsetatr_count); - printf("setatr_time: %u\n", profile_p->SMBsetatr_time); - printf("read_count: %u\n", profile_p->SMBread_count); - printf("read_time: %u\n", profile_p->SMBread_time); - printf("write_count: %u\n", profile_p->SMBwrite_count); - printf("write_time: %u\n", profile_p->SMBwrite_time); - printf("lock_count: %u\n", profile_p->SMBlock_count); - printf("lock_time: %u\n", profile_p->SMBlock_time); - printf("unlock_count: %u\n", profile_p->SMBunlock_count); - printf("unlock_time: %u\n", profile_p->SMBunlock_time); - printf("ctemp_count: %u\n", profile_p->SMBctemp_count); - printf("ctemp_time: %u\n", profile_p->SMBctemp_time); - printf("mknew_count: %u\n", profile_p->SMBmknew_count); - printf("mknew_time: %u\n", profile_p->SMBmknew_time); - printf("chkpth_count: %u\n", profile_p->SMBchkpth_count); - printf("chkpth_time: %u\n", profile_p->SMBchkpth_time); - printf("exit_count: %u\n", profile_p->SMBexit_count); - printf("exit_time: %u\n", profile_p->SMBexit_time); - printf("lseek_count: %u\n", profile_p->SMBlseek_count); - printf("lseek_time: %u\n", profile_p->SMBlseek_time); - printf("lockread_count: %u\n", profile_p->SMBlockread_count); - printf("lockread_time: %u\n", profile_p->SMBlockread_time); - printf("writeunlock_count: %u\n", profile_p->SMBwriteunlock_count); - printf("writeunlock_time: %u\n", profile_p->SMBwriteunlock_time); - printf("readbraw_count: %u\n", profile_p->SMBreadbraw_count); - printf("readbraw_time: %u\n", profile_p->SMBreadbraw_time); - printf("readBmpx_count: %u\n", profile_p->SMBreadBmpx_count); - printf("readBmpx_time: %u\n", profile_p->SMBreadBmpx_time); - printf("readBs_count: %u\n", profile_p->SMBreadBs_count); - printf("readBs_time: %u\n", profile_p->SMBreadBs_time); - printf("writebraw_count: %u\n", profile_p->SMBwritebraw_count); - printf("writebraw_time: %u\n", profile_p->SMBwritebraw_time); - printf("writeBmpx_count: %u\n", profile_p->SMBwriteBmpx_count); - printf("writeBmpx_time: %u\n", profile_p->SMBwriteBmpx_time); - printf("writeBs_count: %u\n", profile_p->SMBwriteBs_count); - printf("writeBs_time: %u\n", profile_p->SMBwriteBs_time); - printf("writec_count: %u\n", profile_p->SMBwritec_count); - printf("writec_time: %u\n", profile_p->SMBwritec_time); - printf("setattrE_count: %u\n", profile_p->SMBsetattrE_count); - printf("setattrE_time: %u\n", profile_p->SMBsetattrE_time); - printf("getattrE_count: %u\n", profile_p->SMBgetattrE_count); - printf("getattrE_time: %u\n", profile_p->SMBgetattrE_time); - printf("lockingX_count: %u\n", profile_p->SMBlockingX_count); - printf("lockingX_time: %u\n", profile_p->SMBlockingX_time); - printf("trans_count: %u\n", profile_p->SMBtrans_count); - printf("trans_time: %u\n", profile_p->SMBtrans_time); - printf("transs_count: %u\n", profile_p->SMBtranss_count); - printf("transs_time: %u\n", profile_p->SMBtranss_time); - printf("ioctl_count: %u\n", profile_p->SMBioctl_count); - printf("ioctl_time: %u\n", profile_p->SMBioctl_time); - printf("ioctls_count: %u\n", profile_p->SMBioctls_count); - printf("ioctls_time: %u\n", profile_p->SMBioctls_time); - printf("copy_count: %u\n", profile_p->SMBcopy_count); - printf("copy_time: %u\n", profile_p->SMBcopy_time); - printf("move_count: %u\n", profile_p->SMBmove_count); - printf("move_time: %u\n", profile_p->SMBmove_time); - printf("echo_count: %u\n", profile_p->SMBecho_count); - printf("echo_time: %u\n", profile_p->SMBecho_time); - printf("writeclose_count: %u\n", profile_p->SMBwriteclose_count); - printf("writeclose_time: %u\n", profile_p->SMBwriteclose_time); - printf("openX_count: %u\n", profile_p->SMBopenX_count); - printf("openX_time: %u\n", profile_p->SMBopenX_time); - printf("readX_count: %u\n", profile_p->SMBreadX_count); - printf("readX_time: %u\n", profile_p->SMBreadX_time); - printf("writeX_count: %u\n", profile_p->SMBwriteX_count); - printf("writeX_time: %u\n", profile_p->SMBwriteX_time); - printf("trans2_count: %u\n", profile_p->SMBtrans2_count); - printf("trans2_time: %u\n", profile_p->SMBtrans2_time); - printf("transs2_count: %u\n", profile_p->SMBtranss2_count); - printf("transs2_time: %u\n", profile_p->SMBtranss2_time); - printf("findclose_count: %u\n", profile_p->SMBfindclose_count); - printf("findclose_time: %u\n", profile_p->SMBfindclose_time); - printf("findnclose_count: %u\n", profile_p->SMBfindnclose_count); - printf("findnclose_time: %u\n", profile_p->SMBfindnclose_time); - printf("tcon_count: %u\n", profile_p->SMBtcon_count); - printf("tcon_time: %u\n", profile_p->SMBtcon_time); - printf("tdis_count: %u\n", profile_p->SMBtdis_count); - printf("tdis_time: %u\n", profile_p->SMBtdis_time); - printf("negprot_count: %u\n", profile_p->SMBnegprot_count); - printf("negprot_time: %u\n", profile_p->SMBnegprot_time); - printf("sesssetupX_count: %u\n", profile_p->SMBsesssetupX_count); - printf("sesssetupX_time: %u\n", profile_p->SMBsesssetupX_time); - printf("ulogoffX_count: %u\n", profile_p->SMBulogoffX_count); - printf("ulogoffX_time: %u\n", profile_p->SMBulogoffX_time); - printf("tconX_count: %u\n", profile_p->SMBtconX_count); - printf("tconX_time: %u\n", profile_p->SMBtconX_time); - printf("dskattr_count: %u\n", profile_p->SMBdskattr_count); - printf("dskattr_time: %u\n", profile_p->SMBdskattr_time); - printf("search_count: %u\n", profile_p->SMBsearch_count); - printf("search_time: %u\n", profile_p->SMBsearch_time); - printf("ffirst_count: %u\n", profile_p->SMBffirst_count); - printf("ffirst_time: %u\n", profile_p->SMBffirst_time); - printf("funique_count: %u\n", profile_p->SMBfunique_count); - printf("funique_time: %u\n", profile_p->SMBfunique_time); - printf("fclose_count: %u\n", profile_p->SMBfclose_count); - printf("fclose_time: %u\n", profile_p->SMBfclose_time); - printf("nttrans_count: %u\n", profile_p->SMBnttrans_count); - printf("nttrans_time: %u\n", profile_p->SMBnttrans_time); - printf("nttranss_count: %u\n", profile_p->SMBnttranss_count); - printf("nttranss_time: %u\n", profile_p->SMBnttranss_time); - printf("ntcreateX_count: %u\n", profile_p->SMBntcreateX_count); - printf("ntcreateX_time: %u\n", profile_p->SMBntcreateX_time); - printf("ntcancel_count: %u\n", profile_p->SMBntcancel_count); - printf("ntcancel_time: %u\n", profile_p->SMBntcancel_time); - printf("splopen_count: %u\n", profile_p->SMBsplopen_count); - printf("splopen_time: %u\n", profile_p->SMBsplopen_time); - printf("splwr_count: %u\n", profile_p->SMBsplwr_count); - printf("splwr_time: %u\n", profile_p->SMBsplwr_time); - printf("splclose_count: %u\n", profile_p->SMBsplclose_count); - printf("splclose_time: %u\n", profile_p->SMBsplclose_time); - printf("splretq_count: %u\n", profile_p->SMBsplretq_count); - printf("splretq_time: %u\n", profile_p->SMBsplretq_time); - printf("sends_count: %u\n", profile_p->SMBsends_count); - printf("sends_time: %u\n", profile_p->SMBsends_time); - printf("sendb_count: %u\n", profile_p->SMBsendb_count); - printf("sendb_time: %u\n", profile_p->SMBsendb_time); - printf("fwdname_count: %u\n", profile_p->SMBfwdname_count); - printf("fwdname_time: %u\n", profile_p->SMBfwdname_time); - printf("cancelf_count: %u\n", profile_p->SMBcancelf_count); - printf("cancelf_time: %u\n", profile_p->SMBcancelf_time); - printf("getmac_count: %u\n", profile_p->SMBgetmac_count); - printf("getmac_time: %u\n", profile_p->SMBgetmac_time); - printf("sendstrt_count: %u\n", profile_p->SMBsendstrt_count); - printf("sendstrt_time: %u\n", profile_p->SMBsendstrt_time); - printf("sendend_count: %u\n", profile_p->SMBsendend_count); - printf("sendend_time: %u\n", profile_p->SMBsendend_time); - printf("sendtxt_count: %u\n", profile_p->SMBsendtxt_count); - printf("sendtxt_time: %u\n", profile_p->SMBsendtxt_time); - printf("invalid_count: %u\n", profile_p->SMBinvalid_count); - printf("invalid_time: %u\n", profile_p->SMBinvalid_time); - printf("************************ Pathworks Calls *************************\n"); - printf("setdir_count: %u\n", profile_p->pathworks_setdir_count); - printf("setdir_time: %u\n", profile_p->pathworks_setdir_time); - printf("************************ Trans2 Calls ****************************\n"); - printf("open_count: %u\n", profile_p->Trans2_open_count); - printf("open_time: %u\n", profile_p->Trans2_open_time); - printf("findfirst_count: %u\n", profile_p->Trans2_findfirst_count); - printf("findfirst_time: %u\n", profile_p->Trans2_findfirst_time); - printf("findnext_count: %u\n", profile_p->Trans2_findnext_count); - printf("findnext_time: %u\n", profile_p->Trans2_findnext_time); - printf("qfsinfo_count: %u\n", profile_p->Trans2_qfsinfo_count); - printf("qfsinfo_time: %u\n", profile_p->Trans2_qfsinfo_time); - printf("setfsinfo_count: %u\n", profile_p->Trans2_setfsinfo_count); - printf("setfsinfo_time: %u\n", profile_p->Trans2_setfsinfo_time); - printf("qpathinfo_count: %u\n", profile_p->Trans2_qpathinfo_count); - printf("qpathinfo_time: %u\n", profile_p->Trans2_qpathinfo_time); - printf("setpathinfo_count: %u\n", profile_p->Trans2_setpathinfo_count); - printf("setpathinfo_time: %u\n", profile_p->Trans2_setpathinfo_time); - printf("qfileinfo_count: %u\n", profile_p->Trans2_qfileinfo_count); - printf("qfileinfo_time: %u\n", profile_p->Trans2_qfileinfo_time); - printf("setfileinfo_count: %u\n", profile_p->Trans2_setfileinfo_count); - printf("setfileinfo_time: %u\n", profile_p->Trans2_setfileinfo_time); - printf("fsctl_count: %u\n", profile_p->Trans2_fsctl_count); - printf("fsctl_time: %u\n", profile_p->Trans2_fsctl_time); - printf("ioctl_count: %u\n", profile_p->Trans2_ioctl_count); - printf("ioctl_time: %u\n", profile_p->Trans2_ioctl_time); - printf("findnotifyfirst_count: %u\n", profile_p->Trans2_findnotifyfirst_count); - printf("findnotifyfirst_time: %u\n", profile_p->Trans2_findnotifyfirst_time); - printf("findnotifynext_count: %u\n", profile_p->Trans2_findnotifynext_count); - printf("findnotifynext_time: %u\n", profile_p->Trans2_findnotifynext_time); - printf("mkdir_count: %u\n", profile_p->Trans2_mkdir_count); - printf("mkdir_time: %u\n", profile_p->Trans2_mkdir_time); - printf("session_setup_count: %u\n", profile_p->Trans2_session_setup_count); - printf("session_setup_time: %u\n", profile_p->Trans2_session_setup_time); - printf("get_dfs_referral_count: %u\n", profile_p->Trans2_get_dfs_referral_count); - printf("get_dfs_referral_time: %u\n", profile_p->Trans2_get_dfs_referral_time); - printf("report_dfs_inconsistancy_count: %u\n", profile_p->Trans2_report_dfs_inconsistancy_count); - printf("report_dfs_inconsistancy_time: %u\n", profile_p->Trans2_report_dfs_inconsistancy_time); - printf("************************ NT Transact Calls ***********************\n"); - printf("create_count: %u\n", profile_p->NT_transact_create_count); - printf("create_time: %u\n", profile_p->NT_transact_create_time); - printf("ioctl_count: %u\n", profile_p->NT_transact_ioctl_count); - printf("ioctl_time: %u\n", profile_p->NT_transact_ioctl_time); - printf("set_security_desc_count: %u\n", profile_p->NT_transact_set_security_desc_count); - printf("set_security_desc_time: %u\n", profile_p->NT_transact_set_security_desc_time); - printf("notify_change_count: %u\n", profile_p->NT_transact_notify_change_count); - printf("notify_change_time: %u\n", profile_p->NT_transact_notify_change_time); - printf("rename_count: %u\n", profile_p->NT_transact_rename_count); - printf("rename_time: %u\n", profile_p->NT_transact_rename_time); - printf("query_security_desc_count: %u\n", profile_p->NT_transact_query_security_desc_count); - printf("query_security_desc_time: %u\n", profile_p->NT_transact_query_security_desc_time); - printf("************************ ACL Calls *******************************\n"); - printf("get_nt_acl_count: %u\n", profile_p->get_nt_acl_count); - printf("get_nt_acl_time: %u\n", profile_p->get_nt_acl_time); - printf("fget_nt_acl_count: %u\n", profile_p->fget_nt_acl_count); - printf("fget_nt_acl_time: %u\n", profile_p->fget_nt_acl_time); - printf("set_nt_acl_count: %u\n", profile_p->set_nt_acl_count); - printf("set_nt_acl_time: %u\n", profile_p->set_nt_acl_time); - printf("fset_nt_acl_count: %u\n", profile_p->fset_nt_acl_count); - printf("fset_nt_acl_time: %u\n", profile_p->fset_nt_acl_time); - printf("chmod_acl_count: %u\n", profile_p->chmod_acl_count); - printf("chmod_acl_time: %u\n", profile_p->chmod_acl_time); - printf("fchmod_acl_count: %u\n", profile_p->fchmod_acl_count); - printf("fchmod_acl_time: %u\n", profile_p->fchmod_acl_time); - printf("************************ NMBD Calls ****************************\n"); - printf("name_release_count: %u\n", profile_p->name_release_count); - printf("name_release_time: %u\n", profile_p->name_release_time); - printf("name_refresh_count: %u\n", profile_p->name_refresh_count); - printf("name_refresh_time: %u\n", profile_p->name_refresh_time); - printf("name_registration_count: %u\n", profile_p->name_registration_count); - printf("name_registration_time: %u\n", profile_p->name_registration_time); - printf("node_status_count: %u\n", profile_p->node_status_count); - printf("node_status_time: %u\n", profile_p->node_status_time); - printf("name_query_count: %u\n", profile_p->name_query_count); - printf("name_query_time: %u\n", profile_p->name_query_time); - printf("host_announce_count: %u\n", profile_p->host_announce_count); - printf("host_announce_time: %u\n", profile_p->host_announce_time); - printf("workgroup_announce_count: %u\n", profile_p->workgroup_announce_count); - printf("workgroup_announce_time: %u\n", profile_p->workgroup_announce_time); - printf("local_master_announce_count: %u\n", profile_p->local_master_announce_count); - printf("local_master_announce_time: %u\n", profile_p->local_master_announce_time); - printf("master_browser_announce_count: %u\n", profile_p->master_browser_announce_count); - printf("master_browser_announce_time: %u\n", profile_p->master_browser_announce_time); - printf("lm_host_announce_count: %u\n", profile_p->lm_host_announce_count); - printf("lm_host_announce_time: %u\n", profile_p->lm_host_announce_time); - printf("get_backup_list_count: %u\n", profile_p->get_backup_list_count); - printf("get_backup_list_time: %u\n", profile_p->get_backup_list_time); - printf("reset_browser_count: %u\n", profile_p->reset_browser_count); - printf("reset_browser_time: %u\n", profile_p->reset_browser_time); - printf("announce_request_count: %u\n", profile_p->announce_request_count); - printf("announce_request_time: %u\n", profile_p->announce_request_time); - printf("lm_announce_request_count: %u\n", profile_p->lm_announce_request_count); - printf("lm_announce_request_time: %u\n", profile_p->lm_announce_request_time); - printf("domain_logon_count: %u\n", profile_p->domain_logon_count); - printf("domain_logon_time: %u\n", profile_p->domain_logon_time); - printf("sync_browse_lists_count: %u\n", profile_p->sync_browse_lists_count); - printf("sync_browse_lists_time: %u\n", profile_p->sync_browse_lists_time); - printf("run_elections_count: %u\n", profile_p->run_elections_count); - printf("run_elections_time: %u\n", profile_p->run_elections_time); - printf("election_count: %u\n", profile_p->election_count); - printf("election_time: %u\n", profile_p->election_time); + d_printf("smb_count: %u\n", profile_p->smb_count); + d_printf("uid_changes: %u\n", profile_p->uid_changes); + d_printf("************************ System Calls ****************************\n"); + d_printf("opendir_count: %u\n", profile_p->syscall_opendir_count); + d_printf("opendir_time: %u\n", profile_p->syscall_opendir_time); + d_printf("readdir_count: %u\n", profile_p->syscall_readdir_count); + d_printf("readdir_time: %u\n", profile_p->syscall_readdir_time); + d_printf("mkdir_count: %u\n", profile_p->syscall_mkdir_count); + d_printf("mkdir_time: %u\n", profile_p->syscall_mkdir_time); + d_printf("rmdir_count: %u\n", profile_p->syscall_rmdir_count); + d_printf("rmdir_time: %u\n", profile_p->syscall_rmdir_time); + d_printf("closedir_count: %u\n", profile_p->syscall_closedir_count); + d_printf("closedir_time: %u\n", profile_p->syscall_closedir_time); + d_printf("open_count: %u\n", profile_p->syscall_open_count); + d_printf("open_time: %u\n", profile_p->syscall_open_time); + d_printf("close_count: %u\n", profile_p->syscall_close_count); + d_printf("close_time: %u\n", profile_p->syscall_close_time); + d_printf("read_count: %u\n", profile_p->syscall_read_count); + d_printf("read_time: %u\n", profile_p->syscall_read_time); + d_printf("read_bytes: %u\n", profile_p->syscall_read_bytes); + d_printf("write_count: %u\n", profile_p->syscall_write_count); + d_printf("write_time: %u\n", profile_p->syscall_write_time); + d_printf("write_bytes: %u\n", profile_p->syscall_write_bytes); + d_printf("lseek_count: %u\n", profile_p->syscall_lseek_count); + d_printf("lseek_time: %u\n", profile_p->syscall_lseek_time); + d_printf("rename_count: %u\n", profile_p->syscall_rename_count); + d_printf("rename_time: %u\n", profile_p->syscall_rename_time); + d_printf("fsync_count: %u\n", profile_p->syscall_fsync_count); + d_printf("fsync_time: %u\n", profile_p->syscall_fsync_time); + d_printf("stat_count: %u\n", profile_p->syscall_stat_count); + d_printf("stat_time: %u\n", profile_p->syscall_stat_time); + d_printf("fstat_count: %u\n", profile_p->syscall_fstat_count); + d_printf("fstat_time: %u\n", profile_p->syscall_fstat_time); + d_printf("lstat_count: %u\n", profile_p->syscall_lstat_count); + d_printf("lstat_time: %u\n", profile_p->syscall_lstat_time); + d_printf("unlink_count: %u\n", profile_p->syscall_unlink_count); + d_printf("unlink_time: %u\n", profile_p->syscall_unlink_time); + d_printf("chmod_count: %u\n", profile_p->syscall_chmod_count); + d_printf("chmod_time: %u\n", profile_p->syscall_chmod_time); + d_printf("fchmod_count: %u\n", profile_p->syscall_fchmod_count); + d_printf("fchmod_time: %u\n", profile_p->syscall_fchmod_time); + d_printf("chown_count: %u\n", profile_p->syscall_chown_count); + d_printf("chown_time: %u\n", profile_p->syscall_chown_time); + d_printf("fchown_count: %u\n", profile_p->syscall_fchown_count); + d_printf("fchown_time: %u\n", profile_p->syscall_fchown_time); + d_printf("chdir_count: %u\n", profile_p->syscall_chdir_count); + d_printf("chdir_time: %u\n", profile_p->syscall_chdir_time); + d_printf("getwd_count: %u\n", profile_p->syscall_getwd_count); + d_printf("getwd_time: %u\n", profile_p->syscall_getwd_time); + d_printf("utime_count: %u\n", profile_p->syscall_utime_count); + d_printf("utime_time: %u\n", profile_p->syscall_utime_time); + d_printf("ftruncate_count: %u\n", profile_p->syscall_ftruncate_count); + d_printf("ftruncate_time: %u\n", profile_p->syscall_ftruncate_time); + d_printf("fcntl_lock_count: %u\n", profile_p->syscall_fcntl_lock_count); + d_printf("fcntl_lock_time: %u\n", profile_p->syscall_fcntl_lock_time); + d_printf("readlink_count: %u\n", profile_p->syscall_readlink_count); + d_printf("readlink_time: %u\n", profile_p->syscall_readlink_time); + d_printf("symlink_count: %u\n", profile_p->syscall_symlink_count); + d_printf("symlink_time: %u\n", profile_p->syscall_symlink_time); + d_printf("************************ Statcache *******************************\n"); + d_printf("lookups: %u\n", profile_p->statcache_lookups); + d_printf("misses: %u\n", profile_p->statcache_misses); + d_printf("hits: %u\n", profile_p->statcache_hits); + d_printf("************************ Writecache ******************************\n"); + d_printf("read_hits: %u\n", profile_p->writecache_read_hits); + d_printf("abutted_writes: %u\n", profile_p->writecache_abutted_writes); + d_printf("total_writes: %u\n", profile_p->writecache_total_writes); + d_printf("non_oplock_writes: %u\n", profile_p->writecache_non_oplock_writes); + d_printf("direct_writes: %u\n", profile_p->writecache_direct_writes); + d_printf("init_writes: %u\n", profile_p->writecache_init_writes); + d_printf("flushed_writes[SEEK]: %u\n", profile_p->writecache_flushed_writes[SEEK_FLUSH]); + d_printf("flushed_writes[READ]: %u\n", profile_p->writecache_flushed_writes[READ_FLUSH]); + d_printf("flushed_writes[WRITE]: %u\n", profile_p->writecache_flushed_writes[WRITE_FLUSH]); + d_printf("flushed_writes[READRAW]: %u\n", profile_p->writecache_flushed_writes[READRAW_FLUSH]); + d_printf("flushed_writes[OPLOCK_RELEASE]: %u\n", profile_p->writecache_flushed_writes[OPLOCK_RELEASE_FLUSH]); + d_printf("flushed_writes[CLOSE]: %u\n", profile_p->writecache_flushed_writes[CLOSE_FLUSH]); + d_printf("flushed_writes[SYNC]: %u\n", profile_p->writecache_flushed_writes[SYNC_FLUSH]); + d_printf("flushed_writes[SIZECHANGE]: %u\n", profile_p->writecache_flushed_writes[SIZECHANGE_FLUSH]); + d_printf("num_perfect_writes: %u\n", profile_p->writecache_num_perfect_writes); + d_printf("num_write_caches: %u\n", profile_p->writecache_num_write_caches); + d_printf("allocated_write_caches: %u\n", profile_p->writecache_allocated_write_caches); + d_printf("************************ SMB Calls *******************************\n"); + d_printf("mkdir_count: %u\n", profile_p->SMBmkdir_count); + d_printf("mkdir_time: %u\n", profile_p->SMBmkdir_time); + d_printf("rmdir_count: %u\n", profile_p->SMBrmdir_count); + d_printf("rmdir_time: %u\n", profile_p->SMBrmdir_time); + d_printf("open_count: %u\n", profile_p->SMBopen_count); + d_printf("open_time: %u\n", profile_p->SMBopen_time); + d_printf("create_count: %u\n", profile_p->SMBcreate_count); + d_printf("create_time: %u\n", profile_p->SMBcreate_time); + d_printf("close_count: %u\n", profile_p->SMBclose_count); + d_printf("close_time: %u\n", profile_p->SMBclose_time); + d_printf("flush_count: %u\n", profile_p->SMBflush_count); + d_printf("flush_time: %u\n", profile_p->SMBflush_time); + d_printf("unlink_count: %u\n", profile_p->SMBunlink_count); + d_printf("unlink_time: %u\n", profile_p->SMBunlink_time); + d_printf("mv_count: %u\n", profile_p->SMBmv_count); + d_printf("mv_time: %u\n", profile_p->SMBmv_time); + d_printf("getatr_count: %u\n", profile_p->SMBgetatr_count); + d_printf("getatr_time: %u\n", profile_p->SMBgetatr_time); + d_printf("setatr_count: %u\n", profile_p->SMBsetatr_count); + d_printf("setatr_time: %u\n", profile_p->SMBsetatr_time); + d_printf("read_count: %u\n", profile_p->SMBread_count); + d_printf("read_time: %u\n", profile_p->SMBread_time); + d_printf("write_count: %u\n", profile_p->SMBwrite_count); + d_printf("write_time: %u\n", profile_p->SMBwrite_time); + d_printf("lock_count: %u\n", profile_p->SMBlock_count); + d_printf("lock_time: %u\n", profile_p->SMBlock_time); + d_printf("unlock_count: %u\n", profile_p->SMBunlock_count); + d_printf("unlock_time: %u\n", profile_p->SMBunlock_time); + d_printf("ctemp_count: %u\n", profile_p->SMBctemp_count); + d_printf("ctemp_time: %u\n", profile_p->SMBctemp_time); + d_printf("mknew_count: %u\n", profile_p->SMBmknew_count); + d_printf("mknew_time: %u\n", profile_p->SMBmknew_time); + d_printf("chkpth_count: %u\n", profile_p->SMBchkpth_count); + d_printf("chkpth_time: %u\n", profile_p->SMBchkpth_time); + d_printf("exit_count: %u\n", profile_p->SMBexit_count); + d_printf("exit_time: %u\n", profile_p->SMBexit_time); + d_printf("lseek_count: %u\n", profile_p->SMBlseek_count); + d_printf("lseek_time: %u\n", profile_p->SMBlseek_time); + d_printf("lockread_count: %u\n", profile_p->SMBlockread_count); + d_printf("lockread_time: %u\n", profile_p->SMBlockread_time); + d_printf("writeunlock_count: %u\n", profile_p->SMBwriteunlock_count); + d_printf("writeunlock_time: %u\n", profile_p->SMBwriteunlock_time); + d_printf("readbraw_count: %u\n", profile_p->SMBreadbraw_count); + d_printf("readbraw_time: %u\n", profile_p->SMBreadbraw_time); + d_printf("readBmpx_count: %u\n", profile_p->SMBreadBmpx_count); + d_printf("readBmpx_time: %u\n", profile_p->SMBreadBmpx_time); + d_printf("readBs_count: %u\n", profile_p->SMBreadBs_count); + d_printf("readBs_time: %u\n", profile_p->SMBreadBs_time); + d_printf("writebraw_count: %u\n", profile_p->SMBwritebraw_count); + d_printf("writebraw_time: %u\n", profile_p->SMBwritebraw_time); + d_printf("writeBmpx_count: %u\n", profile_p->SMBwriteBmpx_count); + d_printf("writeBmpx_time: %u\n", profile_p->SMBwriteBmpx_time); + d_printf("writeBs_count: %u\n", profile_p->SMBwriteBs_count); + d_printf("writeBs_time: %u\n", profile_p->SMBwriteBs_time); + d_printf("writec_count: %u\n", profile_p->SMBwritec_count); + d_printf("writec_time: %u\n", profile_p->SMBwritec_time); + d_printf("setattrE_count: %u\n", profile_p->SMBsetattrE_count); + d_printf("setattrE_time: %u\n", profile_p->SMBsetattrE_time); + d_printf("getattrE_count: %u\n", profile_p->SMBgetattrE_count); + d_printf("getattrE_time: %u\n", profile_p->SMBgetattrE_time); + d_printf("lockingX_count: %u\n", profile_p->SMBlockingX_count); + d_printf("lockingX_time: %u\n", profile_p->SMBlockingX_time); + d_printf("trans_count: %u\n", profile_p->SMBtrans_count); + d_printf("trans_time: %u\n", profile_p->SMBtrans_time); + d_printf("transs_count: %u\n", profile_p->SMBtranss_count); + d_printf("transs_time: %u\n", profile_p->SMBtranss_time); + d_printf("ioctl_count: %u\n", profile_p->SMBioctl_count); + d_printf("ioctl_time: %u\n", profile_p->SMBioctl_time); + d_printf("ioctls_count: %u\n", profile_p->SMBioctls_count); + d_printf("ioctls_time: %u\n", profile_p->SMBioctls_time); + d_printf("copy_count: %u\n", profile_p->SMBcopy_count); + d_printf("copy_time: %u\n", profile_p->SMBcopy_time); + d_printf("move_count: %u\n", profile_p->SMBmove_count); + d_printf("move_time: %u\n", profile_p->SMBmove_time); + d_printf("echo_count: %u\n", profile_p->SMBecho_count); + d_printf("echo_time: %u\n", profile_p->SMBecho_time); + d_printf("writeclose_count: %u\n", profile_p->SMBwriteclose_count); + d_printf("writeclose_time: %u\n", profile_p->SMBwriteclose_time); + d_printf("openX_count: %u\n", profile_p->SMBopenX_count); + d_printf("openX_time: %u\n", profile_p->SMBopenX_time); + d_printf("readX_count: %u\n", profile_p->SMBreadX_count); + d_printf("readX_time: %u\n", profile_p->SMBreadX_time); + d_printf("writeX_count: %u\n", profile_p->SMBwriteX_count); + d_printf("writeX_time: %u\n", profile_p->SMBwriteX_time); + d_printf("trans2_count: %u\n", profile_p->SMBtrans2_count); + d_printf("trans2_time: %u\n", profile_p->SMBtrans2_time); + d_printf("transs2_count: %u\n", profile_p->SMBtranss2_count); + d_printf("transs2_time: %u\n", profile_p->SMBtranss2_time); + d_printf("findclose_count: %u\n", profile_p->SMBfindclose_count); + d_printf("findclose_time: %u\n", profile_p->SMBfindclose_time); + d_printf("findnclose_count: %u\n", profile_p->SMBfindnclose_count); + d_printf("findnclose_time: %u\n", profile_p->SMBfindnclose_time); + d_printf("tcon_count: %u\n", profile_p->SMBtcon_count); + d_printf("tcon_time: %u\n", profile_p->SMBtcon_time); + d_printf("tdis_count: %u\n", profile_p->SMBtdis_count); + d_printf("tdis_time: %u\n", profile_p->SMBtdis_time); + d_printf("negprot_count: %u\n", profile_p->SMBnegprot_count); + d_printf("negprot_time: %u\n", profile_p->SMBnegprot_time); + d_printf("sesssetupX_count: %u\n", profile_p->SMBsesssetupX_count); + d_printf("sesssetupX_time: %u\n", profile_p->SMBsesssetupX_time); + d_printf("ulogoffX_count: %u\n", profile_p->SMBulogoffX_count); + d_printf("ulogoffX_time: %u\n", profile_p->SMBulogoffX_time); + d_printf("tconX_count: %u\n", profile_p->SMBtconX_count); + d_printf("tconX_time: %u\n", profile_p->SMBtconX_time); + d_printf("dskattr_count: %u\n", profile_p->SMBdskattr_count); + d_printf("dskattr_time: %u\n", profile_p->SMBdskattr_time); + d_printf("search_count: %u\n", profile_p->SMBsearch_count); + d_printf("search_time: %u\n", profile_p->SMBsearch_time); + d_printf("ffirst_count: %u\n", profile_p->SMBffirst_count); + d_printf("ffirst_time: %u\n", profile_p->SMBffirst_time); + d_printf("funique_count: %u\n", profile_p->SMBfunique_count); + d_printf("funique_time: %u\n", profile_p->SMBfunique_time); + d_printf("fclose_count: %u\n", profile_p->SMBfclose_count); + d_printf("fclose_time: %u\n", profile_p->SMBfclose_time); + d_printf("nttrans_count: %u\n", profile_p->SMBnttrans_count); + d_printf("nttrans_time: %u\n", profile_p->SMBnttrans_time); + d_printf("nttranss_count: %u\n", profile_p->SMBnttranss_count); + d_printf("nttranss_time: %u\n", profile_p->SMBnttranss_time); + d_printf("ntcreateX_count: %u\n", profile_p->SMBntcreateX_count); + d_printf("ntcreateX_time: %u\n", profile_p->SMBntcreateX_time); + d_printf("ntcancel_count: %u\n", profile_p->SMBntcancel_count); + d_printf("ntcancel_time: %u\n", profile_p->SMBntcancel_time); + d_printf("splopen_count: %u\n", profile_p->SMBsplopen_count); + d_printf("splopen_time: %u\n", profile_p->SMBsplopen_time); + d_printf("splwr_count: %u\n", profile_p->SMBsplwr_count); + d_printf("splwr_time: %u\n", profile_p->SMBsplwr_time); + d_printf("splclose_count: %u\n", profile_p->SMBsplclose_count); + d_printf("splclose_time: %u\n", profile_p->SMBsplclose_time); + d_printf("splretq_count: %u\n", profile_p->SMBsplretq_count); + d_printf("splretq_time: %u\n", profile_p->SMBsplretq_time); + d_printf("sends_count: %u\n", profile_p->SMBsends_count); + d_printf("sends_time: %u\n", profile_p->SMBsends_time); + d_printf("sendb_count: %u\n", profile_p->SMBsendb_count); + d_printf("sendb_time: %u\n", profile_p->SMBsendb_time); + d_printf("fwdname_count: %u\n", profile_p->SMBfwdname_count); + d_printf("fwdname_time: %u\n", profile_p->SMBfwdname_time); + d_printf("cancelf_count: %u\n", profile_p->SMBcancelf_count); + d_printf("cancelf_time: %u\n", profile_p->SMBcancelf_time); + d_printf("getmac_count: %u\n", profile_p->SMBgetmac_count); + d_printf("getmac_time: %u\n", profile_p->SMBgetmac_time); + d_printf("sendstrt_count: %u\n", profile_p->SMBsendstrt_count); + d_printf("sendstrt_time: %u\n", profile_p->SMBsendstrt_time); + d_printf("sendend_count: %u\n", profile_p->SMBsendend_count); + d_printf("sendend_time: %u\n", profile_p->SMBsendend_time); + d_printf("sendtxt_count: %u\n", profile_p->SMBsendtxt_count); + d_printf("sendtxt_time: %u\n", profile_p->SMBsendtxt_time); + d_printf("invalid_count: %u\n", profile_p->SMBinvalid_count); + d_printf("invalid_time: %u\n", profile_p->SMBinvalid_time); + d_printf("************************ Pathworks Calls *************************\n"); + d_printf("setdir_count: %u\n", profile_p->pathworks_setdir_count); + d_printf("setdir_time: %u\n", profile_p->pathworks_setdir_time); + d_printf("************************ Trans2 Calls ****************************\n"); + d_printf("open_count: %u\n", profile_p->Trans2_open_count); + d_printf("open_time: %u\n", profile_p->Trans2_open_time); + d_printf("findfirst_count: %u\n", profile_p->Trans2_findfirst_count); + d_printf("findfirst_time: %u\n", profile_p->Trans2_findfirst_time); + d_printf("findnext_count: %u\n", profile_p->Trans2_findnext_count); + d_printf("findnext_time: %u\n", profile_p->Trans2_findnext_time); + d_printf("qfsinfo_count: %u\n", profile_p->Trans2_qfsinfo_count); + d_printf("qfsinfo_time: %u\n", profile_p->Trans2_qfsinfo_time); + d_printf("setfsinfo_count: %u\n", profile_p->Trans2_setfsinfo_count); + d_printf("setfsinfo_time: %u\n", profile_p->Trans2_setfsinfo_time); + d_printf("qpathinfo_count: %u\n", profile_p->Trans2_qpathinfo_count); + d_printf("qpathinfo_time: %u\n", profile_p->Trans2_qpathinfo_time); + d_printf("setpathinfo_count: %u\n", profile_p->Trans2_setpathinfo_count); + d_printf("setpathinfo_time: %u\n", profile_p->Trans2_setpathinfo_time); + d_printf("qfileinfo_count: %u\n", profile_p->Trans2_qfileinfo_count); + d_printf("qfileinfo_time: %u\n", profile_p->Trans2_qfileinfo_time); + d_printf("setfileinfo_count: %u\n", profile_p->Trans2_setfileinfo_count); + d_printf("setfileinfo_time: %u\n", profile_p->Trans2_setfileinfo_time); + d_printf("fsctl_count: %u\n", profile_p->Trans2_fsctl_count); + d_printf("fsctl_time: %u\n", profile_p->Trans2_fsctl_time); + d_printf("ioctl_count: %u\n", profile_p->Trans2_ioctl_count); + d_printf("ioctl_time: %u\n", profile_p->Trans2_ioctl_time); + d_printf("findnotifyfirst_count: %u\n", profile_p->Trans2_findnotifyfirst_count); + d_printf("findnotifyfirst_time: %u\n", profile_p->Trans2_findnotifyfirst_time); + d_printf("findnotifynext_count: %u\n", profile_p->Trans2_findnotifynext_count); + d_printf("findnotifynext_time: %u\n", profile_p->Trans2_findnotifynext_time); + d_printf("mkdir_count: %u\n", profile_p->Trans2_mkdir_count); + d_printf("mkdir_time: %u\n", profile_p->Trans2_mkdir_time); + d_printf("session_setup_count: %u\n", profile_p->Trans2_session_setup_count); + d_printf("session_setup_time: %u\n", profile_p->Trans2_session_setup_time); + d_printf("get_dfs_referral_count: %u\n", profile_p->Trans2_get_dfs_referral_count); + d_printf("get_dfs_referral_time: %u\n", profile_p->Trans2_get_dfs_referral_time); + d_printf("report_dfs_inconsistancy_count: %u\n", profile_p->Trans2_report_dfs_inconsistancy_count); + d_printf("report_dfs_inconsistancy_time: %u\n", profile_p->Trans2_report_dfs_inconsistancy_time); + d_printf("************************ NT Transact Calls ***********************\n"); + d_printf("create_count: %u\n", profile_p->NT_transact_create_count); + d_printf("create_time: %u\n", profile_p->NT_transact_create_time); + d_printf("ioctl_count: %u\n", profile_p->NT_transact_ioctl_count); + d_printf("ioctl_time: %u\n", profile_p->NT_transact_ioctl_time); + d_printf("set_security_desc_count: %u\n", profile_p->NT_transact_set_security_desc_count); + d_printf("set_security_desc_time: %u\n", profile_p->NT_transact_set_security_desc_time); + d_printf("notify_change_count: %u\n", profile_p->NT_transact_notify_change_count); + d_printf("notify_change_time: %u\n", profile_p->NT_transact_notify_change_time); + d_printf("rename_count: %u\n", profile_p->NT_transact_rename_count); + d_printf("rename_time: %u\n", profile_p->NT_transact_rename_time); + d_printf("query_security_desc_count: %u\n", profile_p->NT_transact_query_security_desc_count); + d_printf("query_security_desc_time: %u\n", profile_p->NT_transact_query_security_desc_time); + d_printf("************************ ACL Calls *******************************\n"); + d_printf("get_nt_acl_count: %u\n", profile_p->get_nt_acl_count); + d_printf("get_nt_acl_time: %u\n", profile_p->get_nt_acl_time); + d_printf("fget_nt_acl_count: %u\n", profile_p->fget_nt_acl_count); + d_printf("fget_nt_acl_time: %u\n", profile_p->fget_nt_acl_time); + d_printf("set_nt_acl_count: %u\n", profile_p->set_nt_acl_count); + d_printf("set_nt_acl_time: %u\n", profile_p->set_nt_acl_time); + d_printf("fset_nt_acl_count: %u\n", profile_p->fset_nt_acl_count); + d_printf("fset_nt_acl_time: %u\n", profile_p->fset_nt_acl_time); + d_printf("chmod_acl_count: %u\n", profile_p->chmod_acl_count); + d_printf("chmod_acl_time: %u\n", profile_p->chmod_acl_time); + d_printf("fchmod_acl_count: %u\n", profile_p->fchmod_acl_count); + d_printf("fchmod_acl_time: %u\n", profile_p->fchmod_acl_time); + d_printf("************************ NMBD Calls ****************************\n"); + d_printf("name_release_count: %u\n", profile_p->name_release_count); + d_printf("name_release_time: %u\n", profile_p->name_release_time); + d_printf("name_refresh_count: %u\n", profile_p->name_refresh_count); + d_printf("name_refresh_time: %u\n", profile_p->name_refresh_time); + d_printf("name_registration_count: %u\n", profile_p->name_registration_count); + d_printf("name_registration_time: %u\n", profile_p->name_registration_time); + d_printf("node_status_count: %u\n", profile_p->node_status_count); + d_printf("node_status_time: %u\n", profile_p->node_status_time); + d_printf("name_query_count: %u\n", profile_p->name_query_count); + d_printf("name_query_time: %u\n", profile_p->name_query_time); + d_printf("host_announce_count: %u\n", profile_p->host_announce_count); + d_printf("host_announce_time: %u\n", profile_p->host_announce_time); + d_printf("workgroup_announce_count: %u\n", profile_p->workgroup_announce_count); + d_printf("workgroup_announce_time: %u\n", profile_p->workgroup_announce_time); + d_printf("local_master_announce_count: %u\n", profile_p->local_master_announce_count); + d_printf("local_master_announce_time: %u\n", profile_p->local_master_announce_time); + d_printf("master_browser_announce_count: %u\n", profile_p->master_browser_announce_count); + d_printf("master_browser_announce_time: %u\n", profile_p->master_browser_announce_time); + d_printf("lm_host_announce_count: %u\n", profile_p->lm_host_announce_count); + d_printf("lm_host_announce_time: %u\n", profile_p->lm_host_announce_time); + d_printf("get_backup_list_count: %u\n", profile_p->get_backup_list_count); + d_printf("get_backup_list_time: %u\n", profile_p->get_backup_list_time); + d_printf("reset_browser_count: %u\n", profile_p->reset_browser_count); + d_printf("reset_browser_time: %u\n", profile_p->reset_browser_time); + d_printf("announce_request_count: %u\n", profile_p->announce_request_count); + d_printf("announce_request_time: %u\n", profile_p->announce_request_time); + d_printf("lm_announce_request_count: %u\n", profile_p->lm_announce_request_count); + d_printf("lm_announce_request_time: %u\n", profile_p->lm_announce_request_time); + d_printf("domain_logon_count: %u\n", profile_p->domain_logon_count); + d_printf("domain_logon_time: %u\n", profile_p->domain_logon_time); + d_printf("sync_browse_lists_count: %u\n", profile_p->sync_browse_lists_count); + d_printf("sync_browse_lists_time: %u\n", profile_p->sync_browse_lists_time); + d_printf("run_elections_count: %u\n", profile_p->run_elections_count); + d_printf("run_elections_time: %u\n", profile_p->run_elections_time); + d_printf("election_count: %u\n", profile_p->election_count); + d_printf("election_time: %u\n", profile_p->election_time); return 0; } @@ -512,7 +512,7 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st return 0; } - printf("%-10.10s %5d %-12s %s", + d_printf("%-10.10s %5d %-12s %s", crec.name,(int)crec.pid, crec.machine, asctime(LocalTime(&crec.start))); @@ -533,7 +533,7 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo return 0; } - printf("%5d %-12s %-12s %-12s (%s)\n", + d_printf("%5d %-12s %-12s %-12s (%s)\n", (int)sessionid.pid, uidtoname(sessionid.uid), gidtoname(sessionid.gid), sessionid.remote_machine, sessionid.hostname); @@ -559,7 +559,7 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo dbf = stderr; if (getuid() != geteuid()) { - printf("smbstatus should not be run setuid\n"); + d_printf("smbstatus should not be run setuid\n"); return(1); } @@ -612,7 +612,7 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo } if (verbose) { - printf("using configfile = %s\n", servicesf); + d_printf("using configfile = %s\n", servicesf); } if (profile_only) { @@ -621,30 +621,30 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); if (!tdb) { - printf("sessionid.tdb not initialised\n"); + d_printf("sessionid.tdb not initialised\n"); } if (locks_only) goto locks; - printf("\nSamba version %s\n",VERSION); - printf("PID Username Group Machine \n"); - printf("-------------------------------------------------------------------\n"); + d_printf("\nSamba version %s\n",VERSION); + d_printf("PID Username Group Machine \n"); + d_printf("-------------------------------------------------------------------\n"); tdb_traverse(tdb, traverse_sessionid, NULL); tdb_close(tdb); tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); if (!tdb) { - printf("connections.tdb not initialised\n"); + d_printf("connections.tdb not initialised\n"); } else if (verbose) { - printf("Opened status file %s\n", fname); + d_printf("Opened status file %s\n", fname); } if (brief) exit(0); - printf("\nService pid machine Connected at\n"); - printf("-------------------------------------------------------\n"); + d_printf("\nService pid machine Connected at\n"); + d_printf("-------------------------------------------------------\n"); tdb_traverse(tdb, traverse_fn1, NULL); tdb_close(tdb); @@ -656,19 +656,19 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo int ret; if (!locking_init(1)) { - printf("Can't initialise locking module - exiting\n"); + d_printf("Can't initialise locking module - exiting\n"); exit(1); } ret = share_mode_forall(print_share_mode); if (ret == 0) { - printf("No locked files\n"); + d_printf("No locked files\n"); } else if (ret == -1) { - printf("locked file list truncated\n"); + d_printf("locked file list truncated\n"); } - printf("\n"); + d_printf("\n"); if (show_brl) { brl_forall(print_brl); -- cgit From b30e75692d68233448b3ad3d7ddd4b4ac423d3ab Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Sep 2001 11:08:57 +0000 Subject: replaced stdio in many parts of samba with a XFILE. XFILE is a cut-down replacemnt of stdio that doesn't suffer from the 8-bit filedescriptor limit that we hit with nasty consequences on some systems I would eventually prefer us to have a configure test to see if we need to replace stdio, but for now this code needs to be tested widely so I'm enabling it by default. (This used to be commit 1af8bf34f1caa3e7ec312d8109c07d32a945a448) --- source3/utils/smbcacls.c | 4 ++-- source3/utils/smbtree.c | 4 ++-- source3/utils/status.c | 4 ++-- source3/utils/testparm.c | 4 ++-- source3/utils/testprns.c | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index b26dbae417..59744a9315 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -802,7 +802,7 @@ You can string acls together with spaces, commas or newlines\n\ pstring filename; extern char *optarg; extern int optind; - extern FILE *dbf; + extern XFILE *dbf; int opt; char *p; static pstring servicesf = CONFIGFILE; @@ -816,7 +816,7 @@ You can string acls together with spaces, commas or newlines\n\ setlinebuf(stdout); - dbf = stderr; + dbf = x_stderr; if (argc < 3 || argv[1][0] == '-') { usage(); diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 41940d9a6c..75390965b3 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -325,7 +325,7 @@ static BOOL print_tree(struct user_auth_info *user_info) { extern char *optarg; extern int optind; - extern FILE *dbf; + extern XFILE *dbf; int opt; char *p; pstring servicesf = CONFIGFILE; @@ -336,7 +336,7 @@ static BOOL print_tree(struct user_auth_info *user_info) setlinebuf(stdout); - dbf = stderr; + dbf = x_stderr; setup_logging(argv[0],True); diff --git a/source3/utils/status.c b/source3/utils/status.c index 91eca9f88f..7cbb1850de 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -45,7 +45,7 @@ struct session_record{ } *srecs; extern int DEBUGLEVEL; -extern FILE *dbf; +extern XFILE *dbf; static pstring Ucrit_username = ""; /* added by OH */ static pid_t Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ @@ -556,7 +556,7 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo setup_logging(argv[0],True); DEBUGLEVEL = 0; - dbf = stderr; + dbf = x_stderr; if (getuid() != geteuid()) { d_printf("smbstatus should not be run setuid\n"); diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 28870fb272..e430fe414b 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -36,7 +36,7 @@ #include "smb.h" /* these live in util.c */ -extern FILE *dbf; +extern XFILE *dbf; extern int DEBUGLEVEL; /*********************************************** @@ -210,7 +210,7 @@ int main(int argc, char *argv[]) else if ((argc == 2) || (argc == 4)) pstrcpy(configfile,argv[optind]); - dbf = stdout; + dbf = x_stdout; DEBUGLEVEL = 2; printf("Load smb config files from %s\n",configfile); diff --git a/source3/utils/testprns.c b/source3/utils/testprns.c index f8fdcd63a1..6a5b35db3b 100644 --- a/source3/utils/testprns.c +++ b/source3/utils/testprns.c @@ -35,7 +35,7 @@ #include "smb.h" /* these live in util.c */ -extern FILE *dbf; +extern XFILE *dbf; extern int DEBUGLEVEL; int main(int argc, char *argv[]) @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) printf("Usage: testprns printername [printcapfile]\n"); else { - dbf = sys_fopen("test.log", "w"); + dbf = x_fopen("test.log", O_WRONLY|O_CREAT|O_TRUNC, 0644); if (dbf == NULL) { printf("Unable to open logfile.\n"); } else { @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) printf("Printer name %s is not valid.\n", argv[1]); else printf("Printer name %s is valid.\n", argv[1]); - fclose(dbf); + x_fclose(dbf); } } return (0); -- cgit From b12a4dd9b655485420d5c67dd143d8f49ac28a40 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Sep 2001 12:14:18 +0000 Subject: declare dbf in one spot (This used to be commit f41c3bb80f1e498a9d27f6e236b0ff3a742764c9) --- source3/utils/smbcacls.c | 1 - source3/utils/smbtree.c | 1 - source3/utils/status.c | 1 - source3/utils/testparm.c | 1 - source3/utils/testprns.c | 1 - 5 files changed, 5 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 59744a9315..914e99367b 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -802,7 +802,6 @@ You can string acls together with spaces, commas or newlines\n\ pstring filename; extern char *optarg; extern int optind; - extern XFILE *dbf; int opt; char *p; static pstring servicesf = CONFIGFILE; diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 75390965b3..191a9124f7 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -325,7 +325,6 @@ static BOOL print_tree(struct user_auth_info *user_info) { extern char *optarg; extern int optind; - extern XFILE *dbf; int opt; char *p; pstring servicesf = CONFIGFILE; diff --git a/source3/utils/status.c b/source3/utils/status.c index 7cbb1850de..47379fd57c 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -45,7 +45,6 @@ struct session_record{ } *srecs; extern int DEBUGLEVEL; -extern XFILE *dbf; static pstring Ucrit_username = ""; /* added by OH */ static pid_t Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index e430fe414b..1caf792543 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -36,7 +36,6 @@ #include "smb.h" /* these live in util.c */ -extern XFILE *dbf; extern int DEBUGLEVEL; /*********************************************** diff --git a/source3/utils/testprns.c b/source3/utils/testprns.c index 6a5b35db3b..df697a0ed1 100644 --- a/source3/utils/testprns.c +++ b/source3/utils/testprns.c @@ -35,7 +35,6 @@ #include "smb.h" /* these live in util.c */ -extern XFILE *dbf; extern int DEBUGLEVEL; int main(int argc, char *argv[]) -- cgit From c5dd2c827154bab6977ba9d768d81c0fae18badd Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Mon, 10 Sep 2001 22:31:59 +0000 Subject: prevent segv by not calling tdb_traverse and tdb_close if tdb_open_log returns NULL. (This used to be commit afdf93836b59d5d9ede2ac0f3298d99471872829) --- source3/utils/status.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 47379fd57c..23e2f4a63c 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -621,32 +621,34 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); if (!tdb) { d_printf("sessionid.tdb not initialised\n"); - } - - if (locks_only) goto locks; + } else { + if (locks_only) goto locks; - d_printf("\nSamba version %s\n",VERSION); - d_printf("PID Username Group Machine \n"); - d_printf("-------------------------------------------------------------------\n"); + d_printf("\nSamba version %s\n",VERSION); + d_printf("PID Username Group Machine \n"); + d_printf("-------------------------------------------------------------------\n"); - tdb_traverse(tdb, traverse_sessionid, NULL); - tdb_close(tdb); + tdb_traverse(tdb, traverse_sessionid, NULL); + tdb_close(tdb); + } tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); if (!tdb) { d_printf("connections.tdb not initialised\n"); - } else if (verbose) { - d_printf("Opened status file %s\n", fname); - } + } else + if (verbose) { + d_printf("Opened status file %s\n", fname); + } - if (brief) - exit(0); - - d_printf("\nService pid machine Connected at\n"); - d_printf("-------------------------------------------------------\n"); + if (brief) + exit(0); + + d_printf("\nService pid machine Connected at\n"); + d_printf("-------------------------------------------------------\n"); - tdb_traverse(tdb, traverse_fn1, NULL); - tdb_close(tdb); + tdb_traverse(tdb, traverse_fn1, NULL); + tdb_close(tdb); + } locks: if (processes_only) exit(0); -- cgit From 866598e430be5af447f6c7740753e3d2c22dd5e5 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Mon, 10 Sep 2001 22:40:15 +0000 Subject: left out { (This used to be commit 70bd17473a2106ef41b5d921595ce537ec1871cb) --- source3/utils/status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/status.c b/source3/utils/status.c index 23e2f4a63c..15c9c4aad4 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -635,7 +635,7 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); if (!tdb) { d_printf("connections.tdb not initialised\n"); - } else + } else { if (verbose) { d_printf("Opened status file %s\n", fname); } -- cgit From 31e8101ea2073fa65437d79c6f4bf722831d09c1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 12 Sep 2001 20:00:42 +0000 Subject: Fixed problems with arg parsing as root with smbpasswd. Jeremy. (This used to be commit 6399cf490dffbd162afa06f18cdd6e0364db567d) --- source3/utils/smbpasswd.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 74f4e8833a..da5f817c80 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -550,7 +550,7 @@ static int process_root(int argc, char *argv[]) { struct passwd *pwd; int result = 0, ch; - BOOL joining_domain = False, got_pass = False; + BOOL joining_domain = False, got_pass = False, got_username = False; int local_flags = 0; BOOL stdin_passwd_get = False; fstring user_name, user_password; @@ -559,12 +559,12 @@ static int process_root(int argc, char *argv[]) char *old_passwd = NULL; char *remote_machine = NULL; - ZERO_STRUCT(user_name); - ZERO_STRUCT(user_password); + ZERO_STRUCT(user_name); + ZERO_STRUCT(user_password); user_name[0] = '\0'; - while ((ch = getopt(argc, argv, "ax:d:e:hmnj:r:sR:D:U:L")) != EOF) { + while ((ch = getopt(argc, argv, "axdehmnj:r:sR:D:U:L")) != EOF) { switch(ch) { case 'L': local_mode = True; @@ -574,17 +574,14 @@ static int process_root(int argc, char *argv[]) break; case 'x': local_flags |= LOCAL_DELETE_USER; - fstrcpy(user_name, optarg); new_passwd = xstrdup("XXXXXX"); break; case 'd': local_flags |= LOCAL_DISABLE_USER; - fstrcpy(user_name, optarg); new_passwd = xstrdup("XXXXXX"); break; case 'e': local_flags |= LOCAL_ENABLE_USER; - fstrcpy(user_name, optarg); break; case 'm': local_flags |= LOCAL_TRUST_ACCOUNT; @@ -616,6 +613,7 @@ static int process_root(int argc, char *argv[]) case 'U': { char *lp; + got_username = True; fstrcpy(user_name, optarg); if ((lp = strchr_m(user_name, '%'))) { @@ -691,12 +689,17 @@ static int process_root(int argc, char *argv[]) switch(argc) { case 0: - fstrcpy(user_name, ""); + if (!got_username) + fstrcpy(user_name, ""); break; case 1: + if (got_username) + usage(); fstrcpy(user_name, argv[0]); break; case 2: + if (got_username || got_pass) + usage(); fstrcpy(user_name, argv[0]); new_passwd = xstrdup(argv[1]); break; -- cgit From 13301415ca339845d63a3c86cd916d00f646dba1 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 15 Sep 2001 14:03:25 +0000 Subject: free memory before returning. tx Andreas Moroder. (This used to be commit 8d60a825f74a340beba11193a28fd83b0c4a8129) --- source3/utils/make_printerdef.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index 5107b124a7..bfbf6fa499 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -154,6 +154,8 @@ static void lookup_strings(FILE *fichier) temp2=(char *)malloc(sizeof(pstring)); if(temp == NULL || temp2 == NULL) { + safe_free(temp); + safe_free(temp2); fprintf(stderr,"lookup_strings: malloc fail !\n"); exit(1); } @@ -216,6 +218,8 @@ static void lookup_entry(FILE *fichier,char *chaine) temp2=(char *)malloc(sizeof(pstring)); if(temp == NULL || temp2 == NULL) { + safe_free(temp); + safe_free(temp2); fprintf(stderr,"lookup_entry: malloc fail !\n"); exit(1); } @@ -272,6 +276,9 @@ static char *find_desc(FILE *fichier,char *text) long_desc=(char *)malloc(sizeof(pstring)); short_desc=(char *)malloc(sizeof(pstring)); if (!chaine || !long_desc || !short_desc) { + safe_free(chaine); + safe_free(long_desc); + safe_free(short_desc); fprintf(stderr,"find_desc: Unable to malloc memory\n"); exit(1); } -- cgit From c0ef0e113e8d3117891b4b137f660ca3c4c6b1f0 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 17 Sep 2001 11:48:29 +0000 Subject: move to SAFE_FREE() (This used to be commit 67db8f03c5c9e81e11b5f3276b50ee23e09a2659) --- source3/utils/make_printerdef.c | 16 ++++++++-------- source3/utils/nmblookup.c | 2 +- source3/utils/smbcacls.c | 22 ++++++++++------------ source3/utils/smbpasswd.c | 12 ++++++------ source3/utils/smbtree.c | 2 +- 5 files changed, 26 insertions(+), 28 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index bfbf6fa499..47589984cc 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -154,8 +154,8 @@ static void lookup_strings(FILE *fichier) temp2=(char *)malloc(sizeof(pstring)); if(temp == NULL || temp2 == NULL) { - safe_free(temp); - safe_free(temp2); + SAFE_FREE(temp); + SAFE_FREE(temp2); fprintf(stderr,"lookup_strings: malloc fail !\n"); exit(1); } @@ -218,8 +218,8 @@ static void lookup_entry(FILE *fichier,char *chaine) temp2=(char *)malloc(sizeof(pstring)); if(temp == NULL || temp2 == NULL) { - safe_free(temp); - safe_free(temp2); + SAFE_FREE(temp); + SAFE_FREE(temp2); fprintf(stderr,"lookup_entry: malloc fail !\n"); exit(1); } @@ -276,9 +276,9 @@ static char *find_desc(FILE *fichier,char *text) long_desc=(char *)malloc(sizeof(pstring)); short_desc=(char *)malloc(sizeof(pstring)); if (!chaine || !long_desc || !short_desc) { - safe_free(chaine); - safe_free(long_desc); - safe_free(short_desc); + SAFE_FREE(chaine); + SAFE_FREE(long_desc); + SAFE_FREE(short_desc); fprintf(stderr,"find_desc: Unable to malloc memory\n"); exit(1); } @@ -307,7 +307,7 @@ static char *find_desc(FILE *fichier,char *text) if (!strcmp(text,long_desc)) found=1; } - free(chaine); + SAFE_FREE(chaine); if (!found || !crap) return(NULL); while(*crap==' ') crap++; pstrcpy(short_desc,crap); diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 2d86cc0a35..ff675a72e5 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -124,7 +124,7 @@ static void do_node_status(int fd, char *name, int type, struct in_addr ip) cleanname,status[i].type, node_status_flags(status[i].flags)); } - free(status); + SAFE_FREE(status); } d_printf("\n"); } diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index 914e99367b..ba5630a9d8 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -328,7 +328,7 @@ static BOOL add_ace(SEC_ACL **the_acl, SEC_ACE *ace) memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE)); memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE)); new = make_sec_acl(ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces); - free(aces); + SAFE_FREE(aces); (*the_acl) = new; return True; } @@ -391,8 +391,8 @@ static SEC_DESC *sec_desc_parse(char *str) ret = make_sec_desc(ctx,revision, owner_sid, grp_sid, NULL, dacl, &sd_size); - if (grp_sid) free(grp_sid); - if (owner_sid) free(owner_sid); + SAFE_FREE(grp_sid); + SAFE_FREE(owner_sid); return ret; } @@ -605,10 +605,8 @@ static int cacl_set(struct cli_state *cli, char *filename, } old->dacl->num_aces--; if (old->dacl->num_aces == 0) { - free(old->dacl->ace); - old->dacl->ace=NULL; - free(old->dacl); - old->dacl = NULL; + SAFE_FREE(old->dacl->ace); + SAFE_FREE(old->dacl); old->off_dacl = 0; } found = True; @@ -713,14 +711,14 @@ struct cli_state *connect_one(char *share) if (!(c=cli_initialise(NULL)) || !cli_connect(c, server, &ip)) { DEBUG(0,("Connection to %s failed\n", server)); cli_shutdown(c); - safe_free(c); + SAFE_FREE(c); return NULL; } if (!cli_session_request(c, &calling, &called)) { DEBUG(0,("session request to %s failed\n", called.name)); cli_shutdown(c); - safe_free(c); + SAFE_FREE(c); if (strcmp(called.name, "*SMBSERVER")) { make_nmb_name(&called , "*SMBSERVER", 0x20); goto again; @@ -733,7 +731,7 @@ struct cli_state *connect_one(char *share) if (!cli_negprot(c)) { DEBUG(0,("protocol negotiation failed\n")); cli_shutdown(c); - safe_free(c); + SAFE_FREE(c); return NULL; } @@ -750,7 +748,7 @@ struct cli_state *connect_one(char *share) lp_workgroup())) { DEBUG(0,("session setup failed: %s\n", cli_errstr(c))); cli_shutdown(c); - safe_free(c); + SAFE_FREE(c); return NULL; } @@ -760,7 +758,7 @@ struct cli_state *connect_one(char *share) password, strlen(password)+1)) { DEBUG(0,("tree connect failed: %s\n", cli_errstr(c))); cli_shutdown(c); - safe_free(c); + SAFE_FREE(c); return NULL; } diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index da5f817c80..14b10c1700 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -491,14 +491,14 @@ static char *prompt_for_new_password(BOOL stdin_get) p = get_pass("New SMB password:", stdin_get); fstrcpy(new_passwd, p); - safe_free(p); + SAFE_FREE(p); p = get_pass("Retype new SMB password:", stdin_get); if (strcmp(p, new_passwd)) { fprintf(stderr, "Mismatch - password unchanged.\n"); ZERO_ARRAY(new_passwd); - safe_free(p); + SAFE_FREE(p); return NULL; } @@ -730,7 +730,7 @@ static int process_root(int argc, char *argv[]) } if (local_flags & LOCAL_ADD_USER) { - safe_free(new_passwd); + SAFE_FREE(new_passwd); new_passwd = xstrdup(user_name); strlower(new_passwd); } @@ -803,7 +803,7 @@ static int process_root(int argc, char *argv[]) } done: - safe_free(new_passwd); + SAFE_FREE(new_passwd); return result; } @@ -898,8 +898,8 @@ static int process_nonroot(int argc, char *argv[]) printf("Password changed for user %s\n", user_name); done: - safe_free(old_passwd); - safe_free(new_passwd); + SAFE_FREE(old_passwd); + SAFE_FREE(new_passwd); return result; } diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index 191a9124f7..d7842d1e02 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -161,7 +161,7 @@ static struct cli_state *get_ipc_connect(char *server, if (cli && cli->initialised) cli_shutdown(cli); - free(cli); + SAFE_FREE(cli); return NULL; } -- cgit From a88ed5d1be987af6fe1353a18298d206fbfca4e0 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 20 Sep 2001 07:27:55 +0000 Subject: Check 'hosts equiv' and 'use rhosts' compatability with 'hostname lookup' value. (This used to be commit 5f5b4b48ca78b3981001965058a2b4e796ba815c) --- source3/utils/testparm.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 1caf792543..f4d072ed77 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -85,6 +85,22 @@ to a valid password server.\n", sec_setting ); ret = 1; } + + /* + * Check 'hosts equiv' and 'use rhosts' compatability with 'hostname lookup' value. + */ + + if(*lp_hosts_equiv() && !lp_hostname_lookups()) { + printf("ERROR: The setting 'hosts equiv = %s' requires that 'hostname lookups = yes'.\n", lp_hosts_equiv()); + ret = 1; + } + + if(lp_use_rhosts() && !lp_hostname_lookups()) { + printf("ERROR: The setting 'use rhosts = yes' requires the 'hostname lookups = yes'.\n"); + ret = 1; + } + + /* * Password chat sanity checks. */ -- cgit From 21532486d264d2f3ec706994f1f4f98f82765165 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 21 Sep 2001 13:37:52 +0000 Subject: Added -s configfile to smbcontrol.c. Volker (This used to be commit 9ecd9db4efc7b736bef0e01a5e157e149a381587) --- source3/utils/smbcontrol.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 40892ba1c0..2b682d9860 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -46,7 +46,7 @@ static void usage(BOOL doexit) { int i; if (doexit) { - printf("Usage: smbcontrol -i\n"); + printf("Usage: smbcontrol -i -s configfile\n"); printf(" smbcontrol \n\n"); } else { printf(" \n\n"); @@ -380,23 +380,26 @@ static BOOL do_command(char *dest, char *msg_name, char **params) TimeInit(); setup_logging(argv[0],True); - lp_load(servicesf,False,False,False); - - if (!message_init()) exit(1); - if (argc < 2) usage(True); - while ((opt = getopt(argc, argv,"i")) != EOF) { + while ((opt = getopt(argc, argv,"is:")) != EOF) { switch (opt) { case 'i': interactive = True; break; + case 's': + pstrcpy(servicesf, optarg); + break; default: printf("Unknown option %c (%d)\n", (char)opt, opt); usage(True); } } + lp_load(servicesf,False,False,False); + + if (!message_init()) exit(1); + argc -= optind; argv = &argv[optind]; -- cgit From 9b1c40b7a41a4c70fba1f93d69c17689511bea01 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 26 Sep 2001 11:28:26 +0000 Subject: Fix up pdbedit to initialise its structures with the standard functions, therfore ensuring sensible defaults for some values, notably account expriries which mean 'locked out' if == 0. This NEEDS to be merged into 2.2.2 or people can get wrongly initilaised TDB records. (which will only fail on future versions of samba). Andrew Bartlett (This used to be commit f0f315f31533bb5dc47d27cd6823ad0b146f1ff9) --- source3/utils/pdbedit.c | 92 ++++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 40 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index f09fd4f773..7025f38362 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -205,23 +205,25 @@ static int set_user_info (char *username, char *fullname, char *homedir, char *d **********************************************************/ static int new_user (char *username, char *fullname, char *homedir, char *drive, char *script, char *profile) { - SAM_ACCOUNT sam_pwent; + SAM_ACCOUNT *sam_pwent=NULL; struct passwd *pwd = NULL; - uchar new_p16[16]; - uchar new_nt_p16[16]; char *password1, *password2; ZERO_STRUCT(sam_pwent); - if (pdb_getsampwnam (&sam_pwent, username)) + pdb_init_sam (&sam_pwent); + + if (pdb_getsampwnam (sam_pwent, username)) { fprintf (stderr, "Username already exist in database!\n"); + pdb_free_sam (sam_pwent); return -1; } if (!(pwd = sys_getpwnam(username))) { fprintf (stderr, "User %s does not exist in system passwd!\n", username); + pdb_free_sam (sam_pwent); return -1; } @@ -230,32 +232,35 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, if (strcmp (password1, password2)) { fprintf (stderr, "Passwords does not match!\n"); + pdb_free_sam (sam_pwent); return -1; } - nt_lm_owf_gen (password1, new_nt_p16, new_p16); - - pdb_set_username(&sam_pwent, username); - if (fullname) pdb_set_fullname(&sam_pwent, fullname); - if (homedir) pdb_set_homedir (&sam_pwent, homedir); - if (drive) pdb_set_dir_drive (&sam_pwent, drive); - if (script) pdb_set_logon_script(&sam_pwent, script); - if (profile) pdb_set_profile_path (&sam_pwent, profile); + + pdb_set_plaintext_passwd(sam_pwent, password1); + + pdb_set_username(sam_pwent, username); + if (fullname) pdb_set_fullname(sam_pwent, fullname); + if (homedir) pdb_set_homedir (sam_pwent, homedir); + if (drive) pdb_set_dir_drive (sam_pwent, drive); + if (script) pdb_set_logon_script(sam_pwent, script); + if (profile) pdb_set_profile_path (sam_pwent, profile); /* TODO: Check uid not being in MACHINE UID range!! */ - sam_pwent.uid = pwd->pw_uid; - sam_pwent.gid = pwd->pw_gid; - sam_pwent.user_rid = pdb_uid_to_user_rid (pwd->pw_uid); - sam_pwent.group_rid = pdb_gid_to_group_rid (pwd->pw_gid); - sam_pwent.lm_pw = new_p16; - sam_pwent.nt_pw = new_nt_p16; - sam_pwent.acct_ctrl = ACB_NORMAL; - - if (pdb_add_sam_account (&sam_pwent)) print_user_info (username, True, False); - else - { + pdb_set_uid (sam_pwent, pwd->pw_uid); + pdb_set_gid (sam_pwent, pwd->pw_gid); + pdb_set_user_rid (sam_pwent, pdb_uid_to_user_rid (pwd->pw_uid)); + pdb_set_group_rid (sam_pwent, pdb_gid_to_group_rid (pwd->pw_gid)); + + pdb_set_acct_ctrl (sam_pwent, ACB_NORMAL); + + if (pdb_add_sam_account (sam_pwent)) { + print_user_info (username, True, False); + } else { fprintf (stderr, "Unable to add user!\n"); + pdb_free_sam (sam_pwent); return -1; } + pdb_free_sam (sam_pwent); return 0; } @@ -264,13 +269,13 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, **********************************************************/ static int new_machine (char *machinename) { - SAM_ACCOUNT sam_pwent; - SAM_ACCOUNT sam_trust; - uchar new_p16[16]; - uchar new_nt_p16[16]; + SAM_ACCOUNT *sam_pwent=NULL; + SAM_ACCOUNT *sam_trust=NULL; char name[16]; char *password = NULL; uid_t uid; + + pdb_init_sam (&sam_pwent); if (machinename[strlen (machinename) -1] == '$') machinename[strlen (machinename) -1] = '\0'; @@ -279,33 +284,40 @@ static int new_machine (char *machinename) string_set (&password, machinename); strlower(password); - nt_lm_owf_gen (password, new_nt_p16, new_p16); - pdb_set_username(&sam_pwent, name); + pdb_set_plaintext_passwd(sam_pwent, password); + + pdb_set_username(sam_pwent, name); - for (uid=BASE_MACHINE_UID; uid<=MAX_MACHINE_UID; uid++) - if (!(pdb_getsampwuid (&sam_trust, uid))) + for (uid=BASE_MACHINE_UID; uid<=MAX_MACHINE_UID; uid++) { + pdb_init_sam (&sam_trust); + if (pdb_getsampwuid (sam_trust, uid)) { + pdb_free_sam (sam_trust); + } else { break; + } + } if (uid>MAX_MACHINE_UID) { fprintf (stderr, "No more free UIDs available to Machine accounts!\n"); + pdb_free_sam(sam_pwent); return -1; } - sam_pwent.uid = uid; - sam_pwent.gid = BASE_MACHINE_UID; /* TODO: set there more appropriate value!! */ - sam_pwent.user_rid = pdb_uid_to_user_rid (uid); - sam_pwent.group_rid = pdb_gid_to_group_rid (BASE_MACHINE_UID); - sam_pwent.lm_pw = new_p16; - sam_pwent.nt_pw = new_nt_p16; - sam_pwent.acct_ctrl = ACB_WSTRUST; + pdb_set_uid(sam_pwent, uid); + pdb_set_gid(sam_pwent, BASE_MACHINE_UID); /* TODO: set there more appropriate value!! */ + pdb_set_user_rid (sam_pwent,pdb_uid_to_user_rid (uid)); + pdb_set_group_rid (sam_pwent, pdb_gid_to_group_rid (BASE_MACHINE_UID)); + pdb_set_acct_ctrl (sam_pwent, ACB_WSTRUST); - if (pdb_add_sam_account (&sam_pwent)) + if (pdb_add_sam_account (sam_pwent)) { print_user_info (name, True, False); - else { + } else { fprintf (stderr, "Unable to add machine!\n"); + pdb_free_sam (sam_pwent); return -1; } + pdb_free_sam (sam_pwent); return 0; } -- cgit From 415cfe0912ec924e0259003051586ed531ce2d4d Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 27 Sep 2001 09:36:38 +0000 Subject: Major update to pdbedit's import and export code, in line with reqests for it to use the pdb_ formatting functions. Similarly, it now uses pdb_set...() rather than accessing passdb members directly. Andrew Bartlett (This used to be commit e3b7cac47f4fd9dff289a367ef6649b14c117d17) --- source3/utils/pdbedit.c | 164 ++++++++++++++++++++++++------------------------ 1 file changed, 83 insertions(+), 81 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index 7025f38362..f0acf2b0b0 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -1,21 +1,25 @@ -/* - * Unix SMB/Netbios implementation. Version 1.9. tdbedit module. Copyright - * (C) Simo Sorce 2000 - * - * 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. - */ +/* + Unix SMB/Netbios implementation. + passdb editing frontend + Version 3.0 + + Copyright (C) Simo Sorce 2000 + Copyright (C) Andrew Bartlett 2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ /* base uid for trust accounts is set to 60000 ! * May be we should add the defines in smb.h to make it possible having @@ -89,19 +93,19 @@ static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdst { char lm_passwd[33]; char nt_passwd[33]; - smbpasswd_sethexpwd(lm_passwd, - pdb_get_lanman_passwd(sam_pwent), - pdb_get_acct_ctrl(sam_pwent)); - smbpasswd_sethexpwd(nt_passwd, - pdb_get_nt_passwd(sam_pwent), - pdb_get_acct_ctrl(sam_pwent)); + pdb_sethexpwd(lm_passwd, + pdb_get_lanman_passwd(sam_pwent), + pdb_get_acct_ctrl(sam_pwent)); + pdb_sethexpwd(nt_passwd, + pdb_get_nt_passwd(sam_pwent), + pdb_get_acct_ctrl(sam_pwent)); - printf("%s:%d:%s:%s:%s:LCT-%08x:\n", + printf("%s:%d:%s:%s:%s:LCT-%08X:\n", pdb_get_username(sam_pwent), pdb_get_uid(sam_pwent), lm_passwd, nt_passwd, - smbpasswd_encode_acb_info(pdb_get_acct_ctrl(sam_pwent)), + pdb_encode_acct_ctrl(pdb_get_acct_ctrl(sam_pwent),NEW_PW_FORMAT_SPACE_PADDED_LEN), (uint32)pdb_get_pass_last_set_time(sam_pwent)); } else @@ -213,13 +217,6 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, pdb_init_sam (&sam_pwent); - if (pdb_getsampwnam (sam_pwent, username)) - { - fprintf (stderr, "Username already exist in database!\n"); - pdb_free_sam (sam_pwent); - return -1; - } - if (!(pwd = sys_getpwnam(username))) { fprintf (stderr, "User %s does not exist in system passwd!\n", username); @@ -256,7 +253,7 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, if (pdb_add_sam_account (sam_pwent)) { print_user_info (username, True, False); } else { - fprintf (stderr, "Unable to add user!\n"); + fprintf (stderr, "Unable to add user! (does it alredy exist?)\n"); pdb_free_sam (sam_pwent); return -1; } @@ -283,11 +280,11 @@ static int new_machine (char *machinename) safe_strcat (name, "$", 16); string_set (&password, machinename); - strlower(password); + strlower_m (password); - pdb_set_plaintext_passwd(sam_pwent, password); + pdb_set_plaintext_passwd (sam_pwent, password); - pdb_set_username(sam_pwent, name); + pdb_set_username (sam_pwent, name); for (uid=BASE_MACHINE_UID; uid<=MAX_MACHINE_UID; uid++) { pdb_init_sam (&sam_trust); @@ -304,8 +301,8 @@ static int new_machine (char *machinename) return -1; } - pdb_set_uid(sam_pwent, uid); - pdb_set_gid(sam_pwent, BASE_MACHINE_UID); /* TODO: set there more appropriate value!! */ + pdb_set_uid (sam_pwent, uid); + pdb_set_gid (sam_pwent, BASE_MACHINE_UID); /* TODO: set there more appropriate value!! */ pdb_set_user_rid (sam_pwent,pdb_uid_to_user_rid (uid)); pdb_set_group_rid (sam_pwent, pdb_gid_to_group_rid (BASE_MACHINE_UID)); pdb_set_acct_ctrl (sam_pwent, ACB_WSTRUST); @@ -313,7 +310,7 @@ static int new_machine (char *machinename) if (pdb_add_sam_account (sam_pwent)) { print_user_info (name, True, False); } else { - fprintf (stderr, "Unable to add machine!\n"); + fprintf (stderr, "Unable to add machine! (does it already exist?)\n"); pdb_free_sam (sam_pwent); return -1; } @@ -350,8 +347,7 @@ static int delete_machine_entry (char *machinename) static int import_users (char *filename) { FILE *fp = NULL; - SAM_ACCOUNT sam_pwent; - SAM_ACCOUNT sam_test; + SAM_ACCOUNT *sam_pwent = NULL; static pstring user_name; static unsigned char smbpwd[16]; static unsigned char smbntpwd[16]; @@ -363,6 +359,10 @@ static int import_users (char *filename) int line = 0; int good = 0; + if (!pdb_init_sam (&sam_pwent)) { + fprintf (stderr, "pdb_init_sam FAILED!\n"); + } + if((fp = sys_fopen(filename, "rb")) == NULL) { fprintf (stderr, "%s\n", strerror (ferror (fp))); @@ -377,6 +377,7 @@ static int import_users (char *filename) if (ferror(fp)) { fprintf (stderr, "%s\n", strerror (ferror (fp))); + pdb_free_sam(sam_pwent); return -1; } if ((linebuf_len = strlen(linebuf)) == 0) @@ -398,19 +399,20 @@ static int import_users (char *filename) if ((linebuf[0] == 0) && feof(fp)) { /*end of file!!*/ + pdb_free_sam(sam_pwent); return 0; } line++; if (linebuf[0] == '#' || linebuf[0] == '\0') continue; - /*pdb_init_sam (&sam_pwent);*/ - sam_pwent.acct_ctrl = ACB_NORMAL; + pdb_set_acct_ctrl (sam_pwent,ACB_NORMAL); /* Get user name */ p = (unsigned char *) strchr_m(linebuf, ':'); if (p == NULL) { fprintf (stderr, "Error: malformed password entry at line %d !!\n", line); + pdb_reset_sam (sam_pwent); continue; } strncpy(user_name, linebuf, PTR_DIFF(p, linebuf)); @@ -421,11 +423,13 @@ static int import_users (char *filename) if(*p == '-') { fprintf (stderr, "Error: negative uid at line %d\n", line); + pdb_reset_sam (sam_pwent); continue; } if (!isdigit(*p)) { fprintf (stderr, "Error: malformed password entry at line %d (uid not number)\n", line); + pdb_reset_sam (sam_pwent); continue; } uidval = atoi((char *) p); @@ -433,11 +437,12 @@ static int import_users (char *filename) if (*p != ':') { fprintf (stderr, "Error: malformed password entry at line %d (no : after uid)\n", line); + pdb_reset_sam (sam_pwent); continue; } - pdb_set_username(&sam_pwent, user_name); - pdb_set_uid (&sam_pwent, uidval); + pdb_set_username(sam_pwent, user_name); + pdb_set_uid (sam_pwent, uidval); /* Get passwords */ p++; @@ -445,46 +450,49 @@ static int import_users (char *filename) { /* Password deliberately invalid */ fprintf (stderr, "Warning: entry invalidated for user %s\n", user_name); - sam_pwent.lm_pw = NULL; - sam_pwent.nt_pw = NULL; - sam_pwent.acct_ctrl |= ACB_DISABLED; + pdb_set_lanman_passwd(sam_pwent, NULL); + pdb_set_nt_passwd(sam_pwent,NULL); + pdb_set_acct_ctrl(sam_pwent, pdb_get_acct_ctrl(sam_pwent) | ACB_DISABLED); } else { if (linebuf_len < (PTR_DIFF(p, linebuf) + 33)) { fprintf (stderr, "Error: malformed password entry at line %d (password too short)\n",line); + pdb_reset_sam (sam_pwent); continue; } if (p[32] != ':') { fprintf (stderr, "Error: malformed password entry at line %d (no terminating :)\n",line); + pdb_reset_sam (sam_pwent); continue; } if (!strncasecmp((char *) p, "NO PASSWORD", 11)) { - sam_pwent.lm_pw = NULL; - sam_pwent.acct_ctrl |= ACB_PWNOTREQ; + pdb_set_lanman_passwd(sam_pwent, NULL); + pdb_set_acct_ctrl(sam_pwent, pdb_get_acct_ctrl(sam_pwent) | ACB_PWNOTREQ); } else { if (!smbpasswd_gethexpwd((char *)p, smbpwd)) { fprintf (stderr, "Error: malformed Lanman password entry at line %d (non hex chars)\n", line); + pdb_reset_sam (sam_pwent); continue; } - sam_pwent.lm_pw = smbpwd; + pdb_set_lanman_passwd(sam_pwent, smbpwd); } /* NT password */ - sam_pwent.nt_pw = NULL; + pdb_set_nt_passwd(sam_pwent, smbpwd); p += 33; if ((linebuf_len >= (PTR_DIFF(p, linebuf) + 33)) && (p[32] == ':')) { if (*p != '*' && *p != 'X') { - if (smbpasswd_gethexpwd((char *)p,smbntpwd)) + if (pdb_gethexpwd((char *)p,smbntpwd)) { - sam_pwent.nt_pw = smbntpwd; + pdb_set_nt_passwd(sam_pwent, smbntpwd); } } p += 33; @@ -494,10 +502,13 @@ static int import_users (char *filename) /* Get ACCT_CTRL field if any */ if (*p == '[') { + uint16 acct_ctrl; unsigned char *end_p = (unsigned char *)strchr_m((char *)p, ']'); - sam_pwent.acct_ctrl = smbpasswd_decode_acb_info((char*)p); - if(sam_pwent.acct_ctrl == 0) sam_pwent.acct_ctrl = ACB_NORMAL; + acct_ctrl = pdb_decode_acct_ctrl((char*)p); + if (acct_ctrl) acct_ctrl = ACB_NORMAL; + + pdb_set_acct_ctrl(sam_pwent, acct_ctrl); /* Get last change time */ if(end_p) p = end_p + 1; @@ -515,69 +526,60 @@ static int import_users (char *filename) } if(i == 8) { - sam_pwent.pass_last_set_time = (time_t)strtol((char *)p, NULL, 16); + pdb_set_pass_last_set_time (sam_pwent, (time_t)strtol((char *)p, NULL, 16)); } } } } - /* Test if workstation */ - else - { - if(sam_pwent.username[strlen(sam_pwent.username) - 1] == '$') - { - sam_pwent.acct_ctrl &= ~ACB_NORMAL; - sam_pwent.acct_ctrl |= ACB_WSTRUST; - } - } - if (sam_pwent.acct_ctrl & ACB_WSTRUST) + /* Old-style workstation account code droped. */ + + if (pdb_get_acct_ctrl(sam_pwent) & ACB_WSTRUST) { - if (!(BASE_MACHINE_UID <= uidval <= MAX_MACHINE_UID)) + if ((uidval < BASE_MACHINE_UID) || (uidval > MAX_MACHINE_UID)) { fprintf (stderr, "Warning: Machine UID out of normal range %d-%d\n", BASE_MACHINE_UID, MAX_MACHINE_UID); } - sam_pwent.gid = BASE_MACHINE_UID; + pdb_set_uid(sam_pwent, BASE_MACHINE_UID); } /* Test if user is valid */ - if (sam_pwent.acct_ctrl & ACB_NORMAL) + if (pdb_get_acct_ctrl(sam_pwent) & ACB_NORMAL) { struct passwd *pwd = NULL; - if (pdb_getsampwnam (&sam_test,user_name)) - { - fprintf (stderr, "Error: Username already exist in database!\n"); - continue; - } if (!(pwd = sys_getpwnam(user_name))) { fprintf (stderr, "Error: User %s does not exist in system passwd!\n", user_name); continue; } - sam_pwent.gid = pwd->pw_gid; + pdb_set_gid(sam_pwent, pwd->pw_gid); } /* Fill in sam_pwent structure */ - sam_pwent.user_rid = pdb_uid_to_user_rid (sam_pwent.uid); - sam_pwent.group_rid = pdb_gid_to_group_rid (sam_pwent.gid); + pdb_set_user_rid(sam_pwent, pdb_uid_to_user_rid (pdb_get_uid(sam_pwent))); + pdb_set_group_rid(sam_pwent, pdb_gid_to_group_rid (pdb_get_gid(sam_pwent))); + /* TODO: set also full_name, home_dir, dir_drive, logon_script, profile_path, ecc... * when defaults will be available (after passdb redesign) * let them blank just now they are not used anyway */ /* Now ADD the entry */ - if (!(pdb_add_sam_account (&sam_pwent))) + if (!(pdb_add_sam_account (sam_pwent))) { fprintf (stderr, "Unable to add user entry!\n"); + pdb_reset_sam (sam_pwent); continue; } printf ("%s imported!\n", user_name); good++; + pdb_reset_sam (sam_pwent); } printf ("%d lines read.\n%d entryes imported\n", line, good); - + pdb_free_sam(sam_pwent); return 0; } -- cgit From a69e900d97194f153afb5c45934820dfb89755eb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 27 Sep 2001 21:20:14 +0000 Subject: Sync 2.2.2 and HEAD (I will keep these the same if it kills me :-). Jeremy. (This used to be commit 76fac3eb945c7ced28c5685849d3616bb7c89ca2) --- source3/utils/pdbedit.c | 230 ++++++++++++++++++++++-------------------------- 1 file changed, 103 insertions(+), 127 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index f0acf2b0b0..41d66777fd 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -68,16 +68,17 @@ static void usage(void) printf(" -i file import account from file (smbpasswd style)\n"); exit(1); } + /********************************************************* Print info from sam structure **********************************************************/ + static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdstyle) { /* TODO: chaeck if entry is a user or a workstation */ if (!sam_pwent) return -1; - if (verbosity) - { + if (verbosity) { printf ("username: %s\n", sam_pwent->username); printf ("user ID/Group: %d/%d\n", sam_pwent->uid, sam_pwent->gid); @@ -88,9 +89,7 @@ static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdst printf ("HomeDir Drive: %s\n", sam_pwent->dir_drive); printf ("Logon Script: %s\n", sam_pwent->logon_script); printf ("Profile Path: %s\n", sam_pwent->profile_path); - } - else if (smbpwdstyle) - { + } else if (smbpwdstyle) { char lm_passwd[33]; char nt_passwd[33]; pdb_sethexpwd(lm_passwd, @@ -107,9 +106,7 @@ static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdst nt_passwd, pdb_encode_acct_ctrl(pdb_get_acct_ctrl(sam_pwent),NEW_PW_FORMAT_SPACE_PADDED_LEN), (uint32)pdb_get_pass_last_set_time(sam_pwent)); - } - else - { + } else { printf ("%s:%d:%s\n", sam_pwent->username, sam_pwent->uid, sam_pwent->full_name); } @@ -119,6 +116,7 @@ static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdst /********************************************************* Get an Print User Info **********************************************************/ + static int print_user_info (char *username, BOOL verbosity, BOOL smbpwdstyle) { SAM_ACCOUNT *sam_pwent=NULL; @@ -157,9 +155,9 @@ static int print_users_list (BOOL verbosity, BOOL smbpwdstyle) exit(1); } - while ((ret = pdb_getsampwent (sam_pwent))) - { - if (verbosity) printf ("---------------\n"); + while ((ret = pdb_getsampwent (sam_pwent))) { + if (verbosity) + printf ("---------------\n"); print_sam_info (sam_pwent, verbosity, smbpwdstyle); pdb_reset_sam(sam_pwent); } @@ -172,6 +170,7 @@ static int print_users_list (BOOL verbosity, BOOL smbpwdstyle) /********************************************************* Set User Info **********************************************************/ + static int set_user_info (char *username, char *fullname, char *homedir, char *drive, char *script, char *profile) { SAM_ACCOUNT *sam_pwent=NULL; @@ -180,22 +179,26 @@ static int set_user_info (char *username, char *fullname, char *homedir, char *d pdb_init_sam(&sam_pwent); ret = pdb_getsampwnam (sam_pwent, username); - if (ret==False) - { + if (ret==False) { fprintf (stderr, "Username not found!\n"); pdb_free_sam(sam_pwent); return -1; } - if (fullname) pdb_set_fullname(sam_pwent, fullname); - if (homedir) pdb_set_homedir(sam_pwent, homedir); - if (drive) pdb_set_dir_drive(sam_pwent,drive); - if (script) pdb_set_logon_script(sam_pwent, script); - if (profile) pdb_set_profile_path (sam_pwent, profile); - - if (pdb_update_sam_account (sam_pwent, True)) print_user_info (username, True, False); - else - { + if (fullname) + pdb_set_fullname(sam_pwent, fullname); + if (homedir) + pdb_set_homedir(sam_pwent, homedir); + if (drive) + pdb_set_dir_drive(sam_pwent,drive); + if (script) + pdb_set_logon_script(sam_pwent, script); + if (profile) + pdb_set_profile_path (sam_pwent, profile); + + if (pdb_update_sam_account (sam_pwent, True)) + print_user_info (username, True, False); + else { fprintf (stderr, "Unable to modify entry!\n"); pdb_free_sam(sam_pwent); return -1; @@ -217,8 +220,7 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, pdb_init_sam (&sam_pwent); - if (!(pwd = sys_getpwnam(username))) - { + if (!(pwd = sys_getpwnam(username))) { fprintf (stderr, "User %s does not exist in system passwd!\n", username); pdb_free_sam (sam_pwent); return -1; @@ -226,8 +228,7 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, password1 = getpass("new password:"); password2 = getpass("retype new password:"); - if (strcmp (password1, password2)) - { + if (strcmp (password1, password2)) { fprintf (stderr, "Passwords does not match!\n"); pdb_free_sam (sam_pwent); return -1; @@ -236,11 +237,16 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, pdb_set_plaintext_passwd(sam_pwent, password1); pdb_set_username(sam_pwent, username); - if (fullname) pdb_set_fullname(sam_pwent, fullname); - if (homedir) pdb_set_homedir (sam_pwent, homedir); - if (drive) pdb_set_dir_drive (sam_pwent, drive); - if (script) pdb_set_logon_script(sam_pwent, script); - if (profile) pdb_set_profile_path (sam_pwent, profile); + if (fullname) + pdb_set_fullname(sam_pwent, fullname); + if (homedir) + pdb_set_homedir (sam_pwent, homedir); + if (drive) + pdb_set_dir_drive (sam_pwent, drive); + if (script) + pdb_set_logon_script(sam_pwent, script); + if (profile) + pdb_set_profile_path (sam_pwent, profile); /* TODO: Check uid not being in MACHINE UID range!! */ pdb_set_uid (sam_pwent, pwd->pw_uid); @@ -264,6 +270,7 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, /********************************************************* Add New Machine **********************************************************/ + static int new_machine (char *machinename) { SAM_ACCOUNT *sam_pwent=NULL; @@ -274,13 +281,14 @@ static int new_machine (char *machinename) pdb_init_sam (&sam_pwent); - if (machinename[strlen (machinename) -1] == '$') machinename[strlen (machinename) -1] = '\0'; + if (machinename[strlen (machinename) -1] == '$') + machinename[strlen (machinename) -1] = '\0'; safe_strcpy (name, machinename, 16); safe_strcat (name, "$", 16); string_set (&password, machinename); - strlower_m (password); + strlower_m(password); pdb_set_plaintext_passwd (sam_pwent, password); @@ -321,6 +329,7 @@ static int new_machine (char *machinename) /********************************************************* Delete user entry **********************************************************/ + static int delete_user_entry (char *username) { return pdb_delete_sam_account (username); @@ -329,21 +338,21 @@ static int delete_user_entry (char *username) /********************************************************* Delete machine entry **********************************************************/ + static int delete_machine_entry (char *machinename) { char name[16]; safe_strcpy (name, machinename, 16); if (name[strlen(name)] != '$') - { safe_strcat (name, "$", 16); - } return pdb_delete_sam_account (name); } /********************************************************* Import smbpasswd style file **********************************************************/ + static int import_users (char *filename) { FILE *fp = NULL; @@ -363,54 +372,47 @@ static int import_users (char *filename) fprintf (stderr, "pdb_init_sam FAILED!\n"); } - if((fp = sys_fopen(filename, "rb")) == NULL) - { + if((fp = sys_fopen(filename, "rb")) == NULL) { fprintf (stderr, "%s\n", strerror (ferror (fp))); return -1; } - while (!feof(fp)) - { + while (!feof(fp)) { /*Get a new line*/ linebuf[0] = '\0'; fgets(linebuf, 256, fp); - if (ferror(fp)) - { + if (ferror(fp)) { fprintf (stderr, "%s\n", strerror (ferror (fp))); pdb_free_sam(sam_pwent); return -1; } - if ((linebuf_len = strlen(linebuf)) == 0) - { + if ((linebuf_len = strlen(linebuf)) == 0) { line++; continue; } - if (linebuf[linebuf_len - 1] != '\n') - { + if (linebuf[linebuf_len - 1] != '\n') { c = '\0'; - while (!ferror(fp) && !feof(fp)) - { + while (!ferror(fp) && !feof(fp)) { c = fgetc(fp); if (c == '\n') break; } - } - else linebuf[linebuf_len - 1] = '\0'; + } else + linebuf[linebuf_len - 1] = '\0'; linebuf[linebuf_len] = '\0'; - if ((linebuf[0] == 0) && feof(fp)) - { + if ((linebuf[0] == 0) && feof(fp)) { /*end of file!!*/ pdb_free_sam(sam_pwent); return 0; } line++; - if (linebuf[0] == '#' || linebuf[0] == '\0') continue; + if (linebuf[0] == '#' || linebuf[0] == '\0') + continue; pdb_set_acct_ctrl (sam_pwent,ACB_NORMAL); /* Get user name */ p = (unsigned char *) strchr_m(linebuf, ':'); - if (p == NULL) - { + if (p == NULL) { fprintf (stderr, "Error: malformed password entry at line %d !!\n", line); pdb_reset_sam (sam_pwent); continue; @@ -420,22 +422,19 @@ static int import_users (char *filename) /* Get smb uid. */ p++; - if(*p == '-') - { + if(*p == '-') { fprintf (stderr, "Error: negative uid at line %d\n", line); pdb_reset_sam (sam_pwent); continue; } - if (!isdigit(*p)) - { + if (!isdigit(*p)) { fprintf (stderr, "Error: malformed password entry at line %d (uid not number)\n", line); pdb_reset_sam (sam_pwent); continue; } uidval = atoi((char *) p); while (*p && isdigit(*p)) p++; - if (*p != ':') - { + if (*p != ':') { fprintf (stderr, "Error: malformed password entry at line %d (no : after uid)\n", line); pdb_reset_sam (sam_pwent); continue; @@ -446,37 +445,28 @@ static int import_users (char *filename) /* Get passwords */ p++; - if (*p == '*' || *p == 'X') - { + if (*p == '*' || *p == 'X') { /* Password deliberately invalid */ fprintf (stderr, "Warning: entry invalidated for user %s\n", user_name); pdb_set_lanman_passwd(sam_pwent, NULL); pdb_set_nt_passwd(sam_pwent,NULL); pdb_set_acct_ctrl(sam_pwent, pdb_get_acct_ctrl(sam_pwent) | ACB_DISABLED); - } - else - { - if (linebuf_len < (PTR_DIFF(p, linebuf) + 33)) - { + } else { + if (linebuf_len < (PTR_DIFF(p, linebuf) + 33)) { fprintf (stderr, "Error: malformed password entry at line %d (password too short)\n",line); pdb_reset_sam (sam_pwent); continue; } - if (p[32] != ':') - { + if (p[32] != ':') { fprintf (stderr, "Error: malformed password entry at line %d (no terminating :)\n",line); pdb_reset_sam (sam_pwent); continue; } - if (!strncasecmp((char *) p, "NO PASSWORD", 11)) - { + if (!strncasecmp((char *) p, "NO PASSWORD", 11)) { pdb_set_lanman_passwd(sam_pwent, NULL); pdb_set_acct_ctrl(sam_pwent, pdb_get_acct_ctrl(sam_pwent) | ACB_PWNOTREQ); - } - else - { - if (!smbpasswd_gethexpwd((char *)p, smbpwd)) - { + } else { + if (!smbpasswd_gethexpwd((char *)p, smbpwd)) { fprintf (stderr, "Error: malformed Lanman password entry at line %d (non hex chars)\n", line); pdb_reset_sam (sam_pwent); continue; @@ -486,12 +476,9 @@ static int import_users (char *filename) /* NT password */ pdb_set_nt_passwd(sam_pwent, smbpwd); p += 33; - if ((linebuf_len >= (PTR_DIFF(p, linebuf) + 33)) && (p[32] == ':')) - { - if (*p != '*' && *p != 'X') - { - if (pdb_gethexpwd((char *)p,smbntpwd)) - { + if ((linebuf_len >= (PTR_DIFF(p, linebuf) + 33)) && (p[32] == ':')) { + if (*p != '*' && *p != 'X') { + if (pdb_gethexpwd((char *)p,smbntpwd)) { pdb_set_nt_passwd(sam_pwent, smbntpwd); } } @@ -500,32 +487,29 @@ static int import_users (char *filename) } /* Get ACCT_CTRL field if any */ - if (*p == '[') - { + if (*p == '[') { uint16 acct_ctrl; unsigned char *end_p = (unsigned char *)strchr_m((char *)p, ']'); acct_ctrl = pdb_decode_acct_ctrl((char*)p); - if (acct_ctrl) acct_ctrl = ACB_NORMAL; + if (acct_ctrl) + acct_ctrl = ACB_NORMAL; pdb_set_acct_ctrl(sam_pwent, acct_ctrl); /* Get last change time */ - if(end_p) p = end_p + 1; - if(*p == ':') - { + if(end_p) + p = end_p + 1; + if(*p == ':') { p++; - if(*p && (StrnCaseCmp((char *)p, "LCT-", 4)==0)) - { + if(*p && (StrnCaseCmp((char *)p, "LCT-", 4)==0)) { int i; p += 4; - for(i = 0; i < 8; i++) - { + for(i = 0; i < 8; i++) { if(p[i] == '\0' || !isxdigit(p[i])) break; } - if(i == 8) - { + if(i == 8) { pdb_set_pass_last_set_time (sam_pwent, (time_t)strtol((char *)p, NULL, 16)); } } @@ -534,10 +518,8 @@ static int import_users (char *filename) /* Old-style workstation account code droped. */ - if (pdb_get_acct_ctrl(sam_pwent) & ACB_WSTRUST) - { - if ((uidval < BASE_MACHINE_UID) || (uidval > MAX_MACHINE_UID)) - { + if (pdb_get_acct_ctrl(sam_pwent) & ACB_WSTRUST) { + if ((uidval < BASE_MACHINE_UID) || (uidval > MAX_MACHINE_UID)) { fprintf (stderr, "Warning: Machine UID out of normal range %d-%d\n", BASE_MACHINE_UID, MAX_MACHINE_UID); @@ -546,12 +528,10 @@ static int import_users (char *filename) } /* Test if user is valid */ - if (pdb_get_acct_ctrl(sam_pwent) & ACB_NORMAL) - { + if (pdb_get_acct_ctrl(sam_pwent) & ACB_NORMAL) { struct passwd *pwd = NULL; - if (!(pwd = sys_getpwnam(user_name))) - { + if (!(pwd = sys_getpwnam(user_name))) { fprintf (stderr, "Error: User %s does not exist in system passwd!\n", user_name); continue; } @@ -568,8 +548,7 @@ static int import_users (char *filename) */ /* Now ADD the entry */ - if (!(pdb_add_sam_account (sam_pwent))) - { + if (!(pdb_add_sam_account (sam_pwent))) { fprintf (stderr, "Unable to add user entry!\n"); pdb_reset_sam (sam_pwent); continue; @@ -586,6 +565,7 @@ static int import_users (char *filename) /********************************************************* Start here. **********************************************************/ + int main (int argc, char **argv) { int ch; @@ -610,9 +590,7 @@ int main (int argc, char **argv) setup_logging("tdbedit", True); - if (argc < 2) - - { + if (argc < 2) { usage(); return 0; } @@ -679,45 +657,43 @@ int main (int argc, char **argv) usage(); } } - if (((add_user?1:0) + (delete_user?1:0) + (list_users?1:0) + (import?1:0) + (setparms?1:0)) > 1) - { + if (((add_user?1:0) + (delete_user?1:0) + (list_users?1:0) + (import?1:0) + (setparms?1:0)) > 1) { fprintf (stderr, "Incompatible options on command line!\n"); usage(); exit(1); } - if (add_user) - { - if (!user_name) - { + if (add_user) { + if (!user_name) { fprintf (stderr, "Username not specified! (use -u option)\n"); return -1; } - if (machine) return new_machine (user_name); - else return new_user (user_name, full_name, home_dir, home_drive, logon_script, profile_path); + if (machine) + return new_machine (user_name); + else + return new_user (user_name, full_name, home_dir, home_drive, logon_script, profile_path); } - if (delete_user) - { - if (!user_name) - { + if (delete_user) { + if (!user_name) { fprintf (stderr, "Username not specified! (use -u option)\n"); return -1; } - if (machine) return delete_machine_entry (user_name); - else return delete_user_entry (user_name); + if (machine) + return delete_machine_entry (user_name); + else + return delete_user_entry (user_name); } - if (user_name) - { - if (setparms) set_user_info ( user_name, - full_name, + if (user_name) { + if (setparms) + set_user_info ( user_name, full_name, home_dir, home_drive, logon_script, profile_path); - - else return print_user_info (user_name, verbose, spstyle); + else + return print_user_info (user_name, verbose, spstyle); return 0; } -- cgit From 75c50613316140314c89546c45d967bb0201c375 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 27 Sep 2001 21:27:12 +0000 Subject: Removed smbpasswd_XX call (how did this get re-added, I removed all these yesterday ?). Jeremy. (This used to be commit e25dc68843ed10d8454cb8166c39ff4b2e6a4159) --- source3/utils/pdbedit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index 41d66777fd..d0629fa258 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -466,7 +466,7 @@ static int import_users (char *filename) pdb_set_lanman_passwd(sam_pwent, NULL); pdb_set_acct_ctrl(sam_pwent, pdb_get_acct_ctrl(sam_pwent) | ACB_PWNOTREQ); } else { - if (!smbpasswd_gethexpwd((char *)p, smbpwd)) { + if (!pdb_gethexpwd((char *)p, smbpwd)) { fprintf (stderr, "Error: malformed Lanman password entry at line %d (non hex chars)\n", line); pdb_reset_sam (sam_pwent); continue; -- cgit From 81697d5ebe33ad95dedfc376118fcdf0367cf052 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 29 Sep 2001 13:08:26 +0000 Subject: Fix up a number of intertwined issues: The big one is a global change to allow us to NULLify the free'ed pointer to a former passdb object. This was done to allow idra's SAFE_FREE() macro to do its magic, and to satisfy the input test in pdb_init_sam() for a NULL pointer to start with. This NULL pointer test was what was breaking the adding of accounts up until now, and this code has been reworked to avoid duplicating work - I hope this will avoid a similar mess-up in future. Finally, I fixed a few nasty bugs where the pdb_ fuctions's return codes were being ignored. Some of these functions malloc() and are permitted to fail. Also, this caught a nasty bug where pdb_set_lanman_password(sam, NULL) acheived precisely didilly-squat, just returning False. Now that we check the returns this bug was spotted. This could allow different LM and NT passwords. - the pdbedit code needs to start checking these too, but I havn't had a chance to fix it. I have also fixed up where some of the password changing code was using the pdb_set functions to store *internal* data. I assume this is from a previous lot of mass conversion work... Most likally (and going on past experience) I have missed somthing, probably in the LanMan password change code which I havn't yet been able to test, but this lot is in much better shape than it was before. If all this is too much to swallow (particularly for 2.2.2) then just adding a sam_pass = NULL to the particular line of passdb.c should do the trick for the ovbious bug. Andrew Bartlett (This used to be commit 762c8758a7869809d89b4da9c2a5249678942930) --- source3/utils/pdbedit.c | 36 ++++++++++++++++++------------------ source3/utils/smbpasswd.c | 8 ++++---- 2 files changed, 22 insertions(+), 22 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index d0629fa258..ce5195a810 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -128,12 +128,12 @@ static int print_user_info (char *username, BOOL verbosity, BOOL smbpwdstyle) if (ret==False) { fprintf (stderr, "Username not found!\n"); - pdb_free_sam(sam_pwent); + pdb_free_sam(&sam_pwent); return -1; } ret=print_sam_info (sam_pwent, verbosity, smbpwdstyle); - pdb_free_sam(sam_pwent); + pdb_free_sam(&sam_pwent); return ret; } @@ -151,7 +151,7 @@ static int print_users_list (BOOL verbosity, BOOL smbpwdstyle) ret = pdb_setsampwent(False); if (ret && errno == ENOENT) { fprintf (stderr,"Password database not found!\n"); - pdb_free_sam(sam_pwent); + pdb_free_sam(&sam_pwent); exit(1); } @@ -163,7 +163,7 @@ static int print_users_list (BOOL verbosity, BOOL smbpwdstyle) } pdb_endsampwent (); - pdb_free_sam(sam_pwent); + pdb_free_sam(&sam_pwent); return 0; } @@ -181,7 +181,7 @@ static int set_user_info (char *username, char *fullname, char *homedir, char *d ret = pdb_getsampwnam (sam_pwent, username); if (ret==False) { fprintf (stderr, "Username not found!\n"); - pdb_free_sam(sam_pwent); + pdb_free_sam(&sam_pwent); return -1; } @@ -200,10 +200,10 @@ static int set_user_info (char *username, char *fullname, char *homedir, char *d print_user_info (username, True, False); else { fprintf (stderr, "Unable to modify entry!\n"); - pdb_free_sam(sam_pwent); + pdb_free_sam(&sam_pwent); return -1; } - pdb_free_sam(sam_pwent); + pdb_free_sam(&sam_pwent); return 0; } @@ -222,7 +222,7 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, if (!(pwd = sys_getpwnam(username))) { fprintf (stderr, "User %s does not exist in system passwd!\n", username); - pdb_free_sam (sam_pwent); + pdb_free_sam (&sam_pwent); return -1; } @@ -230,7 +230,7 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, password2 = getpass("retype new password:"); if (strcmp (password1, password2)) { fprintf (stderr, "Passwords does not match!\n"); - pdb_free_sam (sam_pwent); + pdb_free_sam (&sam_pwent); return -1; } @@ -260,10 +260,10 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive, print_user_info (username, True, False); } else { fprintf (stderr, "Unable to add user! (does it alredy exist?)\n"); - pdb_free_sam (sam_pwent); + pdb_free_sam (&sam_pwent); return -1; } - pdb_free_sam (sam_pwent); + pdb_free_sam (&sam_pwent); return 0; } @@ -297,7 +297,7 @@ static int new_machine (char *machinename) for (uid=BASE_MACHINE_UID; uid<=MAX_MACHINE_UID; uid++) { pdb_init_sam (&sam_trust); if (pdb_getsampwuid (sam_trust, uid)) { - pdb_free_sam (sam_trust); + pdb_free_sam (&sam_trust); } else { break; } @@ -305,7 +305,7 @@ static int new_machine (char *machinename) if (uid>MAX_MACHINE_UID) { fprintf (stderr, "No more free UIDs available to Machine accounts!\n"); - pdb_free_sam(sam_pwent); + pdb_free_sam(&sam_pwent); return -1; } @@ -319,10 +319,10 @@ static int new_machine (char *machinename) print_user_info (name, True, False); } else { fprintf (stderr, "Unable to add machine! (does it already exist?)\n"); - pdb_free_sam (sam_pwent); + pdb_free_sam (&sam_pwent); return -1; } - pdb_free_sam (sam_pwent); + pdb_free_sam (&sam_pwent); return 0; } @@ -383,7 +383,7 @@ static int import_users (char *filename) fgets(linebuf, 256, fp); if (ferror(fp)) { fprintf (stderr, "%s\n", strerror (ferror (fp))); - pdb_free_sam(sam_pwent); + pdb_free_sam(&sam_pwent); return -1; } if ((linebuf_len = strlen(linebuf)) == 0) { @@ -401,7 +401,7 @@ static int import_users (char *filename) linebuf[linebuf_len] = '\0'; if ((linebuf[0] == 0) && feof(fp)) { /*end of file!!*/ - pdb_free_sam(sam_pwent); + pdb_free_sam(&sam_pwent); return 0; } line++; @@ -558,7 +558,7 @@ static int import_users (char *filename) pdb_reset_sam (sam_pwent); } printf ("%d lines read.\n%d entryes imported\n", line, good); - pdb_free_sam(sam_pwent); + pdb_free_sam(&sam_pwent); return 0; } diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 14b10c1700..168547c712 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -524,7 +524,7 @@ static BOOL password_change(const char *remote_machine, char *user_name, return False; } ret = remote_password_change(remote_machine, user_name, - old_passwd, new_passwd, err_str, sizeof(err_str)); + old_passwd, new_passwd, err_str, sizeof(err_str)); if(*err_str) fprintf(stderr, err_str); return ret; @@ -707,7 +707,7 @@ static int process_root(int argc, char *argv[]) usage(); } - if (!user_name[0] && (pwd = sys_getpwuid(0))) { + if (!user_name[0] && (pwd = sys_getpwuid(geteuid()))) { fstrcpy(user_name, pwd->pw_name); } @@ -768,7 +768,7 @@ static int process_root(int argc, char *argv[]) if((sampass != False) && (pdb_get_lanman_passwd(sampass) != NULL)) { new_passwd = xstrdup("XXXX"); /* Don't care. */ } - pdb_free_sam(sampass); + pdb_free_sam(&sampass); } if(!new_passwd) @@ -799,7 +799,7 @@ static int process_root(int argc, char *argv[]) if((ret != False) && (pdb_get_acct_ctrl(sampass) & ACB_PWNOTREQ) ) printf(" User has no password flag set."); printf("\n"); - pdb_free_sam(sampass); + pdb_free_sam(&sampass); } done: -- cgit From 2e3be37878f065b8012e4bb16bede14790f240f0 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 30 Sep 2001 14:51:38 +0000 Subject: Don't try to write the LM password in the NT password feild. (This used to be commit 90dcbe16be065e2113fba1d3cee28f40be1bb86c) --- source3/utils/pdbedit.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/utils') diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index ce5195a810..64a152aaa1 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -474,7 +474,6 @@ static int import_users (char *filename) pdb_set_lanman_passwd(sam_pwent, smbpwd); } /* NT password */ - pdb_set_nt_passwd(sam_pwent, smbpwd); p += 33; if ((linebuf_len >= (PTR_DIFF(p, linebuf) + 33)) && (p[32] == ':')) { if (*p != '*' && *p != 'X') { -- cgit From dc1fc3ee8ec2199bc73bb5d7ec711c6800f61d65 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 2 Oct 2001 04:29:50 +0000 Subject: Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header. (This used to be commit 2d0922b0eabfdc0aaf1d0797482fef47ed7fde8e) --- source3/utils/nmblookup.c | 2 -- source3/utils/pdbedit.c | 1 - source3/utils/rpccheck.c | 2 -- source3/utils/smbfilter.c | 2 -- source3/utils/smbgroupedit.c | 3 --- source3/utils/smbpasswd.c | 1 - source3/utils/status.c | 3 --- source3/utils/testparm.c | 3 --- source3/utils/testprns.c | 4 ---- 9 files changed, 21 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index ff675a72e5..ceec1859e7 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -24,8 +24,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - extern struct in_addr ipzero; static BOOL use_bcast = True; diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index 64a152aaa1..6e7458fb4e 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -32,7 +32,6 @@ #include "includes.h" extern pstring global_myname; -extern int DEBUGLEVEL; /* * Next two lines needed for SunOS and don't diff --git a/source3/utils/rpccheck.c b/source3/utils/rpccheck.c index 1b00d528ac..287b39bd1e 100644 --- a/source3/utils/rpccheck.c +++ b/source3/utils/rpccheck.c @@ -21,8 +21,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - main() { char filter[]="0123456789ABCDEF"; diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c index 8550159955..5c21f22cfd 100644 --- a/source3/utils/smbfilter.c +++ b/source3/utils/smbfilter.c @@ -36,8 +36,6 @@ static char *netbiosname; static char packet[BUFFER_SIZE]; -extern int DEBUGLEVEL; - static void filter_reply(char *buf) { int msg_type = CVAL(buf,0); diff --git a/source3/utils/smbgroupedit.c b/source3/utils/smbgroupedit.c index 4e192ed43d..062271abc5 100644 --- a/source3/utils/smbgroupedit.c +++ b/source3/utils/smbgroupedit.c @@ -23,7 +23,6 @@ #include "includes.h" extern pstring global_myname; -extern int DEBUGLEVEL; extern DOM_SID global_sam_sid; /* @@ -342,5 +341,3 @@ int main (int argc, char **argv) return 0; } - - diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 168547c712..13ca1c0d71 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -22,7 +22,6 @@ #include "includes.h" extern pstring global_myname; -extern int DEBUGLEVEL; /* * Next two lines needed for SunOS and don't diff --git a/source3/utils/status.c b/source3/utils/status.c index 15c9c4aad4..3beae0f815 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -44,8 +44,6 @@ struct session_record{ struct session_record *next; } *srecs; -extern int DEBUGLEVEL; - static pstring Ucrit_username = ""; /* added by OH */ static pid_t Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ static int Ucrit_MaxPid=0; /* added by OH */ @@ -680,4 +678,3 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo return (0); } - diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index f4d072ed77..09948b8635 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -35,9 +35,6 @@ #include "includes.h" #include "smb.h" -/* these live in util.c */ -extern int DEBUGLEVEL; - /*********************************************** Here we do a set of 'hard coded' checks for bad configuration settings. diff --git a/source3/utils/testprns.c b/source3/utils/testprns.c index df697a0ed1..cf26e8aa40 100644 --- a/source3/utils/testprns.c +++ b/source3/utils/testprns.c @@ -34,9 +34,6 @@ #include "includes.h" #include "smb.h" -/* these live in util.c */ -extern int DEBUGLEVEL; - int main(int argc, char *argv[]) { char *pszTemp; @@ -66,4 +63,3 @@ int main(int argc, char *argv[]) } return (0); } - -- cgit From a42efb497153dcca1fad227e28f5eaf41ee943c3 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 3 Oct 2001 21:10:29 +0000 Subject: fix some possible memleaks and not tested reallocs spotted by Andreas Moroder (This used to be commit d30939a091b48f4d77f7618c75668ae151a5592e) --- source3/utils/rpccheck.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/utils') diff --git a/source3/utils/rpccheck.c b/source3/utils/rpccheck.c index 287b39bd1e..3956310241 100644 --- a/source3/utils/rpccheck.c +++ b/source3/utils/rpccheck.c @@ -40,6 +40,7 @@ main() DEBUGLEVEL=10; ctx=talloc_init(); + if (!ctx) exit(1); prs_init(&ps, 1600, 4, ctx, MARSHALL); -- cgit From 76745313b16c07092b0198da4d4fc05b38e600f7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 11 Oct 2001 05:53:15 +0000 Subject: Fixed bug when status=no and max smbd processes > 0. Jeremy. (This used to be commit d1adaee373f08020d350af2aa65b7651da94bdae) --- source3/utils/testparm.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 09948b8635..9397ea2520 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -157,6 +157,11 @@ via the %%o substitution. With encrypted passwords this is not possible.\n", lp_ } } + if (lp_status(-1) && lp_max_smbd_processes()) { + printf("ERROR: the 'max smbd processes' parameter is set and the 'status' parameter is set to 'no'.\n"); + ret = 1; + } + return ret; } -- cgit From 8cec5cf35f17568009c70d37bb8b2a1f360d3422 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 11 Oct 2001 08:40:42 +0000 Subject: first step in converting the head branch to use lang_tdb.c instead of gettext for internationalisation support. There is more to do (This used to be commit ab7f67677a1ade4669e5c2750d0a38422ea616a9) --- source3/utils/smbfilter.c | 52 ++++++++++++++++++++++++++++++++--------------- source3/utils/testparm.c | 5 ----- 2 files changed, 36 insertions(+), 21 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c index 5c21f22cfd..0707db0e22 100644 --- a/source3/utils/smbfilter.c +++ b/source3/utils/smbfilter.c @@ -26,7 +26,7 @@ #define SECURITY_SET 0 /* this forces non-unicode */ -#define CAPABILITY_MASK (CAP_NT_SMBS | CAP_RPC_REMOTE_APIS) +#define CAPABILITY_MASK 0 #define CAPABILITY_SET 0 /* and non-unicode for the client too */ @@ -36,6 +36,22 @@ static char *netbiosname; static char packet[BUFFER_SIZE]; +static void save_file(const char *fname, void *packet, size_t length) +{ + int fd; + fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0644); + if (fd == -1) { + perror(fname); + return; + } + if (write(fd, packet, length) != length) { + fprintf(stderr,"Failed to write %s\n", fname); + return; + } + close(fd); + printf("Wrote %d bytes to %s\n", length, fname); +} + static void filter_reply(char *buf) { int msg_type = CVAL(buf,0); @@ -75,8 +91,8 @@ static void filter_request(char *buf) /* session request */ name_extract(buf,4,name1); name_extract(buf,4 + name_len(buf + 4),name2); - DEBUG(0,("sesion_request: %s -> %s\n", - name1, name2)); + d_printf("sesion_request: %s -> %s\n", + name1, name2); if (netbiosname) { /* replace the destination netbios name */ name_mangle(netbiosname, buf+4, 0x20); @@ -90,6 +106,10 @@ static void filter_request(char *buf) case SMBsesssetupX: /* force the client capabilities */ x = IVAL(buf,smb_vwv11); + d_printf("SMBsesssetupX cap=0x%08x\n", x); + d_printf("pwlen=%d/%d\n", SVAL(buf, smb_vwv7), SVAL(buf, smb_vwv8)); + system("mv sessionsetup.dat sessionsetup1.dat"); + save_file("sessionsetup.dat", smb_buf(buf), SVAL(buf, smb_vwv7)); x = (x | CLI_CAPABILITY_SET) & ~CLI_CAPABILITY_MASK; SIVAL(buf, smb_vwv11, x); break; @@ -103,10 +123,10 @@ static void filter_child(int c, struct in_addr dest_ip) int s; /* we have a connection from a new client, now connect to the server */ - s = open_socket_out(SOCK_STREAM, &dest_ip, 139, LONG_CONNECT_TIMEOUT); + s = open_socket_out(SOCK_STREAM, &dest_ip, 445, LONG_CONNECT_TIMEOUT); if (s == -1) { - DEBUG(0,("Unable to connect to %s\n", inet_ntoa(dest_ip))); + d_printf("Unable to connect to %s\n", inet_ntoa(dest_ip)); exit(1); } @@ -123,28 +143,28 @@ static void filter_child(int c, struct in_addr dest_ip) if (c != -1 && FD_ISSET(c, &fds)) { if (!receive_smb(c, packet, 0)) { - DEBUG(0,("client closed connection\n")); + d_printf("client closed connection\n"); exit(0); } filter_request(packet); if (!send_smb(s, packet)) { - DEBUG(0,("server is dead\n")); + d_printf("server is dead\n"); exit(1); } } if (s != -1 && FD_ISSET(s, &fds)) { if (!receive_smb(s, packet, 0)) { - DEBUG(0,("server closed connection\n")); + d_printf("server closed connection\n"); exit(0); } filter_reply(packet); if (!send_smb(c, packet)) { - DEBUG(0,("client is dead\n")); + d_printf("client is dead\n"); exit(1); } } } - DEBUG(0,("Connection closed\n")); + d_printf("Connection closed\n"); exit(0); } @@ -156,20 +176,20 @@ static void start_filter(char *desthost) CatchChild(); - /* start listening on port 139 locally */ - s = open_socket_in(SOCK_STREAM, 139, 0, 0, True); + /* start listening on port 445 locally */ + s = open_socket_in(SOCK_STREAM, 445, 0, 0, True); if (s == -1) { - DEBUG(0,("bind failed\n")); + d_printf("bind failed\n"); exit(1); } if (listen(s, 5) == -1) { - DEBUG(0,("listen failed\n")); + d_printf("listen failed\n"); } if (!resolve_name(desthost, &dest_ip, 0x20)) { - DEBUG(0,("Unable to resolve host %s\n", desthost)); + d_printf("Unable to resolve host %s\n", desthost); exit(1); } @@ -221,7 +241,7 @@ int main(int argc, char *argv[]) } if (!lp_load(configfile,True,False,False)) { - DEBUG(0,("Unable to load config file\n")); + d_printf("Unable to load config file\n"); } start_filter(desthost); diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 9397ea2520..09948b8635 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -157,11 +157,6 @@ via the %%o substitution. With encrypted passwords this is not possible.\n", lp_ } } - if (lp_status(-1) && lp_max_smbd_processes()) { - printf("ERROR: the 'max smbd processes' parameter is set and the 'status' parameter is set to 'no'.\n"); - ret = 1; - } - return ret; } -- cgit From 10d03317544a070bf91c3249b45acea9e5fa8836 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 19 Oct 2001 16:51:26 +0000 Subject: Add command-line remote management utility (This used to be commit 50c243518aa7996e697876096073598a3b5a8d3a) --- source3/utils/net.c | 1510 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1510 insertions(+) create mode 100644 source3/utils/net.c (limited to 'source3/utils') diff --git a/source3/utils/net.c b/source3/utils/net.c new file mode 100644 index 0000000000..93214dda5a --- /dev/null +++ b/source3/utils/net.c @@ -0,0 +1,1510 @@ +/* + Samba Unix/Linux SMB client library + Version 3.0 + Distributed SMB/CIFS Server Management Utility + Copyright (C) 2001 Steve French (sfrench@us.ibm.com) + Copyright (C) 2001 Jim McDonough (jmcd@us.ibm.com) + + connect_to_ipc based on similar routine + Copyright (C) Andrew Tridgell 1994-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. +*/ + +/*****************************************************/ +/* */ +/* Distributed SMB/CIFS Server Management Utility */ +/* */ +/* The intent was to make the syntax similar */ +/* to the NET utility (first developed in DOS */ +/* with additional interesting & useful functions */ +/* added in later SMB server network operating */ +/* systems). */ +/* */ +/*****************************************************/ + +#include +#include + +/***********************************************************************/ +/* Beginning of internationalization section. Translatable constants */ +/* should be kept in this area and referenced in the rest of the code. */ +/* */ +/* No functions, outside of Samba or LSB (Linux Standards Base) should */ +/* be used (if possible). */ +/***********************************************************************/ + +typedef struct _functable { + int func; + char funcname[12]; +} functable; + +/* functions available */ +#define FILEF 1 +#define SHAREF 2 +#define SESSIONF 3 +#define SERVERF 4 +#define DOMAINF 5 +#define PRINTQF 6 +#define USERF 7 +#define GROUPF 8 +#define VALIDATEF 9 +#define GROUPMEMBERF 10 +#define HELPF 11 + +const functable net_func[] = { + { FILEF, "FILE"}, + { SHAREF, "SHARE"}, + { SESSIONF, "SESSION"}, + { SERVERF, "SERVER"}, + { DOMAINF, "DOMAIN"}, + { PRINTQF, "PRINTQ"}, + { USERF, "USER"}, + { GROUPF, "GROUP"}, + { VALIDATEF, "VALIDATE"}, + { GROUPMEMBERF, "GROUPMEMBER"}, + { HELPF, "HELP"} +}; + +/* subfunctions available */ +#define OTHER_SF 0 +#define LIST_SF 1 /* enumerate */ +#define ADD_SF 2 /* also used for create and start */ +#define DELETE_SF 3 /* also used for close and stop */ +#define INFO_SF 4 /* get information */ + +const functable net_subfunc[] = { + { LIST_SF, "LIST" }, + { LIST_SF, "ENUMERATE" }, + { ADD_SF, "ADD" }, + { ADD_SF, "CREATE" }, + { DELETE_SF, "CLOSE" }, + { DELETE_SF, "DELETE" } +}; + +const char share_type[][6] = { + "Disk", + "Print", + "Dev", + "IPC" +}; + +#define PASSWORD_PROMPT "Password: " +#define YES_STRING "Yes" +#define NO_STRING "No" + +#define NET_USAGE \ + "\nUsage: \n"\ + " net domain \tto list domains \n"\ + " net file \tto list open files on a server \n"\ + " net group \tto list user groups \n"\ + " net groupmember to list users in a group \n"\ + " net printq \tto list the print queues on a server\n"\ + " net server \tto list servers in a domain\n"\ + " net session \tto list clients with open sessions to a server\n"\ + " net share \tto list shares exported by a server\n"\ + " net user \tto list users\n"\ + " net validate \tto check whether a user and the corresponding password are valid\n"\ + " net help\n"\ + "\nType \"net help