Beispiel #1
0
/*
  Open up the notify.tdb database. You should close it down using
  talloc_free(). We need the messaging_ctx to allow for notifications
  via internal messages
*/
struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server, 
				   struct messaging_context *messaging_ctx,
				   struct event_context *ev,
				   connection_struct *conn)
{
	struct notify_context *notify;

	if (!lp_change_notify(conn->params)) {
		return NULL;
	}

	notify = talloc(mem_ctx, struct notify_context);
	if (notify == NULL) {
		return NULL;
	}

	notify->db_recursive = db_open(notify, lock_path("notify.tdb"),
				       0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
				       O_RDWR|O_CREAT, 0644,
				       DBWRAP_LOCK_ORDER_2);
	if (notify->db_recursive == NULL) {
		talloc_free(notify);
		return NULL;
	}

	notify->db_onelevel = db_open(notify, lock_path("notify_onelevel.tdb"),
				      0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
				      O_RDWR|O_CREAT, 0644,
				      DBWRAP_LOCK_ORDER_2);
	if (notify->db_onelevel == NULL) {
		talloc_free(notify);
		return NULL;
	}

	notify->server = server;
	notify->messaging_ctx = messaging_ctx;
	notify->list = NULL;
	notify->array = NULL;
	notify->seqnum = dbwrap_get_seqnum(notify->db_recursive);
	notify->key = string_term_tdb_data(NOTIFY_KEY);

	talloc_set_destructor(notify, notify_destructor);

	/* register with the messaging subsystem for the notify
	   message type */
	messaging_register(notify->messaging_ctx, notify, 
			   MSG_PVFS_NOTIFY, notify_handler);

	notify->sys_notify_ctx = sys_notify_context_create(conn, notify, ev);

	return notify;
}
int main(int argc,char **argv)
{
	static GDBM_FILE gdbm_stotest = NULL;
	datum key,data;
	int i;
	for(i = 1;i<argc;i++)
	{
		key.dptr = "store test1!";
		key.dsize = strlen("store test1")+1;
		data = key;
		gdbm_stotest = db_open(argv[i]);
		printf("\n--------open dbm id:%d-----------\n",gdbm_stotest);
		if(db_store(gdbm_stotest,key,data) < 0) {
			printf("\n---------store err-----------\n");
			db_close(gdbm_stotest);
			break;
		}
		else {
			printf("\n---------store successfully!-----------\n");
			db_close(gdbm_stotest);
		}
		printf("\n--------close dbm id:%d-----------\n",gdbm_stotest);
		key.dptr = "store test2!";
		key.dsize = strlen("store test1")+1;
		data = key;
		gdbm_stotest = db_open(argv[i]);
		printf("\n--------open dbm id:%d-----------\n",gdbm_stotest);
		if(db_store(gdbm_stotest,key,data) < 0) {
			printf("\n---------store err-----------\n");
			db_close(gdbm_stotest);
			break;
		}
		else {
			printf("\n---------store successfully!-----------\n");
			db_close(gdbm_stotest);
		}
		printf("\n--------close dbm id:%d-----------\n",gdbm_stotest);
		
		gdbm_stotest = db_open(argv[i]);
		key.dptr = "store test1!";
		key.dsize = strlen("store test1!")+1;

		data = key;
		if(gdbm_exists(gdbm_stotest,key) != 0){
			printf("-------really exist here!-----");
		}
		else {
			printf("-------not exist here!-------");		
		}
	}
}
Beispiel #3
0
static void
_win_populate_job(void *data)
{
   Win *w = data;
   w->job.populate = NULL;

   if (w->db)
     {
        db_close(w->db);
        w->db = NULL;
     }

   if (access(w->db_path, F_OK|X_OK) == 0)
     w->db = db_open(w->db_path);

   if (!w->db)
     {
        char tmpdir[PATH_MAX];
        lms_t *lms = lms_new(w->db_path);
        if (!lms)
          goto no_lms;
        enjoy_lms_charsets_add(lms);
        if (!enjoy_lms_parsers_add(lms))
          goto no_parsers;

        snprintf(tmpdir, sizeof(tmpdir), "%s/tmpdir-nomusic",
                 enjoy_cache_dir_get());
        ecore_file_mkpath(tmpdir);
        if (lms_process_single_process(lms, tmpdir) != 0)
          CRITICAL("Failed to scan empty directory %s", tmpdir);
        ecore_file_rmdir(tmpdir);
        lms_free(lms);

        w->db = db_open(w->db_path);
        if (!w->db)
          goto no_lms;

        goto populate;

     no_parsers:
        CRITICAL("could not add any lightmediascanner parser!");
        lms_free(lms);
     no_lms:
        CRITICAL("could not create database at %s!", w->db_path);
        exit(-1);
     }

 populate:
   ecore_event_add(ENJOY_EVENT_DB_UNLOCKED, NULL, NULL, NULL);
   list_populate(w->list, w->db);
}
static bool locking_init_internal(bool read_only)
{
	brl_init(read_only);

	if (lock_db)
		return True;

	lock_db = db_open(NULL, lock_path("locking.tdb"),
			  SMB_OPEN_DATABASE_TDB_HASH_SIZE,
			  TDB_DEFAULT|TDB_VOLATILE|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
			  read_only?O_RDONLY:O_RDWR|O_CREAT, 0644,
			  DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);

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

	if (!posix_locking_init(read_only))
		return False;

	dbwrap_watch_db(lock_db, server_messaging_context());

	return True;
}
Beispiel #5
0
NTSTATUS smbXsrv_session_global_init(void)
{
	const char *global_path = NULL;
	struct db_context *db_ctx = NULL;

	if (smbXsrv_session_global_db_ctx != NULL) {
		return NT_STATUS_OK;
	}

	/*
	 * This contains secret information like session keys!
	 */
	global_path = lock_path("smbXsrv_session_global.tdb");

	db_ctx = db_open(NULL, global_path,
			 0, /* hash_size */
			 TDB_DEFAULT |
			 TDB_CLEAR_IF_FIRST |
			 TDB_INCOMPATIBLE_HASH,
			 O_RDWR | O_CREAT, 0600,
			 DBWRAP_LOCK_ORDER_1);
	if (db_ctx == NULL) {
		NTSTATUS status;

		status = map_nt_error_from_unix_common(errno);

		return status;
	}

	smbXsrv_session_global_db_ctx = db_ctx;

	return NT_STATUS_OK;
}
Beispiel #6
0
/* Match pattern against files in locate.db file */
static int
db_locate(
    const wchar_t *pattern)
{
    int count = 0;

#ifdef WIN32
    wchar_t buffer[PATH_MAX + 1];

    /* Open locate.db for read */
    db_open ();
    
    /* Read one directory and file name at a time from database file */
    while (db_read (buffer, PATH_MAX)) {
        /* See if file name in buffer matches the search pattern */
        if (db_match (buffer, pattern)) {
            /* Match found => output file name and path */
            wprintf (L"%s\n", buffer);
            count++;
        }

    }

    db_close ();
#endif

    return count;
}
Beispiel #7
0
static int
es_sqlite_create(duk_context *ctx)
{
    char path[PATH_MAX];
    char errbuf[512];
    es_context_t *ec = es_get(ctx);
    const char *name = duk_safe_to_string(ctx, 0);

    // Create the db-dir for this plugin

    snprintf(path, sizeof(path), "%s/databases", ec->ec_storage);

    if(fa_makedirs(path, errbuf, sizeof(errbuf)))
        duk_error(ctx, DUK_ERR_ERROR, "Unable to create directory %s -- %s",
                  path, errbuf);

    snprintf(path, sizeof(path), "%s/databases/%s", ec->ec_storage, name);

    sqlite3 *db = db_open(path, 0);
    if(db == NULL)
        duk_error(ctx, DUK_ERR_ERROR, "Unable to open database -- check logs");


    es_sqlite_t *es = es_resource_create(ec, &es_resource_sqlite, 0);

    es->es_db = db;
    es->es_name = strdup(name);

    es_resource_push(ctx, &es->super);
    return 1;
}
Beispiel #8
0
/*	p a r s A r g ( )
	Parse the command line arguments.
*/
int
parsArg(int argc, char **argv)
{
    register int	i, c, arg_cnt;
    extern int	bu_optind;

    while ( (c = bu_getopt( argc, argv, "d" )) != EOF )
    {
	switch ( c )
	{
	    case 'd' :
		debug = 1;
		break;
	    case '?' :
		return	0;
	}
    }
    if ( bu_optind >= argc )
    {
	(void) fprintf( stderr, "Missing name of input file!\n" );
	return	0;
    }
    else
	objfile = argv[bu_optind++];
    if ( (dbip = db_open( objfile, "r" )) == DBI_NULL )  {
	perror(objfile);
	return( 0 );		/* FAIL */
    }

    arg_list[0] = argv[0]; /* Program name goes in first.	*/
    for ( i = bu_optind, arg_cnt = 1; i < argc; i++, arg_cnt++ )
	/* Insert objects.	*/
	arg_list[arg_cnt] = argv[i];
    return	1;
}
Beispiel #9
0
/* open up the secrets database with specified private_dir path */
bool secrets_init_path(const char *private_dir)
{
	char *fname = NULL;
	TALLOC_CTX *frame;

	if (db_ctx != NULL) {
		return True;
	}

	if (private_dir == NULL) {
		return False;
	}

	frame = talloc_stackframe();
	fname = talloc_asprintf(frame, "%s/secrets.tdb", private_dir);
	if (fname == NULL) {
		TALLOC_FREE(frame);
		return False;
	}

	db_ctx = db_open(NULL, fname, 0,
			 TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
			 DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);

	if (db_ctx == NULL) {
		DEBUG(0,("Failed to open %s\n", fname));
		TALLOC_FREE(frame);
		return False;
	}

	TALLOC_FREE(frame);
	return True;
}
void 
initDB(/*DB_ENV ** dbenv, */pthread_attr_t * attr, int type)  
{

	pthread_t ptid;

	env_dir_create();
	env_open(&dbenv);
	int ret;
	/*
	///Start a checkpoint thread.
	if ((ret = pthread_create(
	    &ptid, attr, checkpoint_thread, (void *)dbenv)) != 0) {
		fprintf(stderr,
		    "txnapp: failed spawning checkpoint thread: %s\n",
		    strerror(ret));
		exit (1);
	}

	/// Start a logfile removal thread. 
	if ((ret = pthread_create(
	    &ptid, attr, logfile_thread, (void *)dbenv)) != 0) {
		fprintf(stderr,
		    "txnapp: failed spawning log file removal thread: %s\n",
		    strerror(ret));
		exit (1);
	}
	*/
	db_open(dbenv, &db_cats, "cats", type);



}
Beispiel #11
0
int main(int argc, char **argv)
{
  int dev_cnt;
  if(argc>1 && (strcmp(argv[1], "-d")==0) )
    demonize(argv[0]);

  while(1)
  {
    db_open();
    dev_cnt = 0;
    receive_history = true;
    frame_id = 0;
    printf("Wait for cm160 device to be connected\n");
    while((dev_cnt = scan_usb()) == 0)
      sleep(2);
    printf("Found %d compatible device%s\n", dev_cnt, dev_cnt>1?"s":"");

    // Only 1 device supported
    if(!(g_devices[0].hdev = usb_open(g_devices[0].usb_dev)))
    {
      fprintf(stderr, "failed to open device\n");
      db_close();
      break;
    }
    handle_device(0); 
    usb_close(g_devices[0].hdev);
    db_close();
  }

  return 0;
}
Beispiel #12
0
/*
  open the permanent tdb
 */
