s4:libcli/smb2: calculate the correct credit charge in smb2_notify_send()
[Samba.git] / source3 / lib / g_lock.c
blobd8298b6ee33a62e6deed69db721f02a6815a947a
1 /*
2 Unix SMB/CIFS implementation.
3 global locks based on dbwrap and messaging
4 Copyright (C) 2009 by Volker Lendecke
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "system/filesys.h"
22 #include "lib/util/server_id.h"
23 #include "dbwrap/dbwrap.h"
24 #include "dbwrap/dbwrap_open.h"
25 #include "dbwrap/dbwrap_watch.h"
26 #include "g_lock.h"
27 #include "util_tdb.h"
28 #include "../lib/util/tevent_ntstatus.h"
29 #include "messages.h"
30 #include "serverid.h"
32 struct g_lock_ctx {
33 struct db_context *db;
34 struct messaging_context *msg;
38 * The "g_lock.tdb" file contains records, indexed by the 0-terminated
39 * lockname. The record contains an array of "struct g_lock_rec"
40 * structures.
43 #define G_LOCK_REC_LENGTH (SERVER_ID_BUF_LENGTH+1)
45 static void g_lock_rec_put(uint8_t buf[G_LOCK_REC_LENGTH],
46 const struct g_lock_rec rec)
48 SCVAL(buf, 0, rec.lock_type);
49 server_id_put(buf+1, rec.pid);
52 static void g_lock_rec_get(struct g_lock_rec *rec,
53 const uint8_t buf[G_LOCK_REC_LENGTH])
55 rec->lock_type = CVAL(buf, 0);
56 server_id_get(&rec->pid, buf+1);
59 struct g_lock {
60 uint8_t *recsbuf;
61 size_t num_recs;
62 uint8_t *data;
63 size_t datalen;
66 static bool g_lock_parse(uint8_t *buf, size_t buflen, struct g_lock *lck)
68 size_t found_recs, data_ofs;
70 if (buflen < sizeof(uint32_t)) {
71 *lck = (struct g_lock) {0};
72 return true;
75 found_recs = IVAL(buf, 0);
77 buf += sizeof(uint32_t);
78 buflen -= sizeof(uint32_t);
79 if (found_recs > buflen/G_LOCK_REC_LENGTH) {
80 return false;
83 data_ofs = found_recs * G_LOCK_REC_LENGTH;
85 *lck = (struct g_lock) {
86 .recsbuf = buf, .num_recs = found_recs,
87 .data = buf+data_ofs, .datalen = buflen-data_ofs
90 return true;
93 static void g_lock_get_rec(struct g_lock *lck, size_t i,
94 struct g_lock_rec *rec)
96 if (i >= lck->num_recs) {
97 abort();
99 g_lock_rec_get(rec, lck->recsbuf + i*G_LOCK_REC_LENGTH);
102 static void g_lock_rec_del(struct g_lock *lck, size_t i)
104 if (i >= lck->num_recs) {
105 abort();
107 lck->num_recs -= 1;
108 if (i < lck->num_recs) {
109 uint8_t *recptr = lck->recsbuf + i*G_LOCK_REC_LENGTH;
110 memcpy(recptr, lck->recsbuf + lck->num_recs*G_LOCK_REC_LENGTH,
111 G_LOCK_REC_LENGTH);
115 static NTSTATUS g_lock_store(struct db_record *rec, struct g_lock *lck,
116 struct g_lock_rec *add)
118 uint8_t sizebuf[4];
119 uint8_t addbuf[G_LOCK_REC_LENGTH];
121 struct TDB_DATA dbufs[] = {
122 { .dptr = sizebuf, .dsize = sizeof(sizebuf) },
123 { .dptr = lck->recsbuf,
124 .dsize = lck->num_recs * G_LOCK_REC_LENGTH },
125 { 0 },
126 { .dptr = lck->data, .dsize = lck->datalen }
129 if (add != NULL) {
130 g_lock_rec_put(addbuf, *add);
132 dbufs[2] = (TDB_DATA) {
133 .dptr = addbuf, .dsize = G_LOCK_REC_LENGTH
136 lck->num_recs += 1;
139 SIVAL(sizebuf, 0, lck->num_recs);
141 return dbwrap_record_storev(rec, dbufs, ARRAY_SIZE(dbufs), 0);
144 struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx,
145 struct messaging_context *msg)
147 struct g_lock_ctx *result;
148 struct db_context *backend;
149 char *db_path;
151 result = talloc(mem_ctx, struct g_lock_ctx);
152 if (result == NULL) {
153 return NULL;
155 result->msg = msg;
157 db_path = lock_path(talloc_tos(), "g_lock.tdb");
158 if (db_path == NULL) {
159 TALLOC_FREE(result);
160 return NULL;
163 backend = db_open(result, db_path, 0,
164 TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
165 O_RDWR|O_CREAT, 0600,
166 DBWRAP_LOCK_ORDER_3,
167 DBWRAP_FLAG_NONE);
168 TALLOC_FREE(db_path);
169 if (backend == NULL) {
170 DBG_WARNING("Could not open g_lock.tdb\n");
171 TALLOC_FREE(result);
172 return NULL;
175 result->db = db_open_watched(result, &backend, msg);
176 if (result->db == NULL) {
177 DBG_WARNING("db_open_watched failed\n");
178 TALLOC_FREE(result);
179 return NULL;
181 return result;
184 static bool g_lock_conflicts(enum g_lock_type l1, enum g_lock_type l2)
187 * Only tested write locks so far. Very likely this routine
188 * needs to be fixed for read locks....
190 if ((l1 == G_LOCK_READ) && (l2 == G_LOCK_READ)) {
191 return false;
193 return true;
196 static NTSTATUS g_lock_trylock(struct db_record *rec, struct server_id self,
197 enum g_lock_type type,
198 struct server_id *blocker)
200 TDB_DATA data;
201 size_t i;
202 struct g_lock lck;
203 struct g_lock_rec mylock = {0};
204 NTSTATUS status;
205 bool modified = false;
206 bool ok;
208 data = dbwrap_record_get_value(rec);
210 ok = g_lock_parse(data.dptr, data.dsize, &lck);
211 if (!ok) {
212 return NT_STATUS_INTERNAL_DB_CORRUPTION;
215 if ((type == G_LOCK_READ) && (lck.num_recs > 0)) {
216 struct g_lock_rec check_rec;
219 * Read locks can stay around forever if the process
220 * dies. Do a heuristic check for process existence:
221 * Check one random process for existence. Hopefully
222 * this will keep runaway read locks under control.
224 i = generate_random() % lck.num_recs;
226 g_lock_get_rec(&lck, i, &check_rec);
228 if ((check_rec.lock_type == G_LOCK_READ) &&
229 !serverid_exists(&check_rec.pid)) {
230 g_lock_rec_del(&lck, i);
231 modified = true;
236 * For the lock upgrade/downgrade case, remove ourselves from
237 * the list. We re-add ourselves later after we checked the
238 * other entries for conflict.
241 for (i=0; i<lck.num_recs; i++) {
242 struct g_lock_rec lock;
244 g_lock_get_rec(&lck, i, &lock);
246 if (serverid_equal(&self, &lock.pid)) {
247 if (lock.lock_type == type) {
248 status = NT_STATUS_WAS_LOCKED;
249 goto done;
252 mylock = lock;
253 g_lock_rec_del(&lck, i);
254 modified = true;
255 break;
260 * Check for conflicts with everybody else. Not a for-loop
261 * because we remove stale entries in the meantime,
262 * decrementing lck.num_recs.
265 i = 0;
267 while (i < lck.num_recs) {
268 struct g_lock_rec lock;
270 g_lock_get_rec(&lck, i, &lock);
272 if (g_lock_conflicts(type, lock.lock_type)) {
273 struct server_id pid = lock.pid;
276 * As the serverid_exists might recurse into
277 * the g_lock code, we use
278 * SERVERID_UNIQUE_ID_NOT_TO_VERIFY to avoid the loop
280 pid.unique_id = SERVERID_UNIQUE_ID_NOT_TO_VERIFY;
282 if (serverid_exists(&pid)) {
283 status = NT_STATUS_LOCK_NOT_GRANTED;
284 *blocker = lock.pid;
285 goto done;
289 * Delete stale conflicting entry
291 g_lock_rec_del(&lck, i);
292 modified = true;
293 continue;
295 i++;
298 modified = true;
300 mylock = (struct g_lock_rec) {
301 .pid = self,
302 .lock_type = type
305 status = NT_STATUS_OK;
306 done:
307 if (modified) {
308 NTSTATUS store_status;
311 * (Re-)add ourselves if needed via non-NULL
312 * g_lock_store argument
315 store_status = g_lock_store(
316 rec,
317 &lck,
318 mylock.pid.pid != 0 ? &mylock : NULL);
320 if (!NT_STATUS_IS_OK(store_status)) {
321 DBG_WARNING("g_lock_record_store failed: %s\n",
322 nt_errstr(store_status));
323 status = store_status;
326 return status;
329 struct g_lock_lock_state {
330 struct tevent_context *ev;
331 struct g_lock_ctx *ctx;
332 TDB_DATA key;
333 enum g_lock_type type;
336 static void g_lock_lock_retry(struct tevent_req *subreq);
338 struct g_lock_lock_fn_state {
339 struct g_lock_lock_state *state;
340 struct server_id self;
342 struct tevent_req *watch_req;
343 NTSTATUS status;
346 static void g_lock_lock_fn(struct db_record *rec, void *private_data)
348 struct g_lock_lock_fn_state *state = private_data;
349 struct server_id blocker;
351 state->status = g_lock_trylock(rec, state->self, state->state->type,
352 &blocker);
353 if (!NT_STATUS_EQUAL(state->status, NT_STATUS_LOCK_NOT_GRANTED)) {
354 return;
357 state->watch_req = dbwrap_watched_watch_send(
358 state->state, state->state->ev, rec, blocker);
361 struct tevent_req *g_lock_lock_send(TALLOC_CTX *mem_ctx,
362 struct tevent_context *ev,
363 struct g_lock_ctx *ctx,
364 TDB_DATA key,
365 enum g_lock_type type)
367 struct tevent_req *req;
368 struct g_lock_lock_state *state;
369 struct g_lock_lock_fn_state fn_state;
370 NTSTATUS status;
372 req = tevent_req_create(mem_ctx, &state, struct g_lock_lock_state);
373 if (req == NULL) {
374 return NULL;
376 state->ev = ev;
377 state->ctx = ctx;
378 state->key = key;
379 state->type = type;
381 fn_state = (struct g_lock_lock_fn_state) {
382 .state = state, .self = messaging_server_id(ctx->msg)
385 status = dbwrap_do_locked(ctx->db, key, g_lock_lock_fn, &fn_state);
386 if (tevent_req_nterror(req, status)) {
387 DBG_DEBUG("dbwrap_do_locked failed: %s\n",
388 nt_errstr(status));
389 return tevent_req_post(req, ev);
392 if (NT_STATUS_IS_OK(fn_state.status)) {
393 tevent_req_done(req);
394 return tevent_req_post(req, ev);
396 if (!NT_STATUS_EQUAL(fn_state.status, NT_STATUS_LOCK_NOT_GRANTED)) {
397 tevent_req_nterror(req, fn_state.status);
398 return tevent_req_post(req, ev);
401 if (tevent_req_nomem(fn_state.watch_req, req)) {
402 return tevent_req_post(req, ev);
405 if (!tevent_req_set_endtime(
406 fn_state.watch_req, state->ev,
407 timeval_current_ofs(5 + sys_random() % 5, 0))) {
408 return tevent_req_post(req, ev);
410 tevent_req_set_callback(fn_state.watch_req, g_lock_lock_retry, req);
411 return req;
414 static void g_lock_lock_retry(struct tevent_req *subreq)
416 struct tevent_req *req = tevent_req_callback_data(
417 subreq, struct tevent_req);
418 struct g_lock_lock_state *state = tevent_req_data(
419 req, struct g_lock_lock_state);
420 struct g_lock_lock_fn_state fn_state;
421 NTSTATUS status;
423 status = dbwrap_watched_watch_recv(subreq, NULL, NULL);
424 DBG_DEBUG("watch_recv returned %s\n", nt_errstr(status));
425 TALLOC_FREE(subreq);
427 if (!NT_STATUS_IS_OK(status) &&
428 !NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
429 tevent_req_nterror(req, status);
430 return;
433 fn_state = (struct g_lock_lock_fn_state) {
434 .state = state, .self = messaging_server_id(state->ctx->msg)
437 status = dbwrap_do_locked(state->ctx->db, state->key,
438 g_lock_lock_fn, &fn_state);
439 if (tevent_req_nterror(req, status)) {
440 DBG_DEBUG("dbwrap_do_locked failed: %s\n",
441 nt_errstr(status));
442 return;
445 if (NT_STATUS_IS_OK(fn_state.status)) {
446 tevent_req_done(req);
447 return;
449 if (!NT_STATUS_EQUAL(fn_state.status, NT_STATUS_LOCK_NOT_GRANTED)) {
450 tevent_req_nterror(req, fn_state.status);
451 return;
454 if (tevent_req_nomem(fn_state.watch_req, req)) {
455 return;
458 if (!tevent_req_set_endtime(
459 fn_state.watch_req, state->ev,
460 timeval_current_ofs(5 + sys_random() % 5, 0))) {
461 return;
463 tevent_req_set_callback(fn_state.watch_req, g_lock_lock_retry, req);
466 NTSTATUS g_lock_lock_recv(struct tevent_req *req)
468 return tevent_req_simple_recv_ntstatus(req);
471 NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, TDB_DATA key,
472 enum g_lock_type type, struct timeval timeout)
474 TALLOC_CTX *frame = talloc_stackframe();
475 struct tevent_context *ev;
476 struct tevent_req *req;
477 struct timeval end;
478 NTSTATUS status = NT_STATUS_NO_MEMORY;
480 ev = samba_tevent_context_init(frame);
481 if (ev == NULL) {
482 goto fail;
484 req = g_lock_lock_send(frame, ev, ctx, key, type);
485 if (req == NULL) {
486 goto fail;
488 end = timeval_current_ofs(timeout.tv_sec, timeout.tv_usec);
489 if (!tevent_req_set_endtime(req, ev, end)) {
490 goto fail;
492 if (!tevent_req_poll_ntstatus(req, ev, &status)) {
493 goto fail;
495 status = g_lock_lock_recv(req);
496 fail:
497 TALLOC_FREE(frame);
498 return status;
501 struct g_lock_unlock_state {
502 TDB_DATA key;
503 struct server_id self;
504 NTSTATUS status;
507 static void g_lock_unlock_fn(struct db_record *rec,
508 void *private_data)
510 struct g_lock_unlock_state *state = private_data;
511 TDB_DATA value;
512 struct g_lock lck;
513 size_t i;
514 bool ok;
516 value = dbwrap_record_get_value(rec);
518 ok = g_lock_parse(value.dptr, value.dsize, &lck);
519 if (!ok) {
520 DBG_DEBUG("g_lock_get for %s failed\n",
521 hex_encode_talloc(talloc_tos(),
522 state->key.dptr,
523 state->key.dsize));
524 state->status = NT_STATUS_FILE_INVALID;
525 return;
527 for (i=0; i<lck.num_recs; i++) {
528 struct g_lock_rec lockrec;
529 g_lock_get_rec(&lck, i, &lockrec);
530 if (serverid_equal(&state->self, &lockrec.pid)) {
531 break;
534 if (i == lck.num_recs) {
535 DBG_DEBUG("Lock not found, num_rec=%zu\n", lck.num_recs);
536 state->status = NT_STATUS_NOT_FOUND;
537 return;
540 g_lock_rec_del(&lck, i);
542 if ((lck.num_recs == 0) && (lck.datalen == 0)) {
543 state->status = dbwrap_record_delete(rec);
544 return;
546 state->status = g_lock_store(rec, &lck, NULL);
549 NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, TDB_DATA key)
551 struct g_lock_unlock_state state = {
552 .self = messaging_server_id(ctx->msg), .key = key
554 NTSTATUS status;
556 status = dbwrap_do_locked(ctx->db, key, g_lock_unlock_fn, &state);
557 if (!NT_STATUS_IS_OK(status)) {
558 DBG_WARNING("dbwrap_do_locked failed: %s\n",
559 nt_errstr(status));
560 return status;
562 if (!NT_STATUS_IS_OK(state.status)) {
563 DBG_WARNING("g_lock_unlock_fn failed: %s\n",
564 nt_errstr(state.status));
565 return state.status;
568 return NT_STATUS_OK;
571 struct g_lock_write_data_state {
572 TDB_DATA key;
573 struct server_id self;
574 const uint8_t *data;
575 size_t datalen;
576 NTSTATUS status;
579 static void g_lock_write_data_fn(struct db_record *rec,
580 void *private_data)
582 struct g_lock_write_data_state *state = private_data;
583 TDB_DATA value;
584 struct g_lock lck;
585 size_t i;
586 bool ok;
588 value = dbwrap_record_get_value(rec);
590 ok = g_lock_parse(value.dptr, value.dsize, &lck);
591 if (!ok) {
592 DBG_DEBUG("g_lock_parse for %s failed\n",
593 hex_encode_talloc(talloc_tos(),
594 state->key.dptr,
595 state->key.dsize));
596 state->status = NT_STATUS_INTERNAL_DB_CORRUPTION;
597 return;
599 for (i=0; i<lck.num_recs; i++) {
600 struct g_lock_rec lockrec;
601 g_lock_get_rec(&lck, i, &lockrec);
602 if ((lockrec.lock_type == G_LOCK_WRITE) &&
603 serverid_equal(&state->self, &lockrec.pid)) {
604 break;
607 if (i == lck.num_recs) {
608 DBG_DEBUG("Not locked by us\n");
609 state->status = NT_STATUS_NOT_LOCKED;
610 return;
613 lck.data = discard_const_p(uint8_t, state->data);
614 lck.datalen = state->datalen;
615 state->status = g_lock_store(rec, &lck, NULL);
618 NTSTATUS g_lock_write_data(struct g_lock_ctx *ctx, TDB_DATA key,
619 const uint8_t *buf, size_t buflen)
621 struct g_lock_write_data_state state = {
622 .key = key, .self = messaging_server_id(ctx->msg),
623 .data = buf, .datalen = buflen
625 NTSTATUS status;
627 status = dbwrap_do_locked(ctx->db, key,
628 g_lock_write_data_fn, &state);
629 if (!NT_STATUS_IS_OK(status)) {
630 DBG_WARNING("dbwrap_do_locked failed: %s\n",
631 nt_errstr(status));
632 return status;
634 if (!NT_STATUS_IS_OK(state.status)) {
635 DBG_WARNING("g_lock_write_data_fn failed: %s\n",
636 nt_errstr(state.status));
637 return state.status;
640 return NT_STATUS_OK;
643 struct g_lock_locks_state {
644 int (*fn)(TDB_DATA key, void *private_data);
645 void *private_data;
648 static int g_lock_locks_fn(struct db_record *rec, void *priv)
650 TDB_DATA key;
651 struct g_lock_locks_state *state = (struct g_lock_locks_state *)priv;
653 key = dbwrap_record_get_key(rec);
654 return state->fn(key, state->private_data);
657 int g_lock_locks(struct g_lock_ctx *ctx,
658 int (*fn)(TDB_DATA key, void *private_data),
659 void *private_data)
661 struct g_lock_locks_state state;
662 NTSTATUS status;
663 int count;
665 state.fn = fn;
666 state.private_data = private_data;
668 status = dbwrap_traverse_read(ctx->db, g_lock_locks_fn, &state, &count);
669 if (!NT_STATUS_IS_OK(status)) {
670 return -1;
672 return count;
675 struct g_lock_dump_state {
676 TALLOC_CTX *mem_ctx;
677 TDB_DATA key;
678 void (*fn)(const struct g_lock_rec *locks,
679 size_t num_locks,
680 const uint8_t *data,
681 size_t datalen,
682 void *private_data);
683 void *private_data;
684 NTSTATUS status;
687 static void g_lock_dump_fn(TDB_DATA key, TDB_DATA data,
688 void *private_data)
690 struct g_lock_dump_state *state = private_data;
691 struct g_lock_rec *recs;
692 struct g_lock lck;
693 size_t i;
694 bool ok;
696 ok = g_lock_parse(data.dptr, data.dsize, &lck);
697 if (!ok) {
698 DBG_DEBUG("g_lock_parse failed for %s\n",
699 hex_encode_talloc(talloc_tos(),
700 state->key.dptr,
701 state->key.dsize));
702 state->status = NT_STATUS_INTERNAL_DB_CORRUPTION;
703 return;
706 recs = talloc_array(state->mem_ctx, struct g_lock_rec, lck.num_recs);
707 if (recs == NULL) {
708 DBG_DEBUG("talloc failed\n");
709 state->status = NT_STATUS_NO_MEMORY;
710 return;
713 for (i=0; i<lck.num_recs; i++) {
714 g_lock_get_rec(&lck, i, &recs[i]);
717 state->fn(recs, lck.num_recs, lck.data, lck.datalen,
718 state->private_data);
720 TALLOC_FREE(recs);
722 state->status = NT_STATUS_OK;
725 NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, TDB_DATA key,
726 void (*fn)(const struct g_lock_rec *locks,
727 size_t num_locks,
728 const uint8_t *data,
729 size_t datalen,
730 void *private_data),
731 void *private_data)
733 struct g_lock_dump_state state = {
734 .mem_ctx = ctx, .key = key,
735 .fn = fn, .private_data = private_data
737 NTSTATUS status;
739 status = dbwrap_parse_record(ctx->db, key, g_lock_dump_fn, &state);
740 if (!NT_STATUS_IS_OK(status)) {
741 DBG_DEBUG("dbwrap_parse_record returned %s\n",
742 nt_errstr(status));
743 return status;
745 if (!NT_STATUS_IS_OK(state.status)) {
746 DBG_DEBUG("g_lock_dump_fn returned %s\n",
747 nt_errstr(state.status));
748 return state.status;
750 return NT_STATUS_OK;
753 static bool g_lock_init_all(TALLOC_CTX *mem_ctx,
754 struct tevent_context **pev,
755 struct messaging_context **pmsg,
756 struct g_lock_ctx **pg_ctx)
758 struct tevent_context *ev = NULL;
759 struct messaging_context *msg = NULL;
760 struct g_lock_ctx *g_ctx = NULL;
762 ev = samba_tevent_context_init(mem_ctx);
763 if (ev == NULL) {
764 d_fprintf(stderr, "ERROR: could not init event context\n");
765 goto fail;
767 msg = messaging_init(mem_ctx, ev);
768 if (msg == NULL) {
769 d_fprintf(stderr, "ERROR: could not init messaging context\n");
770 goto fail;
772 g_ctx = g_lock_ctx_init(mem_ctx, msg);
773 if (g_ctx == NULL) {
774 d_fprintf(stderr, "ERROR: could not init g_lock context\n");
775 goto fail;
778 *pev = ev;
779 *pmsg = msg;
780 *pg_ctx = g_ctx;
781 return true;
782 fail:
783 TALLOC_FREE(g_ctx);
784 TALLOC_FREE(msg);
785 TALLOC_FREE(ev);
786 return false;
789 NTSTATUS g_lock_do(TDB_DATA key, enum g_lock_type lock_type,
790 struct timeval timeout,
791 void (*fn)(void *private_data), void *private_data)
793 struct tevent_context *ev = NULL;
794 struct messaging_context *msg = NULL;
795 struct g_lock_ctx *g_ctx = NULL;
796 NTSTATUS status;
798 if (!g_lock_init_all(talloc_tos(), &ev, &msg, &g_ctx)) {
799 status = NT_STATUS_ACCESS_DENIED;
800 goto done;
803 status = g_lock_lock(g_ctx, key, lock_type, timeout);
804 if (!NT_STATUS_IS_OK(status)) {
805 goto done;
807 fn(private_data);
808 g_lock_unlock(g_ctx, key);
810 done:
811 TALLOC_FREE(g_ctx);
812 TALLOC_FREE(msg);
813 TALLOC_FREE(ev);
814 return status;