static void pwd_sub(char *buf)
{
	all_string_sub(buf,"\\n","\n",0);
	all_string_sub(buf,"\\r","\r",0);
	all_string_sub(buf,"\\s"," ",0);
	all_string_sub(buf,"\\t","\t",0);
}
Beispiel #2
0
/**
 Something really nasty happened - panic !
**/
_PUBLIC_ _NORETURN_ void smb_panic(const char *why)
{
	int result;

	if (panic_action && *panic_action) {
		char pidstr[20];
		char cmdstring[200];
		safe_strcpy(cmdstring, panic_action, sizeof(cmdstring));
		snprintf(pidstr, sizeof(pidstr), "%u", getpid());
		all_string_sub(cmdstring, "%PID%", pidstr, sizeof(cmdstring));
		if (progname) {
			all_string_sub(cmdstring, "%PROG%", progname, sizeof(cmdstring));
		}
		DEBUG(0, ("smb_panic(): calling panic action [%s]\n", cmdstring));
		result = system(cmdstring);

		if (result == -1)
			DEBUG(0, ("smb_panic(): fork failed in panic action: %s\n",
				  strerror(errno)));
		else
			DEBUG(0, ("smb_panic(): action returned status %d\n",
				  WEXITSTATUS(result)));
	}
	DEBUG(0,("PANIC: %s\n", why));

	call_backtrace();

#ifdef SIGABRT
	CatchSignal(SIGABRT,SIGNAL_CAST SIG_DFL);
#endif
	abort();
}
Beispiel #3
0
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;
}
Beispiel #4
0
static char *tstring(time_t t)
{
	static pstring buf;
	pstrcpy(buf, asctime(LocalTime(&t)));
	all_string_sub(buf," ","&nbsp;",sizeof(buf));
	return buf;
}
Beispiel #5
0
/* load a msg file into the tdb */
static bool load_msg(const char *msg_file)
{
	char **lines;
	int num_lines, i;
	char *msgid, *msgstr;
	TDB_DATA data;

	lines = file_lines_load(msg_file, &num_lines, 0, NULL);

	if (!lines) {
		return False;
	}

	if (tdb_lockall(tdb) != 0) {
		TALLOC_FREE(lines);
		return False;
	}

	/* wipe the db */
	tdb_wipe_all(tdb);

	msgid = NULL;
	
	for (i=0;i<num_lines;i++) {
		if (strncmp(lines[i], "msgid \"", 7) == 0) {
			msgid = lines[i] + 7;
		}
		if (msgid && strncmp(lines[i], "msgstr \"", 8) == 0) {
			msgstr = lines[i] + 8;
			trim_char(msgid, '\0', '\"');
			trim_char(msgstr, '\0', '\"');
			if (*msgstr == 0) {
				msgstr = msgid;
			}
			all_string_sub(msgid, "\\n", "\n", 0);
			all_string_sub(msgstr, "\\n", "\n", 0);
			data = string_term_tdb_data(msgstr);
			tdb_store_bystring(tdb, msgid, data, 0);
			msgid = NULL;
		}
	}

	TALLOC_FREE(lines);
	tdb_unlockall(tdb);

	return True;
}
Beispiel #6
0
/* load a msg file into the tdb */
static BOOL load_msg(const char *msg_file)
{
	char **lines;
	int num_lines, i;
	char *msgid, *msgstr;
	TDB_DATA key, data;

	lines = file_lines_load(msg_file, &num_lines);

	if (!lines) {
		return False;
	}

	if (tdb_lockall(tdb) != 0) return False;

	/* wipe the db */
	tdb_traverse(tdb, tdb_traverse_delete_fn, NULL);

	msgid = NULL;
	
	for (i=0;i<num_lines;i++) {
		if (strncmp(lines[i], "msgid \"", 7) == 0) {
			msgid = lines[i] + 7;
		}
		if (msgid && strncmp(lines[i], "msgstr \"", 8) == 0) {
			msgstr = lines[i] + 8;
			trim_char(msgid, '\0', '\"');
			trim_char(msgstr, '\0', '\"');
			if (*msgstr == 0) {
				msgstr = msgid;
			}
			all_string_sub(msgid, "\\n", "\n", 0);
			all_string_sub(msgstr, "\\n", "\n", 0);
			key.dptr = msgid;
			key.dsize = strlen(msgid)+1;
			data.dptr = msgstr;
			data.dsize = strlen(msgstr)+1;
			tdb_store(tdb, key, data, 0);
			msgid = NULL;
		}
	}

	file_lines_free(lines);
	tdb_unlockall(tdb);

	return True;
}
Beispiel #7
0
void sync_browse_lists(struct work_record *work,
		       char *name, int nm_type, 
		       struct in_addr ip, bool local, bool servers)
{
	struct sync_record *s;
	static int counter;

	START_PROFILE(sync_browse_lists);
	/* Check we're not trying to sync with ourselves. This can
	   happen if we are a domain *and* a local master browser. */
	if (ismyip_v4(ip)) {
done:
		END_PROFILE(sync_browse_lists);
		return;
	}

	s = SMB_MALLOC_P(struct sync_record);
	if (!s) goto done;

	ZERO_STRUCTP(s);

	unstrcpy(s->workgroup, work->work_group);
	unstrcpy(s->server, name);
	s->ip = ip;

	if (asprintf(&s->fname, "%s/sync.%d", lp_lockdir(), counter++) < 0) {
		SAFE_FREE(s);
		goto done;
	}
	/* Safe to use as 0 means no size change. */
	all_string_sub(s->fname,"//", "/", 0);

	DLIST_ADD(syncs, s);

	/* the parent forks and returns, leaving the child to do the
	   actual sync and call END_PROFILE*/
	CatchChild();
	if ((s->pid = sys_fork())) return;

	BlockSignals( False, SIGTERM );

	DEBUG(2,("Initiating browse sync for %s to %s(%s)\n",
		 work->work_group, name, inet_ntoa(ip)));

	fp = x_fopen(s->fname,O_WRONLY|O_CREAT|O_TRUNC, 0644);
	if (!fp) {
		END_PROFILE(sync_browse_lists);
		_exit(1);
	}

	sync_child(name, nm_type, work->work_group, ip, local, servers,
		   s->fname);