static NTSTATUS idmap_tdb2_open_db(void)
{
	char *db_path;
	
	if (idmap_tdb2) {
		/* its already open */
		return NT_STATUS_OK;
	}

	db_path = lp_parm_talloc_string(-1, "tdb", "idmap2.tdb", NULL);
	if (db_path == NULL) {
		/* fall back to the private directory, which, despite
		   its name, is usually on shared storage */
		db_path = talloc_asprintf(NULL, "%s/idmap2.tdb", lp_private_dir());
	}
	NT_STATUS_HAVE_NO_MEMORY(db_path);

	/* Open idmap repository */
	idmap_tdb2 = db_open(NULL, db_path, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644);
	TALLOC_FREE(db_path);

	if (idmap_tdb2 == NULL) {
		DEBUG(0, ("Unable to open idmap_tdb2 database '%s'\n",
			  db_path));
		return NT_STATUS_UNSUCCESSFUL;
	}

	/* load the ranges and high/low water marks */
	return idmap_tdb2_alloc_load();
}
Beispiel #13
0
void doit(char *pathname)
{
	DB		*db;
	char	key[IDXLEN_MAX], *ptr;
	hash_t	hash;
	int		i, nrec;

	if ( (db = db_open(pathname, O_RDONLY, 0)) == NULL)
		err_sys("db_open error");

	nrec = 0;
	while ( (ptr = db_nextrec(db, key)) != NULL) {
		nrec++;
		hash = _db_hash(db, key);
		cntr[hash]++;
	}

	printf("total #records = %d\n", nrec);
	for (i = 0; i < NHASH_DEF; i++) {
		printf("%3d: %6ld\n", i, cntr[i]);
	}

	if ( (i = _db_checkfree(db)) < 0)
		printf("corrupted free list\n");
	else
		printf("%d records on free list\n", i);

	exit(0);
}
/**
 * Builds a directory of the object names.
 *
 * Allocate and initialize information for this instance of an RT
 * model database.
 *
 * Returns -
 * (struct rt_i *) Success
 * RTI_NULL Fatal Error
 */
