<commit_before>#include "security.h"
#include "pagefactory.h"

#include <sys/creds.h>
#include <QString>
#include <DcpAppletDb>
#include <DcpAppletMetadata>
#include <dcpdebug.h>

#include <syslog.h>

void Security::restrictTo (DcpAppletMetadata* metadata)
{
    if (!PageFactory::isInProcessApplets()) {
        long result = creds_confine (qPrintable(metadata->fullBinary()));
        syslog (LOG_DEBUG, "XXX %ld", result);
    }
}

void Security::loadAppletRestricted (const QString& appletName)
{
    DcpAppletDb* db = DcpAppletDb::instance();
    dcp_failfunc_unless (db);
    DcpAppletMetadata* metadata = db->metadata (appletName);
    dcp_failfunc_unless (metadata);

    // restrict:
    restrictTo (metadata);
    
    // load:
    db->applet (appletName);<commit_msg>compatibility<commit_after>#include "security.h"
#include "pagefactory.h"

#include <sys/creds.h>
#include <QString>
#include <DcpAppletDb>
#include <DcpAppletMetadata>
#include <dcpdebug.h>

#include <syslog.h>

void Security::restrictTo (DcpAppletMetadata* metadata)
{
    if (!PageFactory::isInProcessApplets()) {
        // FIXME for compatibility we do not drop the credentials yet if the
        // library does not specify credential for itself
        creds_t myCreds = creds_gettask (0);
        creds_confine2 (qPrintable(metadata->fullBinary()), 0, myCreds);
        creds_free (myCreds);
    }
}

void Security::loadAppletRestricted (const QString& appletName)
{
    DcpAppletDb* db = DcpAppletDb::instance();
    dcp_failfunc_unless (db);
    DcpAppletMetadata* metadata = db->metadata (appletName);
    dcp_failfunc_unless (metadata);

    // restrict:
    restrictTo (metadata);
    
    // load:
    db->applet (appletName);
{'fraction_non_alphanumeric': 0.12689173457508732, 'fraction_numerical': 0.0017462165308498253, 'mean_word_length': 4.162162162162162, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '350548', 'n_tokens_mistral': 589, 'n_tokens_neox': 581, 'n_words': 125}