Grr, the order of these arguments matters
[ira/wip.git] / testsuite / printing / psec.c
index e3490de7598e4df220021530ccd3a25b2fe838cb..9d38b9b10aed60273077bc460d2bfb1cbba5bc66 100644 (file)
@@ -71,7 +71,7 @@ TDB_CONTEXT *tdb;
 
 char *ace_type_to_str(uint ace_type)
 {
-       fstring temp;
+       static fstring temp;
 
        switch(ace_type) {
        case SEC_ACE_TYPE_ACCESS_DENIED:
@@ -99,7 +99,7 @@ uint str_to_ace_type(char *ace_type)
 
 char *ace_mask_to_str(uint32 ace_mask)
 {
-       fstring temp;
+       static fstring temp;
 
        switch (ace_mask) {
        case PRINTER_ACE_FULL_CONTROL:
@@ -132,7 +132,7 @@ uint32 str_to_ace_mask(char *ace_mask)
 
 char *ace_to_str(SEC_ACE *ace)
 {
-       pstring temp;
+       static pstring temp;
        fstring sidstr;
 
        sid_to_string(sidstr, &ace->sid);
@@ -144,7 +144,7 @@ char *ace_to_str(SEC_ACE *ace)
        return temp;
 }
 
-int str_to_ace(SEC_ACE *ace, char *ace_str)
+void str_to_ace(SEC_ACE *ace, char *ace_str)
 {
        SEC_ACCESS sa;
        DOM_SID sid;
@@ -165,9 +165,13 @@ int psec_getsec(char *printer)
        prs_struct ps;
        int result = 0, i;
 
+       ZERO_STRUCT(ps);
+
        /* Open tdb for reading */
 
-       slprintf(tdb_path, "%s/ntdrivers.tdb", LOCKDIR);
+       slprintf(tdb_path, sizeof(tdb_path) - 1, "%s/ntdrivers.tdb", 
+                lp_lockdir());
+
        tdb = tdb_open(tdb_path, 0, 0, O_RDONLY, 0600);
 
        if (!tdb) {
@@ -230,7 +234,6 @@ int psec_getsec(char *printer)
 
        for (i = 0; i < secdesc_ctr->sec->dacl->num_aces; i++) {
                SEC_ACE *ace = &secdesc_ctr->sec->dacl->ace[i];
-               fstring sidstr;
 
                sid_to_string(sidstr, &ace->sid);
 
@@ -242,6 +245,7 @@ int psec_getsec(char *printer)
        if (tdb) tdb_close(tdb);
        if (mem_ctx) talloc_destroy(mem_ctx);
        if (secdesc_ctr) free_sec_desc_buf(&secdesc_ctr);
+       prs_mem_free(&ps);
 
        return result;
 }
@@ -252,7 +256,7 @@ int psec_setsec(char *printer)
 {
        DOM_SID user_sid, group_sid;
        SEC_ACE *ace_list = NULL;
-       SEC_ACL *dacl;
+       SEC_ACL *dacl = NULL;
        SEC_DESC *sd;
        SEC_DESC_BUF *sdb = NULL;
        int result = 0, num_aces = 0;
@@ -262,9 +266,13 @@ int psec_setsec(char *printer)
        TALLOC_CTX *mem_ctx = NULL;
        BOOL has_user_sid = False, has_group_sid = False;
 
+       ZERO_STRUCT(ps);
+
        /* Open tdb for reading */
 
-       slprintf(tdb_path, "%s/ntdrivers.tdb", LOCKDIR);
+       slprintf(tdb_path, sizeof(tdb_path) - 1, "%s/ntdrivers.tdb", 
+                lp_lockdir());
+
        tdb = tdb_open(tdb_path, 0, 0, O_RDWR, 0600);
 
        if (!tdb) {
@@ -319,14 +327,15 @@ int psec_setsec(char *printer)
 
        /* Create security descriptor */
 
-       sd = make_sec_desc(SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE |
-                          SEC_DESC_DACL_PRESENT, 
+       sd = make_sec_desc(SEC_DESC_REVISION,
                           has_user_sid ? &user_sid : NULL, 
                           has_group_sid ? &group_sid : NULL,
                           NULL, /* System ACL */
                           dacl, /* Discretionary ACL */
                           &size);
 
+       free_sec_acl(&dacl);
+
        sdb = make_sec_desc_buf(size, sd);
 
        free_sec_desc(&sd);
@@ -360,6 +369,7 @@ int psec_setsec(char *printer)
        if (tdb) tdb_close(tdb);
        if (sdb) free_sec_desc_buf(&sdb);
        if (mem_ctx) talloc_destroy(mem_ctx);
+       prs_mem_free(&ps);
 
        return result;
 }
@@ -375,6 +385,8 @@ void usage(void)
 
 int main(int argc, char **argv)
 {
+       pstring servicesf = CONFIGFILE;
+
        /* Argument check */
 
        if (argc == 1) {
@@ -382,6 +394,16 @@ int main(int argc, char **argv)
                return 1;
        }
 
+       /* Load smb.conf file */
+
+       charset_initialise();
+
+       if (!lp_load(servicesf,False,False,True)) {
+               fprintf(stderr, "Couldn't load confiuration file %s\n",
+                       servicesf);
+               return 1;
+       }
+
        /* Do commands */
 
        if (strcmp(argv[1], "setsec") == 0) {