NTSTATUS smbXsrv_session_global_init(struct messaging_context *msg_ctx) { char *global_path = NULL; struct db_context *backend = 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"); if (global_path == NULL) { return NT_STATUS_NO_MEMORY; } backend = 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 (backend == NULL) { NTSTATUS status; status = map_nt_error_from_unix_common(errno); return status; } db_ctx = db_open_watched(NULL, backend, server_messaging_context()); if (db_ctx == NULL) { TALLOC_FREE(backend); return NT_STATUS_NO_MEMORY; } smbXsrv_session_global_db_ctx = db_ctx; return NT_STATUS_OK; }
bool run_dbwrap_watch1(int dummy) { struct tevent_context *ev = NULL; struct messaging_context *msg = NULL; struct db_context *backend = NULL; struct db_context *db = NULL; const char *keystr = "key"; TDB_DATA key = string_term_tdb_data(keystr); struct db_record *rec = NULL; struct tevent_req *req = NULL; NTSTATUS status; bool ret = false; ev = samba_tevent_context_init(talloc_tos()); if (ev == NULL) { fprintf(stderr, "tevent_context_init failed\n"); goto fail; } msg = messaging_init(ev, ev); if (msg == NULL) { fprintf(stderr, "messaging_init failed\n"); goto fail; } backend = db_open(msg, "test_watch.tdb", 0, TDB_DEFAULT, O_CREAT|O_RDWR, 0644, DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE); if (backend == NULL) { fprintf(stderr, "db_open failed: %s\n", strerror(errno)); goto fail; } db = db_open_watched(ev, backend, msg); rec = dbwrap_fetch_locked(db, db, key); if (rec == NULL) { fprintf(stderr, "dbwrap_fetch_locked failed\n"); goto fail; } req = dbwrap_watched_watch_send(talloc_tos(), ev, rec, (struct server_id){0});
bool run_dbwrap_do_locked1(int dummy) { struct tevent_context *ev; struct messaging_context *msg; struct db_context *backend; struct db_context *db; const char *dbname = "test_do_locked.tdb"; const char *keystr = "key"; TDB_DATA key = string_term_tdb_data(keystr); const char *valuestr = "value"; TDB_DATA value = string_term_tdb_data(valuestr); struct do_locked1_state state = { .value = value }; int ret = false; NTSTATUS status; ev = server_event_context(); if (ev == NULL) { fprintf(stderr, "server_event_context() failed\n"); return false; } msg = server_messaging_context(); if (msg == NULL) { fprintf(stderr, "server_messaging_context() failed\n"); return false; } backend = db_open(talloc_tos(), dbname, 0, TDB_CLEAR_IF_FIRST, O_CREAT|O_RDWR, 0644, DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE); if (backend == NULL) { fprintf(stderr, "db_open failed: %s\n", strerror(errno)); return false; } db = db_open_watched(talloc_tos(), backend, msg); if (db == NULL) { fprintf(stderr, "db_open_watched failed: %s\n", strerror(errno)); return false; } status = dbwrap_do_locked(db, key, do_locked1_cb, &state); if (!NT_STATUS_IS_OK(status)) { fprintf(stderr, "dbwrap_do_locked failed: %s\n", nt_errstr(status)); goto fail; } if (!NT_STATUS_IS_OK(state.status)) { fprintf(stderr, "store returned %s\n", nt_errstr(state.status)); goto fail; } status = dbwrap_parse_record(db, key, do_locked1_check, &state); if (!NT_STATUS_IS_OK(status)) { fprintf(stderr, "dbwrap_parse_record failed: %s\n", nt_errstr(status)); goto fail; } if (!NT_STATUS_IS_OK(state.status)) { fprintf(stderr, "data compare returned %s\n", nt_errstr(status)); goto fail; } status = dbwrap_do_locked(db, key, do_locked1_del, &state); if (!NT_STATUS_IS_OK(status)) { fprintf(stderr, "dbwrap_do_locked failed: %s\n", nt_errstr(status)); goto fail; } if (!NT_STATUS_IS_OK(state.status)) { fprintf(stderr, "delete returned %s\n", nt_errstr(status)); goto fail; } status = dbwrap_parse_record(db, key, do_locked1_check, &state); if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) { fprintf(stderr, "parse_record returned %s, " "expected NOT_FOUND\n", nt_errstr(status)); goto fail; } ret = true; fail: TALLOC_FREE(db); unlink(dbname); return ret; }