コード例 #1
0
ファイル: oils_auth.c プロジェクト: IISH/Evergreen
// returns true if the provided identifier matches the barcode regex.
static int oilsAuthIdentIsBarcode(const char* identifier, int org_id) {

    if (org_id < 1)
        org_id = oilsUtilsGetRootOrgId();

    char* bc_regex = oilsUtilsFetchOrgSetting(org_id, "opac.barcode_regex");

    if (!bc_regex) {
        // if no regex is set, assume any identifier starting
        // with a number is a barcode.
        bc_regex = strdup("^\\d"); // dupe for later free'ing
    }

    const char *err_str;
    int err_offset, match_ret;

    pcre *compiled = pcre_compile(
        bc_regex, 0, &err_str, &err_offset, NULL);

    if (compiled == NULL) {
        osrfLogError(OSRF_LOG_MARK,
            "Could not compile '%s': %s", bc_regex, err_str);
        free(bc_regex);
        pcre_free(compiled);
        return 0;
    }

    pcre_extra *extra = pcre_study(compiled, 0, &err_str);

    if(err_str != NULL) {
        osrfLogError(OSRF_LOG_MARK,
            "Could not study regex '%s': %s", bc_regex, err_str);
        free(bc_regex);
        pcre_free(compiled);
        return 0;
    } 

    match_ret = pcre_exec(
        compiled, extra, identifier, strlen(identifier), 0, 0, NULL, 0);       

    free(bc_regex);
    pcre_free(compiled);
    if (extra) pcre_free(extra);

    if (match_ret >= 0) return 1; // regex matched

    if (match_ret != PCRE_ERROR_NOMATCH) 
        osrfLogError(OSRF_LOG_MARK, "Unknown error processing barcode regex");

    return 0; // regex did not match
}
コード例 #2
0
oilsEvent* oilsUtilsCheckPerms( int userid, int orgid, char* permissions[], int size ) {
    if (!permissions) return NULL;
    int i;

    // Check perms against the root org unit if no org unit is provided.
    if (orgid == -1)
        orgid = oilsUtilsGetRootOrgId();

    for( i = 0; i < size && permissions[i]; i++ ) {
        oilsEvent* evt = NULL;
        char* perm = permissions[i];

        jsonObject* params = jsonParseFmt(
            "{\"from\":[\"permission.usr_has_perm\",\"%d\",\"%s\",\"%d\"]}",
            userid, perm, orgid
        );

        // Execute the query
        jsonObject* result = oilsUtilsCStoreReq(
            "open-ils.cstore.json_query", params);

        const jsonObject* hasPermStr = 
            jsonObjectGetKeyConst(result, "permission.usr_has_perm");

        if (!oilsUtilsIsDBTrue(jsonObjectGetString(hasPermStr))) {
            evt = oilsNewEvent3(
                OSRF_LOG_MARK, OILS_EVENT_PERM_FAILURE, perm, orgid);
        }

        jsonObjectFree(params);
        jsonObjectFree(result);

        // return first failed permission check.
        if (evt) return evt;
    }

    return NULL; // all perm checks succeeded
}