Changeset 745 for trunk/server/source3/lib/conn_tdb.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/lib/conn_tdb.c
r414 r745 19 19 20 20 #include "includes.h" 21 #include "system/filesys.h" 22 #include "smbd/globals.h" 23 #include "dbwrap.h" 21 24 22 25 static struct db_context *connections_db_ctx(bool rw) 23 26 { 24 27 static struct db_context *db_ctx; 28 int open_flags; 25 29 26 30 if (db_ctx != NULL) { … … 28 32 } 29 33 30 if (rw) { 31 db_ctx = db_open(NULL, lock_path("connections.tdb"), 0, 32 TDB_CLEAR_IF_FIRST|TDB_DEFAULT, 33 O_RDWR | O_CREAT, 0644); 34 } 35 else { 36 db_ctx = db_open(NULL, lock_path("connections.tdb"), 0, 37 TDB_CLEAR_IF_FIRST|TDB_DEFAULT, O_RDONLY, 0); 38 } 34 open_flags = rw ? (O_RDWR|O_CREAT) : O_RDONLY; 39 35 36 db_ctx = db_open(NULL, lock_path("connections.tdb"), 0, 37 TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH|TDB_DEFAULT, open_flags, 0644); 40 38 return db_ctx; 41 39 } 42 40 43 st ruct db_record *connections_fetch_record(TALLOC_CTX *mem_ctx,44 41 static struct db_record *connections_fetch_record(TALLOC_CTX *mem_ctx, 42 TDB_DATA key) 45 43 { 46 44 struct db_context *ctx = connections_db_ctx(True); … … 61 59 62 60 ZERO_STRUCT(ckey); 63 ckey.pid = procid_self();64 ckey.cnum = conn ? conn->cnum : -1;61 ckey.pid = sconn_server_id(conn->sconn); 62 ckey.cnum = conn->cnum; 65 63 strlcpy(ckey.name, name, sizeof(ckey.name)); 66 64 … … 113 111 void *private_data) 114 112 { 113 struct db_context *ctx; 115 114 struct conn_traverse_state state; 115 116 ctx = connections_db_ctx(true); 117 if (ctx == NULL) { 118 return -1; 119 } 116 120 117 121 state.fn = fn; 118 122 state.private_data = private_data; 119 123 120 return connections_traverse(conn_traverse_fn, (void *)&state); 124 return ctx->traverse(ctx, conn_traverse_fn, (void *)&state); 125 } 126 127 struct conn_traverse_read_state { 128 int (*fn)(const struct connections_key *key, 129 const struct connections_data *data, 130 void *private_data); 131 void *private_data; 132 }; 133 134 static int connections_forall_read_fn(struct db_record *rec, 135 void *private_data) 136 { 137 struct conn_traverse_read_state *state = 138 (struct conn_traverse_read_state *)private_data; 139 140 if ((rec->key.dsize != sizeof(struct connections_key)) 141 || (rec->value.dsize != sizeof(struct connections_data))) { 142 return 0; 143 } 144 return state->fn((const struct connections_key *)rec->key.dptr, 145 (const struct connections_data *)rec->value.dptr, 146 state->private_data); 147 } 148 149 int connections_forall_read(int (*fn)(const struct connections_key *key, 150 const struct connections_data *data, 151 void *private_data), 152 void *private_data) 153 { 154 struct db_context *ctx; 155 struct conn_traverse_read_state state; 156 157 ctx = connections_db_ctx(false); 158 if (ctx == NULL) { 159 return -1; 160 } 161 162 state.fn = fn; 163 state.private_data = private_data; 164 165 return ctx->traverse_read(ctx, connections_forall_read_fn, 166 (void *)&state); 121 167 } 122 168
Note:
See TracChangeset
for help on using the changeset viewer.