s3:winbindd: add an explanatory comment to _wbint_Sids2UnixIDs()
[kai/samba.git] / source3 / utils / pdbedit.c
index ac41dc0ad07fa54276a150f6552fc50af291008d..908f0ba0afed40f345f4e2b248222376d9a06f71 100644 (file)
 */
 
 #include "includes.h"
+#include "popt_common.h"
+#include "../librpc/gen_ndr/samr.h"
+#include "../libcli/security/security.h"
+#include "passdb.h"
 
 #define BIT_BACKEND    0x00000004
 #define BIT_VERBOSE    0x00000008
@@ -55,7 +59,7 @@
 #define MASK_ALWAYS_GOOD       0x0000001F
 #define MASK_USER_GOOD         0x60405FE0
 
-static int get_sid_from_cli_string(DOM_SID *sid, const char *str_sid)
+static int get_sid_from_cli_string(struct dom_sid *sid, const char *str_sid)
 {
        uint32_t rid;
 
@@ -103,7 +107,7 @@ static int export_database (struct pdb_methods *in,
        while (u_search->next_entry(u_search, &userentry)) {
                struct samu *user;
                struct samu *account;
-               DOM_SID user_sid;
+               struct dom_sid user_sid;
 
                DEBUG(4, ("Processing account %s\n", userentry.account_name));
 
@@ -171,7 +175,7 @@ static int export_database (struct pdb_methods *in,
 
 static int export_groups (struct pdb_methods *in, struct pdb_methods *out)
 {
-       GROUP_MAP *maps = NULL;
+       GROUP_MAP **maps = NULL;
        size_t i, entries = 0;
        NTSTATUS status;
 
@@ -184,10 +188,10 @@ static int export_groups (struct pdb_methods *in, struct pdb_methods *out)
        }
 
        for (i=0; i<entries; i++) {
-               out->add_group_mapping_entry(out, &(maps[i]));
+               out->add_group_mapping_entry(out, maps[i]);
        }
 
-       SAFE_FREE( maps );
+       TALLOC_FREE(maps);
 
        return 0;
 }
@@ -201,7 +205,7 @@ static int reinit_account_policies (void)
        int i;
 
        for (i=1; decode_account_policy_name(i) != NULL; i++) {
-               uint32 policy_value;
+               uint32_t policy_value;
                if (!account_policy_get_default(i, &policy_value)) {
                        fprintf(stderr, "Can't get default account policy\n");
                        return -1;
@@ -225,7 +229,7 @@ static int export_account_policies (struct pdb_methods *in, struct pdb_methods *
        int i;
 
        for ( i=1; decode_account_policy_name(i) != NULL; i++ ) {
-               uint32 policy_value;
+               uint32_t policy_value;
                NTSTATUS status;
 
                status = in->get_account_policy(in, i, &policy_value);
@@ -261,7 +265,7 @@ static int print_sam_info (struct samu *sam_pwent, bool verbosity, bool smbpwdst
 
        if (verbosity) {
                char temp[44];
-               const uint8 *hours;
+               const uint8_t *hours;
 
                printf ("Unix username:        %s\n", pdb_get_username(sam_pwent));
                printf ("NT username:          %s\n", pdb_get_nt_username(sam_pwent));
@@ -328,7 +332,7 @@ static int print_sam_info (struct samu *sam_pwent, bool verbosity, bool smbpwdst
                       lm_passwd,
                       nt_passwd,
                       pdb_encode_acct_ctrl(pdb_get_acct_ctrl(sam_pwent),NEW_PW_FORMAT_SPACE_PADDED_LEN),
-                      (uint32)convert_time_t_to_uint32(pdb_get_pass_last_set_time(sam_pwent)));
+                      (uint32)convert_time_t_to_uint32_t(pdb_get_pass_last_set_time(sam_pwent)));
        } else {
                uid = nametouid(pdb_get_username(sam_pwent));
                printf ("%s:%lu:%s\n", pdb_get_username(sam_pwent), (unsigned long)uid,
@@ -376,7 +380,7 @@ static int print_users_list(bool verbosity, bool smbpwdstyle)
        struct samr_displayentry userentry;
        struct samu *sam_pwent;
        TALLOC_CTX *tosctx;
-       DOM_SID user_sid;
+       struct dom_sid user_sid;
        bool bret;
        int ret;
 
@@ -434,7 +438,7 @@ static int fix_users_list(void)
        struct samr_displayentry userentry;
        struct samu *sam_pwent;
        TALLOC_CTX *tosctx;
-       DOM_SID user_sid;
+       struct dom_sid user_sid;
        NTSTATUS status;
        bool bret;
        int ret;
@@ -504,7 +508,7 @@ static int set_user_info(const char *username, const char *fullname,
        uint32_t acb_flags;
        uint32_t not_settable;
        uint32_t new_flags;
-       DOM_SID u_sid;
+       struct dom_sid u_sid;
        bool ret;
 
        sam_pwent = samu_new(NULL);
@@ -523,7 +527,7 @@ static int set_user_info(const char *username, const char *fullname,
                hours_len = pdb_get_hours_len(sam_pwent);
                memset(hours_array, 0xff, hours_len);
 
-               pdb_set_hours(sam_pwent, hours_array, PDB_CHANGED);
+               pdb_set_hours(sam_pwent, hours_array, hours_len, PDB_CHANGED);
        }
 
        if (!pdb_update_autolock_flag(sam_pwent, &updated_autolock)) {
@@ -592,7 +596,7 @@ static int set_user_info(const char *username, const char *fullname,
                                return -1;
                        }
 
-                       value = convert_uint32_to_time_t(num);
+                       value = convert_uint32_t_to_time_t(num);
                }
 
                pdb_set_kickoff_time(sam_pwent, value, PDB_CHANGED);
@@ -618,7 +622,7 @@ static int set_machine_info(const char *machinename,
        uint32_t acb_flags;
        uint32_t not_settable;
        uint32_t new_flags;
-       DOM_SID m_sid;
+       struct dom_sid m_sid;
        char *name;
        int len;
        bool ret;
@@ -651,7 +655,11 @@ static int set_machine_info(const char *machinename,
                return -1;
        }
 
-       strlower_m(name);
+       if (!strlower_m(name)) {
+               fprintf(stderr, "strlower_m %s failed\n", name);
+               TALLOC_FREE(sam_pwent);
+               return -1;
+       }
 
        ret = pdb_getsampwnam(sam_pwent, name);
        if (!ret) {
@@ -709,7 +717,7 @@ static int new_user(const char *username, const char *fullname,
        struct samu *sam_pwent = NULL;
        TALLOC_CTX *tosctx;
        NTSTATUS status;
-       DOM_SID u_sid;
+       struct dom_sid u_sid;
        int flags;
        int ret;
 
@@ -806,7 +814,7 @@ static int new_machine(const char *machinename, char *machine_sid)
        struct samu *sam_pwent = NULL;
        TALLOC_CTX *tosctx;
        NTSTATUS status;
-       DOM_SID m_sid;
+       struct dom_sid m_sid;
        char *compatpwd;
        char *name;
        int flags;
@@ -849,7 +857,10 @@ static int new_machine(const char *machinename, char *machine_sid)
                return -1;
        }
 
-       strlower_m(name);
+       if (!strlower_m(name)) {
+               fprintf(stderr, "strlower_m %s failed\n", name);
+               return -1;
+       }
 
        flags = LOCAL_ADD_USER | LOCAL_TRUST_ACCOUNT | LOCAL_SET_PASSWORD;
 
@@ -954,8 +965,8 @@ static int delete_machine_entry(const char *machinename)
        if (!pdb_getsampwnam(samaccount, name)) {
                fprintf (stderr,
                         "machine %s does not exist in the passdb\n", name);
-               return -1;
                TALLOC_FREE(samaccount);
+               return -1;
        }
 
        if (!NT_STATUS_IS_OK(pdb_delete_sam_account(samaccount))) {
@@ -1055,7 +1066,7 @@ int main (int argc, char **argv)
 
        load_case_tables();
 
-       setup_logging("pdbedit", True);
+       setup_logging("pdbedit", DEBUG_STDOUT);
 
        pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
                            POPT_CONTEXT_KEEP_FIRST);
@@ -1073,7 +1084,7 @@ int main (int argc, char **argv)
        if (user_name == NULL)
                user_name = poptGetArg(pc);
 
-       if (!lp_load(get_dyn_CONFIGFILE(),True,False,False,True)) {
+       if (!lp_load_global(get_dyn_CONFIGFILE())) {
                fprintf(stderr, "Can't load %s - run testparm to debug it\n", get_dyn_CONFIGFILE());
                exit(1);
        }
@@ -1113,7 +1124,7 @@ int main (int argc, char **argv)
                /* HACK: set the global passdb backend by overwriting globals.
                 * This way we can use regular pdb functions for default
                 * operations that do not involve passdb migrations */
-               lp_set_passdb_backend(backend);
+               lp_set_cmdline("passdb backend", backend);
        } else {
                backend = lp_passdb_backend();
        }
@@ -1132,13 +1143,13 @@ int main (int argc, char **argv)
 
        /* account policy operations */
        if ((checkparms & BIT_ACCPOLICY) && !(checkparms & ~(BIT_ACCPOLICY + BIT_ACCPOLVAL))) {
-               uint32 value;
+               uint32_t value;
                enum pdb_policy_type field = account_policy_name_to_typenum(account_policy);
                if (field == 0) {
                        const char **names;
                        int count;
                        int i;
-                       account_policy_names_list(&names, &count);
+                       account_policy_names_list(talloc_tos(), &names, &count);
                        fprintf(stderr, "No account policy by that name!\n");
                        if (count !=0) {
                                fprintf(stderr, "Account policy names are:\n");
@@ -1146,7 +1157,7 @@ int main (int argc, char **argv)
                                        d_fprintf(stderr, "%s\n", names[i]);
                                }
                        }
-                       SAFE_FREE(names);
+                       TALLOC_FREE(names);
                        exit(1);
                }
                if (!pdb_get_account_policy(field, &value)) {