Exemplo n.º 1
0
bool HTTPCookieAuth::handleRequest(HTTPRequestPtr& request, TCPConnectionPtr& tcp_conn)
{
	if (processLogin(request,tcp_conn)) {
		return false; // we processed login/logout request, no future processing for this request permitted
	}

	if (!needAuthentication(request)) {
		return true; // this request does not require authentication
	}

	// check if it is redirection page.. If yes, then do not test its credentials ( as used for login)
	if (!m_redirect.empty() && m_redirect==request->getResource()) {
		return true; // this request does not require authentication
	}
	
	// check cache for expiration
	PionDateTime time_now(boost::posix_time::second_clock::universal_time());
	expireCache(time_now);

	// if we are here, we need to check if access authorized...
	const std::string auth_cookie(request->getCookie(AUTH_COOKIE_NAME));
	if (! auth_cookie.empty()) {
		// check if this cookie is in user cache
		boost::mutex::scoped_lock cache_lock(m_cache_mutex);
		PionUserCache::iterator user_cache_itr=m_user_cache.find(auth_cookie);
		if (user_cache_itr != m_user_cache.end()) {
			// we find those credential in our cache...
			// we can approve authorization now!
			request->setUser(user_cache_itr->second.second);
			// and update cache timeout
			user_cache_itr->second.first = time_now;
			return true;
		}
	}

	// user not found
	handleUnauthorized(request,tcp_conn);
	return false;
}
Exemplo n.º 2
0
int main( int argc, char **argv )
{
    msgSender=0;
    // Initialize the mime++ library
    DwInitialize();

    KApplication *a=new KApplication ( argc, argv, "krn" );
    //a.enableSessionManagement();

    app=a;
    conf=a->getConfig();

    checkConf();
    nls=a->getLocale();
    keys = new KStdAccel(conf);
    kbp=new KBusyPtr();
    msgSender=new KRNSender();
    msgSender->readConfig();
    msgSender->setMethod(KMSender::smSMTP);
    KMMessage::readConfig();

    addrBook=new KMAddrBook();
    addrBook->readConfig();
    addrBook->load();


    // Create our directory. If it exists, no problem
    // Should do some checking, though

    testDir( "/share" );
    testDir( "/share/config" );
    testDir( "/share/apps" );
    testDir( "/share/apps/krn" );
    testDir( "/share/apps/krn/cache" );
    testDir( "/share/apps/krn/groupinfo" );
    testDir( "/share/apps/krn/outgoing" );

    krnpath = KApplication::localkdedir() + "/share/apps/krn/";

    mkdir (krnpath.data(),S_IREAD|S_IWRITE|S_IEXEC);
    cachepath=krnpath+"/cache/";
    mkdir (cachepath.data(),S_IREAD|S_IWRITE|S_IEXEC);
    groupinfopath=krnpath+"/groupinfo/";
    mkdir (groupinfopath.data(),S_IREAD|S_IWRITE|S_IEXEC);
    outpath=krnpath+"outgoing/";
    mkdir (outpath.data(),S_IREAD|S_IWRITE|S_IEXEC);

    // Create the articles database


    artinfopath=krnpath+"/artinfo.db";
    artdb=gdbm_open(artinfopath.data(),0,GDBM_WRCREAT | GDBM_FAST,448,0);
    artinfopath=krnpath+"/refs.db";
    refsdb=gdbm_open(artinfopath.data(),0,GDBM_WRCREAT | GDBM_FAST,448,0);
    artinfopath=krnpath+"/scores.db";
    scoredb=gdbm_open(artinfopath.data(),0,GDBM_WRCREAT | GDBM_FAST,448,0);

    if ((!artdb) || (!refsdb) || (!scoredb)) //the gdbm open failed!
    {
        int i=KMsgBox::yesNo(0,"KRN - Error",
                             "I have detected another Krn running\n"
                             "Do you REALLY want to continue?\n"
                             "If you are sure there isn't one, press \"Yes\"\n"
                             "But if there *is* another one, it's going to be UGLY\n");
    }
    // Fill the unreadDict
    datum key=gdbm_firstkey ( artdb );
    datum nextkey;


    while ( key.dptr )
    {
        unreadDict.insert(key.dptr,key.dptr);
        nextkey = gdbm_nextkey ( artdb, key );
        free (key.dptr);
        key = nextkey;
    };

    // Load the rules
    ruleFile=new KSimpleConfig(krnpath+"/rules");
    Rule::updateGlobals();


    Groupdlg *k=new Groupdlg();
    main_widget = k;

    //insert this:
    if (a->isRestored())
        k->restore(1);

    a->setMainWidget( k );
    a->setTopWidget( k );

    k->setMinimumSize( 250, 250 );
    k->show();

    a->exec();

    expireCache();

//    k->close();
    gdbm_reorganize(artdb);
    gdbm_reorganize(refsdb);
    gdbm_reorganize(scoredb);

    gdbm_close(artdb);
    gdbm_close(refsdb);
    gdbm_close(scoredb);
//    delete k;
}