	x_fclose(fp);
	END_PROFILE(sync_browse_lists);
	_exit(0);
}
Beispiel #8
0
/* return a DNS name in the for aa.bb.cc from the DN  
   "dc=AA,dc=BB,dc=CC".  caller must free
*/
char *ads_build_domain(const char *dn)
{
	char *dnsdomain = NULL;

	/* result should always be shorter than the DN */

	if ( (dnsdomain = SMB_STRDUP( dn )) == NULL ) {
		DEBUG(0,("ads_build_domain: malloc() failed!\n"));		
		return NULL;		
	}	

	if (!strlower_m( dnsdomain )) {
		SAFE_FREE(dnsdomain);
		return NULL;
	}

	all_string_sub( dnsdomain, "dc=", "", 0);
	all_string_sub( dnsdomain, ",", ".", 0 );

	return dnsdomain;	
}
Beispiel #9
0
/***************************************************** 
parse a smb path into its components. 
server is one of
  1) the name of the SMB server
  2) WORKGROUP#1D for share listing
  3) WORKGROUP#__ for workgroup listing
share is the share on the server to query
path is the SMB path on the server
return the full path (ie. add cwd if needed)
*******************************************************/
char *smbw_parse_path(const char *fname, char *server, char *share, char *path)
{
	static pstring s;
	char *p;
	int len;
	fstring workgroup;

	/* add cwd if necessary */
	if (fname[0] != '/') {
		slprintf(s, sizeof(s), "%s/%s", smbw_cwd, fname);
	} else {
		pstrcpy(s, fname);
	}
	clean_fname(s);

	/* see if it has the right prefix */
	len = strlen(smbw_prefix)-1;
	if (strncmp(s,smbw_prefix,len) || 
	    (s[len] != '/' && s[len] != 0)) return s;

	/* ok, its for us. Now parse out the workgroup, share etc. */
	p = s+len;
	if (*p == '/') p++;
	if (!next_token(&p, workgroup, "/", sizeof(fstring))) {
		/* we're in /smb - give a list of workgroups */
		slprintf(server,sizeof(fstring), "%s#01", smbw_find_workgroup());
		fstrcpy(share,"IPC$");
		pstrcpy(path,"");
		return s;
	}

	if (!next_token(&p, server, "/", sizeof(fstring))) {
		/* we are in /smb/WORKGROUP */
		slprintf(server,sizeof(fstring), "%s#1D", workgroup);
		fstrcpy(share,"IPC$");
		pstrcpy(path,"");
	}

	if (!next_token(&p, share, "/", sizeof(fstring))) {
		/* we are in /smb/WORKGROUP/SERVER */
		fstrcpy(share,"IPC$");
		pstrcpy(path,"");
	}

	pstrcpy(path, p);

	all_string_sub(path, "/", "\\", 0);

	return s;
}
void ical_property_RESOURCES(struct exchange2ical *exchange2ical)
{
	char		*NonSendableBcc = NULL;
	icalproperty 	*prop;

	/* Sanity check */
	if (!exchange2ical->NonSendableBcc) return;
	
	NonSendableBcc = talloc_strdup(exchange2ical->mem_ctx, exchange2ical->NonSendableBcc);
	all_string_sub(NonSendableBcc, ";", ",", 0);
	prop = icalproperty_new_resources(NonSendableBcc);
	icalcomponent_add_property(exchange2ical->vevent, prop);
	talloc_free(NonSendableBcc);
}
Beispiel #11
0
/*
  convert a windows path to a unix path - don't do any manging or case sensitive handling
*/
char *cifspsx_unix_path(struct ntvfs_module_context *ntvfs,
		     struct ntvfs_request *req, const char *name)
{
	struct cifspsx_private *p = ntvfs->private_data;
	char *ret;
	char *name_lower = strlower_talloc(p, name);

	if (*name != '\\') {
		ret = talloc_asprintf(req, "%s/%s", p->connectpath, name_lower);
	} else {
		ret = talloc_asprintf(req, "%s%s", p->connectpath, name_lower);
	}
	all_string_sub(ret, "\\", "/", 0);
	talloc_free(name_lower);
	return ret;
}
Beispiel #12
0
/*
  convert a windows path to a unix path - don't do any manging or case sensitive handling
*/
char *svfs_unix_path(struct ntvfs_module_context *ntvfs,
		     struct ntvfs_request *req, const char *name)
{
	struct svfs_private *p = ntvfs->private_data;
	char *ret;

	if (*name != '\\') {
		ret = talloc_asprintf(req, "%s/%s", p->connectpath, name);
	} else {
		ret = talloc_asprintf(req, "%s%s", p->connectpath, name);
	}
	all_string_sub(ret, "\\", "/", 0);

	strlower(ret + strlen(p->connectpath));

