tests/krb5: Clarify checksum type assertion message
[Samba.git] / source3 / smbd / smbXsrv_client.c
blobe0658d87969ae12cc70cdc2e3cfe49809d6c320f
1 /*
2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan Metzmacher 2014
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 <tevent.h>
23 #include "lib/util/server_id.h"
24 #include "smbd/smbd.h"
25 #include "smbd/globals.h"
26 #include "dbwrap/dbwrap.h"
27 #include "dbwrap/dbwrap_rbt.h"
28 #include "dbwrap/dbwrap_open.h"
29 #include "dbwrap/dbwrap_watch.h"
30 #include "session.h"
31 #include "auth.h"
32 #include "auth/gensec/gensec.h"
33 #include "../lib/tsocket/tsocket.h"
34 #include "../libcli/security/security.h"
35 #include "messages.h"
36 #include "lib/util/util_tdb.h"
37 #include "librpc/gen_ndr/ndr_smbXsrv.h"
38 #include "serverid.h"
39 #include "lib/util/tevent_ntstatus.h"
40 #include "lib/util/iov_buf.h"
42 struct smbXsrv_client_table {
43 struct {
44 uint32_t max_clients;
45 uint32_t num_clients;
46 } local;
47 struct {
48 struct db_context *db_ctx;
49 } global;
52 static struct db_context *smbXsrv_client_global_db_ctx = NULL;
54 NTSTATUS smbXsrv_client_global_init(void)
56 const char *global_path = NULL;
57 struct db_context *db_ctx = NULL;
59 if (smbXsrv_client_global_db_ctx != NULL) {
60 return NT_STATUS_OK;
64 * This contains secret information like client keys!
66 global_path = lock_path(talloc_tos(), "smbXsrv_client_global.tdb");
67 if (global_path == NULL) {
68 return NT_STATUS_NO_MEMORY;
71 db_ctx = db_open(NULL, global_path,
72 0, /* hash_size */
73 TDB_DEFAULT |
74 TDB_CLEAR_IF_FIRST |
75 TDB_INCOMPATIBLE_HASH,
76 O_RDWR | O_CREAT, 0600,
77 DBWRAP_LOCK_ORDER_1,
78 DBWRAP_FLAG_NONE);
79 if (db_ctx == NULL) {
80 NTSTATUS status;
82 status = map_nt_error_from_unix_common(errno);
84 return status;
87 smbXsrv_client_global_db_ctx = db_ctx;
89 return NT_STATUS_OK;
93 * NOTE:
94 * We need to store the keys in big endian so that dbwrap_rbt's memcmp
95 * has the same result as integer comparison between the uint32_t
96 * values.
98 * TODO: implement string based key
101 #define SMBXSRV_CLIENT_GLOBAL_TDB_KEY_SIZE 16
103 static TDB_DATA smbXsrv_client_global_id_to_key(const struct GUID *client_guid,
104 uint8_t *key_buf)
106 TDB_DATA key = { .dsize = 0, };
107 NTSTATUS status;
108 DATA_BLOB b;
110 status = GUID_to_ndr_blob(client_guid, talloc_tos(), &b);
111 if (!NT_STATUS_IS_OK(status)) {
112 return key;
114 memcpy(key_buf, b.data, SMBXSRV_CLIENT_GLOBAL_TDB_KEY_SIZE);
115 data_blob_free(&b);
117 key = make_tdb_data(key_buf, SMBXSRV_CLIENT_GLOBAL_TDB_KEY_SIZE);
119 return key;
122 static struct db_record *smbXsrv_client_global_fetch_locked(
123 struct db_context *db,
124 const struct GUID *client_guid,
125 TALLOC_CTX *mem_ctx)
127 TDB_DATA key;
128 uint8_t key_buf[SMBXSRV_CLIENT_GLOBAL_TDB_KEY_SIZE];
129 struct db_record *rec = NULL;
131 key = smbXsrv_client_global_id_to_key(client_guid, key_buf);
133 rec = dbwrap_fetch_locked(db, mem_ctx, key);
135 if (rec == NULL) {
136 struct GUID_txt_buf buf;
137 DBG_DEBUG("Failed to lock guid [%s], key '%s'\n",
138 GUID_buf_string(client_guid, &buf),
139 hex_encode_talloc(talloc_tos(), key.dptr, key.dsize));
142 return rec;
145 static NTSTATUS smbXsrv_client_table_create(TALLOC_CTX *mem_ctx,
146 struct messaging_context *msg_ctx,
147 uint32_t max_clients,
148 struct smbXsrv_client_table **_table)
150 struct smbXsrv_client_table *table;
151 NTSTATUS status;
153 if (max_clients > 1) {
154 return NT_STATUS_INTERNAL_ERROR;
157 table = talloc_zero(mem_ctx, struct smbXsrv_client_table);
158 if (table == NULL) {
159 return NT_STATUS_NO_MEMORY;
162 table->local.max_clients = max_clients;
164 status = smbXsrv_client_global_init();
165 if (!NT_STATUS_IS_OK(status)) {
166 TALLOC_FREE(table);
167 return status;
170 table->global.db_ctx = smbXsrv_client_global_db_ctx;
172 *_table = table;
173 return NT_STATUS_OK;
176 static int smbXsrv_client_global_destructor(struct smbXsrv_client_global0 *global)
178 return 0;
181 static void smbXsrv_client_global_verify_record(struct db_record *db_rec,
182 bool *is_free,
183 bool *was_free,
184 TALLOC_CTX *mem_ctx,
185 struct smbXsrv_client_global0 **_g)
187 TDB_DATA key;
188 TDB_DATA val;
189 DATA_BLOB blob;
190 struct smbXsrv_client_globalB global_blob;
191 enum ndr_err_code ndr_err;
192 struct smbXsrv_client_global0 *global = NULL;
193 bool exists;
194 TALLOC_CTX *frame = talloc_stackframe();
196 *is_free = false;
198 if (was_free) {
199 *was_free = false;
201 if (_g) {
202 *_g = NULL;
205 key = dbwrap_record_get_key(db_rec);
207 val = dbwrap_record_get_value(db_rec);
208 if (val.dsize == 0) {
209 TALLOC_FREE(frame);
210 *is_free = true;
211 if (was_free) {
212 *was_free = true;
214 return;
217 blob = data_blob_const(val.dptr, val.dsize);
219 ndr_err = ndr_pull_struct_blob(&blob, frame, &global_blob,
220 (ndr_pull_flags_fn_t)ndr_pull_smbXsrv_client_globalB);
221 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
222 NTSTATUS status = ndr_map_error2ntstatus(ndr_err);
223 DBG_WARNING("smbXsrv_client_global_verify_record: "
224 "key '%s' ndr_pull_struct_blob - %s\n",
225 hex_encode_talloc(frame, key.dptr, key.dsize),
226 nt_errstr(status));
227 TALLOC_FREE(frame);
228 return;
231 DBG_DEBUG("client_global:\n");
232 if (DEBUGLVL(DBGLVL_DEBUG)) {
233 NDR_PRINT_DEBUG(smbXsrv_client_globalB, &global_blob);
236 if (global_blob.version != SMBXSRV_VERSION_0) {
237 DBG_ERR("key '%s' use unsupported version %u\n",
238 hex_encode_talloc(frame, key.dptr, key.dsize),
239 global_blob.version);
240 NDR_PRINT_DEBUG(smbXsrv_client_globalB, &global_blob);
241 TALLOC_FREE(frame);
242 return;
245 global = global_blob.info.info0;
247 exists = serverid_exists(&global->server_id);
248 if (!exists) {
249 struct server_id_buf tmp;
251 DBG_NOTICE("key '%s' server_id %s does not exist.\n",
252 hex_encode_talloc(frame, key.dptr, key.dsize),
253 server_id_str_buf(global->server_id, &tmp));
254 if (DEBUGLVL(DBGLVL_NOTICE)) {
255 NDR_PRINT_DEBUG(smbXsrv_client_globalB, &global_blob);
257 TALLOC_FREE(frame);
258 dbwrap_record_delete(db_rec);
259 *is_free = true;
260 return;
263 if (_g) {
264 *_g = talloc_move(mem_ctx, &global);
266 TALLOC_FREE(frame);
269 NTSTATUS smb2srv_client_lookup_global(struct smbXsrv_client *client,
270 struct GUID client_guid,
271 TALLOC_CTX *mem_ctx,
272 struct smbXsrv_client_global0 **_global)
274 struct smbXsrv_client_table *table = client->table;
275 struct smbXsrv_client_global0 *global = NULL;
276 bool is_free = false;
277 struct db_record *db_rec;
279 db_rec = smbXsrv_client_global_fetch_locked(table->global.db_ctx,
280 &client_guid,
281 talloc_tos());
282 if (db_rec == NULL) {
283 return NT_STATUS_INTERNAL_DB_ERROR;
286 smbXsrv_client_global_verify_record(db_rec,
287 &is_free,
288 NULL,
289 mem_ctx,
290 &global);
291 TALLOC_FREE(db_rec);
293 if (is_free) {
294 return NT_STATUS_OBJECTID_NOT_FOUND;
297 if (global == NULL) {
299 * most likely ndr_pull_struct_blob() failed
301 return NT_STATUS_INTERNAL_DB_CORRUPTION;
304 *_global = global;
305 return NT_STATUS_OK;
308 NTSTATUS smb2srv_client_connection_pass(struct smbd_smb2_request *smb2req,
309 struct smbXsrv_client_global0 *global)
311 DATA_BLOB blob;
312 enum ndr_err_code ndr_err;
313 NTSTATUS status;
314 struct smbXsrv_connection_pass0 pass_info0;
315 struct smbXsrv_connection_passB pass_blob;
316 ssize_t reqlen;
317 struct iovec iov;
319 pass_info0.initial_connect_time = global->initial_connect_time;
320 pass_info0.client_guid = global->client_guid;
322 reqlen = iov_buflen(smb2req->in.vector, smb2req->in.vector_count);
323 if (reqlen == -1) {
324 return NT_STATUS_INVALID_BUFFER_SIZE;
327 pass_info0.negotiate_request.length = reqlen;
328 pass_info0.negotiate_request.data = talloc_array(talloc_tos(), uint8_t,
329 reqlen);
330 if (pass_info0.negotiate_request.data == NULL) {
331 return NT_STATUS_NO_MEMORY;
333 iov_buf(smb2req->in.vector, smb2req->in.vector_count,
334 pass_info0.negotiate_request.data,
335 pass_info0.negotiate_request.length);
337 ZERO_STRUCT(pass_blob);
338 pass_blob.version = smbXsrv_version_global_current();
339 pass_blob.info.info0 = &pass_info0;
341 if (DEBUGLVL(DBGLVL_DEBUG)) {
342 NDR_PRINT_DEBUG(smbXsrv_connection_passB, &pass_blob);
345 ndr_err = ndr_push_struct_blob(&blob, talloc_tos(), &pass_blob,
346 (ndr_push_flags_fn_t)ndr_push_smbXsrv_connection_passB);
347 data_blob_free(&pass_info0.negotiate_request);
348 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
349 status = ndr_map_error2ntstatus(ndr_err);
350 return status;
353 iov.iov_base = blob.data;
354 iov.iov_len = blob.length;
356 status = messaging_send_iov(smb2req->xconn->client->msg_ctx,
357 global->server_id,
358 MSG_SMBXSRV_CONNECTION_PASS,
359 &iov, 1,
360 &smb2req->xconn->transport.sock, 1);
361 data_blob_free(&blob);
362 if (!NT_STATUS_IS_OK(status)) {
363 return status;
366 return NT_STATUS_OK;
369 static NTSTATUS smbXsrv_client_global_store(struct smbXsrv_client_global0 *global)
371 struct smbXsrv_client_globalB global_blob;
372 DATA_BLOB blob = data_blob_null;
373 TDB_DATA key;
374 TDB_DATA val;
375 NTSTATUS status;
376 enum ndr_err_code ndr_err;
377 bool saved_stored = global->stored;
380 * TODO: if we use other versions than '0'
381 * we would add glue code here, that would be able to
382 * store the information in the old format.
385 SMB_ASSERT(global->local_address != NULL);
386 SMB_ASSERT(global->remote_address != NULL);
387 SMB_ASSERT(global->remote_name != NULL);
389 if (global->db_rec == NULL) {
390 return NT_STATUS_INTERNAL_ERROR;
393 key = dbwrap_record_get_key(global->db_rec);
394 val = dbwrap_record_get_value(global->db_rec);
396 ZERO_STRUCT(global_blob);
397 global_blob.version = smbXsrv_version_global_current();
398 if (val.dsize >= 8) {
399 global_blob.seqnum = IVAL(val.dptr, 4);
401 global_blob.seqnum += 1;
402 global_blob.info.info0 = global;
404 global->stored = true;
405 ndr_err = ndr_push_struct_blob(&blob, global->db_rec, &global_blob,
406 (ndr_push_flags_fn_t)ndr_push_smbXsrv_client_globalB);
407 global->stored = saved_stored;
408 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
409 status = ndr_map_error2ntstatus(ndr_err);
410 DBG_WARNING("key '%s' ndr_push - %s\n",
411 hex_encode_talloc(global->db_rec, key.dptr, key.dsize),
412 nt_errstr(status));
413 TALLOC_FREE(global->db_rec);
414 return status;
417 val = make_tdb_data(blob.data, blob.length);
418 status = dbwrap_record_store(global->db_rec, val, TDB_REPLACE);
419 if (!NT_STATUS_IS_OK(status)) {
420 DBG_WARNING("key '%s' store - %s\n",
421 hex_encode_talloc(global->db_rec, key.dptr, key.dsize),
422 nt_errstr(status));
423 TALLOC_FREE(global->db_rec);
424 return status;
427 global->stored = true;
429 if (DEBUGLVL(DBGLVL_DEBUG)) {
430 DBG_DEBUG("key '%s' stored\n",
431 hex_encode_talloc(global->db_rec, key.dptr, key.dsize));
432 NDR_PRINT_DEBUG(smbXsrv_client_globalB, &global_blob);
435 TALLOC_FREE(global->db_rec);
437 return NT_STATUS_OK;
440 static NTSTATUS smbXsrv_client_global_remove(struct smbXsrv_client_global0 *global)
442 TDB_DATA key;
443 NTSTATUS status;
446 * TODO: if we use other versions than '0'
447 * we would add glue code here, that would be able to
448 * store the information in the old format.
451 if (global->db_rec == NULL) {
452 return NT_STATUS_INTERNAL_ERROR;
455 key = dbwrap_record_get_key(global->db_rec);
457 status = dbwrap_record_delete(global->db_rec);
458 if (!NT_STATUS_IS_OK(status)) {
459 DBG_WARNING("key '%s' delete - %s\n",
460 hex_encode_talloc(global->db_rec, key.dptr, key.dsize),
461 nt_errstr(status));
462 TALLOC_FREE(global->db_rec);
463 return status;
465 global->stored = false;
466 DBG_DEBUG("key '%s' delete\n",
467 hex_encode_talloc(global->db_rec, key.dptr, key.dsize));
469 TALLOC_FREE(global->db_rec);
471 return NT_STATUS_OK;
474 static int smbXsrv_client_destructor(struct smbXsrv_client *client)
476 NTSTATUS status;
478 status = smbXsrv_client_remove(client);
479 if (!NT_STATUS_IS_OK(status)) {
480 DBG_ERR("smbXsrv_client_remove() failed: %s\n",
481 nt_errstr(status));
484 TALLOC_FREE(client->global);
486 return 0;
489 static bool smbXsrv_client_connection_pass_filter(struct messaging_rec *rec, void *private_data);
490 static void smbXsrv_client_connection_pass_loop(struct tevent_req *subreq);
492 NTSTATUS smbXsrv_client_create(TALLOC_CTX *mem_ctx,
493 struct tevent_context *ev_ctx,
494 struct messaging_context *msg_ctx,
495 NTTIME now,
496 struct smbXsrv_client **_client)
498 struct smbXsrv_client_table *table;
499 struct smbXsrv_client *client = NULL;
500 struct smbXsrv_client_global0 *global = NULL;
501 NTSTATUS status;
502 struct tevent_req *subreq = NULL;
504 status = smbXsrv_client_table_create(mem_ctx,
505 msg_ctx,
506 1, /* max_clients */
507 &table);
508 if (!NT_STATUS_IS_OK(status)) {
509 return status;
512 if (table->local.num_clients >= table->local.max_clients) {
513 TALLOC_FREE(table);
514 return NT_STATUS_INSUFFICIENT_RESOURCES;
517 client = talloc_zero(mem_ctx, struct smbXsrv_client);
518 if (client == NULL) {
519 TALLOC_FREE(table);
520 return NT_STATUS_NO_MEMORY;
522 client->raw_ev_ctx = ev_ctx;
523 client->msg_ctx = msg_ctx;
525 client->server_multi_channel_enabled =
526 smbXsrv_server_multi_channel_enabled();
527 if (client->server_multi_channel_enabled) {
528 client->next_channel_id = 1;
530 client->table = talloc_move(client, &table);
531 table = client->table;
533 global = talloc_zero(client, struct smbXsrv_client_global0);
534 if (global == NULL) {
535 TALLOC_FREE(client);
536 return NT_STATUS_NO_MEMORY;
538 talloc_set_destructor(global, smbXsrv_client_global_destructor);
539 client->global = global;
541 global->initial_connect_time = now;
543 global->server_id = messaging_server_id(client->msg_ctx);
545 table->local.num_clients += 1;
547 talloc_set_destructor(client, smbXsrv_client_destructor);
549 if (DEBUGLVL(DBGLVL_DEBUG)) {
550 struct smbXsrv_clientB client_blob = {
551 .version = SMBXSRV_VERSION_0,
552 .info.info0 = client,
554 struct GUID_txt_buf buf;
556 DBG_DEBUG("client_guid[%s] created\n",
557 GUID_buf_string(&global->client_guid, &buf));
558 NDR_PRINT_DEBUG(smbXsrv_clientB, &client_blob);
561 subreq = messaging_filtered_read_send(client,
562 client->raw_ev_ctx,
563 client->msg_ctx,
564 smbXsrv_client_connection_pass_filter,
565 client);
566 if (subreq == NULL) {
567 TALLOC_FREE(client);
568 return NT_STATUS_NO_MEMORY;
570 tevent_req_set_callback(subreq, smbXsrv_client_connection_pass_loop, client);
572 *_client = client;
573 return NT_STATUS_OK;
576 static bool smbXsrv_client_connection_pass_filter(struct messaging_rec *rec, void *private_data)
578 if (rec->msg_type != MSG_SMBXSRV_CONNECTION_PASS) {
579 return false;
582 if (rec->num_fds != 1) {
583 return false;
586 if (rec->buf.length < SMB2_HDR_BODY) {
587 return false;
590 /* TODO: verify client_guid...? */
592 return true;
595 static void smbXsrv_client_connection_pass_loop(struct tevent_req *subreq)
597 struct smbXsrv_client *client =
598 tevent_req_callback_data(subreq,
599 struct smbXsrv_client);
600 struct smbXsrv_connection *xconn = NULL;
601 int ret;
602 struct messaging_rec *rec = NULL;
603 struct smbXsrv_connection_passB pass_blob;
604 enum ndr_err_code ndr_err;
605 struct smbXsrv_connection_pass0 *pass_info0 = NULL;
606 NTSTATUS status;
607 int sock_fd = -1;
608 uint64_t seq_low;
610 ret = messaging_filtered_read_recv(subreq, talloc_tos(), &rec);
611 TALLOC_FREE(subreq);
612 if (ret != 0) {
613 goto next;
616 if (rec->num_fds != 1) {
617 DBG_ERR("MSG_SMBXSRV_CONNECTION_PASS: num_fds[%u]\n",
618 rec->num_fds);
619 goto next;
622 sock_fd = rec->fds[0];
623 DBG_DEBUG("MSG_SMBXSRV_CONNECTION_PASS: got sock_fd[%d]\n", sock_fd);
625 ndr_err = ndr_pull_struct_blob(&rec->buf, rec, &pass_blob,
626 (ndr_pull_flags_fn_t)ndr_pull_smbXsrv_connection_passB);
627 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
628 status = ndr_map_error2ntstatus(ndr_err);
629 DBG_WARNING("ndr_pull_struct_blob - %s\n", nt_errstr(status));
630 goto next;
633 if (DEBUGLVL(DBGLVL_DEBUG)) {
634 NDR_PRINT_DEBUG(smbXsrv_connection_passB, &pass_blob);
637 if (pass_blob.version != SMBXSRV_VERSION_0) {
638 DBG_ERR("ignore invalid version %u\n", pass_blob.version);
639 NDR_PRINT_DEBUG(smbXsrv_connection_passB, &pass_blob);
640 goto next;
643 pass_info0 = pass_blob.info.info0;
644 if (pass_info0 == NULL) {
645 DBG_ERR("ignore NULL info %u\n", pass_blob.version);
646 NDR_PRINT_DEBUG(smbXsrv_connection_passB, &pass_blob);
647 goto next;
650 if (!GUID_equal(&client->global->client_guid, &pass_info0->client_guid))
652 struct GUID_txt_buf buf1, buf2;
654 DBG_WARNING("client's client_guid [%s] != passed guid [%s]\n",
655 GUID_buf_string(&client->global->client_guid,
656 &buf1),
657 GUID_buf_string(&pass_info0->client_guid,
658 &buf2));
659 if (DEBUGLVL(DBGLVL_WARNING)) {
660 NDR_PRINT_DEBUG(smbXsrv_connection_passB, &pass_blob);
662 goto next;
665 if (client->global->initial_connect_time !=
666 pass_info0->initial_connect_time)
668 DBG_WARNING("client's initial connect time [%s] (%llu) != "
669 "passed initial connect time [%s] (%llu)\n",
670 nt_time_string(talloc_tos(),
671 client->global->initial_connect_time),
672 (unsigned long long)client->global->initial_connect_time,
673 nt_time_string(talloc_tos(),
674 pass_info0->initial_connect_time),
675 (unsigned long long)pass_info0->initial_connect_time);
676 if (DEBUGLVL(DBGLVL_WARNING)) {
677 NDR_PRINT_DEBUG(smbXsrv_connection_passB, &pass_blob);
679 goto next;
682 status = smbd_add_connection(client,
683 sock_fd,
684 pass_info0->initial_connect_time,
685 &xconn);
686 if (NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_ACCESS_DENIED)) {
687 rec->num_fds = 0;
688 DLIST_REMOVE(client->connections, xconn);
689 TALLOC_FREE(xconn);
691 if (!NT_STATUS_IS_OK(status)) {
692 DBG_ERR("smbd_add_connection => %s\n", nt_errstr(status));
693 NDR_PRINT_DEBUG(smbXsrv_connection_passB, &pass_blob);
694 goto next;
696 rec->num_fds = 0;
699 * Set seq_low to mid received in negprot
701 seq_low = BVAL(pass_info0->negotiate_request.data,
702 SMB2_HDR_MESSAGE_ID);
704 xconn->smb2.client.guid_verified = true;
705 smbd_smb2_process_negprot(xconn, seq_low,
706 pass_info0->negotiate_request.data,
707 pass_info0->negotiate_request.length);
709 next:
710 if (rec != NULL) {
711 uint8_t fd_idx;
713 for (fd_idx = 0; fd_idx < rec->num_fds; fd_idx++) {
714 sock_fd = rec->fds[fd_idx];
715 close(sock_fd);
717 rec->num_fds = 0;
719 TALLOC_FREE(rec);
722 subreq = messaging_filtered_read_send(client,
723 client->raw_ev_ctx,
724 client->msg_ctx,
725 smbXsrv_client_connection_pass_filter,
726 client);
727 if (subreq == NULL) {
728 const char *r;
729 r = "messaging_read_send(MSG_SMBXSRV_CONNECTION_PASS failed";
730 exit_server_cleanly(r);
731 return;
733 tevent_req_set_callback(subreq, smbXsrv_client_connection_pass_loop, client);
736 NTSTATUS smbXsrv_client_update(struct smbXsrv_client *client)
738 struct smbXsrv_client_table *table = client->table;
739 NTSTATUS status;
741 if (client->global->db_rec != NULL) {
742 struct GUID_txt_buf buf;
743 DBG_ERR("guid [%s]: Called with db_rec != NULL'\n",
744 GUID_buf_string(&client->global->client_guid,
745 &buf));
746 return NT_STATUS_INTERNAL_ERROR;
749 client->global->db_rec = smbXsrv_client_global_fetch_locked(
750 table->global.db_ctx,
751 &client->global->client_guid,
752 client->global /* TALLOC_CTX */);
753 if (client->global->db_rec == NULL) {
754 return NT_STATUS_INTERNAL_DB_ERROR;
757 status = smbXsrv_client_global_store(client->global);
758 if (!NT_STATUS_IS_OK(status)) {
759 struct GUID_txt_buf buf;
760 DBG_ERR("client_guid[%s] store failed - %s\n",
761 GUID_buf_string(&client->global->client_guid,
762 &buf),
763 nt_errstr(status));
764 return status;
767 if (DEBUGLVL(DBGLVL_DEBUG)) {
768 struct smbXsrv_clientB client_blob = {
769 .version = SMBXSRV_VERSION_0,
770 .info.info0 = client,
772 struct GUID_txt_buf buf;
774 DBG_DEBUG("client_guid[%s] stored\n",
775 GUID_buf_string(&client->global->client_guid,
776 &buf));
777 NDR_PRINT_DEBUG(smbXsrv_clientB, &client_blob);
780 return NT_STATUS_OK;
783 NTSTATUS smbXsrv_client_remove(struct smbXsrv_client *client)
785 struct smbXsrv_client_table *table = client->table;
786 NTSTATUS status;
788 if (client->global->db_rec != NULL) {
789 struct GUID_txt_buf buf;
790 DBG_ERR("client_guid[%s]: Called with db_rec != NULL'\n",
791 GUID_buf_string(&client->global->client_guid,
792 &buf));
793 return NT_STATUS_INTERNAL_ERROR;
796 if (!client->global->stored) {
797 return NT_STATUS_OK;
800 client->global->db_rec = smbXsrv_client_global_fetch_locked(
801 table->global.db_ctx,
802 &client->global->client_guid,
803 client->global /* TALLOC_CTX */);
804 if (client->global->db_rec == NULL) {
805 return NT_STATUS_INTERNAL_DB_ERROR;
808 status = smbXsrv_client_global_remove(client->global);
809 if (!NT_STATUS_IS_OK(status)) {
810 struct GUID_txt_buf buf;
811 DBG_ERR("client_guid[%s] store failed - %s\n",
812 GUID_buf_string(&client->global->client_guid, &buf),
813 nt_errstr(status));
814 return status;
817 if (DEBUGLVL(DBGLVL_DEBUG)) {
818 struct smbXsrv_clientB client_blob = {
819 .version = SMBXSRV_VERSION_0,
820 .info.info0 = client,
822 struct GUID_txt_buf buf;
824 DBG_DEBUG("client_guid[%s] stored\n",
825 GUID_buf_string(&client->global->client_guid, &buf));
826 NDR_PRINT_DEBUG(smbXsrv_clientB, &client_blob);
829 return NT_STATUS_OK;