Do not use a variable format string
[ira/wip.git] / source3 / passdb / machine_sid.c
index 9921fdb096c4cdf770518ce53dd2c4a789e5d9ed..c7c3cc474b9dcb213036191fa1b716e0ceb2d1d4 100644 (file)
@@ -35,21 +35,21 @@ static DOM_SID *global_sam_sid=NULL;
  style of SID storage
 ****************************************************************************/
 
-static BOOL read_sid_from_file(const char *fname, DOM_SID *sid)
+static bool read_sid_from_file(const char *fname, DOM_SID *sid)
 {
        char **lines;
        int numlines;
-       BOOL ret;
+       bool ret;
 
-       lines = file_lines_load(fname, &numlines,0);
+       lines = file_lines_load(fname, &numlines,0, NULL);
        
        if (!lines || numlines < 1) {
-               if (lines) file_lines_free(lines);
+               if (lines) TALLOC_FREE(lines);
                return False;
        }
        
        ret = string_to_sid(sid, lines[0]);
-       file_lines_free(lines);
+       TALLOC_FREE(lines);
        return ret;
 }
 
@@ -128,7 +128,10 @@ static DOM_SID *pdb_generate_sam_sid(void)
        }
 
        /* check for an old MACHINE.SID file for backwards compatibility */
-       asprintf(&fname, "%s/MACHINE.SID", lp_private_dir());
+       if (asprintf(&fname, "%s/MACHINE.SID", lp_private_dir()) == -1) {
+               SAFE_FREE(sam_sid);
+               return NULL;
+       }
 
        if (read_sid_from_file(fname, sam_sid)) {
                /* remember it for future reference and unlink the old MACHINE.SID */
@@ -178,16 +181,38 @@ static DOM_SID *pdb_generate_sam_sid(void)
 /* return our global_sam_sid */
 DOM_SID *get_global_sam_sid(void)
 {
+       struct db_context *db;
+
        if (global_sam_sid != NULL)
                return global_sam_sid;
        
-       /* memory for global_sam_sid is allocated in 
-          pdb_generate_sam_sid() as needed */
+       /*
+        * memory for global_sam_sid is allocated in
+        * pdb_generate_sam_sid() as needed
+        *
+        * Note: this is garded by a transaction
+        *       to prevent races on startup which
+        *       can happen with some dbwrap backends
+        */
+
+       db = secrets_db_ctx();
+       if (!db) {
+               smb_panic("could not open secrets db");
+       }
+
+       if (db->transaction_start(db) != 0) {
+               smb_panic("could not start transaction on secrets db");
+       }
 
        if (!(global_sam_sid = pdb_generate_sam_sid())) {
+               db->transaction_cancel(db);
                smb_panic("could not generate a machine SID");
        }
 
+       if (db->transaction_commit(db) != 0) {
+               smb_panic("could not start commit secrets db");
+       }
+
        return global_sam_sid;
 }
 
@@ -203,7 +228,7 @@ void reset_global_sam_sid(void)
  Check if the SID is our domain SID (S-1-5-21-x-y-z).
 *****************************************************************/  
 
-BOOL sid_check_is_domain(const DOM_SID *sid)
+bool sid_check_is_domain(const DOM_SID *sid)
 {
        return sid_equal(sid, get_global_sam_sid());
 }
@@ -212,7 +237,7 @@ BOOL sid_check_is_domain(const DOM_SID *sid)
  Check if the SID is our domain SID (S-1-5-21-x-y-z).
 *****************************************************************/  
 
-BOOL sid_check_is_in_our_domain(const DOM_SID *sid)
+bool sid_check_is_in_our_domain(const DOM_SID *sid)
 {
        DOM_SID dom_sid;
        uint32 rid;