struct rt_i *
rt_dirbuild(const char *filename, char *buf, int len)
{
    register struct rt_i *rtip;
    register struct db_i *dbip;		/* Database instance ptr */

    if (rt_uniresource.re_magic == 0)
	rt_init_resource(&rt_uniresource, 0, NULL);

    if ((dbip = db_open(filename, DB_OPEN_READONLY)) == DBI_NULL)
	return RTI_NULL;		/* FAIL */
    RT_CK_DBI(dbip);

    if (db_dirbuild(dbip) < 0) {
	db_close(dbip);
	return RTI_NULL;		/* FAIL */
    }

    rtip = rt_new_rti(dbip);		/* clones dbip */
    db_close(dbip);				/* releases original dbip */

    if (buf != (char *)NULL)
	bu_strlcpy(buf, dbip->dbi_title, len);

    return rtip;				/* OK */
}
static gboolean
backend_get_packages_thread (PkBackend *backend)
{
	PkBitfield filters;
	GList *list = NULL;
	sqlite3 *db = NULL;

	filters = pk_backend_get_uint (backend, "filters");

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);

	pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);

	db = db_open();

	if ((pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED) &&
	     pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) ||
	    (!pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED) &&
	     !pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED))) {
		list = box_db_repos_packages_search_all (db, NULL, 0);
	} else if (pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED)) {
		list = box_db_repos_packages_search_installed (db, NULL, 0);
	} else if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) {
		list = box_db_repos_packages_search_available (db, NULL, 0);
	}

	add_packages_from_list (backend, list, FALSE);
	box_db_repos_package_list_free (list);

	db_close(db);
	pk_backend_finished (backend);
	return TRUE;
}
Beispiel #16
0
int main() {
    table *tab;
    field **defs;

    if(db_open("db")) {
        g_error("db_open");
        return 1;
    }

    tab = table_open("test");
    if(!tab) {
        g_error("table_open");
        return 1;
    }

    defs = table_get_field_defs(tab);
    while(!table_end(tab)) {

    }

    if(db_close()) {
        g_error("db_clos ");
        return 1;
    }

    return 0;
}
Beispiel #17
0
static bool acl_tdb_init(struct db_context **pp_db)
{
    char *dbname;

    if (acl_db) {
        *pp_db = acl_db;
        ref_count++;
        return true;
    }

    dbname = state_path("file_ntacls.tdb");

    if (dbname == NULL) {
        errno = ENOSYS;
        return false;
    }

    become_root();
    *pp_db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
    unbecome_root();

    if (*pp_db == NULL) {
#if defined(ENOTSUP)
        errno = ENOTSUP;
#else
        errno = ENOSYS;
#endif
        TALLOC_FREE(dbname);
        return false;
    }

    ref_count++;
    TALLOC_FREE(dbname);
    return true;
}
Beispiel #18
0
WERROR regdb_open( void )
{
	WERROR result = WERR_OK;

	if ( regdb ) {
		DEBUG(10, ("regdb_open: incrementing refcount (%d->%d)\n",
			   regdb_refcount, regdb_refcount+1));
		regdb_refcount++;
		return WERR_OK;
	}

	become_root();

	regdb = db_open(NULL, state_path("registry.tdb"), 0,
			REG_TDB_FLAGS, O_RDWR, 0600,
			DBWRAP_LOCK_ORDER_1);
	if ( !regdb ) {
		result = ntstatus_to_werror( map_nt_error_from_unix( errno ) );
		DEBUG(0,("regdb_open: Failed to open %s! (%s)\n",
			state_path("registry.tdb"), strerror(errno) ));
	}

	unbecome_root();

	regdb_refcount = 1;
	DEBUG(10, ("regdb_open: registry db opened. refcount reset (%d)\n",
		   regdb_refcount));

	return result;
}
Beispiel #19
0
void thread(void *arg)
{
	  char * ptr=(char *)arg;
	  
	  sleep(1);

	  FILE *datafp = NULL;;
	  datafp=fopen("student.txt", "w+");
	  fwrite(ptr,1,20,datafp);
	  fclose(datafp);

	  DBHANDLE	db;

	if ((db = db_open("db4", O_RDWR | O_CREAT | O_TRUNC,
	  FILE_MODE)) == NULL)
		err_sys("db_open error");

	if (db_store(db, "Alpha", "data1", DB_INSERT) != 0)
		err_quit("db_store error for alpha");
	if (db_store(db, "beta", "Data for beta", DB_INSERT) != 0)
		err_quit("db_store error for beta");
	if (db_store(db, "gamma", "record3", DB_INSERT) != 0)
		err_quit("db_store error for gamma");

	db_close(db);
	exit(0);

	  
	  //printf("hello world! %s\n",ptr);
}
Beispiel #20
0
static int
list_geometry(ClientData UNUSED(clientData), Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
{
    static struct db_i *dbip;
    struct directory *dp;
    int i;
    struct bu_vls tclstr = BU_VLS_INIT_ZERO;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "file varname");
	return TCL_ERROR;
    }

    if ((dbip = db_open(Tcl_GetString(objv[1]), "r")) == DBI_NULL) {
	bu_log("Unable to open geometry file (%s)\n", Tcl_GetString(objv[1]));
	return TCL_ERROR;
    }
    db_dirbuild(dbip);
    for (i = 0; i < RT_DBNHASH; i++) {
	for (dp = dbip->dbi_Head[i]; dp != RT_DIR_NULL; dp = dp->d_forw) {
	    if (dp->d_flags & RT_DIR_HIDDEN) continue;
	    bu_vls_sprintf(&tclstr, "set %s [concat $%s [list %s]]", Tcl_GetString(objv[2]), Tcl_GetString(objv[2]), dp->d_namep);
	    Tcl_Eval(interp, bu_vls_addr(&tclstr));
	}
    }
    db_close(dbip);
    bu_vls_free(&tclstr);
    return TCL_OK;
}
static gboolean
backend_get_depends_requires_thread (PkBackend *backend)
{
	GList *list = NULL;
	sqlite3 *db;
	gchar **package_ids;
	int deps_type;
        gchar **package_id_data;

	db = db_open ();
	package_ids = pk_backend_get_strv (backend, "package_ids");
	deps_type = pk_backend_get_uint (backend, "type");
	/* FIXME: support multiple packages */
	package_id_data = pk_package_id_split (package_ids[0]);

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);

	if (deps_type == DEPS_TYPE_DEPENDS)
		list = box_db_repos_get_depends (db, package_id_data[PK_PACKAGE_ID_NAME]);
	else if (deps_type == DEPS_TYPE_REQUIRES)
		list = box_db_repos_get_requires (db, package_id_data[PK_PACKAGE_ID_NAME]);

	add_packages_from_list (backend, list, FALSE);
	box_db_repos_package_list_free (list);

	db_close (db);

	pk_backend_finished (backend);
	return TRUE;
}
static gboolean
backend_get_details_thread (PkBackend *backend)
{
	PackageSearch *ps;
	GList *list;
	sqlite3 *db;
	gchar **package_ids;
	gchar **package_id_data;

	package_ids = pk_backend_get_strv (backend, "package_ids");
	/* FIXME: support multiple packages */
	package_id_data = pk_package_id_split (package_ids[0]);

	db = db_open ();

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);

	/* only one element is returned */
	list = box_db_repos_packages_search_by_data (db, package_id_data[PK_PACKAGE_ID_NAME], package_id_data[PK_PACKAGE_ID_VERSION]);

	if (list == NULL) {
		pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "cannot find package by id");
		db_close (db);
		return FALSE;
	}
	ps = (PackageSearch*) list->data;

	pk_backend_details (backend, package_ids[0], "unknown", PK_GROUP_ENUM_OTHER, ps->description, "", 0);

	box_db_repos_package_list_free (list);

	db_close (db);
	pk_backend_finished (backend);
	return TRUE;
}
Beispiel #23
0
void
setup_database(char *DBFile)
{
    int i;

    if ((i = db_create(&db, NULL, 0)) != 0)
    {
        fprintf(ErrFile, "error creating database.\n%s\n", db_strerror(i));
        _exit(-1);
    }
//#ifndef WIN32 // for some reason the win berkeley DOES NOT LIKE this ... :-/
//    if ((i=db_set_re_len(db, sizeof(db_val))) != 0)
//    {
//        fprintf(ErrFile, "error setting record length.\n%s\n", db_strerror(i));
//        _exit(-1);
//    }
//#endif
    if ((i = db_open(db, DBFile, DB_BTREE, DB_CREATE)) != 0)
    {
        fprintf(ErrFile, "error opening database.\n%s\n", db_strerror(i));
        _exit(-1);
    }
    memset(&dbkey, 0, sizeof(dbkey));          // initialize to zero
    memset(&dbval, 0, sizeof(dbval));
    dbkey.data = (void*)&key;                  // set all those things so
    dbkey.size = sizeof(db_key);               // we do not have to set them
    dbval.data = (void*)&val;                  // in the packet handler function
    dbval.size = sizeof(db_val);               // again every time :)
    assert(dbkey.data == &key);
}
Beispiel #24
0
static bool acl_tdb_init(void)
{
	char *dbname;

	if (acl_db) {
		ref_count++;
		return true;
	}

	dbname = state_path("file_ntacls.tdb");

	if (dbname == NULL) {
		errno = ENOSYS;
		return false;
	}

	become_root();
	acl_db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
			 DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
	unbecome_root();

	if (acl_db == NULL) {
#if defined(ENOTSUP)
		errno = ENOTSUP;
#else
		errno = ENOSYS;
#endif
		TALLOC_FREE(dbname);
		return false;
	}

	ref_count++;
	TALLOC_FREE(dbname);
	return true;
}
Beispiel #25
0
NTSTATUS smbXsrv_tcon_global_init(void)
{
	char *global_path = NULL;
	struct db_context *db_ctx = NULL;

	if (smbXsrv_tcon_global_db_ctx != NULL) {
		return NT_STATUS_OK;
	}

	global_path = lock_path("smbXsrv_tcon_global.tdb");
	if (global_path == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	db_ctx = db_open(NULL, global_path,
			 0, /* hash_size */
			 TDB_DEFAULT |
			 TDB_CLEAR_IF_FIRST |
			 TDB_INCOMPATIBLE_HASH,
			 O_RDWR | O_CREAT, 0600,
			 DBWRAP_LOCK_ORDER_1,
			 DBWRAP_FLAG_NONE);
	TALLOC_FREE(global_path);
	if (db_ctx == NULL) {
		NTSTATUS status;

		status = map_nt_error_from_unix_common(errno);

		return status;
	}

	smbXsrv_tcon_global_db_ctx = db_ctx;

	return NT_STATUS_OK;
}
Beispiel #26
0
/*
 * Open the database
 *
 */
static int berkeleydb_open(const char *path,DB **mbdb)
{
    int ret;

#if DB_VERSION_FULL < 0x03000000
    ret = db_open(path, DB_HASH, DB_CREATE, 0664, NULL, NULL, mbdb);
#else /* DB_VERSION_FULL < 0x03000000 */
    ret = db_create(mbdb, NULL, 0);
    if (ret == 0 && *mbdb != NULL)
    {
#if DB_VERSION_FULL >= 0x04010000
	ret = (*mbdb)->open(*mbdb, NULL, path, NULL, DB_HASH, DB_CREATE, 0664);
#else
	ret = (*mbdb)->open(*mbdb, path, NULL, DB_HASH, DB_CREATE, 0664);
#endif
	if (ret != 0)
	{
	    (void) (*mbdb)->close(*mbdb, 0);
	    *mbdb = NULL;
	}
    }
#endif /* DB_VERSION_FULL < 0x03000000 */

    if (ret != 0) {
	fprintf(stderr,"Error opening password file %s\n", path);
	return SASL_FAIL;
    }

    return SASL_OK;
}
Beispiel #27
0
int dbopen()
{
    LOG;
	char basedir[] = "./dbbench/";
	char dbname[] = "test.db";

	e = env_open(basedir, -1);
	db = db_open(e, dbname);
	if (!db) {
		fprintf(stderr, "open db error, see ness.event for details\n");
		return 0;
	}

	if (!env_set_cache_size(e, FLAGS_cache_size)) {
		fprintf(stderr, "set cache size error, see ness.event for details\n");
		return 0;
	}

	if (!env_set_compress_method(e, FLAGS_method)) {
		fprintf(stderr, "set compress method error, see ness.event for details\n");
		return 0;
	}

    LOG;
	return 1;
}
Beispiel #28
0
int
main (int argc, char * argv [])
{	const char *db_name = "./.sndfile-regtest.db" ;
	REG_DB *reg_db ;
	int k, retval ;

	if (argc < 2)
	{	printf ("\nUsage message goes here.\n\n") ;
		exit (0) ;
		} ;

	if (argc == 2 && strcmp (argv [1], "--create-db") == 0)
		return db_create (db_name) ;

	reg_db = db_open (db_name) ;

	if (argc == 2)
	{	if (strcmp (argv [1], "--list-all") == 0)
			return db_list_all (reg_db) ;

		if (strcmp (argv [1], "--check-all") == 0)
		{	print_libsndfile_version () ;
			retval = db_check_all (reg_db) ;
			puts ("\nDone.\n") ;
			return retval ;
			} ;
		} ;

	if (argc == 3 && strcmp (argv [1], "--del-entry") == 0)
	{	db_del_entry (reg_db, argv [2]) ;
		db_close (reg_db) ;
		return 0 ;
		} ;

	if (strcmp (argv [1], "--check-file") == 0)
	{	print_libsndfile_version () ;

		for (k = 2 ; k < argc ; k++)
			db_check_file (reg_db, argv [k]) ;
		db_close (reg_db) ;
		return 0 ;
		} ;

	if (strcmp (argv [1], "--add-file") == 0)
	{	print_libsndfile_version () ;

		for (k = 2 ; k < argc ; k++)
			db_add_file (reg_db, argv [k]) ;
		db_close (reg_db) ;
		return 0 ;
		} ;

	printf ("\nError : unhandled command line args :") ;
	for (k = 1 ; k < argc ; k++)
		printf (" %s", argv [k]) ;
	puts ("\n") ;

	return 1 ;
} /* main */
Beispiel #29
0
int
emp_run()
{
	if (do_emp_tracking) {
		if ((emp_db = db_open("emp.db", DB_HASH, 0, DB_CREATE | DB_AUTO_COMMIT, NULL)) == NULL) {
			nts_log("emp: EMP database open failed");
			return -1;
		}

		if ((emp_last_decayed_db = db_open("emp_last_decayed_idx.db", 
				DB_BTREE, DB_DUP, DB_CREATE | DB_AUTO_COMMIT,
				emp_compare_last_decayed)) == NULL) {
			nts_log("emp: EMP last seen index open failed");
			return -1;
		}

		emp_db->associate(emp_db, NULL, emp_last_decayed_db,
				emp_get_last_decayed, DB_AUTO_COMMIT);
	}

	if (do_phl_tracking) {
		if ((phl_db = db_open("phl.db", DB_HASH, 0,
				DB_CREATE | DB_AUTO_COMMIT, NULL)) == NULL) {
			nts_log("emp: Posting-Host/Lines (PHL) database open failed");
			return -1;
		}

		if ((phl_last_decayed_db = db_open("phl_last_decayed_idx.db",
				DB_BTREE, DB_DUP, DB_CREATE | DB_AUTO_COMMIT,
				phl_compare_last_decayed)) == NULL) {
			nts_log("emp: Posting-Host/Lines (PHL) last seen index open failed");
			return -1;
		}

		phl_db->associate(phl_db, NULL, phl_last_decayed_db,
				phl_get_last_decayed, DB_AUTO_COMMIT);
	}

	if (do_phl_tracking || do_emp_tracking) {
		uv_timer_init(loop, &emp_clean_timer);
		uv_timer_start(&emp_clean_timer, start_emp_clean,
			       3600 * 1000, 3600 * 1000);
	}

	return 0;
}
Beispiel #30
0
int mail_cache_db_open(const char * filename,
    struct mail_cache_db ** pcache_db)
{
#if DBVERS >= 1
  DB * dbp;
#if DBVERS > 1
  int r;
#endif
  struct mail_cache_db * cache_db;

#if DB_VERSION_MAJOR >= 3
  r = db_create(&dbp, NULL, 0);
  if (r != 0)
    goto err;

#if (DB_VERSION_MAJOR >= 4) && ((DB_VERSION_MAJOR > 4) || (DB_VERSION_MINOR >= 1))
  r = dbp->open(dbp, NULL, filename, NULL, DB_BTREE, DB_CREATE,
      S_IRUSR | S_IWUSR);
#else
  r = dbp->open(dbp, filename, NULL, DB_BTREE, DB_CREATE, S_IRUSR | S_IWUSR);
#endif
  if (r != 0)
    goto close_db;
#else
#if DBVERS > 1  
  r = db_open(filename, DB_BTREE, DB_CREATE, S_IRUSR | S_IWUSR,
      NULL, NULL, &dbp);
  if (r != 0)
    goto err;
#elif DBVERS == 1
  dbp = dbopen(filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, DB_BTREE, NULL);
  if (dbp == NULL)
    goto err;
#else
  goto err;
#endif  
#endif

  cache_db = mail_cache_db_new(dbp);
  if (cache_db == NULL)
    goto close_db;
  
  * pcache_db = cache_db;

  return 0;

 close_db:
#if DBVERS > 1  
  dbp->close(dbp, 0);
#elif DBVERS == 1
  dbp->close(dbp);
#endif
 err:
  return -1;
#else
  return -1;
#endif
}