s3/lib: add parent_smb_fname()
[vlendec/samba-autobuild/.git] / source3 / printing / printing_db.c
index ecb8ff6463cffa579f2e86bd02f4b7c17ad154c2..3fa85579f20b6e0da3943ce3a83f97a07814e1c2 100644 (file)
@@ -35,9 +35,11 @@ static struct tdb_print_db *print_db_head;
 struct tdb_print_db *get_print_db_byname(const char *printername)
 {
        struct tdb_print_db *p = NULL, *last_entry = NULL;
-       int num_open = 0;
+       size_t num_open = 0;
        char *printdb_path = NULL;
        bool done_become_root = False;
+       char *print_cache_path;
+       int ret;
 
        SMB_ASSERT(printername != NULL);
 
@@ -65,9 +67,9 @@ struct tdb_print_db *get_print_db_byname(const char *printername)
                        if (p->ref_count)
                                continue;
                        if (p->tdb) {
-                               if (tdb_close(print_db_head->tdb)) {
+                               if (tdb_close(p->tdb)) {
                                        DEBUG(0,("get_print_db: Failed to close tdb for printer %s\n",
-                                                               print_db_head->printer_name ));
+                                                               p->printer_name ));
                                        return NULL;
                                }
                        }
@@ -93,9 +95,16 @@ struct tdb_print_db *get_print_db_byname(const char *printername)
                DLIST_ADD(print_db_head, p);
        }
 
-       if (asprintf(&printdb_path, "%s%s.tdb",
-                               cache_path("printing/"),
-                               printername) < 0) {
+       print_cache_path = cache_path(talloc_tos(), "printing/");
+       if (print_cache_path == NULL) {
+               DLIST_REMOVE(print_db_head, p);
+               SAFE_FREE(p);
+               return NULL;
+       }
+       ret = asprintf(&printdb_path, "%s%s.tdb",
+                      print_cache_path, printername);
+       TALLOC_FREE(print_cache_path);
+       if (ret < 0) {
                DLIST_REMOVE(print_db_head, p);
                SAFE_FREE(p);
                return NULL;