Exemplo n.º 1
0
static TDB_CONTEXT * tdbsam_tdbopen (const char *name, int open_flags)
{
	TDB_CONTEXT 	*pdb_tdb;
	tdbsamver_t	version;
	
	/* Try to open tdb passwd */
	if (!(pdb_tdb = tdb_open_log(name, 0, TDB_DEFAULT, 
				     open_flags, 0600))) {
		DEBUG(0, ("Unable to open/create TDB passwd\n"));
		return NULL;
	}

	/* Check the version */
	version = (tdbsamver_t) tdb_fetch_int32(pdb_tdb, 
						TDBSAM_VERSION_STRING);
	if (version == -1)
		version = 0;	/* Version not found, assume version 0 */
	
	/* Compare the version */
	if (version > TDBSAM_VERSION) {
		/* Version more recent than the latest known */ 
		DEBUG(0, ("TDBSAM version unknown: %d\n", version));
		tdb_close(pdb_tdb);
		pdb_tdb = NULL;
	} 
	else if (version < TDBSAM_VERSION) {
		/* Older version, must be converted */
		DEBUG(1, ("TDBSAM version too old (%d), trying to convert it.\n", version));
		
		/* Reopen the pdb file with read-write access if needed */
		if (!(open_flags & O_RDWR)) {
			DEBUG(10, ("tdbsam_tdbopen: TDB file opened with read only access, reopen it with read-write access.\n"));
			tdb_close(pdb_tdb);
			pdb_tdb = tdb_open_log(name, 0, TDB_DEFAULT, (open_flags & 07777770) | O_RDWR, 0600);
		}
		
		/* Convert */
		if (!tdbsam_convert(pdb_tdb, version)){
			DEBUG(0, ("tdbsam_tdbopen: Error when trying to convert tdbsam: %s\n",name));
			tdb_close(pdb_tdb);
			pdb_tdb = NULL;
		} else {
			DEBUG(1, ("TDBSAM converted successfully.\n"));
		}

		/* Reopen the pdb file as it must be */
		if (!(open_flags & O_RDWR)) {
			tdb_close(pdb_tdb);
			pdb_tdb = tdb_open_log(name, 0, TDB_DEFAULT, open_flags, 0600);
		}
	}
	
	return pdb_tdb;
}
Exemplo n.º 2
0
/****************************************************************************
send a message to a named destination
****************************************************************************/
static BOOL send_message(char *dest, int msg_type, void *buf, int len, BOOL duplicates)
{
	BOOL retval = False;
	pid_t pid = 0;
	TDB_CONTEXT *the_tdb;

	the_tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDWR, 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")) {
		retval = message_send_all(the_tdb,msg_type, buf, len, duplicates, NULL);
	} else if (strequal(dest,"nmbd")) {
		pid = pidfile_pid(dest);
		if (pid == 0) {
			fprintf(stderr,"Can't find pid for nmbd\n");
		}
	} else if (strequal(dest,"self")) {
		pid = getpid();
	} else {
		pid = atoi(dest);
		if (pid == 0) {
			fprintf(stderr,"Not a valid pid\n");
		}		
	} 

	tdb_close(the_tdb);
	if (pid)
		return message_send_pid(pid, msg_type, buf, len, duplicates);
	else
		return retval;
}
Exemplo n.º 3
0
/***********************************************************
 Dump the current idmap
 **********************************************************/
