mirror of
https://github.com/samba-team/samba.git
synced 2025-01-08 21:18:16 +03:00
lib: Modernize tdb_fetch_lifetime()
Just came across this, avoid mallocs. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
e6136139be
commit
46f710c95f
@ -273,30 +273,37 @@ const char *lpcfg_sam_dnsname(struct loadparm_context *lp_ctx)
|
||||
}
|
||||
}
|
||||
|
||||
static long tdb_fetch_lifetime(TALLOC_CTX *mem_ctx, struct tdb_context *tdb, const char *keystr)
|
||||
static int
|
||||
tdb_fetch_lifetime_fn(TDB_DATA key, TDB_DATA data, void *private_data)
|
||||
{
|
||||
TDB_DATA key;
|
||||
TDB_DATA ret;
|
||||
char *tmp = NULL;
|
||||
long result;
|
||||
if (data.dsize < 256) {
|
||||
long *result = private_data;
|
||||
char tmp[data.dsize + 1];
|
||||
memcpy(tmp, data.dptr, data.dsize);
|
||||
tmp[data.dsize] = '\0';
|
||||
*result = atol(tmp);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
key.dptr = discard_const_p(unsigned char, keystr);
|
||||
key.dsize = strlen(keystr);
|
||||
static long tdb_fetch_lifetime(struct tdb_context *tdb,
|
||||
const char *keystr)
|
||||
{
|
||||
long result = -1;
|
||||
int ret;
|
||||
|
||||
if (!key.dptr)
|
||||
ret = tdb_parse_record(
|
||||
tdb,
|
||||
(TDB_DATA){
|
||||
.dptr = discard_const_p(uint8_t, keystr),
|
||||
.dsize = strlen(keystr),
|
||||
},
|
||||
tdb_fetch_lifetime_fn,
|
||||
&result);
|
||||
if (ret == -1) {
|
||||
return -1;
|
||||
|
||||
ret = tdb_fetch(tdb, key);
|
||||
if (ret.dsize == 0)
|
||||
return -1;
|
||||
|
||||
tmp = talloc_realloc(mem_ctx, tmp, char, ret.dsize+1);
|
||||
memset(tmp, 0, ret.dsize+1);
|
||||
memcpy(tmp, ret.dptr, ret.dsize);
|
||||
free(ret.dptr);
|
||||
|
||||
result = atol(tmp);
|
||||
talloc_free(tmp);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -314,15 +321,15 @@ void lpcfg_default_kdc_policy(TALLOC_CTX *mem_ctx,
|
||||
if (kdc_tdb)
|
||||
ctx = tdb_open(kdc_tdb, 0, TDB_DEFAULT, O_RDWR, 0600);
|
||||
|
||||
if (!ctx || ( val = tdb_fetch_lifetime(mem_ctx, ctx, "kdc:service_ticket_lifetime") ) == -1 )
|
||||
if (!ctx || ( val = tdb_fetch_lifetime(ctx, "kdc:service_ticket_lifetime") ) == -1 )
|
||||
val = lpcfg_parm_long(lp_ctx, NULL, "kdc", "service ticket lifetime", 10);
|
||||
*svc_tkt_lifetime = val * 60 * 60;
|
||||
|
||||
if (!ctx || ( val = tdb_fetch_lifetime(mem_ctx, ctx, "kdc:user_ticket_lifetime") ) == -1 )
|
||||
if (!ctx || ( val = tdb_fetch_lifetime(ctx, "kdc:user_ticket_lifetime") ) == -1 )
|
||||
val = lpcfg_parm_long(lp_ctx, NULL, "kdc", "user ticket lifetime", 10);
|
||||
*usr_tkt_lifetime = val * 60 * 60;
|
||||
|
||||
if (!ctx || ( val = tdb_fetch_lifetime(mem_ctx, ctx, "kdc:renewal_lifetime") ) == -1 )
|
||||
if (!ctx || ( val = tdb_fetch_lifetime(ctx, "kdc:renewal_lifetime") ) == -1 )
|
||||
val = lpcfg_parm_long(lp_ctx, NULL, "kdc", "renewal lifetime", 24 * 7);
|
||||
*renewal_lifetime = val * 60 * 60;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user