	return ret;
}
Beispiel #13
0
/* This hardcoded value should go into a ldb database! */
const char *dcesrv_common_get_share_path(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, struct share_config *scfg)
{
	const char *sharetype;
	char *p;
	
	sharetype = share_string_option(scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT);
	
	if (sharetype && strcasecmp(sharetype, "IPC") == 0) {
		return talloc_strdup(mem_ctx, "");
	}

	p = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_PATH, ""));
	if (!p) {
		return NULL;
	}
	if (p[0] == '\0') {
		return p;
	}
	all_string_sub(p, "/", "\\", 0);
	
	return talloc_asprintf(mem_ctx, "C:%s", p);
}
Beispiel #14
0
/****************************************************************************
  main program
****************************************************************************/
 int main(int argc,char *argv[])
{
	char *share[NSERVERS];
	int opt;
	char *p;
	int seed, server;

	setlinebuf(stdout);

	load_case_tables();

	if (argc < 3 || argv[1][0] == '-') {
		usage();
		exit(1);
	}

	setup_logging(argv[0], DEBUG_STDOUT);

	for (server=0;server<NSERVERS;server++) {
		share[server] = argv[1+server];
		all_string_sub(share[server],"/","\\",0);
	}

	argc -= NSERVERS;
	argv += NSERVERS;

	lp_load_global(get_dyn_CONFIGFILE());
	load_interfaces();

	if (getenv("USER")) {
		fstrcpy(username[0],getenv("USER"));
		fstrcpy(username[1],getenv("USER"));
	}

	seed = time(NULL);

	while ((opt = getopt(argc, argv, "U:s:ho:aAW:OkR:B:M:EZ")) != EOF) {
		switch (opt) {
		case 'k':
#ifdef HAVE_KRB5
			use_kerberos = True;
#else
			d_printf("No kerberos support compiled in\n");
			exit(1);
#endif
			break;
		case 'U':
			got_user = 1;
			if (got_pass == 2) {
				d_printf("Max of 2 usernames\n");
				exit(1);
			}
			fstrcpy(username[got_pass],optarg);
			p = strchr_m(username[got_pass],'%');
			if (p) {
				*p = 0;
				fstrcpy(password[got_pass], p+1);
				got_pass++;
			}
			break;
		case 'R':
			lock_range = strtol(optarg, NULL, 0);
			break;
		case 'B':
			lock_base = strtol(optarg, NULL, 0);
			break;
		case 'M':
			min_length = strtol(optarg, NULL, 0);
			break;
		case 's':
			seed = atoi(optarg);
			break;
		case 'u':
			hide_unlock_fails = True;
			break;
		case 'o':
			numops = atoi(optarg);
			break;
		case 'O':
			use_oplocks = True;
			break;
		case 'a':
			showall = True;
			break;
		case 'A':
			analyze = True;
			break;
		case 'Z':
			zero_zero = True;
			break;
		case 'E':
			exact_error_codes = True;
			break;
		case 'h':
			usage();
			exit(1);
		default:
			printf("Unknown option %c (%d)\n", (char)opt, opt);
			exit(1);
		}
	}

	if(use_kerberos && !got_user) got_pass = True;

	argc -= optind;
	argv += optind;

	DEBUG(0,("seed=%u\n", seed));
	srandom(seed);

	test_locks(share);

	return(0);
}
Beispiel #15
0
static BOOL chat_with_program(char *passwordprogram,char *name,char *chatsequence, BOOL as_root)
{
  char *slavedev;
  int master;
  pid_t pid, wpid;
  int wstat;
  BOOL chstat = False;    

  /* allocate a pseudo-terminal device */
  if ((master = findpty (&slavedev)) < 0) {
    DEBUG(3,("Cannot Allocate pty for password change: %s\n",name));
    return(False);
  }

  /*
   * We need to temporarily stop CatchChild from eating
   * SIGCLD signals as it also eats the exit status code. JRA.
   */

  CatchChildLeaveStatus();

#ifdef __uClinux__
  /* Hmmm, need to check this one further... */
  DEBUG(0,("%s(%d): vfork()ing\n",__FILE__,__LINE__));
  if ((pid = vfork()) < 0) {
#else
  if ((pid = fork()) < 0) {
#endif
    DEBUG(3,("Cannot fork() child for password change: %s\n",name));
    close(master);
    CatchChild();
    return(False);
  }

  /* we now have a pty */
  if (pid > 0){			/* This is the parent process */
    if ((chstat = talktochild(master, chatsequence)) == False) {
      DEBUG(3,("Child failed to change password: %s\n",name));
      kill(pid, SIGKILL); /* be sure to end this process */
    }

	while((wpid = sys_waitpid(pid, &wstat, 0)) < 0) {
      if(errno == EINTR) {
        errno = 0;
        continue;
      }
	  break;
    }

    if (wpid < 0) {
      DEBUG(3,("The process is no longer waiting!\n\n"));
      close(master);
      CatchChild();
      return(False);
    }

    /*
     * Go back to ignoring children.
     */
    CatchChild();

    close(master);

    if (pid != wpid) {
      DEBUG(3,("We were waiting for the wrong process ID\n"));	
      return(False);
    }
    if (WIFEXITED(wstat) == 0) {
      DEBUG(3,("The process exited while we were waiting\n"));
      return(False);
    }
    if (WEXITSTATUS(wstat) != 0) {
      DEBUG(3,("The status of the process exiting was %d\n", wstat));
      return(False);
    }
    
  } else {
    /* CHILD */

    /*
     * Lose any oplock capabilities.
     */
    set_process_capability(KERNEL_OPLOCK_CAPABILITY, False);
    set_inherited_process_capability(KERNEL_OPLOCK_CAPABILITY, False);

    /* make sure it doesn't freeze */
    alarm(20);

    if (as_root)
      become_root(False);
    DEBUG(3,("Dochild for user %s (uid=%d,gid=%d)\n",name,(int)getuid(),(int)getgid()));
    chstat = dochild(master, slavedev, name, passwordprogram, as_root);

	/*
	 * The child should never return from dochild() ....
	 */

	DEBUG(0,("chat_with_program: Error: dochild() returned %d\n", chstat ));
	exit(1);
  }

  if (chstat)
    DEBUG(3,("Password change %ssuccessful for user %s\n", (chstat?"":"un"), name));
  return (chstat);
}


BOOL chgpasswd(char *name,char *oldpass,char *newpass, BOOL as_root)
{
  pstring passwordprogram;
  pstring chatsequence;
  size_t i;
  size_t len;

  strlower(name); 
  DEBUG(3,("Password change for user: %s\n",name));

#if DEBUG_PASSWORD
  DEBUG(100,("Passwords: old=%s new=%s\n",oldpass,newpass)); 
#endif

  /* Take the passed information and test it for minimum criteria */
  /* Minimum password length */
  if (strlen(newpass) < lp_min_passwd_length()) /* too short, must be at least MINPASSWDLENGTH */ 
    {
      DEBUG(0,("Password Change: user %s, New password is shorter than minimum password length = %d\n",
            name, lp_min_passwd_length()));
      return (False);		/* inform the user */
    }
  
  /* Password is same as old password */
  if (strcmp(oldpass,newpass) == 0) /* don't allow same password */
    {
      DEBUG(2,("Password Change: %s, New password is same as old\n",name)); /* log the attempt */
      return (False);		/* inform the user */
    }

  pstrcpy(passwordprogram,lp_passwd_program());
  pstrcpy(chatsequence,lp_passwd_chat());

  if (!*chatsequence) {
    DEBUG(2,("Null chat sequence - no password changing\n"));
    return(False);
  }

  if (!*passwordprogram) {
    DEBUG(2,("Null password program - no password changing\n"));
    return(False);
  }

  /* 
   * Check the old and new passwords don't contain any control
   * characters.
   */

  len = strlen(oldpass); 
  for(i = 0; i < len; i++) {
    if (iscntrl((int)oldpass[i])) {
      DEBUG(0,("chat_with_program: oldpass contains control characters (disallowed).\n"));
      return False;
    }
  }

  len = strlen(newpass);
  for(i = 0; i < len; i++) {
    if (iscntrl((int)newpass[i])) {
      DEBUG(0,("chat_with_program: newpass contains control characters (disallowed).\n"));
      return False;
    }
  }

  pstring_sub(passwordprogram,"%u",name);
  /* note that we do NOT substitute the %o and %n in the password program
     as this would open up a security hole where the user could use
     a new password containing shell escape characters */

  pstring_sub(chatsequence,"%u",name);
  all_string_sub(chatsequence,"%o",oldpass,sizeof(pstring));
  all_string_sub(chatsequence,"%n",newpass,sizeof(pstring));
  return(chat_with_program(passwordprogram,name,chatsequence, as_root));
}
Beispiel #16
0
int find_service(fstring service)
{
	int iService;
	struct smbd_server_connection *sconn = smbd_server_conn;

	all_string_sub(service,"\\","/",0);

	iService = lp_servicenumber(service);

	/* now handle the special case of a home directory */
	if (iService < 0) {
		char *phome_dir = get_user_home_dir(talloc_tos(), service);

		if(!phome_dir) {
			/*
			 * Try mapping the servicename, it may
			 * be a Windows to unix mapped user name.
			 */
			if(map_username(sconn, service))
				phome_dir = get_user_home_dir(
					talloc_tos(), service);
		}

		DEBUG(3,("checking for home directory %s gave %s\n",service,
			phome_dir?phome_dir:"(NULL)"));

		iService = add_home_service(service,service /* 'username' */, phome_dir);
	}

	/* If we still don't have a service, attempt to add it as a printer. */
	if (iService < 0) {
		int iPrinterService;

		if ((iPrinterService = lp_servicenumber(PRINTERS_NAME)) < 0) {
			iPrinterService = load_registry_service(PRINTERS_NAME);
		}
		if (iPrinterService) {
			DEBUG(3,("checking whether %s is a valid printer name...\n", service));
			if (pcap_printername_ok(service)) {
				DEBUG(3,("%s is a valid printer name\n", service));
				DEBUG(3,("adding %s as a printer service\n", service));
				lp_add_printer(service, iPrinterService);
				iService = lp_servicenumber(service);
				if (iService < 0) {
					DEBUG(0,("failed to add %s as a printer service!\n", service));
				}
			} else {
				DEBUG(3,("%s is not a valid printer name\n", service));
			}
		}
	}

	/* Check for default vfs service?  Unsure whether to implement this */
	if (iService < 0) {
	}

	if (iService < 0) {
		iService = load_registry_service(service);
	}

	/* Is it a usershare service ? */
	if (iService < 0 && *lp_usershare_path()) {
		/* Ensure the name is canonicalized. */
		strlower_m(service);
		iService = load_usershare_service(service);
	}

	/* just possibly it's a default service? */
	if (iService < 0) {
		char *pdefservice = lp_defaultservice();
		if (pdefservice && *pdefservice && !strequal(pdefservice,service) && !strstr_m(service,"..")) {
			/*
			 * We need to do a local copy here as lp_defaultservice() 
			 * returns one of the rotating lp_string buffers that
			 * could get overwritten by the recursive find_service() call
			 * below. Fix from Josef Hinteregger <*****@*****.**>.
			 */
			char *defservice = SMB_STRDUP(pdefservice);

			if (!defservice) {
				goto fail;
			}

			/* Disallow anything except explicit share names. */
			if (strequal(defservice,HOMES_NAME) ||
					strequal(defservice, PRINTERS_NAME) ||
					strequal(defservice, "IPC$")) {
				SAFE_FREE(defservice);
				goto fail;
			}

			iService = find_service(defservice);
			if (iService >= 0) {
				all_string_sub(service, "_","/",0);
				iService = lp_add_service(service, iService);
			}
			SAFE_FREE(defservice);
		}
	}

	if (iService >= 0) {
		if (!VALID_SNUM(iService)) {
			DEBUG(0,("Invalid snum %d for %s\n",iService, service));
			iService = -1;
		}
	}

  fail:

	if (iService < 0)
		DEBUG(3,("find_service() failed to find service %s\n", service));

	return (iService);
}
Beispiel #17
0
/* run a test that simulates an approximate netbench client load */
static bool run_netbench(struct torture_context *tctx, struct smbcli_state *cli, int client)
{
	int torture_nprocs = torture_setting_int(tctx, "nprocs", 4);
	int i;
	char line[1024];
	char *cname;
	FILE *f;
	bool correct = true;
	double target_rate = torture_setting_double(tctx, "targetrate", 0);	
	int n;

	if (target_rate != 0 && client == 0) {
		printf("Targetting %.4f MByte/sec\n", target_rate);
	}

	nb_setup(cli, client);

	if (torture_nprocs == 1) {
		if (!read_only) {
			NB_RETRY(torture_setup_dir(cli, "\\clients"));
		}
	}

	asprintf(&cname, "client%d", client+1);

	f = fopen(loadfile, "r");

	if (!f) {
		perror(loadfile);
		return false;
	}

again:
	nbio_time_reset();

	while (fgets(line, sizeof(line)-1, f)) {
		NTSTATUS status;
		const char **params0, **params;

		nbench_line_count++;

		line[strlen(line)-1] = 0;

		all_string_sub(line,"client1", cname, sizeof(line));
		
		params = params0 = str_list_make_shell(NULL, line, " ");
		i = str_list_length(params);

		if (i > 0 && isdigit(params[0][0])) {
			double targett = strtod(params[0], NULL);
			if (target_rate != 0) {
				nbio_target_rate(target_rate);
			} else {
				nbio_time_delay(targett);
			}
			params++;
			i--;
		} else if (target_rate != 0) {
			nbio_target_rate(target_rate);
		}

		if (i < 2 || params[0][0] == '#') continue;

		if (!strncmp(params[0],"SMB", 3)) {
			printf("ERROR: You are using a dbench 1 load file\n");
			nb_exit(1);
		}

		if (strncmp(params[i-1], "NT_STATUS_", 10) != 0 &&
		    strncmp(params[i-1], "0x", 2) != 0) {
			printf("Badly formed status at line %d\n", nbench_line_count);
			talloc_free(params);
			continue;
		}

		/* accept numeric or string status codes */
		if (strncmp(params[i-1], "0x", 2) == 0) {
			status = NT_STATUS(strtoul(params[i-1], NULL, 16));
		} else {
			status = nt_status_string_to_code(params[i-1]);
		}

		DEBUG(9,("run_netbench(%d): %s %s\n", client, params[0], params[1]));

		if (!strcmp(params[0],"NTCreateX")) {
			NB_RETRY(nb_createx(params[1], ival(params[2]), ival(params[3]), 
					    ival(params[4]), status));
		} else if (!strcmp(params[0],"Close")) {
			NB_RETRY(nb_close(ival(params[1]), status));
		} else if (!read_only && !strcmp(params[0],"Rename")) {
			NB_RETRY(nb_rename(params[1], params[2], status, n>0));
		} else if (!read_only && !strcmp(params[0],"Unlink")) {
			NB_RETRY(nb_unlink(params[1], ival(params[2]), status, n>0));
		} else if (!read_only && !strcmp(params[0],"Deltree")) {
			NB_RETRY(nb_deltree(params[1], n>0));
		} else if (!read_only && !strcmp(params[0],"Rmdir")) {
			NB_RETRY(nb_rmdir(params[1], status, n>0));
		} else if (!read_only && !strcmp(params[0],"Mkdir")) {
			NB_RETRY(nb_mkdir(params[1], status, n>0));
		} else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
			NB_RETRY(nb_qpathinfo(params[1], ival(params[2]), status));
		} else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
			NB_RETRY(nb_qfileinfo(ival(params[1]), ival(params[2]), status));
		} else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
			NB_RETRY(nb_qfsinfo(ival(params[1]), status));
		} else if (!read_only && !strcmp(params[0],"SET_FILE_INFORMATION")) {
			NB_RETRY(nb_sfileinfo(ival(params[1]), ival(params[2]), status));
		} else if (!strcmp(params[0],"FIND_FIRST")) {
			NB_RETRY(nb_findfirst(params[1], ival(params[2]), 
					      ival(params[3]), ival(params[4]), status));
		} else if (!read_only && !strcmp(params[0],"WriteX")) {
			NB_RETRY(nb_writex(ival(params[1]), 
					   ival(params[2]), ival(params[3]), ival(params[4]),
					   status));
		} else if (!read_only && !strcmp(params[0],"Write")) {
			NB_RETRY(nb_write(ival(params[1]), 
					  ival(params[2]), ival(params[3]), ival(params[4]),
					  status));
		} else if (!strcmp(params[0],"LockX")) {
			NB_RETRY(nb_lockx(ival(params[1]), 
					  ival(params[2]), ival(params[3]), status));
		} else if (!strcmp(params[0],"UnlockX")) {
			NB_RETRY(nb_unlockx(ival(params[1]), 
					    ival(params[2]), ival(params[3]), status));
		} else if (!strcmp(params[0],"ReadX")) {
			NB_RETRY(nb_readx(ival(params[1]), 
					  ival(params[2]), ival(params[3]), ival(params[4]),
					  status));
		} else if (!strcmp(params[0],"Flush")) {
			NB_RETRY(nb_flush(ival(params[1]), status));
		} else if (!strcmp(params[0],"Sleep")) {
			nb_sleep(ival(params[1]), status);
		} else {
			printf("[%d] Unknown operation %s\n", nbench_line_count, params[0]);
		}

		if (n > nb_max_retries) {
			printf("Maximum reconnect retries reached for op '%s'\n", params[0]);
			nb_exit(1);
		}

		talloc_free(params0);
		
		if (nb_tick()) goto done;
	}

	rewind(f);
	goto again;

