Commit 141ac794 authored by jan.koester's avatar jan.koester
Browse files

some changes

parent 361f0f10
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ find_package(libcryptplus REQUIRED)
find_package(htmlpp REQUIRED)
find_package(httppp REQUIRED)
find_package(PostgreSQL REQUIRED)
find_package(OpenLDAP REQUIRED)
find_package(OpenLDAP)
find_package(OpenSSL REQUIRED)
find_package(Hiredis REQUIRED)

@@ -21,6 +21,10 @@ include_directories(
    ${CMAKE_SOURCE_DIR}/src
)

if(${OPENLDAP_FOUND})
    add_compile_definitions(LDAPSUPPORT=TRUE)
endif()

add_subdirectory(src)
add_subdirectory(plugins)
add_subdirectory(tests)
+3 −3
Original line number Diff line number Diff line
@@ -66,14 +66,14 @@ namespace blogi {
                    excep[libhttppp::HTTPException::Critical] << "no tag data found for this name!";
                    throw excep;
                }else {
                    sql = "select content.id,content.title,content.descrition,users.username,content.created from content ";
                    sql = "select content.id,content.title,content.descrition,users.displayname,content.created from content ";
                    sql <<"LEFT JOIN users ON content.author=users.id LEFT JOIN tags_content ON tags_content.content_id=content.id where tags_content.tag_id='"
                    << res[0][0]
                    <<"' ORDER BY id DESC OFFSET '" << start << "' LIMIT " << end;
                    ncount=Args->database->exec(&sql,res);
                }
            } else {
                sql="select content.id,content.title,content.descrition,users.username,content.created from content LEFT JOIN users ON content.author=users.id ORDER BY id DESC";
                sql="select content.id,content.title,content.descrition,users.displayname,content.created from content LEFT JOIN users ON content.author=users.id ORDER BY id DESC";
                sql << " OFFSET '" << start << "' LIMIT " << end;
                ncount=Args->database->exec(&sql,res);
            }
@@ -159,7 +159,7 @@ namespace blogi {

            blogi::SQL sql;

            sql << "select content.id,content.title,content.text,users.username,content.created from content LEFT JOIN users ON content.author=users.id WHERE content.id='" << cid <<"' LIMIT 1";
            sql << "select content.id,content.title,content.text,users.displayname,content.created from content LEFT JOIN users ON content.author=users.id WHERE content.id='" << cid <<"' LIMIT 1";

            blogi::DBResult res;

+8 −13
Original line number Diff line number Diff line
@@ -49,10 +49,7 @@ blogi::Auth::~Auth(){

bool blogi::Auth::login(const char* username, const char* password, std::string& ssid){
#ifdef LDAPSUPPORT
    if(!ldapLogin(username,password,ssid))
        return locallogin(username,password,ssid);
    else
        return true;
    return ldapLogin(username,password,ssid);
#else
    return locallogin(username,password,ssid);
#endif
@@ -62,7 +59,7 @@ bool blogi::Auth::locallogin(const char* username, const char* password, std::st
    return false;
}


#ifdef LDAPSUPPORT
bool blogi::Auth::ldapLogin(const char *username,const char *password,std::string &ssid){
    libhttppp::HTTPException excep;
    timeval ltimeout;
@@ -106,7 +103,7 @@ bool blogi::Auth::ldapLogin(const char *username,const char *password,std::strin
        throw excep;
    }

    char* attrs[] = { (char*)"objectSid",(char*)"userPrincipalName",(char*)"sAMAccountName",(char*)"mail",NULL };
    char* attrs[] = { (char*)"objectSid",(char*)"userPrincipalName",(char*)"mail",NULL };
    LDAPMessage* answer, * entry;
    struct timeval timeout;

@@ -146,9 +143,8 @@ bool blogi::Auth::ldapLogin(const char *username,const char *password,std::strin
                if (strcmp(attribute, "userPrincipalName") == 0) {
                    for (int i = 0; values[i]; i++) {
                        if (strncmp(username, values[i]->bv_val, values[i]->bv_len) == 0) {
                                goto LOGINUSERFOUND;
                                goto LDAPLOGINUSERFOUND;
                        }

                    }
                }
            }
@@ -162,7 +158,7 @@ bool blogi::Auth::ldapLogin(const char *username,const char *password,std::strin
    return false;


    LOGINUSERFOUND:
LDAPLOGINUSERFOUND:
         SID* mysid;
         initSID(&mysid);
         berval** values;
@@ -199,9 +195,8 @@ bool blogi::Auth::ldapLogin(const char *username,const char *password,std::strin
        ldap_msgfree(answer);
        ldap_unbind_ext_s(userldap, &userserverctls, &userclientctls);
        return true;
    LOGINFAILED:
        return false;
}
#endif

bool blogi::Auth::isLoggedIn(libhttppp::HttpRequest *curreq,std::string &sessionid){
        libhttppp::HttpCookie cookie;
+6 −0
Original line number Diff line number Diff line
@@ -34,7 +34,9 @@

extern "C" {
    #include <stdio.h>
#ifdef LDAPSUPPORT
    #include <ldap.h>
#endif
}

namespace blogi {
@@ -46,12 +48,16 @@ namespace blogi {
        bool login(const char *username,const char *password,std::string &ssid);
        bool isLoggedIn(libhttppp::HttpRequest *curreq,std::string &sessionid);
    private:
#ifdef LDAPSUPPORT
        bool ldapLogin(const char *username,const char *password,std::string &ssid);
#endif
        bool locallogin(const char *username,const char *password,std::string &ssid);

        blogi::Database *_dbconn;
        blogi::Session  *_session;
#ifdef LDAPSUPPORT
        LDAPControl    *_serverctrls;
        LDAPControl    *_clientctrls;
#endif
    };
};