2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 3 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "lib/util/debug.h"
18 #include "lib/util/server_id_db.h"
19 #include "notifyd_private.h"
20 #include "notifyd_db.h"
22 struct notifyd_parse_db_state
{
23 bool (*fn
)(const char *path
,
24 struct server_id server
,
25 const struct notify_instance
*instance
,
30 static bool notifyd_parse_db_parser(TDB_DATA key
, TDB_DATA value
,
33 struct notifyd_parse_db_state
*state
= private_data
;
34 char path
[key
.dsize
+1];
35 struct notifyd_instance
*instances
= NULL
;
36 size_t num_instances
= 0;
40 memcpy(path
, key
.dptr
, key
.dsize
);
43 ok
= notifyd_parse_entry(value
.dptr
,
49 DBG_DEBUG("Could not parse entry for path %s\n", path
);
53 for (i
=0; i
<num_instances
; i
++) {
54 ok
= state
->fn(path
, instances
[i
].client
,
55 &instances
[i
].instance
,
65 static NTSTATUS
notifyd_parse_db(
69 bool (*fn
)(const char *path
,
70 struct server_id server
,
71 const struct notify_instance
*instance
,
75 struct notifyd_parse_db_state state
= {
76 .fn
= fn
, .private_data
= private_data
81 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
83 *log_index
= BVAL(buf
, 0);
88 status
= dbwrap_parse_marshall_buf(
89 buf
, buflen
, notifyd_parse_db_parser
, &state
);
93 NTSTATUS
notify_walk(struct messaging_context
*msg_ctx
,
94 bool (*fn
)(const char *path
, struct server_id server
,
95 const struct notify_instance
*instance
,
99 struct server_id_db
*names_db
= NULL
;
100 struct server_id notifyd
= { .pid
= 0, };
101 struct tevent_context
*ev
= NULL
;
102 struct tevent_req
*req
= NULL
;
103 struct messaging_rec
*rec
= NULL
;
109 names_db
= messaging_names_db(msg_ctx
);
110 ok
= server_id_db_lookup_one(names_db
, "notify-daemon", ¬ifyd
);
112 DBG_WARNING("No notify daemon around\n");
113 return NT_STATUS_SERVER_UNAVAILABLE
;
116 ev
= samba_tevent_context_init(msg_ctx
);
118 return NT_STATUS_NO_MEMORY
;
121 req
= messaging_read_send(ev
, ev
, msg_ctx
, MSG_SMB_NOTIFY_DB
);
124 return NT_STATUS_NO_MEMORY
;
127 ok
= tevent_req_set_endtime(req
, ev
, timeval_current_ofs(10, 0));
130 return NT_STATUS_NO_MEMORY
;
133 status
= messaging_send_buf(
134 msg_ctx
, notifyd
, MSG_SMB_NOTIFY_GET_DB
, NULL
, 0);
135 if (!NT_STATUS_IS_OK(status
)) {
136 DBG_DEBUG("messaging_send_buf failed: %s\n",
142 ok
= tevent_req_poll(req
, ev
);
144 DBG_DEBUG("tevent_req_poll failed\n");
146 return NT_STATUS_INTERNAL_ERROR
;
149 ret
= messaging_read_recv(req
, ev
, &rec
);
151 DBG_DEBUG("messaging_read_recv failed: %s\n",
154 return map_nt_error_from_unix(ret
);
157 status
= notifyd_parse_db(
158 rec
->buf
.data
, rec
->buf
.length
, &log_idx
, fn
, private_data
);
159 if (!NT_STATUS_IS_OK(status
)) {
160 DBG_DEBUG("notifyd_parse_db failed: %s\n",