s3-param Remove lp_set_passdb_backend()
[samba.git] / source3 / utils / pdbedit.c
index dce2f05a834b51473cb0d56c7c4f7a3ce9eeae2f..dc126594dbc19bb041ff9fb9e5150d4e9a3689e7 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
 #define BIT_FIX_INIT    0x04000000
 #define BIT_BADPWRESET 0x08000000
 #define BIT_LOGONHOURS 0x10000000
+#define BIT_KICKOFFTIME        0x20000000
+#define BIT_DESCRIPTION 0x40000000
 
 #define MASK_ALWAYS_GOOD       0x0000001F
-#define MASK_USER_GOOD         0x00405FE0
+#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;
 
@@ -66,8 +72,7 @@ static int get_sid_from_cli_string(DOM_SID *sid, const char *str_sid)
                                        "a complete SID or RID!\n");
                        return -1;
                }
-               sid_copy(sid, get_global_sam_sid());
-               sid_append_rid(sid, rid);
+               sid_compose(sid, get_global_sam_sid(), rid);
        }
 
        return 0;
@@ -102,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));
 
@@ -200,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;
@@ -224,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);
@@ -260,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));
@@ -327,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,
@@ -375,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;
 
@@ -433,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;
@@ -493,7 +498,8 @@ static int set_user_info(const char *username, const char *fullname,
                         const char *drive, const char *script,
                         const char *profile, const char *account_control,
                         const char *user_sid, const char *user_domain,
-                        const bool badpw, const bool hours)
+                        const bool badpw, const bool hours,
+                        const char *kickoff_time)
 {
        bool updated_autolock = False, updated_badpw = False;
        struct samu *sam_pwent;
@@ -502,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);
@@ -521,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)) {
@@ -578,6 +584,24 @@ static int set_user_info(const char *username, const char *fullname,
                pdb_set_bad_password_time(sam_pwent, 0, PDB_CHANGED);
        }
 
+       if (kickoff_time) {
+               char *endptr;
+               time_t value = get_time_t_max();
+
+               if (strcmp(kickoff_time, "never") != 0) {
+                       uint32_t num = strtoul(kickoff_time, &endptr, 10);
+
+                       if ((endptr == kickoff_time) || (endptr[0] != '\0')) {
+                               fprintf(stderr, "Failed to parse kickoff time\n");
+                               return -1;
+                       }
+
+                       value = convert_uint32_t_to_time_t(num);
+               }
+
+               pdb_set_kickoff_time(sam_pwent, value, PDB_CHANGED);
+       }
+
        if (NT_STATUS_IS_OK(pdb_update_sam_account(sam_pwent))) {
                print_user_info(username, True, False);
        } else {
@@ -598,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;
@@ -689,7 +713,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;
 
@@ -786,7 +810,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;
@@ -989,6 +1013,7 @@ int main (int argc, char **argv)
        static char *pwd_time_format = NULL;
        static int pw_from_stdin = False;
        struct pdb_methods *bin, *bout;
+       static char *kickoff_time = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
        NTSTATUS status;
        poptContext pc;
@@ -1025,6 +1050,7 @@ int main (int argc, char **argv)
                {"logon-hours-reset", 'Z', POPT_ARG_NONE, &hours_reset, 0, "reset logon hours", NULL},
                {"time-format", 0, POPT_ARG_STRING, &pwd_time_format, 0, "The time format for time parameters", NULL },
                {"password-from-stdin", 't', POPT_ARG_NONE, &pw_from_stdin, 0, "get password from standard in", NULL},
+               {"kickoff-time", 'K', POPT_ARG_STRING, &kickoff_time, 0, "set the kickoff time", NULL},
                POPT_COMMON_SAMBA
                POPT_TABLEEND
        };
@@ -1033,7 +1059,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);
@@ -1083,13 +1109,15 @@ int main (int argc, char **argv)
                        (backend_in ? BIT_IMPORT : 0) +
                        (backend_out ? BIT_EXPORT : 0) +
                        (badpw_reset ? BIT_BADPWRESET : 0) +
-                       (hours_reset ? BIT_LOGONHOURS : 0);
+                       (hours_reset ? BIT_LOGONHOURS : 0) +
+                       (kickoff_time ? BIT_KICKOFFTIME : 0) +
+                       (acct_desc ? BIT_DESCRIPTION : 0);
 
        if (setparms & BIT_BACKEND) {
                /* 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();
        }
@@ -1108,7 +1136,7 @@ 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;
@@ -1279,7 +1307,8 @@ int main (int argc, char **argv)
                                                     home_drive, logon_script,
                                                     profile_path, account_control,
                                                     user_sid, user_domain,
-                                                    badpw_reset, hours_reset);
+                                                    badpw_reset, hours_reset,
+                                                    kickoff_time);
                        }
                }
        }