summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2007-03-13 14:05:38 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:18:36 -0500
commite6ccc787d93289b76db5e5cbaa3b109047e7139c (patch)
tree97b8a684916dc5d020fa53afe6d01eb186e5c843 /source3
parentc55d05b03cd929fba837259f99c73baadc7897f8 (diff)
downloadsamba-e6ccc787d93289b76db5e5cbaa3b109047e7139c.tar.gz
samba-e6ccc787d93289b76db5e5cbaa3b109047e7139c.tar.bz2
samba-e6ccc787d93289b76db5e5cbaa3b109047e7139c.zip
r21819: Wrap all steps in secrets_store_machine_password into one single
transaction. Succeed all or store nothing. Volker (This used to be commit 4efc7b45985e807532214959c1872cd6e7865ab8)
Diffstat (limited to 'source3')
-rw-r--r--source3/passdb/secrets.c62
1 files changed, 50 insertions, 12 deletions
diff --git a/source3/passdb/secrets.c b/source3/passdb/secrets.c
index e450205060..15c79745a0 100644
--- a/source3/passdb/secrets.c
+++ b/source3/passdb/secrets.c
@@ -556,40 +556,78 @@ the password is assumed to be a null terminated ascii string
BOOL secrets_store_machine_password(const char *pass, const char *domain, uint32 sec_channel)
{
char *key = NULL;
- BOOL ret;
+ BOOL ret = False;
uint32 last_change_time;
uint32 sec_channel_type;
- asprintf(&key, "%s/%s", SECRETS_MACHINE_PASSWORD, domain);
- if (!key)
+ if (tdb_transaction_start(tdb) == -1) {
+ DEBUG(5, ("tdb_transaction_start failed: %s\n",
+ tdb_errorstr(tdb)));
return False;
+ }
+
+ if (asprintf(&key, "%s/%s", SECRETS_MACHINE_PASSWORD, domain) == -1) {
+ DEBUG(5, ("asprintf failed\n"));
+ goto fail;
+ }
strupper_m(key);
ret = secrets_store(key, pass, strlen(pass)+1);
SAFE_FREE(key);
- if (!ret)
- return ret;
+ if (!ret) {
+ DEBUG(5, ("secrets_store failed: %s\n",
+ tdb_errorstr(tdb)));
+ goto fail;
+ }
- asprintf(&key, "%s/%s", SECRETS_MACHINE_LAST_CHANGE_TIME, domain);
- if (!key)
- return False;
+ if (asprintf(&key, "%s/%s", SECRETS_MACHINE_LAST_CHANGE_TIME,
+ domain) == -1) {
+ DEBUG(5, ("asprintf failed\n"));
+ goto fail;
+ }
strupper_m(key);
SIVAL(&last_change_time, 0, time(NULL));
ret = secrets_store(key, &last_change_time, sizeof(last_change_time));
SAFE_FREE(key);
- asprintf(&key, "%s/%s", SECRETS_MACHINE_SEC_CHANNEL_TYPE, domain);
- if (!key)
- return False;
+ if (!ret) {
+ DEBUG(5, ("secrets_store failed: %s\n",
+ tdb_errorstr(tdb)));
+ goto fail;
+ }
+
+ if (asprintf(&key, "%s/%s", SECRETS_MACHINE_SEC_CHANNEL_TYPE,
+ domain) == -1) {
+ DEBUG(5, ("asprintf failed\n"));
+ goto fail;
+ }
strupper_m(key);
SIVAL(&sec_channel_type, 0, sec_channel);
ret = secrets_store(key, &sec_channel_type, sizeof(sec_channel_type));
SAFE_FREE(key);
- return ret;
+ if (!ret) {
+ DEBUG(5, ("secrets_store failed: %s\n",
+ tdb_errorstr(tdb)));
+ goto fail;
+ }
+
+ if (tdb_transaction_commit(tdb) != 0) {
+ DEBUG(5, ("tdb_transaction_commit failed: %s\n",
+ tdb_errorstr(tdb)));
+ return False;
+ }
+
+ return True;
+
+ fail:
+ if (tdb_transaction_cancel(tdb) != 0) {
+ smb_panic("tdb_transaction_cancel failed!\n");
+ }
+ return False;
}
/************************************************************************