const char* OSP_BLAHBLAH = "/usr/share/privilege-control/OSP_blahblah.smack";
const char* WRT_BLAHBLAH = "/usr/share/privilege-control/WGT_blahblah.smack";
const char* OTHER_BLAHBLAH = "/usr/share/privilege-control/blahblah.smack";
+const char* OSP_BLAHBLAH_DAC = "/usr/share/privilege-control/OSP_blahblah.dac";
+const char* WRT_BLAHBLAH_DAC = "/usr/share/privilege-control/WGT_blahblah.dac";
+const char* OTHER_BLAHBLAH_DAC = "/usr/share/privilege-control/blahblah.dac";
const char* BLAHBLAH_FEATURE = "http://feature/blah/blahblah";
/**
smack_file.close();
}
+void osp_blahblah_dac_check(int line_no, const std::vector<unsigned>& gids)
+{
+ std::ifstream dac_file(OSP_BLAHBLAH_DAC);
+ RUNNER_ASSERT_MSG(dac_file, "Line: " << line_no << " Failed to create " << OSP_BLAHBLAH_DAC);
+
+ auto it = gids.begin();
+ std::string line;
+ while(std::getline(dac_file,line)) {
+ std::istringstream is(line);
+ unsigned gid;
+ is >> gid;
+ RUNNER_ASSERT_MSG(it != gids.end(), "Line: " << line_no << "Additional line in file: " << gid);
+ RUNNER_ASSERT_MSG(*it == gid, "Line: " << line_no << " " << *it << "!=" << gid);
+ it++;
+ }
+
+ RUNNER_ASSERT_MSG(it == gids.end(), "Line: " << line_no << " Missing line in file: " << *it);
+
+ dac_file.close();
+}
+
void remove_smack_files()
{
+ // TODO array
unlink(OSP_BLAHBLAH);
unlink(WRT_BLAHBLAH);
unlink(OTHER_BLAHBLAH);
+ unlink(OSP_BLAHBLAH_DAC);
+ unlink(WRT_BLAHBLAH_DAC);
+ unlink(OTHER_BLAHBLAH_DAC);
}
int smack_file_name(const char* app_id, char** path)
// argument validation
- result = add_api_feature(APP_TYPE_OSP, NULL, NULL, NULL);
+ result = add_api_feature(APP_TYPE_OSP, NULL, NULL, NULL, 0);
RUNNER_ASSERT(result == PC_ERR_INVALID_PARAM);
- result = add_api_feature(APP_TYPE_OSP,"" , NULL, NULL);
+ result = add_api_feature(APP_TYPE_OSP,"" , NULL, NULL, 0);
RUNNER_ASSERT(result == PC_ERR_INVALID_PARAM);
// already existing features
- result = add_api_feature(APP_TYPE_OSP,"messaging" , NULL, NULL);
+ result = add_api_feature(APP_TYPE_OSP,"messaging" , NULL, NULL, 0);
RUNNER_ASSERT(result == PC_ERR_INVALID_PARAM);
- result = add_api_feature(APP_TYPE_OSP,"blahblah/messaging" , NULL, NULL);
+ result = add_api_feature(APP_TYPE_OSP,"blahblah/messaging" , NULL, NULL, 0);
RUNNER_ASSERT(result == PC_ERR_INVALID_PARAM);
- result = add_api_feature(APP_TYPE_WGT,"blahblahblah/messaging" , NULL, NULL);
+ result = add_api_feature(APP_TYPE_WGT,"blahblahblah/messaging" , NULL, NULL, 0);
RUNNER_ASSERT(result == PC_ERR_INVALID_PARAM);
- result = add_api_feature(APP_TYPE_OTHER,"blah/messaging" , NULL, NULL);
+ result = add_api_feature(APP_TYPE_OTHER,"blah/messaging" , NULL, NULL, 0);
RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
// empty features
- result = add_api_feature(APP_TYPE_OSP,"blahblah" , NULL, NULL);
+ result = add_api_feature(APP_TYPE_OSP,"blahblah" , NULL, NULL, 0);
RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
- result = add_api_feature(APP_TYPE_WGT,"blahblah" , NULL, NULL);
+ result = add_api_feature(APP_TYPE_WGT,"blahblah" , NULL, NULL, 0);
RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
- result = add_api_feature(APP_TYPE_OTHER,"blahblah" , NULL, NULL);
+ result = add_api_feature(APP_TYPE_OTHER,"blahblah" , NULL, NULL, 0);
RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
// empty rules
- result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , { NULL }, NULL);
+ result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , { NULL }, NULL, 0);
RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
result = file_exists(OSP_BLAHBLAH);
RUNNER_ASSERT(result == -1);
- result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "", NULL }, NULL);
+ result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "", NULL }, NULL, 0);
RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
result = file_exists(OSP_BLAHBLAH);
RUNNER_ASSERT(result == 0);
remove_smack_files();
- result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ " \t\n", "\t \n", "\n\t ", NULL }, NULL);
+ result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ " \t\n", "\t \n", "\n\t ", NULL }, NULL, 0);
RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
result = file_exists(OSP_BLAHBLAH);
RUNNER_ASSERT(result == 0);
// malformed rules
- result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "malformed", NULL }, NULL);
+ result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "malformed", NULL }, NULL, 0);
RUNNER_ASSERT(result == PC_ERR_INVALID_PARAM);
result = file_exists(OSP_BLAHBLAH);
RUNNER_ASSERT(result == -1);
- result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "malformed malformed", NULL }, NULL);
+ result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "malformed malformed", NULL }, NULL, 0);
RUNNER_ASSERT(result == PC_ERR_INVALID_PARAM);
result = file_exists(OSP_BLAHBLAH);
RUNNER_ASSERT(result == -1);
- result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "-malformed malformed rwxat", NULL }, NULL);
+ result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "-malformed malformed rwxat", NULL }, NULL, 0);
RUNNER_ASSERT(result == PC_ERR_INVALID_PARAM);
result = file_exists(OSP_BLAHBLAH);
RUNNER_ASSERT(result == -1);
- result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "~/\"\\\ malformed rwxat", NULL }, NULL);
+ result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "~/\"\\\ malformed rwxat", NULL }, NULL, 0);
RUNNER_ASSERT(result == PC_ERR_INVALID_PARAM);
result = file_exists(OSP_BLAHBLAH);
RUNNER_ASSERT(result == -1);
- result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "subject object rwxat something else", NULL }, NULL);
+ result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "subject object rwxat something else", NULL }, NULL, 0);
RUNNER_ASSERT(result == PC_ERR_INVALID_PARAM);
result = file_exists(OSP_BLAHBLAH);
RUNNER_ASSERT(result == -1);
// correct rules
- result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "malformed malformed maaaaaalformed", NULL }, NULL);
+ result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "malformed malformed maaaaaalformed", NULL }, NULL, 0);
RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
osp_blahblah_check(__LINE__, { "malformed malformed r--a-" });
remove_smack_files();
- result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "subject object foo", NULL }, NULL);
+ result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "subject object foo", NULL }, NULL, 0);
RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
osp_blahblah_check(__LINE__, { "subject object -----" });
remove_smack_files();
" \t \n",
"subject2\tobject2 txarw",
"",
- NULL }, NULL);
+ NULL }, NULL, 0);
RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
osp_blahblah_check(__LINE__, { "subject object rwxat", "subject2 object2 rwxat"});
remove_smack_files();
result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){
"Sub::jE,ct object a-RwX",
- NULL }, NULL);
+ NULL }, NULL, 0);
RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
osp_blahblah_check(__LINE__, { "Sub::jE,ct object rwxa-"});
remove_smack_files();
" \t \n",
"subject object txarw",
"",
- NULL }, NULL);
+ NULL }, NULL, 0);
RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
osp_blahblah_check(__LINE__, { "subject object rwxat", "subject object rwxat"});
remove_smack_files();
- // TODO database group ids
+ // empty group ids
+ result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){"a a a",NULL},(const gid_t[]){0,1,2},0);
+ RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
+ osp_blahblah_check(__LINE__, { "a a ---a-"});
+ result = file_exists(OSP_BLAHBLAH_DAC);
+ RUNNER_ASSERT(result == -1);
+ remove_smack_files();
+
+
+ // valid group ids
+ result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){"a a a",NULL},(const gid_t[]){0,1,2},3);
+ printf("%d \n", result);
+ RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
+ osp_blahblah_check(__LINE__, { "a a ---a-"});
+ osp_blahblah_dac_check(__LINE__, {0,1,2});
+ remove_smack_files();
+
+ result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){"a a a",NULL},(const gid_t[]){0,1,2},1);
+ RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
+ osp_blahblah_check(__LINE__, { "a a ---a-"});
+ osp_blahblah_dac_check(__LINE__, {0});
+ remove_smack_files();
+
+ result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){"a a a",NULL},(const gid_t[]){1,1,1},3);
+ RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
+ osp_blahblah_check(__LINE__, { "a a ---a-"});
+ osp_blahblah_dac_check(__LINE__, {1,1,1});
+ remove_smack_files();
}
/*