static int net_idmap_dump(struct net_context *c, int argc, const char **argv)
{
	TDB_CONTEXT *idmap_tdb;

	if ( argc != 1  || c->display_usage) {
		d_printf(_("Usage:\n"
			   "net idmap dump <inputfile>\n"
			   "  Dump current ID mapping.\n"
			   "    inputfile\tTDB file to read mappings from.\n"));
		return c->display_usage?0:-1;
	}

	idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDONLY, 0);

	if (idmap_tdb == NULL) {
		d_fprintf(stderr, _("Could not open idmap: %s\n"), argv[0]);
		return -1;
	}

	tdb_traverse(idmap_tdb, net_idmap_dump_one_entry, NULL);

	tdb_close(idmap_tdb);

	return 0;
}
Exemplo n.º 4
0
static bool tdbsam_upgrade_next_rid(struct db_context *db)
{
	TDB_CONTEXT *tdb;
	uint32 rid;
	bool ok = false;

	ok = dbwrap_fetch_uint32(db, NEXT_RID_STRING, &rid);
	if (ok) {
		return true;
	}

	tdb = tdb_open_log(state_path("winbindd_idmap.tdb"), 0,
			   TDB_DEFAULT, O_RDONLY, 0644);

	if (tdb) {
		ok = tdb_fetch_uint32(tdb, "RID_COUNTER", &rid);
		if (!ok) {
			rid = BASE_RID;
		}
		tdb_close(tdb);
	} else {
		rid = BASE_RID;
	}

	if (dbwrap_store_uint32(db, NEXT_RID_STRING, rid) != 0) {
		return false;
	}

	return true;
}
Exemplo n.º 5
0
/****************************************************************************
 all unexpected packets are passed in here, to be stored in a unexpected
 packet database. This allows nmblookup and other tools to receive packets
 erroneoously sent to the wrong port by broken MS systems
  **************************************************************************/
void unexpected_packet(struct packet_struct *p)
{
	static int count;
	TDB_DATA kbuf, dbuf;
	struct unexpected_key key;
	char buf[1024];
	int len=0;

	if (!tdbd) {
		tdbd = tdb_open_log(lock_path("unexpected.tdb"), 0,
			       TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
			       O_RDWR | O_CREAT, 0644);
		if (!tdbd) {
			DEBUG(0,("Failed to open unexpected.tdb\n"));
			return;
		}
	}

	memset(buf,'\0',sizeof(buf));

	len = build_packet(buf, p);

	key.packet_type = p->packet_type;
	key.timestamp = p->timestamp;
	key.count = count++;

	kbuf.dptr = (char *)&key;
	kbuf.dsize = sizeof(key);
	dbuf.dptr = buf;
	dbuf.dsize = len;

	tdb_store(tdbd, kbuf, dbuf, TDB_REPLACE);
}
Exemplo n.º 6
0
static bool do_winbind_online(struct tevent_context *ev_ctx,
			      struct messaging_context *msg_ctx,
			      const struct server_id pid,
			      const int argc, const char **argv)
{
	TDB_CONTEXT *tdb;

	if (argc != 1) {
		fprintf(stderr, "Usage: smbcontrol winbindd online\n");
		return False;
	}

	/* Remove the entry in the winbindd_cache tdb to tell a later
	   starting winbindd that we're online. */

	tdb = tdb_open_log(state_path("winbindd_cache.tdb"), 0, TDB_DEFAULT, O_RDWR, 0600);
	if (!tdb) {
		fprintf(stderr, "Cannot open the tdb %s for writing.\n",
			state_path("winbindd_cache.tdb"));
		return False;
	}

	tdb_delete_bystring(tdb, "WINBINDD_OFFLINE");
	tdb_close(tdb);

	return send_message(msg_ctx, pid, MSG_WINBIND_ONLINE, NULL, 0);
}
Exemplo n.º 7
0
BOOL share_info_db_init(void)
{
	const char *vstring = "INFO/version";
	int32 vers_id;
 
	if (share_tdb) {
		return True;
	}

	share_tdb = tdb_open_log(lock_path("share_info.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
	if (!share_tdb) {
		DEBUG(0,("Failed to open share info database %s (%s)\n",
			lock_path("share_info.tdb"), strerror(errno) ));
		return False;
	}
 
	/* handle a Samba upgrade */
	tdb_lock_bystring(share_tdb, vstring);

	/* Cope with byte-reversed older versions of the db. */
	vers_id = tdb_fetch_int32(share_tdb, vstring);
	if ((vers_id == SHARE_DATABASE_VERSION_V1) || (IREV(vers_id) == SHARE_DATABASE_VERSION_V1)) {
		/* Written on a bigendian machine with old fetch_int code. Save as le. */
		tdb_store_int32(share_tdb, vstring, SHARE_DATABASE_VERSION_V2);
		vers_id = SHARE_DATABASE_VERSION_V2;
	}

	if (vers_id != SHARE_DATABASE_VERSION_V2) {
		tdb_traverse(share_tdb, tdb_traverse_delete_fn, NULL);
		tdb_store_int32(share_tdb, vstring, SHARE_DATABASE_VERSION_V2);
	}
	tdb_unlock_bystring(share_tdb, vstring);

	return True;
}
Exemplo n.º 8
0
BOOL gencache_init(void)
{
	char* cache_fname = NULL;
	
	/* skip file open if it's already opened */
	if (cache) return True;

	asprintf(&cache_fname, "%s/%s", lp_lockdir(), "gencache.tdb");
	if (cache_fname)
		DEBUG(5, ("Opening cache file at %s\n", cache_fname));
	else {
		DEBUG(0, ("Filename allocation failed.\n"));
		return False;
	}

	cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT,
	                     O_RDWR|O_CREAT, 0644);

	SAFE_FREE(cache_fname);
	if (!cache) {
		DEBUG(5, ("Attempt to open gencache.tdb has failed.\n"));
		return False;
	}
	return True;
}
Exemplo n.º 9
0
BOOL namecache_enable(void)
{
	/* Check if we have been here before, or name caching disabled
           by setting the name cache timeout to zero. */ 

	if (done_namecache_init)
		return False;

	done_namecache_init = True;

	if (lp_name_cache_timeout() == 0) {
		DEBUG(5, ("namecache_init: disabling netbios name cache\n"));
		return False;
	}

	/* Open namecache tdb in read/write or readonly mode */

	namecache_tdb = tdb_open_log(
		lock_path("namecache.tdb"), 0,
		TDB_DEFAULT, O_RDWR | O_CREAT, 0644);

	if (!namecache_tdb) {
		DEBUG(5, ("namecache_init: could not open %s\n",
			  lock_path("namecache.tdb")));
		return False;
	}

	DEBUG(5, ("namecache_init: enabling netbios namecache, timeout %d "
		  "seconds\n", lp_name_cache_timeout()));

	enable_namecache = True;

	return True;
}
Exemplo n.º 10
0
static bool _reg_perfcount_get_counter_data(TDB_DATA key, TDB_DATA *data)
{
	TDB_CONTEXT *counters;
	char *fname;

	fname = counters_directory(DATA_DB);
	if (fname == NULL) {
		return false;
	}

	counters = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);

	if (counters == NULL) {
		DEBUG(1, ("reg_perfcount_get_counter_data: unable to open [%s].\n", fname));
		TALLOC_FREE(fname);
		return False;
	}
	TALLOC_FREE(fname);

	*data = tdb_fetch(counters, key);

	tdb_close(counters);

	return True;
}
Exemplo n.º 11
0
bool login_cache_init(void)
{
	char* cache_fname = NULL;

	/* skip file open if it's already opened */
	if (cache) return True;

	cache_fname = cache_path(LOGIN_CACHE_FILE);
	if (cache_fname == NULL) {
		DEBUG(0, ("Filename allocation failed.\n"));
		return False;
	}

	DEBUG(5, ("Opening cache file at %s\n", cache_fname));

	cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT,
	                     O_RDWR|O_CREAT, 0644);

	if (!cache)
		DEBUG(5, ("Attempt to open %s failed.\n", cache_fname));

	TALLOC_FREE(cache_fname);

	return (cache ? True : False);
}
Exemplo n.º 12
0
struct idmap_cache_ctx *idmap_cache_init(TALLOC_CTX *memctx)
{
	struct idmap_cache_ctx *cache;
	char* cache_fname = NULL;

	cache = talloc(memctx, struct idmap_cache_ctx);
	if ( ! cache) {
		DEBUG(0, ("Out of memory!\n"));
		return NULL;
	}

	cache_fname = lock_path("idmap_cache.tdb");

