📄 pdbedit.c
字号:
static char *logon_script = NULL; static char *profile_path = NULL; static char *user_domain = NULL; static char *account_control = NULL; static char *account_policy = NULL; static char *user_sid = NULL; static char *group_sid = NULL; static long int account_policy_value = 0; BOOL account_policy_value_set = False; static BOOL badpw_reset = False; static BOOL hours_reset = False; static char *pwd_can_change_time = NULL; static char *pwd_must_change_time = NULL; static char *pwd_time_format = NULL; static BOOL pw_from_stdin = False; struct pdb_context *bin; struct pdb_context *bout; struct pdb_context *bdef; poptContext pc; struct poptOption long_options[] = { POPT_AUTOHELP {"list", 'L', POPT_ARG_NONE, &list_users, 0, "list all users", NULL}, {"verbose", 'v', POPT_ARG_NONE, &verbose, 0, "be verbose", NULL }, {"smbpasswd-style", 'w',POPT_ARG_NONE, &spstyle, 0, "give output in smbpasswd style", NULL}, {"user", 'u', POPT_ARG_STRING, &user_name, 0, "use username", "USER" }, {"account-desc", 'N', POPT_ARG_STRING, &acct_desc, 0, "set account description", NULL}, {"fullname", 'f', POPT_ARG_STRING, &full_name, 0, "set full name", NULL}, {"homedir", 'h', POPT_ARG_STRING, &home_dir, 0, "set home directory", NULL}, {"drive", 'D', POPT_ARG_STRING, &home_drive, 0, "set home drive", NULL}, {"script", 'S', POPT_ARG_STRING, &logon_script, 0, "set logon script", NULL}, {"profile", 'p', POPT_ARG_STRING, &profile_path, 0, "set profile path", NULL}, {"domain", 'I', POPT_ARG_STRING, &user_domain, 0, "set a users' domain", NULL}, {"user SID", 'U', POPT_ARG_STRING, &user_sid, 0, "set user SID or RID", NULL}, {"group SID", 'G', POPT_ARG_STRING, &group_sid, 0, "set group SID or RID", NULL}, {"create", 'a', POPT_ARG_NONE, &add_user, 0, "create user", NULL}, {"modify", 'r', POPT_ARG_NONE, &modify_user, 0, "modify user", NULL}, {"machine", 'm', POPT_ARG_NONE, &machine, 0, "account is a machine account", NULL}, {"delete", 'x', POPT_ARG_NONE, &delete_user, 0, "delete user", NULL}, {"backend", 'b', POPT_ARG_STRING, &backend, 0, "use different passdb backend as default backend", NULL}, {"import", 'i', POPT_ARG_STRING, &backend_in, 0, "import user accounts from this backend", NULL}, {"export", 'e', POPT_ARG_STRING, &backend_out, 0, "export user accounts to this backend", NULL}, {"group", 'g', POPT_ARG_NONE, &transfer_groups, 0, "use -i and -e for groups", NULL}, {"policies", 'y', POPT_ARG_NONE, &transfer_account_policies, 0, "use -i and -e to move account policies between backends", NULL}, {"policies-reset", 0, POPT_ARG_NONE, &reset_account_policies, 0, "restore default policies", NULL}, {"account-policy", 'P', POPT_ARG_STRING, &account_policy, 0,"value of an account policy (like maximum password age)",NULL}, {"value", 'C', POPT_ARG_LONG, &account_policy_value, 'C',"set the account policy to this value", NULL}, {"account-control", 'c', POPT_ARG_STRING, &account_control, 0, "Values of account control", NULL}, {"force-initialized-passwords", 0, POPT_ARG_NONE, &force_initialised_password, 0, "Force initialization of corrupt password strings in a passdb backend", NULL}, {"bad-password-count-reset", 'z', POPT_ARG_NONE, &badpw_reset, 0, "reset bad password count", NULL}, {"logon-hours-reset", 'Z', POPT_ARG_NONE, &hours_reset, 0, "reset logon hours", NULL}, {"pwd-can-change-time", 0, POPT_ARG_STRING, &pwd_can_change_time, 0, "Set password can change time (unix time in seconds since 1970 if time format not provided)", NULL }, {"pwd-must-change-time", 0, POPT_ARG_STRING, &pwd_must_change_time, 0, "Set password must change time (unix time in seconds since 1970 if time format not provided)", 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}, POPT_COMMON_SAMBA POPT_TABLEEND }; load_case_tables(); setup_logging("pdbedit", True); pc = poptGetContext(NULL, argc, (const char **) argv, long_options, POPT_CONTEXT_KEEP_FIRST); while((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case 'C': account_policy_value_set = True; break; } } poptGetArg(pc); /* Drop argv[0], the program name */ if (user_name == NULL) user_name = poptGetArg(pc); if (!lp_load(dyn_CONFIGFILE,True,False,False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE); exit(1); } if(!initialize_password_db(False)) exit(1); if (!init_names()) exit(1); setparms = (backend ? BIT_BACKEND : 0) + (verbose ? BIT_VERBOSE : 0) + (spstyle ? BIT_SPSTYLE : 0) + (full_name ? BIT_FULLNAME : 0) + (home_dir ? BIT_HOMEDIR : 0) + (home_drive ? BIT_HDIRDRIVE : 0) + (logon_script ? BIT_LOGSCRIPT : 0) + (profile_path ? BIT_PROFILE : 0) + (user_domain ? BIT_USERDOMAIN : 0) + (machine ? BIT_MACHINE : 0) + (user_name ? BIT_USER : 0) + (list_users ? BIT_LIST : 0) + (force_initialised_password ? BIT_FIX_INIT : 0) + (modify_user ? BIT_MODIFY : 0) + (add_user ? BIT_CREATE : 0) + (delete_user ? BIT_DELETE : 0) + (account_control ? BIT_ACCTCTRL : 0) + (account_policy ? BIT_ACCPOLICY : 0) + (account_policy_value_set ? BIT_ACCPOLVAL : 0) + (backend_in ? BIT_IMPORT : 0) + (backend_out ? BIT_EXPORT : 0) + (badpw_reset ? BIT_BADPWRESET : 0) + (hours_reset ? BIT_LOGONHOURS : 0) + (pwd_can_change_time ? BIT_CAN_CHANGE: 0) + (pwd_must_change_time ? BIT_MUST_CHANGE: 0); if (setparms & BIT_BACKEND) { if (!NT_STATUS_IS_OK(make_pdb_context_string(&bdef, backend))) { fprintf(stderr, "Can't initialize passdb backend.\n"); return 1; } } else { if (!NT_STATUS_IS_OK(make_pdb_context_list(&bdef, lp_passdb_backend()))) { fprintf(stderr, "Can't initialize passdb backend.\n"); return 1; } } /* the lowest bit options are always accepted */ checkparms = setparms & ~MASK_ALWAYS_GOOD; if (checkparms & BIT_FIX_INIT) { return fix_users_list(bdef); } /* account policy operations */ if ((checkparms & BIT_ACCPOLICY) && !(checkparms & ~(BIT_ACCPOLICY + BIT_ACCPOLVAL))) { uint32 value; int field = account_policy_name_to_fieldnum(account_policy); if (field == 0) { char *apn = account_policy_names_list(); fprintf(stderr, "No account policy by that name\n"); if (apn) { fprintf(stderr, "Account policy names are :\n%s\n", apn); } SAFE_FREE(apn); exit(1); } if (!pdb_get_account_policy(field, &value)) { fprintf(stderr, "valid account policy, but unable to fetch value!\n"); if (!account_policy_value_set) exit(1); } printf("account policy \"%s\" description: %s\n", account_policy, account_policy_get_desc(field)); if (account_policy_value_set) { printf("account policy \"%s\" value was: %u\n", account_policy, value); if (!pdb_set_account_policy(field, account_policy_value)) { fprintf(stderr, "valid account policy, but unable to set value!\n"); exit(1); } printf("account policy \"%s\" value is now: %lu\n", account_policy, account_policy_value); exit(0); } else { printf("account policy \"%s\" value is: %u\n", account_policy, value); exit(0); } } if (reset_account_policies) { if (!reinit_account_policies()) { exit(1); } exit(0); } /* import and export operations */ if (((checkparms & BIT_IMPORT) || (checkparms & BIT_EXPORT)) && !(checkparms & ~(BIT_IMPORT +BIT_EXPORT +BIT_USER))) { if (backend_in) { if (!NT_STATUS_IS_OK(make_pdb_context_string(&bin, backend_in))) { fprintf(stderr, "Can't initialize passdb backend.\n"); return 1; } } else { bin = bdef; } if (backend_out) { if (!NT_STATUS_IS_OK(make_pdb_context_string(&bout, backend_out))) { fprintf(stderr, "Can't initialize %s.\n", backend_out); return 1; } } else { bout = bdef; } if (transfer_account_policies) { if (!(checkparms & BIT_USER)) return export_account_policies(bin, bout); } else if (transfer_groups) { if (!(checkparms & BIT_USER)) return export_groups(bin, bout); } else { if (checkparms & BIT_USER) return export_database(bin, bout, user_name); else return export_database(bin, bout, NULL); } } /* if BIT_USER is defined but nothing else then threat it as -l -u for compatibility */ /* fake up BIT_LIST if only BIT_USER is defined */ if ((checkparms & BIT_USER) && !(checkparms & ~BIT_USER)) { checkparms += BIT_LIST; } /* modify flag is optional to maintain backwards compatibility */ /* fake up BIT_MODIFY if BIT_USER and at least one of MASK_USER_GOOD is defined */ if (!((checkparms & ~MASK_USER_GOOD) & ~BIT_USER) && (checkparms & MASK_USER_GOOD)) { checkparms += BIT_MODIFY; } /* list users operations */ if (checkparms & BIT_LIST) { if (!(checkparms & ~BIT_LIST)) { return print_users_list (bdef, verbose, spstyle); } if (!(checkparms & ~(BIT_USER + BIT_LIST))) { return print_user_info (bdef, user_name, verbose, spstyle); } } /* mask out users options */ checkparms &= ~MASK_USER_GOOD; /* if bad password count is reset, we must be modifying */ if (checkparms & BIT_BADPWRESET) { checkparms |= BIT_MODIFY; checkparms &= ~BIT_BADPWRESET; } /* if logon hours is reset, must modify */ if (checkparms & BIT_LOGONHOURS) { checkparms |= BIT_MODIFY; checkparms &= ~BIT_LOGONHOURS; } /* account operation */ if ((checkparms & BIT_CREATE) || (checkparms & BIT_MODIFY) || (checkparms & BIT_DELETE)) { /* check use of -u option */ if (!(checkparms & BIT_USER)) { fprintf (stderr, "Username not specified! (use -u option)\n"); return -1; } /* account creation operations */ if (!(checkparms & ~(BIT_CREATE + BIT_USER + BIT_MACHINE))) { if (checkparms & BIT_MACHINE) { return new_machine (bdef, user_name); } else { return new_user (bdef, user_name, full_name, home_dir, home_drive, logon_script, profile_path, user_sid, group_sid, pw_from_stdin); } } /* account deletion operations */ if (!(checkparms & ~(BIT_DELETE + BIT_USER + BIT_MACHINE))) { if (checkparms & BIT_MACHINE) { return delete_machine_entry (bdef, user_name); } else { return delete_user_entry (bdef, user_name); } } /* account modification operations */ if (!(checkparms & ~(BIT_MODIFY + BIT_USER))) { time_t pwd_can_change = -1; time_t pwd_must_change = -1; const char *errstr; if (pwd_can_change_time) { errstr = "can"; if (pwd_time_format) { struct tm tm; char *ret; memset(&tm, 0, sizeof(struct tm)); ret = strptime(pwd_can_change_time, pwd_time_format, &tm); if (ret == NULL || *ret != '\0') { goto error; } pwd_can_change = mktime(&tm); if (pwd_can_change == -1) { goto error; } } else { /* assume it is unix time */ errno = 0; pwd_can_change = strtol(pwd_can_change_time, NULL, 10); if (errno) { goto error; } } } if (pwd_must_change_time) { errstr = "must"; if (pwd_time_format) { struct tm tm; char *ret; memset(&tm, 0, sizeof(struct tm)); ret = strptime(pwd_must_change_time, pwd_time_format, &tm); if (ret == NULL || *ret != '\0') { goto error; } pwd_must_change = mktime(&tm); if (pwd_must_change == -1) { goto error; } } else { /* assume it is unix time */ errno = 0; pwd_must_change = strtol(pwd_must_change_time, NULL, 10); if (errno) { goto error; } } } return set_user_info (bdef, user_name, full_name, home_dir, acct_desc, home_drive, logon_script, profile_path, account_control, user_sid, group_sid, user_domain, badpw_reset, hours_reset, pwd_can_change, pwd_must_change);error: fprintf (stderr, "Error parsing the time in pwd-%s-change-time!\n", errstr); return -1; } } if (setparms >= 0x20) { fprintf (stderr, "Incompatible or insufficient options on command line!\n"); } poptPrintHelp(pc, stderr, 0); return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -