static bool add_mapping_entry(GROUP_MAP *map, int flag) { char *key, *buf; int len; NTSTATUS status; key = group_mapping_key(talloc_tos(), &map->sid); if (key == NULL) { return false; } len = tdb_pack(NULL, 0, "ddff", map->gid, map->sid_name_use, map->nt_name, map->comment); buf = talloc_array(key, char, len); if (!buf) { TALLOC_FREE(key); return false; } len = tdb_pack((uint8 *)buf, len, "ddff", map->gid, map->sid_name_use, map->nt_name, map->comment); status = dbwrap_trans_store( db, string_term_tdb_data(key), make_tdb_data((uint8_t *)buf, len), TDB_REPLACE); TALLOC_FREE(key); return NT_STATUS_IS_OK(status); }
static int regdb_pack_values(REGVAL_CTR *values, char *buf, int buflen) { int len = 0; int i; REGISTRY_VALUE *val; int num_values; if ( !values ) return 0; num_values = regval_ctr_numvals( values ); /* pack the number of values first */ len += tdb_pack( buf+len, buflen-len, "d", num_values ); /* loop over all values */ for ( i=0; i<num_values; i++ ) { val = regval_ctr_specific_value( values, i ); len += tdb_pack(buf+len, buflen-len, "fdB", regval_name(val), regval_type(val), regval_size(val), regval_data_p(val) ); } return len; }
bool login_cache_write(const struct samu *sampass, const struct login_cache *entry) { char *keystr; TDB_DATA databuf; bool ret; uint32_t entry_timestamp; uint32_t bad_password_time = entry->bad_password_time; if (!login_cache_init()) return False; if (pdb_get_nt_username(sampass) == NULL) { return False; } keystr = SMB_STRDUP(pdb_get_nt_username(sampass)); if (!keystr || !keystr[0]) { SAFE_FREE(keystr); return False; } entry_timestamp = (uint32_t)time(NULL); databuf.dsize = tdb_pack(NULL, 0, SAM_CACHE_FORMAT, entry_timestamp, entry->acct_ctrl, entry->bad_password_count, bad_password_time); databuf.dptr = SMB_MALLOC_ARRAY(uint8_t, databuf.dsize); if (!databuf.dptr) { SAFE_FREE(keystr); return False; } if (tdb_pack(databuf.dptr, databuf.dsize, SAM_CACHE_FORMAT, entry_timestamp, entry->acct_ctrl, entry->bad_password_count, bad_password_time) != databuf.dsize) { SAFE_FREE(keystr); SAFE_FREE(databuf.dptr); return False; } ret = tdb_store_bystring(cache, keystr, databuf, 0); SAFE_FREE(keystr); SAFE_FREE(databuf.dptr); return ret == 0; }
BOOL login_cache_write(const struct samu *sampass, LOGIN_CACHE entry) { TDB_DATA keybuf, databuf; BOOL ret; if (!login_cache_init()) return False; if (pdb_get_nt_username(sampass) == NULL) { return False; } keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass)); if (!keybuf.dptr || !strlen(keybuf.dptr)) { SAFE_FREE(keybuf.dptr); return False; } keybuf.dsize = strlen(keybuf.dptr) + 1; entry.entry_timestamp = time(NULL); databuf.dsize = tdb_pack(NULL, 0, SAM_CACHE_FORMAT, entry.entry_timestamp, entry.acct_ctrl, entry.bad_password_count, entry.bad_password_time); databuf.dptr = SMB_MALLOC_ARRAY(char, databuf.dsize); if (!databuf.dptr) { SAFE_FREE(keybuf.dptr); return False; } if (tdb_pack(databuf.dptr, databuf.dsize, SAM_CACHE_FORMAT, entry.entry_timestamp, entry.acct_ctrl, entry.bad_password_count, entry.bad_password_time) != databuf.dsize) { SAFE_FREE(keybuf.dptr); SAFE_FREE(databuf.dptr); return False; } ret = tdb_store(cache, keybuf, databuf, 0); SAFE_FREE(keybuf.dptr); SAFE_FREE(databuf.dptr); return ret == 0; }
/** * Pack TRUSTED_DOM_PASS passed by pointer * * @param pack_buf pointer to buffer which is to be filled with packed data * @param bufsize size of the buffer * @param pass pointer to trusted domain password to be packed * * @return length of the packed representation of the whole structure **/ static size_t tdb_trusted_dom_pass_pack(uint8 *pack_buf, int bufsize, TRUSTED_DOM_PASS* pass) { int idx, len = 0; uint8 *p = pack_buf; int remaining_space = pack_buf ? bufsize : 0; if (!pass) { return -1; } /* packing unicode domain name and password */ len += tdb_pack(p, remaining_space, "d", pass->uni_name_len); if (pack_buf) { p = pack_buf + len; remaining_space = bufsize - len; } for (idx = 0; idx < 32; idx++) { len += tdb_pack(p, remaining_space, "w", pass->uni_name[idx]); if (pack_buf) { p = pack_buf + len; remaining_space = bufsize - len; } } len += tdb_pack(p, remaining_space, "dPd", pass->pass_len, pass->pass, pass->mod_time); if (pack_buf) { p = pack_buf + len; remaining_space = bufsize - len; } /* packing SID structure */ len += tdb_sid_pack(p, remaining_space, &pass->domain_sid); if (pack_buf) { p = pack_buf + len; remaining_space = bufsize - len; } return len; }
static bool flatten_message(struct notify_queue *q) { struct spoolss_notify_msg *msg = q->msg; uint8 *buf = NULL; size_t buflen = 0, len; again: len = 0; /* Pack header */ len += tdb_pack(buf + len, buflen - len, "f", msg->printer); len += tdb_pack(buf + len, buflen - len, "ddddddd", (uint32)q->tv.tv_sec, (uint32)q->tv.tv_usec, msg->type, msg->field, msg->id, msg->len, msg->flags); /* Pack data */ if (msg->len == 0) len += tdb_pack(buf + len, buflen - len, "dd", msg->notify.value[0], msg->notify.value[1]); else len += tdb_pack(buf + len, buflen - len, "B", msg->len, msg->notify.data); if (buflen != len) { buf = (uint8 *)TALLOC_REALLOC(send_ctx, buf, len); if (!buf) return False; buflen = len; goto again; } q->buf = buf; q->buflen = buflen; return True; }
/** * Pack SID passed by pointer * * @param pack_buf pointer to buffer which is to be filled with packed data * @param bufsize size of packing buffer * @param sid pointer to sid to be packed * * @return length of the packed representation of the whole structure **/ static size_t tdb_sid_pack(uint8 *pack_buf, int bufsize, DOM_SID* sid) { int idx; size_t len = 0; uint8 *p = pack_buf; int remaining_space = pack_buf ? bufsize : 0; if (!sid) { return -1; } len += tdb_pack(p, remaining_space, "bb", sid->sid_rev_num, sid->num_auths); if (pack_buf) { p = pack_buf + len; remaining_space = bufsize - len; } for (idx = 0; idx < 6; idx++) { len += tdb_pack(p, remaining_space, "b", sid->id_auth[idx]); if (pack_buf) { p = pack_buf + len; remaining_space = bufsize - len; } } for (idx = 0; idx < MAXSUBAUTHS; idx++) { len += tdb_pack(p, remaining_space, "d", sid->sub_auths[idx]); if (pack_buf) { p = pack_buf + len; remaining_space = bufsize - len; } } return len; }
NTSTATUS printer_list_mark_reload(void) { struct db_context *db; TDB_DATA data; uint32_t time_h, time_l; time_t now = time_mono(NULL); NTSTATUS status; int len; db = get_printer_list_db(); if (db == NULL) { return NT_STATUS_INTERNAL_DB_CORRUPTION; } time_l = ((uint64_t)now) & 0xFFFFFFFFL; time_h = ((uint64_t)now) >> 32; len = tdb_pack(NULL, 0, PL_TSTAMP_FORMAT, time_h, time_l); data.dptr = talloc_array(talloc_tos(), uint8_t, len); if (!data.dptr) { DEBUG(0, ("Failed to allocate tdb data buffer!\n")); status = NT_STATUS_NO_MEMORY; goto done; } data.dsize = len; len = tdb_pack(data.dptr, data.dsize, PL_TSTAMP_FORMAT, time_h, time_l); status = dbwrap_store_bystring(db, PL_TIMESTAMP_KEY, data, TDB_REPLACE); done: TALLOC_FREE(data.dptr); return status; }
NTSTATUS printer_list_set_printer(TALLOC_CTX *mem_ctx, const char *name, const char *comment, const char *location, time_t last_refresh) { struct db_context *db; char *key; TDB_DATA data; uint64_t time_64; uint32_t time_h, time_l; const char *str = NULL; const char *str2 = NULL; NTSTATUS status; int len; db = get_printer_list_db(); if (db == NULL) { return NT_STATUS_INTERNAL_DB_CORRUPTION; } key = talloc_asprintf(mem_ctx, PL_KEY_FORMAT, name); if (!key) { DEBUG(0, ("Failed to allocate key name!\n")); return NT_STATUS_NO_MEMORY; } if (comment) { str = comment; } else { str = ""; } if (location) { str2 = location; } else { str2 = ""; } time_64 = last_refresh; time_l = time_64 & 0xFFFFFFFFL; time_h = time_64 >> 32; len = tdb_pack(NULL, 0, PL_DATA_FORMAT, time_h, time_l, name, str, str2); data.dptr = talloc_array(key, uint8_t, len); if (!data.dptr) { DEBUG(0, ("Failed to allocate tdb data buffer!\n")); status = NT_STATUS_NO_MEMORY; goto done; } data.dsize = len; len = tdb_pack(data.dptr, data.dsize, PL_DATA_FORMAT, time_h, time_l, name, str, str2); status = dbwrap_store_bystring_upper(db, key, data, TDB_REPLACE); done: TALLOC_FREE(key); return status; }
static BOOL regdb_store_keys_internal( const char *key, REGSUBKEY_CTR *ctr ) { TDB_DATA kbuf, dbuf; char *buffer; int i = 0; uint32 len, buflen; BOOL ret = True; uint32 num_subkeys = regsubkey_ctr_numkeys( ctr ); pstring keyname; if ( !key ) return False; pstrcpy( keyname, key ); normalize_reg_path( keyname ); /* allocate some initial memory */ if (!(buffer = (char *)SMB_MALLOC(sizeof(pstring)))) { return False; } buflen = sizeof(pstring); len = 0; /* store the number of subkeys */ len += tdb_pack(buffer+len, buflen-len, "d", num_subkeys ); /* pack all the strings */ for (i=0; i<num_subkeys; i++) { len += tdb_pack( buffer+len, buflen-len, "f", regsubkey_ctr_specific_key(ctr, i) ); if ( len > buflen ) { /* allocate some extra space */ if ((buffer = (char *)SMB_REALLOC( buffer, len*2 )) == NULL) { DEBUG(0,("regdb_store_keys: Failed to realloc memory of size [%d]\n", len*2)); ret = False; goto done; } buflen = len*2; len = tdb_pack( buffer+len, buflen-len, "f", regsubkey_ctr_specific_key(ctr, i) ); } } /* finally write out the data */ kbuf.dptr = keyname; kbuf.dsize = strlen(keyname)+1; dbuf.dptr = buffer; dbuf.dsize = len; if ( tdb_store( tdb_reg, kbuf, dbuf, TDB_REPLACE ) == -1) { ret = False; goto done; } done: SAFE_FREE( buffer ); return ret; }