	DEBUG(10, ("Opening cache file at %s\n", cache_fname));

	cache->tdb = tdb_open_log(cache_fname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);

	if (!cache->tdb) {
		DEBUG(5, ("Attempt to open %s has failed.\n", cache_fname));
		return NULL;
	}

	talloc_set_destructor(cache, idmap_cache_destructor);

	return cache;
}
Exemplo n.º 13
0
static NTSTATUS net_idmap_fixup_hwm(void)
{
	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
	TDB_CONTEXT *idmap_tdb;
	char *tdbfile = NULL;

	struct hwms hwms;
	struct hwms highest;

	if (!lp_idmap_uid(&hwms.user_hwm, &highest.user_hwm) ||
	    !lp_idmap_gid(&hwms.group_hwm, &highest.group_hwm)) {
		d_fprintf(stderr, "idmap range missing\n");
		return NT_STATUS_UNSUCCESSFUL;
	}

	tdbfile = SMB_STRDUP(lock_path("winbindd_idmap.tdb"));
	if (!tdbfile) {
		DEBUG(0, ("idmap_init: out of memory!\n"));
		return NT_STATUS_NO_MEMORY;
	}

	idmap_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0);

	if (idmap_tdb == NULL) {
		d_fprintf(stderr, "Could not open idmap: %s\n", tdbfile);
		return NT_STATUS_NO_SUCH_FILE;
	}

	hwms.ok = True;

	tdb_traverse(idmap_tdb, net_idmap_find_max_id, &hwms);

	if (!hwms.ok) {
		goto done;
	}

	d_printf("USER HWM: %d  GROUP HWM: %d\n",
		 hwms.user_hwm, hwms.group_hwm);

	if (hwms.user_hwm >= highest.user_hwm) {
		d_fprintf(stderr, "Highest UID out of uid range\n");
		goto done;
	}

	if (hwms.group_hwm >= highest.group_hwm) {
		d_fprintf(stderr, "Highest GID out of gid range\n");
		goto done;
	}

	if ((tdb_store_int32(idmap_tdb, "USER HWM", (int32)hwms.user_hwm) != 0) ||
	    (tdb_store_int32(idmap_tdb, "GROUP HWM", (int32)hwms.group_hwm) != 0)) {
		d_fprintf(stderr, "Could not store HWMs\n");
		goto done;
	}

	result = NT_STATUS_OK;
 done:
	tdb_close(idmap_tdb);
	return result;
}
Exemplo n.º 14
0
TDB_CONTEXT *elog_init_tdb( char *tdbfilename )
{
	TDB_CONTEXT *tdb;

	DEBUG(10,("elog_init_tdb: Initializing eventlog tdb (%s)\n",
		tdbfilename));

	tdb = tdb_open_log( tdbfilename, 0, TDB_DEFAULT,
		O_RDWR|O_CREAT|O_TRUNC, 0660 );

	if ( !tdb ) {
		DEBUG( 0, ( "Can't open tdb for [%s]\n", tdbfilename ) );
		return NULL;
	}

	/* initialize with defaults, copy real values in here from registry */

	tdb_store_int32( tdb, EVT_OLDEST_ENTRY, 1 );
	tdb_store_int32( tdb, EVT_NEXT_RECORD, 1 );
	tdb_store_int32( tdb, EVT_MAXSIZE, 0x80000 );
	tdb_store_int32( tdb, EVT_RETENTION, 0x93A80 );

	tdb_store_int32( tdb, EVT_VERSION, EVENTLOG_DATABASE_VERSION_V1 );

	return tdb;
}
Exemplo n.º 15
0
WERROR regdb_open( void )
{
	WERROR result = WERR_OK;

	if ( tdb_reg ) {
		DEBUG(10,("regdb_open: incrementing refcount (%d)\n", tdb_refcount));
		tdb_refcount++;
		return WERR_OK;
	}
	
	become_root();

	tdb_reg = tdb_open_log(lock_path("registry.tdb"), 0, TDB_DEFAULT, O_RDWR, 0600);
	if ( !tdb_reg ) {
		result = ntstatus_to_werror( map_nt_error_from_unix( errno ) );
		DEBUG(0,("regdb_open: Failed to open %s! (%s)\n", 
			lock_path("registry.tdb"), strerror(errno) ));
	}

	unbecome_root();

	tdb_refcount = 1;
	DEBUG(10,("regdb_open: refcount reset (%d)\n", tdb_refcount));

	return result;
}
Exemplo n.º 16
0
BOOL locking_init(int read_only)
{
	brl_init(read_only);

	if (tdb)
		return True;

	tdb = tdb_open_log(lock_path("locking.tdb"), 
			lp_open_files_db_hash_size(),
			TDB_DEFAULT|(read_only?0x0:TDB_CLEAR_IF_FIRST), 
			read_only?O_RDONLY:O_RDWR|O_CREAT,
			0644);

	if (!tdb) {
		DEBUG(0,("ERROR: Failed to initialise locking database\n"));
		return False;
	}

	if (!posix_locking_init(read_only))
		return False;

	open_read_only = read_only;

	return True;
}
Exemplo n.º 17
0
static BOOL send_message(pid_t pid, int msg_type, const void *buf, int len,
			 BOOL duplicates)
{
	TDB_CONTEXT *tdb;
	BOOL ret;
	int n_sent = 0;

	if (!message_init())
		return False;

	if (pid != 0)
		return message_send_pid(pid, msg_type, buf, len, duplicates);

	tdb = tdb_open_log(lock_path("connections.tdb"), 0, 
			   TDB_DEFAULT, O_RDWR, 0);
	if (!tdb) {
		fprintf(stderr,"Failed to open connections database"
			": %s\n", strerror(errno));
		return False;
	}
	
	ret = message_send_all(tdb,msg_type, buf, len, duplicates,
			       &n_sent);
	DEBUG(10,("smbcontrol/send_message: broadcast message to "
		  "%d processes\n", n_sent));
	
	tdb_close(tdb);
	
	return ret;
}
Exemplo n.º 18
0
Arquivo: status.c Projeto: aosm/samba
static BOOL send_status_message(struct process_id pid)
{
	TDB_CONTEXT *tdb;
	BOOL ret;
	int n_sent = 0;

	if (!message_init())
		return False;

	if (procid_to_pid(&pid) != 0) {
		return NT_STATUS_IS_OK(message_send_pid(pid, MSG_USR_STATS,
				    NULL, 0, False /* duplicates */));
	}

	tdb = tdb_open_log(lock_path("connections.tdb"), 0,
			   TDB_DEFAULT, O_RDWR, 0);
	if (!tdb) {
		fprintf(stderr,"Failed to open connections database"
			": %s\n", strerror(errno));
		return False;
	}

	ret = message_send_all(tdb, MSG_USR_STATS, NULL, 0,
				False /* duplicates */, &n_sent);
	DEBUG(10,("smbcontrol/send_message: broadcast message to "
		  "%d processes\n", n_sent));
	tdb_close(tdb);
	return ret;
}
Exemplo n.º 19
0
TDB_CONTEXT *conn_tdb_ctx(void)
{
	if (!tdb)
		tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, 
			       O_RDWR | O_CREAT, 0644);

	return tdb;
}
Exemplo n.º 20
0
/* initialise the privilege database */
BOOL privilege_init(void)
{
	tdb = tdb_open_log(lock_path("privilege.tdb"), 0, TDB_DEFAULT, 
			   O_RDWR|O_CREAT, 0600);
	if (!tdb) {
		DEBUG(0,("Failed to open privilege database\n"));
		return False;
	}

	return True;
}
Exemplo n.º 21
0
static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, SAM_ACCOUNT *sam_pass)
{
	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
	struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data;
	TDB_CONTEXT 	*pwd_tdb;
	TDB_DATA 	key;
	fstring 	keystr;
	uint32		rid;
	fstring		name;
	
	fstrcpy(name, pdb_get_username(sam_pass));
	strlower_m(name);
	
	/* open the TDB */
	if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR, 0600))) {
		DEBUG(0, ("Unable to open TDB passwd!"));
		return nt_status;
	}
  
  	/* set the search key */
	slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name);
	key.dptr = keystr;
	key.dsize = strlen (keystr) + 1;
	
	rid = pdb_get_user_rid(sam_pass);

	/* it's outaa here!  8^) */
	if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) {
		DEBUG(5, ("Error deleting entry from tdb passwd database!\n"));
		DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
		tdb_close(pwd_tdb); 
		return nt_status;
	}	

	/* delete also the RID key */

  	/* set the search key */
	slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid);
	key.dptr = keystr;
	key.dsize = strlen (keystr) + 1;

	/* it's outaa here!  8^) */
	if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) {
		DEBUG(5, ("Error deleting entry from tdb rid database!\n"));
		DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
		tdb_close(pwd_tdb); 
		return nt_status;
	}
	
	tdb_close(pwd_tdb);
	
	return NT_STATUS_OK;
}
Exemplo n.º 22
0
uint32_t reg_perfcount_get_base_index(void)
{
	char *fname;
	TDB_CONTEXT *names;
	TDB_DATA kbuf, dbuf;
	char key[] = "1";
	uint32_t retval = 0;
	char buf[PERFCOUNT_MAX_LEN];

	fname = counters_directory(NAMES_DB);
	if (fname == NULL) {
		return 0;
	}

	names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);

	if ( !names ) {
		DEBUG(2, ("reg_perfcount_get_base_index: unable to open [%s].\n", fname));
		TALLOC_FREE(fname);
		return 0;
	}
	/* needs to read the value of key "1" from the counter_names.tdb file, as that is
	   where the total number of counters is stored. We're assuming no holes in the
	   enumeration.
	   The format for the counter_names.tdb file is:
	   key        value
	   1          num_counters
	   2          perf_counter1
	   3          perf_counter1_help
	   4          perf_counter2
	   5          perf_counter2_help
	   even_num   perf_counter<even_num>
	   even_num+1 perf_counter<even_num>_help
	   and so on.
	   So last_counter becomes num_counters*2, and last_help will be last_counter+1 */
	kbuf = string_tdb_data(key);
	dbuf = tdb_fetch(names, kbuf);
	if(dbuf.dptr == NULL)
	{
		DEBUG(1, ("reg_perfcount_get_base_index: failed to find key \'1\' in [%s].\n", fname));
		tdb_close(names);
		TALLOC_FREE(fname);
		return 0;
	}

	tdb_close(names);
	TALLOC_FREE(fname);
	memset(buf, 0, PERFCOUNT_MAX_LEN);
	memcpy(buf, dbuf.dptr, dbuf.dsize);
	retval = (uint32_t)atoi(buf);
	SAFE_FREE(dbuf.dptr);
	return retval;
}
Exemplo n.º 23
0
BOOL init_account_policy(void)
{

	const char *vstring = "INFO/version";
	uint32 version;
	int i;

	if (tdb) {
		return True;
	}

	tdb = tdb_open_log(lock_path("account_policy.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
	if (!tdb) {
		DEBUG(0,("Failed to open account policy database\n"));
		return False;
	}

	/* handle a Samba upgrade */
	tdb_lock_bystring(tdb, vstring);
	if (!tdb_fetch_uint32(tdb, vstring, &version) || version != DATABASE_VERSION) {

		tdb_store_uint32(tdb, vstring, DATABASE_VERSION);

		for (i=0; account_policy_names[i].field; i++) {

			if (!account_policy_set_default_on_empty(account_policy_names[i].field)) {
				DEBUG(0,("failed to set default value in account policy tdb\n"));
				return False;
			}
		}
	}

	tdb_unlock_bystring(tdb, vstring);

	/* These exist by default on NT4 in [HKLM\SECURITY\Policy\Accounts] */

	privilege_create_account( &global_sid_World );
	privilege_create_account( &global_sid_Builtin_Account_Operators );
	privilege_create_account( &global_sid_Builtin_Server_Operators );
	privilege_create_account( &global_sid_Builtin_Print_Operators );
	privilege_create_account( &global_sid_Builtin_Backup_Operators );

	/* BUILTIN\Administrators get everything -- *always* */

	if ( lp_enable_privileges() ) {
		if ( !grant_all_privileges( &global_sid_Builtin_Administrators ) ) {
			DEBUG(1,("init_account_policy: Failed to grant privileges "
				"to BUILTIN\\Administrators!\n"));
		}
	}

	return True;
}
Exemplo n.º 24
0
bool netsamlogon_cache_init(void)
{
    bool first_try = true;
    char *path = NULL;
    int ret;
    struct tdb_context *tdb;

    if (netsamlogon_tdb) {
        return true;
    }

    path = cache_path(NETSAMLOGON_TDB);
    if (path == NULL) {
        return false;
    }
again:
    tdb = tdb_open_log(path, 0, TDB_DEFAULT|TDB_INCOMPATIBLE_HASH,
                       O_RDWR | O_CREAT, 0600);
    if (tdb == NULL) {
        DEBUG(0,("tdb_open_log('%s') - failed\n", path));
        goto clear;
    }

    ret = tdb_check(tdb, NULL, NULL);
    if (ret != 0) {
        tdb_close(tdb);
        DEBUG(0,("tdb_check('%s') - failed\n", path));
        goto clear;
    }

    netsamlogon_tdb = tdb;
    talloc_free(path);
    return true;

clear:
    if (!first_try) {
        talloc_free(path);
        return false;
    }
    first_try = false;

    DEBUG(0,("retry after truncate for '%s'\n", path));
    ret = truncate(path, 0);
    if (ret == -1) {
        DBG_ERR("truncate failed: %s\n", strerror(errno));
        talloc_free(path);
        return false;
    }

    goto again;
}
Exemplo n.º 25
0
BOOL regdb_init( void )
{
	const char *vstring = "INFO/version";
	uint32 vers_id;

	if ( tdb_reg )
		return True;

	if ( !(tdb_reg = tdb_open_log(lock_path("registry.tdb"), 0, TDB_DEFAULT, O_RDWR, 0600)) )
	{
		tdb_reg = tdb_open_log(lock_path("registry.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
		if ( !tdb_reg ) {
			DEBUG(0,("regdb_init: Failed to open registry %s (%s)\n",
				lock_path("registry.tdb"), strerror(errno) ));
			return False;
		}
		
		DEBUG(10,("regdb_init: Successfully created registry tdb\n"));
	}

	tdb_refcount = 1;
		

	vers_id = tdb_fetch_int32(tdb_reg, vstring);

	if ( vers_id != REGVER_V1 ) {
		/* any upgrade code here if needed */
	}

	/* always setup the necessary keys and values */

	if ( !init_registry_data() ) {
		DEBUG(0,("init_registry: Failed to initialize data in registry!\n"));
		return False;
	}

	return True;
}
Exemplo n.º 26
0
static NTSTATUS tdbsam_setsampwent(struct pdb_methods *my_methods, BOOL update)
{
	struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data;
	
	/* Open tdb passwd */
	if (!(tdb_state->passwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, update?(O_RDWR|O_CREAT):O_RDONLY, 0600)))
	{
		DEBUG(0, ("Unable to open/create TDB passwd\n"));
		return NT_STATUS_UNSUCCESSFUL;
	}
	
	tdb_state->key = tdb_firstkey(tdb_state->passwd_tdb);

	return NT_STATUS_OK;
}
Exemplo n.º 27
0
uint32_t reg_perfcount_get_counter_names(uint32_t base_index, char **retbuf)
{
	char *buf1 = NULL;
	uint32_t buffer_size = 0;
	TDB_CONTEXT *names;
	char *fname;
	int i;

	if (base_index == 0) {
		return 0;
	}

	fname = counters_directory(NAMES_DB);
	if (fname == NULL) {
		return 0;
	}

	names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);

	if (names == NULL) {
		DEBUG(1, ("reg_perfcount_get_counter_names: unable to open [%s].\n", fname));
		TALLOC_FREE(fname);
		return 0;
	}
	TALLOC_FREE(fname);

	buffer_size = _reg_perfcount_multi_sz_from_tdb(names, 1, retbuf, buffer_size);

	for(i = 1; i <= base_index; i++)
	{
		buffer_size = _reg_perfcount_multi_sz_from_tdb(names, i*2, retbuf, buffer_size);
	}
	tdb_close(names);

	/* Now terminate the MULTI_SZ with a double unicode NULL */
	buf1 = *retbuf;
	buf1 = (char *)SMB_REALLOC(buf1, buffer_size + 2);
	if(!buf1) {
		buffer_size = 0;
	} else {
		buf1[buffer_size++] = '\0';
		buf1[buffer_size++] = '\0';
	}

	*retbuf=buf1;

	return buffer_size;
}
Exemplo n.º 28
0
Arquivo: status.c Projeto: aosm/samba
static void dump_user_stats(void)
{
	TDB_CONTEXT *tdb;
	int nump = 0;
	message_register(MSG_USR_STATS, handle_usr_stat_reply, NULL);
	tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
	if (!tdb) {
		d_printf("\nsessionid.tdb not initialised\n");
	} else {
		d_printf("\nPID     Username      Group         OpCount              ByteCount            \n");
		d_printf("------------------------------------------------------------------------------\n");
		nump = tdb_traverse(tdb, traverse_processes, NULL);
		//DEBUG(10,("Total %d procs traversed\n", nump));
		tdb_close(tdb);
	}
	message_deregister(MSG_USR_STATS);
}
Exemplo n.º 29
0
/***********************************************************
 Delete a SID mapping from a winbindd_idmap.tdb
 **********************************************************/
static int net_idmap_delete(int argc, const char **argv)
{
	TDB_CONTEXT *idmap_tdb;
	TDB_DATA key, data;
	fstring sid;

	if (argc != 2)
		return net_help_idmap(argc, argv);

	idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDWR, 0);

	if (idmap_tdb == NULL) {
		d_fprintf(stderr, "Could not open idmap: %s\n", argv[0]);
		return -1;
	}

	fstrcpy(sid, argv[1]);

	if (strncmp(sid, "S-1-5-", strlen("S-1-5-")) != 0) {
		d_fprintf(stderr, "Can only delete SIDs, %s is does not start with "
			 "S-1-5-\n", sid);
		return -1;
	}

	key.dptr = sid;
	key.dsize = strlen(key.dptr)+1;

	data = tdb_fetch(idmap_tdb, key);

	if (data.dptr == NULL) {
		d_fprintf(stderr, "Could not find sid %s\n", argv[1]);
		return -1;
	}

	if (tdb_delete(idmap_tdb, key) != 0) {
		d_fprintf(stderr, "Could not delete key %s\n", argv[1]);
		return -1;
	}

	if (tdb_delete(idmap_tdb, data) != 0) {
		d_fprintf(stderr, "Could not delete key %s\n", data.dptr);
		return -1;
	}

	return 0;
}
Exemplo n.º 30
0
/*
 * tdb validation function.
 * returns 0 if tdb is ok, != 0 if it isn't.
 * this is a wrapper around the actual validation function that opens and closes
 * the tdb.
 */
int tdb_validate_open(const char *tdb_path, tdb_validate_data_func validate_fn)
{
	TDB_CONTEXT *tdb = NULL;
	int ret = 1;

	DEBUG(5, ("tdb_validate_open called for tdb '%s'\n", tdb_path));

	tdb = tdb_open_log(tdb_path, 0, TDB_DEFAULT, O_RDONLY, 0);
	if (!tdb) {
		DEBUG(1, ("Error opening tdb %s\n", tdb_path));
		return ret;
	}

	ret = tdb_validate(tdb, validate_fn);
	tdb_close(tdb);
	return ret;
}