void test_ignoreLicense_withNomosLicense() { License notIgnored; notIgnored.refId = 0; notIgnored.shortname = "testLicense"; char* text_ptr = g_strdup("License by Nomos."); notIgnored.tokens = tokenize(text_ptr, DELIMITERS); CU_ASSERT_TRUE(isIgnoredLicense(¬Ignored)); tokens_free(notIgnored.tokens); g_free(text_ptr); }
void test_ignoreLicense_withGoodLicenseBranch2() { License notIgnored; notIgnored.refId = 0; notIgnored.shortname = "testLicense"; char* text_ptr = g_strdup("Licence by Me."); //same token length as an ignored notIgnored.tokens = tokenize(text_ptr, DELIMITERS); CU_ASSERT_FALSE(isIgnoredLicense(¬Ignored)); tokens_free(notIgnored.tokens); g_free(text_ptr); }
void test_ignoreLicense_withGoodLicense() { License notIgnored; notIgnored.refId = 0; notIgnored.shortname = "testLicense"; char* text_ptr = g_strdup("this is a real license."); notIgnored.tokens = tokenize(text_ptr, DELIMITERS); CU_ASSERT_FALSE(isIgnoredLicense(¬Ignored)); tokens_free(notIgnored.tokens); g_free(text_ptr); }
int matchCliFileWithLicenses(MonkState* state, const Licenses* licenses, int argi, char** argv) { File file; file.id = argi; file.fileName = argv[argi]; if (!readTokensFromFile(file.fileName, &(file.tokens), DELIMITERS)) return 0; int result = matchFileWithLicenses(state, &file, licenses, &cliCallbacks); tokens_free(file.tokens); return result; }
void test_ignoreLicense_withIgnoredName() { License notIgnored; notIgnored.refId = 0; notIgnored.shortname = "Void"; char* text_ptr = g_strdup("a good license text"); notIgnored.tokens = tokenize(text_ptr, DELIMITERS); CU_ASSERT_TRUE(isIgnoredLicense(¬Ignored)); notIgnored.shortname = "No_license_found"; CU_ASSERT_TRUE(isIgnoredLicense(¬Ignored)); tokens_free(notIgnored.tokens); g_free(text_ptr); }
int matchPFileWithLicenses(MonkState* state, long pFileId, const Licenses* licenses, const MatchCallbacks* callbacks) { File file; file.id = pFileId; file.fileName = getFileName(state, pFileId); int result = 0; if (file.fileName != NULL) { result = readTokensFromFile(file.fileName, &(file.tokens), DELIMITERS); if (result) { result = matchFileWithLicenses(state, &file, licenses, callbacks); tokens_free(file.tokens); } free(file.fileName); } return result; }
/** * @brief Check if the server is known. * * Checks the user's known host file for a previous connection to the * current server. * * @param[in] session The SSH session to use. * * @returns SSH_SERVER_KNOWN_OK: The server is known and has not changed.\n * SSH_SERVER_KNOWN_CHANGED: The server key has changed. Either you * are under attack or the administrator * changed the key. You HAVE to warn the * user about a possible attack.\n * SSH_SERVER_FOUND_OTHER: The server gave use a key of a type while * we had an other type recorded. It is a * possible attack.\n * SSH_SERVER_NOT_KNOWN: The server is unknown. User should * confirm the MD5 is correct.\n * SSH_SERVER_FILE_NOT_FOUND: The known host file does not exist. The * host is thus unknown. File will be * created if host key is accepted.\n * SSH_SERVER_ERROR: Some error happened. * * @see ssh_get_pubkey_hash() * * @bug There is no current way to remove or modify an entry into the known * host table. */ int ssh_is_server_known(ssh_session session) { FILE *file = NULL; char **tokens; char *host; char *hostport; const char *type; int match; int ret = SSH_SERVER_NOT_KNOWN; enter_function(); if (session->knownhosts == NULL) { if (ssh_options_apply(session) < 0) { ssh_set_error(session, SSH_REQUEST_DENIED, "Can't find a known_hosts file"); leave_function(); return SSH_SERVER_FILE_NOT_FOUND; } } if (session->host == NULL) { ssh_set_error(session, SSH_FATAL, "Can't verify host in known hosts if the hostname isn't known"); leave_function(); return SSH_SERVER_ERROR; } if (session->current_crypto == NULL){ ssh_set_error(session, SSH_FATAL, "ssh_is_host_known called without cryptographic context"); leave_function(); return SSH_SERVER_ERROR; } host = ssh_lowercase(session->host); hostport = ssh_hostport(host,session->port); if (host == NULL || hostport == NULL) { ssh_set_error_oom(session); SAFE_FREE(host); SAFE_FREE(hostport); leave_function(); return SSH_SERVER_ERROR; } do { tokens = ssh_get_knownhost_line(session, &file, session->knownhosts, &type); /* End of file, return the current state */ if (tokens == NULL) { break; } match = match_hashed_host(session, host, tokens[0]); if (match == 0){ match = match_hostname(hostport, tokens[0], strlen(tokens[0])); } if (match == 0) { match = match_hostname(host, tokens[0], strlen(tokens[0])); } if (match == 0) { match = match_hashed_host(session, hostport, tokens[0]); } if (match) { /* We got a match. Now check the key type */ if (strcmp(session->current_crypto->server_pubkey_type, type) != 0) { /* Different type. We don't override the known_changed error which is * more important */ if (ret != SSH_SERVER_KNOWN_CHANGED) ret = SSH_SERVER_FOUND_OTHER; tokens_free(tokens); continue; } /* so we know the key type is good. We may get a good key or a bad key. */ match = check_public_key(session, tokens); tokens_free(tokens); if (match < 0) { ret = SSH_SERVER_ERROR; break; } else if (match == 1) { ret = SSH_SERVER_KNOWN_OK; break; } else if(match == 0) { /* We override the status with the wrong key state */ ret = SSH_SERVER_KNOWN_CHANGED; } } else { tokens_free(tokens); } } while (1); if ( (ret == SSH_SERVER_NOT_KNOWN) && (session->StrictHostKeyChecking == 0) ) { ssh_write_knownhost(session); ret = SSH_SERVER_KNOWN_OK; } SAFE_FREE(host); SAFE_FREE(hostport); if (file != NULL) { fclose(file); } /* Return the current state at end of file */ leave_function(); return ret; }