s3/lib: add parent_smb_fname()
[vlendec/samba-autobuild/.git] / source3 / printing / printing_db.c
index e442551b833f0aa54c5d3b6d277400ff13df473c..3fa85579f20b6e0da3943ce3a83f97a07814e1c2 100644 (file)
@@ -20,6 +20,7 @@
 */
 
 #include "includes.h"
+#include "system/passwd.h" /* uid_wrapper */
 #include "system/filesys.h"
 #include "printing.h"
 #include "util_tdb.h"
@@ -34,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);
 
@@ -64,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;
                                }
                        }
@@ -92,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;
@@ -192,7 +202,7 @@ TDB_DATA get_printer_notify_pid_list(struct tdb_context *tdb, const char *printe
        for( i = 0; i < data.dsize; i += 8) {
                pid_t pid = (pid_t)IVAL(data.dptr, i);
 
-               if (pid == sys_getpid())
+               if (pid == getpid())
                        continue;
 
                /* Entry is dead if process doesn't exist or refcount is zero. */