mirror of
https://github.com/altlinux/admc.git
synced 2024-10-26 17:25:38 +03:00
append dollar sign to computer sam names
This commit is contained in:
parent
2bae36744e
commit
18bc548c75
@ -293,6 +293,11 @@ const long long MILLIS_TO_100_NANOS = 10000LL;
|
||||
#define SAM_APP_QUERY_GROUP 0x40000001
|
||||
#define SAM_ACCOUNT_TYPE_MAX 0x7fffffff
|
||||
|
||||
// NOTE: this is according to Microsoft, haven't found
|
||||
// any better source
|
||||
#define SAM_NAME_MAX_LENGTH 20
|
||||
#define SAM_NAME_COMPUTER_MAX_LENGTH 16
|
||||
|
||||
enum SearchScope {
|
||||
SearchScope_Object,
|
||||
SearchScope_Children,
|
||||
|
@ -124,6 +124,7 @@ set(ADMC_SOURCES
|
||||
attribute_edits/string_other_edit.cpp
|
||||
attribute_edits/string_large_edit.cpp
|
||||
attribute_edits/sam_name_edit.cpp
|
||||
attribute_edits/computer_sam_name_edit.cpp
|
||||
attribute_edits/country_edit.cpp
|
||||
attribute_edits/expiry_edit.cpp
|
||||
attribute_edits/expiry_widget.cpp
|
||||
|
88
src/admc/attribute_edits/computer_sam_name_edit.cpp
Normal file
88
src/admc/attribute_edits/computer_sam_name_edit.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* ADMC - AD Management Center
|
||||
*
|
||||
* Copyright (C) 2020-2021 BaseALT Ltd.
|
||||
* Copyright (C) 2020-2021 Dmitry Degtyarev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "attribute_edits/computer_sam_name_edit.h"
|
||||
|
||||
#include "adldap.h"
|
||||
#include "globals.h"
|
||||
#include "utils.h"
|
||||
#include "attribute_edits/sam_name_edit.h"
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QRegularExpression>
|
||||
|
||||
ComputerSamNameEdit::ComputerSamNameEdit(QLineEdit *edit_arg, QLineEdit *domain_edit, QObject *parent)
|
||||
: AttributeEdit(parent) {
|
||||
edit = edit_arg;
|
||||
|
||||
edit->setMaxLength(SAM_NAME_COMPUTER_MAX_LENGTH);
|
||||
|
||||
const QString domain_text = []() {
|
||||
const QString domain = g_adconfig->domain();
|
||||
const QString domain_name = domain.split(".")[0];
|
||||
const QString out = domain_name + "\\";
|
||||
|
||||
return out;
|
||||
}();
|
||||
|
||||
domain_edit->setText(domain_text);
|
||||
|
||||
connect(
|
||||
edit, &QLineEdit::textChanged,
|
||||
this, &AttributeEdit::edited);
|
||||
}
|
||||
|
||||
void ComputerSamNameEdit::load(AdInterface &ad, const AdObject &object) {
|
||||
UNUSED_ARG(ad);
|
||||
|
||||
// NOTE: display value without the '$' at the end
|
||||
const QString value = [&]() {
|
||||
QString out = object.get_string(ATTRIBUTE_SAM_ACCOUNT_NAME);
|
||||
|
||||
if (out.endsWith('$')) {
|
||||
out.chop(1);
|
||||
}
|
||||
|
||||
return out;
|
||||
}();
|
||||
edit->setText(value);
|
||||
}
|
||||
|
||||
// NOTE: requirements are from here
|
||||
// https://social.technet.microsoft.com/wiki/contents/articles/11216.active-directory-requirements-for-creating-objects.aspx#Note_Regarding_the_quot_quot_Character_in_sAMAccountName
|
||||
bool ComputerSamNameEdit::verify(AdInterface &ad, const QString &dn) const {
|
||||
UNUSED_ARG(ad);
|
||||
UNUSED_ARG(dn);
|
||||
|
||||
const bool out = sam_name_edit_verify(edit);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
bool ComputerSamNameEdit::apply(AdInterface &ad, const QString &dn) const {
|
||||
const QString new_value = QString("%1$").arg(edit->text());
|
||||
const bool success = ad.attribute_replace_string(dn, ATTRIBUTE_SAM_ACCOUNT_NAME, new_value);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void ComputerSamNameEdit::set_enabled(const bool enabled) {
|
||||
edit->setEnabled(enabled);
|
||||
}
|
43
src/admc/attribute_edits/computer_sam_name_edit.h
Normal file
43
src/admc/attribute_edits/computer_sam_name_edit.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* ADMC - AD Management Center
|
||||
*
|
||||
* Copyright (C) 2020-2021 BaseALT Ltd.
|
||||
* Copyright (C) 2020-2021 Dmitry Degtyarev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef COMPUTER_SAM_NAME_EDIT_H
|
||||
#define COMPUTER_SAM_NAME_EDIT_H
|
||||
|
||||
#include "attribute_edits/attribute_edit.h"
|
||||
|
||||
class QLineEdit;
|
||||
|
||||
class ComputerSamNameEdit final : public AttributeEdit {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ComputerSamNameEdit(QLineEdit *edit, QLineEdit *domain_edit, QObject *parent);
|
||||
|
||||
void load(AdInterface &ad, const AdObject &object) override;
|
||||
bool verify(AdInterface &ad, const QString &dn) const override;
|
||||
bool apply(AdInterface &ad, const QString &dn) const override;
|
||||
|
||||
void set_enabled(const bool enabled);
|
||||
|
||||
private:
|
||||
QLineEdit *edit;
|
||||
};
|
||||
|
||||
#endif /* COMPUTER_SAM_NAME_EDIT_H */
|
@ -27,28 +27,11 @@
|
||||
#include <QLineEdit>
|
||||
#include <QRegularExpression>
|
||||
|
||||
// NOTE: object class arg is required by ctor to set
|
||||
// edit length limit. Can't do this in load() because
|
||||
// create dialogs use sam name edit but never call
|
||||
// load() (because there's no object).
|
||||
SamNameEdit::SamNameEdit(QLineEdit *edit_arg, QLineEdit *domain_edit, const QString &object_class, QObject *parent)
|
||||
SamNameEdit::SamNameEdit(QLineEdit *edit_arg, QLineEdit *domain_edit, QObject *parent)
|
||||
: AttributeEdit(parent) {
|
||||
edit = edit_arg;
|
||||
|
||||
// NOTE: not using limit_edit() here because need
|
||||
// custom length here different from the upper
|
||||
// range defined in schema. According to microsoft,
|
||||
// it's 16 for computers and 20 for users, but
|
||||
// groups can also have sam names so defaulting to
|
||||
// value for users.
|
||||
const int max_length = [&]() {
|
||||
if (object_class == CLASS_COMPUTER) {
|
||||
return 16;
|
||||
} else {
|
||||
return 20;
|
||||
}
|
||||
}();
|
||||
edit->setMaxLength(max_length);
|
||||
edit->setMaxLength(SAM_NAME_MAX_LENGTH);
|
||||
|
||||
const QString domain_text = []() {
|
||||
const QString domain = g_adconfig->domain();
|
||||
@ -72,12 +55,18 @@ void SamNameEdit::load(AdInterface &ad, const AdObject &object) {
|
||||
edit->setText(value);
|
||||
}
|
||||
|
||||
// NOTE: requirements are from here
|
||||
// https://social.technet.microsoft.com/wiki/contents/articles/11216.active-directory-requirements-for-creating-objects.aspx#Note_Regarding_the_quot_quot_Character_in_sAMAccountName
|
||||
bool SamNameEdit::verify(AdInterface &ad, const QString &dn) const {
|
||||
UNUSED_ARG(ad);
|
||||
UNUSED_ARG(dn);
|
||||
|
||||
const bool out = sam_name_edit_verify(edit);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// NOTE: requirements are from here
|
||||
// https://social.technet.microsoft.com/wiki/contents/articles/11216.active-directory-requirements-for-creating-objects.aspx#Note_Regarding_the_quot_quot_Character_in_sAMAccountName
|
||||
bool sam_name_edit_verify(QLineEdit *edit) {
|
||||
const QString new_value = edit->text();
|
||||
|
||||
const bool contains_bad_chars = string_contains_bad_chars(new_value, SAM_NAME_BAD_CHARS);
|
||||
@ -87,8 +76,8 @@ bool SamNameEdit::verify(AdInterface &ad, const QString &dn) const {
|
||||
const bool value_is_valid = (!contains_bad_chars && !ends_with_dot);
|
||||
|
||||
if (!value_is_valid) {
|
||||
const QString error_text = QString(tr("Input field for Logon name (pre-Windows 2000) contains one or more of the following illegal characters: @ \" [ ] : ; | = + * ? < > / \\ ,"));
|
||||
message_box_warning(edit, tr("Error"), error_text);
|
||||
const QString error_text = QString(QCoreApplication::translate("SamNameEdit", "Input field for Logon name (pre-Windows 2000) contains one or more of the following illegal characters: @ \" [ ] : ; | = + * ? < > / \\ ,"));
|
||||
message_box_warning(edit, QCoreApplication::translate("SamNameEdit", "Error"), error_text);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class QLineEdit;
|
||||
class SamNameEdit final : public AttributeEdit {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SamNameEdit(QLineEdit *edit, QLineEdit *domain_edit, const QString &object_class, QObject *parent);
|
||||
SamNameEdit(QLineEdit *edit, QLineEdit *domain_edit, QObject *parent);
|
||||
|
||||
void load(AdInterface &ad, const AdObject &object) override;
|
||||
bool verify(AdInterface &ad, const QString &dn) const override;
|
||||
@ -40,4 +40,6 @@ private:
|
||||
QLineEdit *edit;
|
||||
};
|
||||
|
||||
bool sam_name_edit_verify(QLineEdit *edit);
|
||||
|
||||
#endif /* SAM_NAME_EDIT_H */
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "ui_create_computer_dialog.h"
|
||||
|
||||
#include "adldap.h"
|
||||
#include "attribute_edits/sam_name_edit.h"
|
||||
#include "attribute_edits/computer_sam_name_edit.h"
|
||||
#include "attribute_edits/upn_edit.h"
|
||||
#include "utils.h"
|
||||
#include "settings.h"
|
||||
@ -40,7 +40,7 @@ CreateComputerDialog::CreateComputerDialog(const QString &parent_dn, QWidget *pa
|
||||
// "The following user or group may join this computer to a domain". Tried to figure out how this is implemented and couldn't see any easy ways via attributes, so probably something to do with setting ACL'S.
|
||||
// "This is a managed computer" checkbox and an edit for guid/uuid which I assume modifies objectGUID?
|
||||
|
||||
auto sam_name_edit = new SamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, CLASS_COMPUTER, this);
|
||||
auto sam_name_edit = new ComputerSamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, this);
|
||||
|
||||
const QList<AttributeEdit *> edit_list = {
|
||||
sam_name_edit,
|
||||
|
@ -38,7 +38,7 @@ CreateGroupDialog::CreateGroupDialog(const QString &parent_dn, QWidget *parent)
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
auto sam_name_edit = new SamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, CLASS_GROUP, this);
|
||||
auto sam_name_edit = new SamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, this);
|
||||
auto scope_edit = new GroupScopeEdit(ui->scope_combo, this);
|
||||
auto type_edit = new GroupTypeEdit(ui->type_combo, this);
|
||||
|
||||
|
@ -41,7 +41,7 @@ CreateUserDialog::CreateUserDialog(AdInterface &ad, const QString &parent_dn, QW
|
||||
auto first_name_edit = new StringEdit(ui->first_name_edit, ATTRIBUTE_FIRST_NAME, this);
|
||||
auto last_name_edit = new StringEdit(ui->last_name_edit, ATTRIBUTE_LAST_NAME, this);
|
||||
auto initials_edit = new StringEdit(ui->initials_edit, ATTRIBUTE_INITIALS, this);
|
||||
auto sam_name_edit = new SamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, CLASS_USER, this);
|
||||
auto sam_name_edit = new SamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, this);
|
||||
auto password_edit = new PasswordEdit(ui->password_main_edit, ui->password_confirm_edit, this);
|
||||
|
||||
auto upn_edit = new UpnEdit(ui->upn_prefix_edit, ui->upn_suffix_edit, this);
|
||||
|
@ -31,7 +31,7 @@ RenameGroupDialog::RenameGroupDialog(AdInterface &ad, const QString &target_arg,
|
||||
ui = new Ui::RenameGroupDialog();
|
||||
ui->setupUi(this);
|
||||
|
||||
auto sam_name_edit = new SamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, CLASS_GROUP, this);
|
||||
auto sam_name_edit = new SamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, this);
|
||||
|
||||
const QList<AttributeEdit *> edit_list = {
|
||||
sam_name_edit,
|
||||
|
@ -41,7 +41,7 @@ RenameUserDialog::RenameUserDialog(AdInterface &ad, const QString &target_arg, Q
|
||||
auto upn_edit = new UpnEdit(ui->upn_prefix_edit, ui->upn_suffix_edit, this);
|
||||
upn_edit->init_suffixes(ad);
|
||||
|
||||
auto sam_name_edit = new SamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, CLASS_USER, this);
|
||||
auto sam_name_edit = new SamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, this);
|
||||
|
||||
const QList<AttributeEdit *> edit_list = {
|
||||
first_name_edit,
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
#include "adldap.h"
|
||||
#include "attribute_edits/general_name_edit.h"
|
||||
#include "attribute_edits/sam_name_edit.h"
|
||||
#include "attribute_edits/computer_sam_name_edit.h"
|
||||
#include "attribute_edits/string_edit.h"
|
||||
|
||||
GeneralComputerTab::GeneralComputerTab(QList<AttributeEdit *> *edit_list, QWidget *parent)
|
||||
@ -32,7 +32,7 @@ GeneralComputerTab::GeneralComputerTab(QList<AttributeEdit *> *edit_list, QWidge
|
||||
ui->setupUi(this);
|
||||
|
||||
auto name_edit = new GeneralNameEdit(ui->name_label, this);
|
||||
auto sam_name_edit = new SamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, CLASS_COMPUTER, this);
|
||||
auto sam_name_edit = new ComputerSamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, this);
|
||||
auto dns_edit = new StringEdit(ui->dns_host_name_edit, ATTRIBUTE_DNS_HOST_NAME, this);
|
||||
auto description_edit = new StringEdit(ui->description_edit, ATTRIBUTE_DESCRIPTION, this);
|
||||
auto location_edit = new StringEdit(ui->location_edit, ATTRIBUTE_LOCATION, this);
|
||||
|
@ -34,7 +34,7 @@ GeneralGroupTab::GeneralGroupTab(QList<AttributeEdit *> *edit_list, QWidget *par
|
||||
ui->setupUi(this);
|
||||
|
||||
auto name_edit = new GeneralNameEdit(ui->name_label, this);
|
||||
auto sam_name_edit = new SamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, CLASS_GROUP, this);
|
||||
auto sam_name_edit = new SamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, this);
|
||||
auto description_edit = new StringEdit(ui->description_edit, ATTRIBUTE_DESCRIPTION, this);
|
||||
auto email_edit = new StringEdit(ui->email_edit, ATTRIBUTE_MAIL, this);
|
||||
auto notes_edit = new StringEdit(ui->notes_edit, ATTRIBUTE_INFO, this);
|
||||
|
Loading…
Reference in New Issue
Block a user