You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.7 KiB
57 lines
1.7 KiB
#include "pamtest.h"
|
|
|
|
#include <QDebug>
|
|
|
|
#include <security/pam_appl.h>
|
|
|
|
PamTest::PamTest(QObject *parent)
|
|
: QObject (parent)
|
|
{
|
|
}
|
|
|
|
PamTest::~PamTest()
|
|
{
|
|
}
|
|
|
|
void PamTest::startPam()
|
|
{
|
|
pam_handle_t *pamHandle = nullptr;
|
|
pam_conv conv = {PAMConversation, static_cast<void *>(this)};
|
|
// pam_start第一個參數對應於/etc/pam.d下面的指定的PAM文件,第二個參數對應於登錄的賬戶名
|
|
int ret = pam_start("test_pam", "uos", &conv, &pamHandle);
|
|
if (ret != PAM_SUCCESS) {
|
|
//qCritical() << "ERROR: PAM start failed, error: " << pam_strerror(pamHandle, ret) << ", start infomation: " << ret;
|
|
} else {
|
|
qDebug() << "PAM start...";
|
|
}
|
|
|
|
// 可以在此處設置密碼
|
|
//const char *password = "testpassword";
|
|
//pam_set_item(pamHandle, PAM_AUTHTOK, password);
|
|
|
|
int rc = pam_authenticate(pamHandle, 0);
|
|
if (rc != PAM_SUCCESS) {
|
|
//qWarning() << "PAM authenticate failed, error: " << pam_strerror(pamHandle, rc) << ", PAM authenticate: " << rc;
|
|
} else {
|
|
qDebug() << "PAM authenticate finished.";
|
|
}
|
|
|
|
int tmpRt = pam_acct_mgmt(pamHandle, 1);
|
|
if (tmpRt != PAM_SUCCESS) {
|
|
//qCritical() << "PAM acct failed:" << pam_strerror(pamHandle, tmpRt) << "PAM end infomation: " << tmpRt;
|
|
} else {
|
|
qDebug() << "PAM acct finished.";
|
|
}
|
|
|
|
int re = pam_end(pamHandle, rc);
|
|
if (re != PAM_SUCCESS) {
|
|
//qCritical() << "PAM end failed:" << pam_strerror(pamHandle, re) << "PAM end infomation: " << re;
|
|
} else {
|
|
qDebug() << "PAM end...";
|
|
}
|
|
}
|
|
|
|
int PamTest::PAMConversation(int num_msg, const pam_message **msg, pam_response **resp, void *app_data)
|
|
{
|
|
return PAM_SUCCESS;
|
|
}
|
|
|