@ -1,5 +1,5 @@
/***************************************************************************
* Copyright ( C ) 2012 - 201 5 by Timothy Pearson *
* Copyright ( C ) 2012 - 201 3 by Timothy Pearson *
* kb9vqf @ pearsoncomputing . net *
* *
* This program is free software ; you can redistribute it and / or modify *
@ -21,19 +21,16 @@
# ifndef _LIBTDELDAP_H_
# define _LIBTDELDAP_H_
# include <stdint.h>
# include <unistd.h>
# include <sys/stat.h>
# include <ldap.h>
# include <kadm5/admin.h>
# include <tqobject.h>
# include <tqstring.h>
# include <tqdatetime.h>
# include <tqvaluelist.h>
# include <tqfile.h>
# include < tde simpleconfig.h>
# include < k simpleconfig.h>
// FIXME
// Connect this to CMake/Automake
@ -50,8 +47,6 @@
# define KERBEROS_PKI_PEM_FILE KERBEROS_PKI_ANCHORDIR "tdeca.pem"
# define KERBEROS_PKI_PEMKEY_FILE KERBEROS_PKI_ANCHORDIR "tdeca.key.pem"
# define KERBEROS_PKI_CRL_FILE KERBEROS_PKI_ANCHORDIR "tdecrl.pem"
# define KERBEROS_PKI_CRLDB_FILE KERBEROS_PKI_ANCHORDIR "tdecrl.db"
# define KERBEROS_PKI_KDC_FILE KERBEROS_PKI_PUBLICDIR "@@@KDCSERVER@@@.pki.crt"
# define KERBEROS_PKI_KDCKEY_FILE KERBEROS_PKI_PRIVATEDIR "@@@KDCSERVER@@@.pki.key"
# define KERBEROS_PKI_KDCREQ_FILE KERBEROS_PKI_PRIVATEDIR "@@@KDCSERVER@@@.pki.req"
@ -59,23 +54,14 @@
# define LDAP_CERT_FILE KERBEROS_PKI_PUBLICDIR "@@@ADMINSERVER@@@.ldap.crt"
# define LDAP_CERTKEY_FILE KERBEROS_PKI_PRIVATEDIR "@@@ADMINSERVER@@@.ldap.key"
# define LDAP_CERTREQ_FILE KERBEROS_PKI_PRIVATEDIR "@@@ADMINSERVER@@@.ldap.req"
# define LDAP_CERTREVOC_FILE KERBEROS_PKI_PUBLICDIR "@@@ADMINSERVER@@@.ldap.crl"
# define OPENSSL_EXTENSIONS_FILE TDE_CERTIFICATE_DIR " o penssl.cfg "
# define OPENSSL_EXTENSIONS_FILE TDE_CERTIFICATE_DIR " pki_ext ension s"
# define DEFAULT_IGNORED_USERS_LIST "avahi,avahi-autoipd,backup,bin,colord,daemon,games,gnats,haldaemon,hplip,irc,klog,landscape,libuuid,list,lp,mail,man,messagebus,news,ntp,polkituser,postfix,proxy,pulse,root,rtkit,saned,sshd,statd,sync,sys,syslog,timidity,usbmux,uucp,www-data"
# define CRON_UPDATE_PRIMARY_REALM_CERTIFICATES_FILE " / etc / cron.daily / tde-upd-pri-rlm-certs"
# define CRON_UPDATE_PRIMARY_REALM_CERTIFICATES_COMMAND TDE_BINDIR " / primaryrccertupdater"
// 1 year
# define KERBEROS_PKI_PEMKEY_EXPIRY_DAYS 365
// 1 month
# define KERBEROS_PKI_CRL_EXPIRY_DAYS 30
# define KERBEROS_PKI_KRB_EXPIRY_DAYS 30
# define KERBEROS_PKI_LDAP_EXPIRY_DAYS 30
// Values from hdb.asn1
enum LDAPKRB5Flags {
KRB5_INITIAL = 0x00000001 ,
@ -155,20 +141,7 @@ inline KRB5TicketFlags operator&(KRB5TicketFlags a, KRB5TicketFlags b)
typedef TQValueList < uid_t > UserList ;
typedef TQValueList < gid_t > GroupList ;
namespace PKICertificateStatus {
enum PKICertificateStatusEnum {
Invalid = 0 ,
Valid = 1 ,
Revoked = 2
} ;
}
typedef TQValueList < TQByteArray > TQByteArrayList ;
typedef TQPair < uint32_t , TQByteArray > PKICertificateEntry ;
typedef TQValueList < PKICertificateEntry > PKICertificateEntryList ;
class TDE_EXPORT LDAPCredentials
class KDE_EXPORT LDAPCredentials
{
public :
LDAPCredentials ( ) ;
@ -176,16 +149,15 @@ class TDE_EXPORT LDAPCredentials
public :
TQString username ;
TQ String password ;
TQ C String password ;
TQString realm ;
bool use_tls ;
bool use_gssapi ;
bool use_smartcard ;
TQString service ;
} ;
// PRIVATE
class T DE_EXPORT LDAPRealmConfig
class K DE_EXPORT LDAPRealmConfig
{
public :
TQString name ;
@ -201,16 +173,11 @@ class TDE_EXPORT LDAPRealmConfig
bool pkinit_require_krbtgt_otherName ;
bool win2k_pkinit ;
bool win2k_pkinit_require_binding ;
TQString certificate_revocation_list_url ;
} ;
// PRIVATE
class T DE_EXPORT LDAPCertConfig
class K DE_EXPORT LDAPCertConfig
{
public :
LDAPCertConfig ( ) ;
~ LDAPCertConfig ( ) ;
public :
bool generate_certs ;
TQString provided_kerberos_pem ;
@ -220,11 +187,6 @@ class TDE_EXPORT LDAPCertConfig
TQString provided_ldap_crt ;
TQString provided_ldap_key ;
int caExpiryDays ;
int caCrlExpiryDays ;
int kerberosExpiryDays ;
int ldapExpiryDays ;
TQString countryName ;
TQString stateOrProvinceName ;
TQString localityName ;
@ -235,15 +197,13 @@ class TDE_EXPORT LDAPCertConfig
} ;
// PRIVATE
class T DE_EXPORT LDAPPamConfig
class K DE_EXPORT LDAPPamConfig
{
public :
LDAPPamConfig ( ) ;
~ LDAPPamConfig ( ) ;
public :
bool enable_pkcs11_login ;
int pkcs11_login_card_slot ;
bool enable_cached_credentials ;
bool autocreate_user_directories_enable ;
mode_t autocreate_user_directories_umask ;
@ -251,7 +211,7 @@ class TDE_EXPORT LDAPPamConfig
} ;
// PRIVATE
class T DE_EXPORT LDAPClientRealmConfig
class K DE_EXPORT LDAPClientRealmConfig
{
public :
bool enable_bonding ;
@ -274,7 +234,7 @@ class TDE_EXPORT LDAPClientRealmConfig
typedef TQMap < TQString , LDAPRealmConfig > LDAPRealmConfigList ;
class T DE_EXPORT LDAPUserInfo
class K DE_EXPORT LDAPUserInfo
{
public :
LDAPUserInfo ( ) ;
@ -292,7 +252,7 @@ class TDE_EXPORT LDAPUserInfo
gid_t primary_gid ;
bool tde_builtin_account ;
LDAPKRB5Flags status ; // Default active user is 586 [KRB5_ACTIVE_DEFAULT] and locked out user is 7586 [KRB5_DISABLED_ACCOUNT]
TQ String new_password ;
TQ C String new_password ;
TQDateTime account_created ;
TQDateTime account_modified ;
TQDateTime password_last_changed ;
@ -352,12 +312,9 @@ class TDE_EXPORT LDAPUserInfo
TQString businessCategory ;
TQString carLicense ;
TQString notes ;
// PKI
PKICertificateEntryList pkiCertificates ;
} ;
class T DE_EXPORT LDAPGroupInfo
class KDE_EXPORT LDAPGroupInfo
{
public :
LDAPGroupInfo ( ) ;
@ -374,7 +331,7 @@ class TDE_EXPORT LDAPGroupInfo
TQStringList userlist ;
} ;
class T DE_EXPORT LDAPMachineInfo
class K DE_EXPORT LDAPMachineInfo
{
public :
LDAPMachineInfo ( ) ;
@ -391,7 +348,7 @@ class TDE_EXPORT LDAPMachineInfo
LDAPKRB5Flags status ; // Default is 126 [KRB5_MACHINE_ACCOUNT_DEFAULT]
} ;
class T DE_EXPORT LDAPServiceInfo
class K DE_EXPORT LDAPServiceInfo
{
public :
LDAPServiceInfo ( ) ;
@ -409,7 +366,7 @@ class TDE_EXPORT LDAPServiceInfo
LDAPKRB5Flags status ; // Default is 126 [KRB5_SERVICE_PRINCIPAL_DEFAULT]
} ;
class T DE_EXPORT LDAPTDEBuiltinsInfo
class K DE_EXPORT LDAPTDEBuiltinsInfo
{
public :
LDAPTDEBuiltinsInfo ( ) ;
@ -423,7 +380,7 @@ class TDE_EXPORT LDAPTDEBuiltinsInfo
TQString builtinStandardUserGroup ;
} ;
class T DE_EXPORT LDAPMasterReplicationMapping
class K DE_EXPORT LDAPMasterReplicationMapping
{
public :
LDAPMasterReplicationMapping ( ) ;
@ -436,7 +393,7 @@ class TDE_EXPORT LDAPMasterReplicationMapping
typedef TQValueList < LDAPMasterReplicationMapping > LDAPMasterReplicationMap ;
class T DE_EXPORT LDAPMasterReplicationInfo
class K DE_EXPORT LDAPMasterReplicationInfo
{
public :
LDAPMasterReplicationInfo ( ) ;
@ -450,14 +407,14 @@ class TDE_EXPORT LDAPMasterReplicationInfo
int timeout ;
int syncMethod ;
TQString syncDN ;
TQ String syncPassword ;
TQ C String syncPassword ;
TQString certificateFile ;
TQString caCertificateFile ;
bool ignore_ssl_failure ;
bool replicate_olcGlobal ;
} ;
class T DE_EXPORT KerberosTicketInfo
class K DE_EXPORT KerberosTicketInfo
{
public :
KerberosTicketInfo ( ) ;
@ -488,8 +445,8 @@ typedef TQValueList<KerberosTicketInfo> KerberosTicketInfoList;
class PtyProcess ;
class T DE_EXPORT LDAPManager : public TQObject {
T Q_OBJECT
class K DE_EXPORT LDAPManager : public TQObject {
Q_OBJECT
public :
LDAPManager ( TQString realm , TQString host , TQObject * parent = 0 , const char * name = 0 ) ;
@ -522,54 +479,37 @@ class TDE_EXPORT LDAPManager : public TQObject {
int deleteServiceInfo ( LDAPServiceInfo service , TQString * errstr = 0 ) ;
int exportKeytabForPrincipal ( TQString principal , TQString fileName , TQString * errstr = 0 ) ;
int deleteKeytabEntriesForPrincipal ( TQString principal , TQString fileName , TQString * errstr = 0 ) ;
LDAPCredentials currentLDAPCredentials ( bool inferGSSAPIData = false ) ;
LDAPCredentials currentLDAPCredentials ( ) ;
int moveKerberosEntries ( TQString newSuffix , TQString * errstr = 0 ) ;
int writeCertificateFileIntoDirectory ( TQByteArray cert , TQString attr , TQString * errstr = 0 ) ;
int writePKICertificateFilesIntoDirectory ( LDAPUserInfo user , TQString attr , TQString * errstr = 0 ) ;
TQString getRealmCAMaster ( TQString * errstr = 0 ) ;
int setRealmCAMaster ( TQString masterFQDN , TQString * errstr = 0 ) ;
int getLdapCertificateStoreAttribute ( TQString attribute , TQString * value , TQString * errstr = 0 ) ;
int setLdapCertificateStoreAttribute ( TQString attribute , TQString value , TQString * errstr = 0 ) ;
LDAPTDEBuiltinsInfo getTDEBuiltinMappings ( TQString * errstr = 0 ) ;
LDAPMasterReplicationInfo getLDAPMasterReplicationSettings ( TQString * errstr = 0 ) ;
int setLDAPMasterReplicationSettings ( LDAPMasterReplicationInfo replicationinfo , TQString * errstr = 0 ) ;
int writeSudoersConfFile ( TQString * errstr = 0 ) ;
int getTDECertificate ( TQString certificateName , TQFile * fileHandle , TQString * errstr = 0 ) ;
int getTDECertificate ( TQString certificateName , TQString fileName , TQString * errstr = 0 ) ;
int getTDECertificate ( TQString certificateName , TQByteArray * certificate , TQString * errstr = 0 ) ;
int setPasswordForUser ( LDAPUserInfo user , TQString * errstr ) ;
static int writePrimaryRealmCertificateUpdateCronFile ( TQString * errstr = 0 ) ;
static int installCACertificateInHostCAStore ( TQString * errstr = 0 ) ;
static int retrieveAndInstallCaCrl ( LDAPManager * manager = 0 , TQString * errstr = 0 ) ;
static TQString getMachineFQDN ( ) ;
static int writeTDERealmList ( LDAPRealmConfigList realms , TDESimpleConfig * config , TQString * errstr = 0 ) ;
static LDAPRealmConfigList fetchAndReadTDERealmList ( TQString * defaultRealm = 0 ) ;
static LDAPRealmConfigList readTDERealmList ( TDESimpleConfig * config , bool disableAllBonds = false ) ;
static int writeTDERealmList ( LDAPRealmConfigList realms , KSimpleConfig * config , TQString * errstr = 0 ) ;
static LDAPRealmConfigList readTDERealmList ( KSimpleConfig * config , bool disableAllBonds = false ) ;
static TQDateTime getCertificateExpiration ( TQString certfile ) ;
static TQDateTime getCertificateExpiration ( TQByteArray certfileContents ) ;
static int generatePublicKerberosCACertificate ( LDAPCertConfig certinfo , LDAPRealmConfig realmcfg );
static int generatePublicKerberosCACertificate ( LDAPCertConfig certinfo );
static int generatePublicKerberosCertificate ( LDAPCertConfig certinfo , LDAPRealmConfig realmcfg ) ;
static int generatePublicLDAPCertificate ( LDAPCertConfig certinfo , LDAPRealmConfig realmcfg , uid_t ldap_uid , gid_t ldap_gid ) ;
static int generateClientCertificatePair ( int expirydays , LDAPUserInfo user , LDAPRealmConfig realmcfg , TQString signingPrivateKeyFile , TQString privateKeyFile , TQString publicCertFile , int clientKeyBitLength = 2048 , TQString autoLoginPIN = TQString : : null , TQString * errstr = 0 ) ;
static int generateClientCertificatePrivateKey ( TQString privateKeyFile , int clientKeyBitLength = 2048 , TQString * errstr = 0 ) ;
static int generateClientCertificatePublicCertificate ( int expirydays , LDAPUserInfo user , LDAPRealmConfig realmcfg , TQString signingPrivateKeyFile , TQString privateKeyFile , TQString publicCertFile , TQString autoLoginPIN = TQString : : null , TQString * errstr = 0 ) ;
int generatePKICRL ( int expirydays , LDAPRealmConfig realmcfg , TQString crlFile , TQString signingPrivateKeyFile , TQString revocationDatabaseFile , TQString * errstr = 0 ) ;
static TQString ldapdnForRealm ( TQString realm ) ;
static TQString openssldcForRealm ( TQString realm ) ;
static TQString cnFromDn ( TQString dn ) ;
static KerberosTicketInfoList getKerberosTicketList ( TQString cache = TQString : : null , TQString * cacheFileName = 0 ) ;
static int getKerberosPassword ( LDAPCredentials & creds , TQString prompt , bool requestServicePrincipal = false , bool allowSmartCard = false , TQWidget * parent = 0 ) ;
static int getKerberosPassword ( LDAPCredentials & creds , TQString prompt , bool requestServicePrincipal = false , TQWidget * parent = 0 ) ;
static int obtainKerberosTicket ( LDAPCredentials creds , TQString principal , TQString * errstr = 0 ) ;
static int obtainKerberosServiceTicket ( TQString principal , TQString * errstr = 0 ) ;
static int destroyKerberosTicket ( TQString principal , TQString * errstr = 0 ) ;
@ -577,28 +517,18 @@ class TDE_EXPORT LDAPManager : public TQObject {
static TQString detailedKAdminErrorMessage ( TQString initialMessage ) ;
static TQString readFullLineFromPtyProcess ( PtyProcess * proc ) ;
static LDAPClientRealmConfig loadClientRealmConfig ( TDE SimpleConfig* config , bool useDefaults = false ) ;
static int saveClientRealmConfig ( LDAPClientRealmConfig clientRealmConfig , TDE SimpleConfig* config , TQString * errstr = 0 ) ;
static LDAPClientRealmConfig loadClientRealmConfig ( K SimpleConfig* config , bool useDefaults = false ) ;
static int saveClientRealmConfig ( LDAPClientRealmConfig clientRealmConfig , K SimpleConfig* config , TQString * errstr = 0 ) ;
static int writeClientKrb5ConfFile ( LDAPClientRealmConfig clientRealmConfig , LDAPRealmConfigList realmList , TQString * errstr = 0 ) ;
static int writeLDAPConfFile ( LDAPRealmConfig realmcfg , LDAPMachineRole machineRole , TQString * errstr = 0 ) ;
static int writeNSSwitchFile ( TQString * errstr = 0 ) ;
static int writeOpenSSLConfigurationFile ( LDAPRealmConfig realmcfg , TQString * errstr = 0 ) ;
static int writeOpenSSLConfigurationFile ( LDAPRealmConfig realmcfg , LDAPUserInfo user , TQString opensslConfigFile , TQString caRootKeyFile = TQString : : null , TQString caRootCertFile = TQString : : null , TQString caRootDatabaseFile = TQString : : null , TQString autoLoginPIN = TQString : : null , TQString * errstr = 0 ) ;
static int writeClientCronFiles ( TQString * errstr = 0 ) ;
static int rehashClientPKCSCertificates ( TQString * errstr = 0 ) ;
static int writePAMFiles ( LDAPPamConfig pamConfig , TQString * errstr = 0 ) ;
static bool pkcsLoginEnabled ( ) ;
static int bondRealm ( const TQString & adminUserName , const TQString & adminPassword ,
const TQString & adminRealm , TQString * errstr = 0 ) ;
static int unbondRealm ( LDAPRealmConfig realmcfg , const TQString & adminUserName ,
const TQString & adminPassword , const TQString & adminRealm , TQString * errstr = 0 ) ;
static int bondRealm ( TQString adminUserName , const char * adminPassword , TQString adminRealm , TQString * errstr = 0 ) ;
static int unbondRealm ( LDAPRealmConfig realmcfg , TQString adminUserName , const char * adminPassword , TQString adminRealm , TQString * errstr = 0 ) ;
private :
int bindKAdmin ( LDAPCredentials * administrativeCredentials = NULL , TQString * errstr = 0 ) ;
int unbindKAdmin ( TQString * errstr = 0 ) ;
int kAdminAddNewPrincipal ( TQString principalName , TQString newPassword , TQString * errstr = 0 ) ;
int kAdminDeletePrincipal ( TQString principalName , TQString * errstr = 0 ) ;
LDAPUserInfo parseLDAPUserRecord ( LDAPMessage * entry ) ;
LDAPGroupInfo parseLDAPGroupRecord ( LDAPMessage * entry ) ;
LDAPMachineInfo parseLDAPMachineRecord ( LDAPMessage * entry ) ;
@ -607,7 +537,6 @@ class TDE_EXPORT LDAPManager : public TQObject {
LDAPMasterReplicationInfo parseLDAPMasterReplicationRecord ( LDAPMasterReplicationInfo replicationinfo , LDAPMessage * entry ) ;
TQString parseLDAPSyncProvOverlayConfigRecord ( LDAPMessage * entry ) ;
bool parseLDAPTDEStringAttribute ( LDAPMessage * entry , TQString attribute , TQString & retval ) ;
static TQString getOpenSSLVersion ( ) ;
private :
TQString m_realm ;
@ -616,12 +545,6 @@ class TDE_EXPORT LDAPManager : public TQObject {
TQString m_basedc ;
LDAPCredentials * m_creds ;
LDAP * m_ldap ;
// kadmin interface
krb5_context m_krb5admContext ;
void * m_krb5admHandle ;
char * m_krb5admKeytabFilename ;
char * m_krb5admRealmName ;
} ;
# endif // _LIBTDELDAP_H_