done:
	fclose(f);

	if (!read_only && torture_nprocs == 1) {
		smbcli_deltree(cli->tree, "\\clients");
	}
	if (!torture_close_connection(cli)) {
		correct = false;
	}
	
	return correct;
}
Beispiel #18
0
BOOL chgpasswd(char *name,char *oldpass,char *newpass, BOOL as_root)
{
  pstring passwordprogram;
  pstring chatsequence;
  size_t i;
  size_t len;

  strlower(name); 
  DEBUG(3,("Password change for user: %s\n",name));

#if DEBUG_PASSWORD
  DEBUG(100,("Passwords: old=%s new=%s\n",oldpass,newpass)); 
#endif

  /* Take the passed information and test it for minimum criteria */
  /* Minimum password length */
  if (strlen(newpass) < lp_min_passwd_length()) /* too short, must be at least MINPASSWDLENGTH */ 
    {
      DEBUG(0,("Password Change: user %s, New password is shorter than minimum password length = %d\n",
            name, lp_min_passwd_length()));
      return (False);		/* inform the user */
    }
  
  /* Password is same as old password */
  if (strcmp(oldpass,newpass) == 0) /* don't allow same password */
    {
      DEBUG(2,("Password Change: %s, New password is same as old\n",name)); /* log the attempt */
      return (False);		/* inform the user */
    }

  pstrcpy(passwordprogram,lp_passwd_program());
  pstrcpy(chatsequence,lp_passwd_chat());

  if (!*chatsequence) {
    DEBUG(2,("Null chat sequence - no password changing\n"));
    return(False);
  }

  if (!*passwordprogram) {
    DEBUG(2,("Null password program - no password changing\n"));
    return(False);
  }

  /* 
   * Check the old and new passwords don't contain any control
   * characters.
   */

  len = strlen(oldpass); 
  for(i = 0; i < len; i++) {
    if (iscntrl((int)oldpass[i])) {
      DEBUG(0,("chat_with_program: oldpass contains control characters (disallowed).\n"));
      return False;
    }
  }

  len = strlen(newpass);
  for(i = 0; i < len; i++) {
    if (iscntrl((int)newpass[i])) {
      DEBUG(0,("chat_with_program: newpass contains control characters (disallowed).\n"));
      return False;
    }
  }

  pstring_sub(passwordprogram,"%u",name);
  /* note that we do NOT substitute the %o and %n in the password program
     as this would open up a security hole where the user could use
     a new password containing shell escape characters */

  pstring_sub(chatsequence,"%u",name);
  all_string_sub(chatsequence,"%o",oldpass,sizeof(pstring));
  all_string_sub(chatsequence,"%n",newpass,sizeof(pstring));
  return(chat_with_program(passwordprogram,name,chatsequence, as_root));
}
Beispiel #19
0
/****************************************************************************
  main program
****************************************************************************/
 int main(int argc,char *argv[])
{
	char *share1, *share2;
	struct cli_state *cli1, *cli2;	
	extern char *optarg;
	extern int optind;
	extern FILE *dbf;
	int opt;
	char *p;
	int seed;

	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();

	if (getenv("USER")) {
		pstrcpy(username,getenv("USER"));
	}

	seed = time(NULL);

	while ((opt = getopt(argc, argv, "U:s:hm:f:a")) != EOF) {
		switch (opt) {
		case 'U':
			pstrcpy(username,optarg);
			p = strchr(username,'%');
			if (p) {
				*p = 0;
				pstrcpy(password, p+1);
				got_pass = 1;
			}
			break;
		case 's':
			seed = atoi(optarg);
			break;
		case 'h':
			usage();
			exit(1);
		case 'm':
			maskchars = optarg;
			break;
		case 'f':
			filechars = optarg;
			break;
		case 'a':
			showall = 1;
			break;
		default:
			printf("Unknown option %c (%d)\n", (char)opt, opt);
			exit(1);
		}
	}

	argc -= optind;
	argv += optind;

	DEBUG(0,("seed=%d\n", seed));
	srandom(seed);

	cli1 = connect_one(share1);
	if (!cli1) {
		DEBUG(0,("Failed to connect to %s\n", share1));
		exit(1);
	}

	cli2 = connect_one(share2);
	if (!cli2) {
		DEBUG(0,("Failed to connect to %s\n", share2));
		exit(1);
	}


	test_mask(argc, argv, cli1, cli2);

	return(0);
}
Beispiel #20
0
/****************************************************************************
  main program
****************************************************************************/
 int main(int argc,char *argv[])
{
	char *share1, *share2, *nfspath1, *nfspath2;
	extern char *optarg;
	extern int optind;
	int opt;
	char *p;
	int seed;

	setlinebuf(stdout);

	dbf = x_stderr;

	if (argc < 5 || argv[1][0] == '-') {
		usage();
		exit(1);
	}

	share1 = argv[1];
	share2 = argv[2];
	nfspath1 = argv[3];
	nfspath2 = argv[4];

	all_string_sub(share1,"/","\\",0);
	all_string_sub(share2,"/","\\",0);

	setup_logging(argv[0], DEBUG_STDOUT);

	argc -= 4;
	argv += 4;

	lp_load();

	if (getenv("USER")) {
		fstrcpy(username,getenv("USER"));
	}

	seed = time(NULL);

	while ((opt = getopt(argc, argv, "U:s:ho:aAW:O")) != EOF) {
		switch (opt) {
		case 'U':
			fstrcpy(username,optarg);
			p = strchr_m(username,'%');
			if (p) {
				*p = 0;
				fstrcpy(password, p+1);
				got_pass = 1;
			}
			break;
		case 's':
			seed = atoi(optarg);
			break;
		case 'u':
			hide_unlock_fails = True;
			break;
		case 'o':
			numops = atoi(optarg);
			break;
		case 'O':
			use_oplocks = True;
			break;
		case 'a':
			showall = True;
			break;
		case 'A':
			analyze = True;
			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=%u\n", seed));
	srandom(seed);

	locking_init(1);
	test_locks(share1, share2, nfspath1, nfspath2);

	return(0);
}
Beispiel #21
0
void child_run(struct child_struct *child0, const char *loadfile)
{
	int i;
	char line[MAX_PARM_LEN], fname[MAX_PARM_LEN], fname2[MAX_PARM_LEN];
	char **sparams, **params;
	char *p;
	const char *status;
	gzFile *gzf;
	pid_t parent = getppid();
	double targett;
	struct child_struct *child;
	int have_random = 0;
	unsigned loop_count = 0;
	z_off_t loop_start = 0;

	gzf = gzopen(loadfile, "r");
	if (gzf == NULL) {
		perror(loadfile);
		exit(1);
	}

	for (child=child0;child<child0+options.clients_per_process;child++) {
		child->line = 0;
		asprintf(&child->cname,"client%d", child->id);
	}

	sparams = calloc(20, sizeof(char *));
	for (i=0;i<20;i++) {
		sparams[i] = malloc(MAX_PARM_LEN);
		memset(sparams[i], 0, MAX_PARM_LEN);
	}

again:
	for (child=child0;child<child0+options.clients_per_process;child++) {
		nb_time_reset(child);
	}

	while (gzgets(gzf, line, sizeof(line)-1)) {
		unsigned repeat_count = 1;

		for (child=child0;child<child0+options.clients_per_process;child++) {
			if (child->done) goto done;
			child->line++;
		}


		params = sparams;

		if (kill(parent, 0) == -1) {
			exit(1);
		}

loop_again:
		/* if this is a "LOOP <xxx>" line, 
		 * remember the current file position and move to the next line
		 */
		if (strncmp(line, "LOOP", 4) == 0) {
			if (sscanf(line, "LOOP %u\n", &loop_count) != 1) {
				fprintf(stderr, "Incorrect LOOP at line %d\n", child0->line);
				goto done;
			}

	       		for (child=child0;child<child0+options.clients_per_process;child++) {
				child->line++;
			}
			loop_start = gztell(gzf);
			gzgets(gzf, line, sizeof(line)-1);
			goto loop_again;
	        }

		if (strncmp(line, "ENDLOOP", 7) == 0) {
			loop_count--;

			gzgets(gzf, line, sizeof(line)-1);

			if (loop_count > 0) {
				gzseek(gzf, loop_start, SEEK_SET);
			}
			
			gzgets(gzf, line, sizeof(line)-1);
			goto loop_again;
		}			

		/* if this is a "REPEAT <xxx>" line, just replace the
		 * currently read line with the next line
		 */
		if (strncmp(line, "REPEAT", 6) == 0) {
			if (sscanf(line, "REPEAT %u\n", &repeat_count) != 1) {
				fprintf(stderr, "Incorrect REPEAT at line %d\n", child0->line);
				goto done;
			}

	       		for (child=child0;child<child0+options.clients_per_process;child++) {
				child->line++;
			}
			gzgets(gzf, line, sizeof(line)-1);
	        }


		/* WRITEPATTERN */
		if (strncmp(line, "WRITEPATTERN", 12) == 0) {
			char *ptr = rw_buf;
			int count = RWBUFSIZE;
			
			while (count > 0) {
			      int len;

			      len = count;
			      if (len > strlen(line +13)) {
			     	      len = strlen(line +13);
			      }
			      memcpy(ptr, line+13, len);
			      ptr += len;
			      count -= len;
			}
			goto again;
		}


		/* RANDOMSTRING */
		if (strncmp(line, "RANDOMSTRING", 12) == 0) {
			have_random = 1;
			if (parse_randomstring(line) != 0) {
				fprintf(stderr, "Incorrect RANDOMSTRING at line %d\n", child0->line);
				goto done;
			}
			goto again;
		}


		line[strlen(line)-1] = 0;

		all_string_sub(line,"\\", "/");
		all_string_sub(line," /", " ");

		/* substitute all $<digit> stored strings */
		while (have_random && (p = index(line, '$')) != NULL) {
			char sstr[3], *nstr;
			unsigned int idx;
		      
		      	idx = *(p+1) - '0';
			if (idx >= MAX_RND_STR) {
				fprintf(stderr, "$%d is an invalid filename/string\n", idx);
				goto done;
			}

			sstr[0] = '$';
			sstr[1] = idx+'0';
			sstr[2] = '\0';

			nstr = get_random_string(idx);
			all_string_sub(line, sstr, nstr);
		}
		
		p = line;
		for (i=0; 
		     i<19 && next_token(&p, params[i], " ");
		     i++) ;

		params[i][0] = 0;

		if (i < 2 || params[0][0] == '#') continue;

		if (!strncmp(params[0],"SMB", 3)) {
			printf("ERROR: You are using a dbench 1 load file\n");
			exit(1);
		}

		if (i > 0 && isdigit(params[0][0])) {
			targett = strtod(params[0], NULL);
			params++;
			i--;
		} else {
			targett = 0.0;
		}

		if (strncmp(params[i-1], "NT_STATUS_", 10) != 0 &&
		    strncmp(params[i-1], "0x", 2) != 0 &&
		    strncmp(params[i-1], "SUCCESS", 7) != 0 &&
		    strncmp(params[i-1], "ERROR", 7) != 0 &&
		    strncmp(params[i-1], "*", 1) != 0) {
			printf("Badly formed status at line %d\n", child->line);
			continue;
		}

		status = params[i-1];

		
		for (child=child0;child<child0+options.clients_per_process;child++) {
			unsigned child_repeat_count = repeat_count;
			int pcount = 1;

			fname[0] = 0;
			fname2[0] = 0;

			if (i>1 && params[1][0] == '/') {
				snprintf(fname, sizeof(fname), "%s%s", child->directory, params[1]);
				all_string_sub(fname,"client1", child->cname);
				pcount++;
			}
			if (i>2 && params[2][0] == '/') {
				snprintf(fname2, sizeof(fname2), "%s%s", child->directory, params[2]);
				all_string_sub(fname2,"client1", child->cname);
				pcount++;
			}

			if (options.targetrate != 0 || targett == 0.0) {
				nb_target_rate(child, options.targetrate);
			} else {
				nb_time_delay(child, targett);
			}
			while (child_repeat_count--) {
				child_op(child, params[0], fname, fname2, params+pcount, status);
			}
		}
	}

	if (options.run_once) {
		goto done;
	}

	gzrewind(gzf);
	goto again;

done:
	gzclose(gzf);
	for (child=child0;child<child0+options.clients_per_process;child++) {
		child->cleanup = 1;
		fflush(stdout);
		if (!options.skip_cleanup) {
			nb_ops->cleanup(child);
		}
		child->cleanup_finished = 1;
		if(child->cname){
			free(child->cname);
			child->cname = NULL;
		}
	}
}
Beispiel #22
0
/***************************************************** 
initialise structures
*******************************************************/
void smbw_init(void)
{
	extern BOOL in_client;
	static int initialised;
	static pstring servicesf = CONFIGFILE;
	extern FILE *dbf;
	char *p;
	int eno;
	pstring line;

	if (initialised) return;
	initialised = 1;

	eno = errno;

	smbw_busy++;

	DEBUGLEVEL = 0;
	AllowDebugChange = False;
	setup_logging("smbsh",True);

	dbf = stderr;

	if ((p=smbw_getshared("LOGFILE"))) {
		dbf = sys_fopen(p, "a");
	}

	smbw_file_bmap = bitmap_allocate(SMBW_MAX_OPEN);
	if (!smbw_file_bmap) {
		exit(1);
	}

	charset_initialise();

	in_client = True;

	load_interfaces();

	if ((p=smbw_getshared("SERVICESF"))) {
		pstrcpy(servicesf, p);
	}

	lp_load(servicesf,True,False,False);
	codepage_initialise(lp_client_code_page());

	get_myname(global_myname);

	if ((p=smbw_getshared("DEBUG"))) {
		DEBUGLEVEL = atoi(p);
	}

	if ((p=smbw_getshared("RESOLVE_ORDER"))) {
		lp_set_name_resolve_order(p);
	}

	if ((p=smbw_getshared("PREFIX"))) {
		slprintf(smbw_prefix,sizeof(fstring)-1, "/%s/", p);
		all_string_sub(smbw_prefix,"//", "/", 0);
		DEBUG(2,("SMBW_PREFIX is %s\n", smbw_prefix));
	}

	slprintf(line,sizeof(line)-1,"PWD_%d", (int)getpid());
	
	p = smbw_getshared(line);
	if (!p) {
		sys_getwd(smbw_cwd);
	}
	pstrcpy(smbw_cwd, p);
	DEBUG(4,("Initial cwd is %s\n", smbw_cwd));

	smbw_busy--;

	set_maxfiles(SMBW_MAX_OPEN);

	BlockSignals(True,SIGPIPE);

	errno = eno;
}
Beispiel #23
0
/****************************************************************************
  main program
****************************************************************************/
 int main(int argc,char *argv[])
{
	char *share[NSERVERS];
	int opt;
	int seed, server;
	int username_count=0;
	struct tevent_context *ev;
	struct loadparm_context *lp_ctx;
	poptContext pc;
	int argc_new, i;
	char **argv_new;
	enum {OPT_UNCLIST=1000};
	struct poptOption long_options[] = {
		POPT_AUTOHELP
		{"seed",	  0, POPT_ARG_INT,  &seed, 	0,	"Seed to use for randomizer", 	NULL},
		{"num-ops",	  0, POPT_ARG_INT,  &numops, 	0, 	"num ops",	NULL},
		{"lockrange",     0, POPT_ARG_INT,  &lock_range,0,      "locking range", NULL},
		{"lockbase",      0, POPT_ARG_INT,  &lock_base, 0,      "locking base", NULL},
		{"minlength",     0, POPT_ARG_INT,  &min_length,0,      "min lock length", NULL},
		{"hidefails",     0, POPT_ARG_NONE, &hide_unlock_fails,0,"hide unlock fails", NULL},
		{"oplocks",       0, POPT_ARG_NONE, &use_oplocks,0,      "use oplocks", NULL},
		{"showall",       0, POPT_ARG_NONE, &showall,    0,      "display all operations", NULL},
		{"analyse",       0, POPT_ARG_NONE, &analyze,    0,      "do backtrack analysis", NULL},
		{"zerozero",      0, POPT_ARG_NONE, &zero_zero,    0,      "do zero/zero lock", NULL},
		{"exacterrors",   0, POPT_ARG_NONE, &exact_error_codes,0,"use exact error codes", NULL},
		{"unclist",	  0, POPT_ARG_STRING,	NULL, 	OPT_UNCLIST,	"unclist", 	NULL},
		{ "user", 'U',       POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" },
		POPT_COMMON_SAMBA
		POPT_COMMON_CONNECTION
		POPT_COMMON_CREDENTIALS
		POPT_COMMON_VERSION
		{ NULL }
	};

	setlinebuf(stdout);
	seed = time(NULL);

	pc = poptGetContext("locktest", argc, (const char **) argv, long_options, 
			    POPT_CONTEXT_KEEP_FIRST);

	poptSetOtherOptionHelp(pc, "<unc1> <unc2>");

	lp_ctx = cmdline_lp_ctx;
	servers[0] = cli_credentials_init(talloc_autofree_context());
	servers[1] = cli_credentials_init(talloc_autofree_context());
	cli_credentials_guess(servers[0], lp_ctx);
	cli_credentials_guess(servers[1], lp_ctx);

	while((opt = poptGetNextOpt(pc)) != -1) {
		switch (opt) {
		case OPT_UNCLIST:
			lp_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc));
			break;
		case 'U':
			if (username_count == 2) {
				usage(pc);
				exit(1);
			}
			cli_credentials_parse_string(servers[username_count], poptGetOptArg(pc), CRED_SPECIFIED);
			username_count++;
			break;
		}
	}

	argv_new = discard_const_p(char *, poptGetArgs(pc));
	argc_new = argc;
	for (i=0; i<argc; i++) {
		if (argv_new[i] == NULL) {
			argc_new = i;
			break;
		}
	}

	if (!(argc_new >= 3)) {
		usage(pc);
		exit(1);
	}

	setup_logging("locktest", DEBUG_STDOUT);

	for (server=0;server<NSERVERS;server++) {
		share[server] = argv_new[1+server];
		all_string_sub(share[server],"/","\\",0);
	}

	lp_ctx = cmdline_lp_ctx;

	if (username_count == 0) {
		usage(pc);
		return -1;
	}
	if (username_count == 1) {
		servers[1] = servers[0];
	}

	ev = s4_event_context_init(talloc_autofree_context());

	gensec_init(lp_ctx);

	DEBUG(0,("seed=%u base=%d range=%d min_length=%d\n", 
		 seed, lock_base, lock_range, min_length));
	srandom(seed);

	return test_locks(ev, lp_ctx, NULL, share);
}
Beispiel #24
0
/****************************************************************************
  find a service entry
****************************************************************************/
int find_service(char *service)
{
   int iService;

   all_string_sub(service,"\\","/",0);

   iService = lp_servicenumber(service);

   /* now handle the special case of a home directory */
   if (iService < 0)
   {
     int iHomeService;

     /* We check that the HOMES_NAME exists before calling expensive
	functions like get_user_home_dir */

     if ((iHomeService = lp_servicenumber(HOMES_NAME)) >= 0)
     {

      char *phome_dir = get_user_home_dir(service);

      if(!phome_dir)
      {
        /*
         * Try mapping the servicename, it may
         * be a Windows to unix mapped user name.
         */
        if(map_username(service))
          phome_dir = get_user_home_dir(service);
      }

      DEBUG(3,("checking for home directory %s gave %s\n",service,
            phome_dir?phome_dir:"(NULL)"));

      if (phome_dir)
      {   
	lp_add_home(service,iHomeService,phome_dir);
	iService = lp_servicenumber(service);
      }
     }
   }
#ifdef PRINTING
   /* If we still don't have a service, attempt to add it as a printer. */
   if (iService < 0)
   {
      int iPrinterService;

      if ((iPrinterService = lp_servicenumber(PRINTERS_NAME)) >= 0)
      {
         char *pszTemp;

         DEBUG(3,("checking whether %s is a valid printer name...\n", service));
         pszTemp = PRINTCAP;
         if ((pszTemp != NULL) && pcap_printername_ok(service, pszTemp))
         {
            DEBUG(3,("%s is a valid printer name\n", service));
            DEBUG(3,("adding %s as a printer service\n", service));
            lp_add_printer(service,iPrinterService);
            iService = lp_servicenumber(service);
            if (iService < 0)
               DEBUG(0,("failed to add %s as a printer service!\n", service));
         }
         else
            DEBUG(3,("%s is not a valid printer name\n", service));
      }
   }
#endif
   /* just possibly it's a default service? */
   if (iService < 0) 
   {
     char *pdefservice = lp_defaultservice();
     if (pdefservice && *pdefservice && 
	 !strequal(pdefservice,service) &&
	 !strstr(service,".."))
     {
       /*
        * We need to do a local copy here as lp_defaultservice() 
        * returns one of the rotating lp_string buffers that
        * could get overwritten by the recursive find_service() call
        * below. Fix from Josef Hinteregger <*****@*****.**>.
        */
       pstring defservice;
       pstrcpy(defservice, pdefservice);
       iService = find_service(defservice);
       if (iService >= 0)
       {
         all_string_sub(service,"_","/",0);
         iService = lp_add_service(service,iService);
       }
     }
   }

   if (iService >= 0)
     if (!VALID_SNUM(iService))
     {
       DEBUG(0,("Invalid snum %d for %s\n",iService,service));
       iService = -1;
     }

   if (iService < 0)
     DEBUG(3,("find_service() failed to find service %s\n", service));

   return (iService);
}