Skip to content

Commit

Permalink
fixed realm, better logging
Browse files Browse the repository at this point in the history
* realm setting is now properly used
* improved logging, might be tuned in the future
* added ssl and crypto flags to linker
  • Loading branch information
nilsbehlen committed Sep 22, 2023
1 parent 73a1917 commit d78f8d2
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 73 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CC = g++
CFLAGS = -g -Wall -fPIC -Iinclude
LDFLAGS = -Wno-undef -lcurl --shared
LDFLAGS = -Wno-undef -lcurl -lcrypto -lssl --shared

# Determine which folder to use
libdir.x86_64 = /lib64/security
Expand All @@ -10,7 +10,7 @@ MACHINE := $(shell uname -m)
libdir = $(libdir.$(MACHINE))

target = pam_privacyidea.so
objects = src/pam_privacyidea.o src/PrivacyIDEA.o
objects = src/pam_privacyidea.o src/privacyidea.o

all: pam_privacyidea.so

Expand Down
Empty file modified include/config.h
100644 → 100755
Empty file.
6 changes: 4 additions & 2 deletions include/privacyIDEA.h → include/privacyidea.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "response.h"
#include "json.hpp"

#define PAM_PRIVACYIDEA_USERAGENT "privacyidea-pam/1.0.0"
#define PAM_PRIVACYIDEA_USERAGENT "PAM/1.0.0"

#define OFFLINE_SUCCESS 0
#define OFFLINE_FAIL 1
Expand All @@ -22,7 +22,7 @@
class PrivacyIDEA
{
public:
PrivacyIDEA(pam_handle_t* pamh, std::string baseURL, bool sslVerify, std::string offlineFile, bool debug);
PrivacyIDEA(pam_handle_t* pamh, std::string baseURL, std::string realm, bool sslVerify, std::string offlineFile, bool debug);

~PrivacyIDEA();

Expand All @@ -45,6 +45,7 @@ class PrivacyIDEA

std::string baseURL;
bool sslVerify;
std::string realm;

std::string offlineFile = "/etc/privacyidea/pam.txt";
nlohmann::json offlineData;
Expand All @@ -54,6 +55,7 @@ class PrivacyIDEA
std::string base64Encode(const unsigned char* data, size_t length);

std::vector<unsigned char> base64Decode(const std::string& encoded_string);

// Returns the outer right value of the passlib format and cuts it off the input string including the $
std::string getNextValue(std::string& in);

Expand Down
Empty file modified include/response.h
100644 → 100755
Empty file.
22 changes: 18 additions & 4 deletions src/pam_privacyidea.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <unistd.h>
#include <stdbool.h>
#include <syslog.h>
#include "privacyIDEA.h"
#include "privacyidea.h"
#include "config.h"
#include "response.h"

Expand Down Expand Up @@ -54,49 +54,63 @@ static int pam_prompt(pam_handle_t *pamh, int msg_style, const char *prompt, std
return retval;
}

void getConfig(int argc, const char **argv, Config &config)
void getConfig(pam_handle_t *pamh, int argc, const char **argv, Config &config)
{
for (int i = 0; i < argc; i++)
{
char *pArg;
memcpy(&pArg, &argv[i], sizeof(pArg));
string tmp(pArg);
//pam_syslog(pamh, LOG_DEBUG, "Argument: %s\n", tmp.c_str());

if (tmp.rfind("url=", 0) == 0)
{
config.url = tmp.substr(4);
pam_syslog(pamh, LOG_DEBUG, "Setting url=%s\n", config.url.c_str());
}
else if (tmp == "debug")
{
config.debug = true;
pam_syslog(pamh, LOG_DEBUG, "Setting debug=true\n");
}
else if (tmp == "nossl")
{
config.disableSSLVerify = true;
pam_syslog(pamh, LOG_DEBUG, "Setting nossl=true\n");
}
else if (tmp == "sendEmptyPass")
{
config.sendEmptyPass = true;
pam_syslog(pamh, LOG_DEBUG, "Setting sendEmptyPass=true\n");
}
else if (tmp == "sendPassword")
{
config.sendPassword = true;
pam_syslog(pamh, LOG_DEBUG, "Setting sendPassword=true\n");
}
else if (tmp.rfind("realm=", 0) == 0)
{
config.realm = tmp.substr(6);
pam_syslog(pamh, LOG_DEBUG, "Setting realm=%s\n", config.realm.c_str());
}
else if (tmp.rfind("offlineFile=", 0) == 0)
{
config.offlineFile = tmp.substr(12);
pam_syslog(pamh, LOG_DEBUG, "Setting offlineFile=%s\n", config.offlineFile.c_str());
}
else if (tmp.rfind("prompt=", 0) == 0)
{
config.promptText = tmp.substr(7);
pam_syslog(pamh, LOG_DEBUG, "Setting prompt=%s\n", config.promptText.c_str());
}
else if (tmp.rfind("pollTime=", 0) == 0)
{
config.pollTimeInSeconds = atoi(tmp.substr(9,11).c_str());
pam_syslog(pamh, LOG_DEBUG, "Setting pollTime=%i\n", config.pollTimeInSeconds);
}
else
{
pam_syslog(pamh, LOG_DEBUG, "Unknown Argument: %s\n", tmp.c_str());
}
}
}
Expand Down Expand Up @@ -145,8 +159,8 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, cons
}

Config config;
getConfig(argc, argv, config);
PrivacyIDEA privacyidea(pamh, config.url, !config.disableSSLVerify, config.offlineFile, config.debug);
getConfig(pamh, argc, argv, config);
PrivacyIDEA privacyidea(pamh, config.url, config.realm, !config.disableSSLVerify, config.offlineFile, config.debug);

// Username
int retval = PAM_SUCCESS;
Expand Down
Loading

0 comments on commit d78f8d2

Please sign in to comment.