Exemplo n.º 1
0
END_TEST

START_TEST(test_oswritexml_failures)
{
    char xml_in_file_name[256];
    create_xml_file("<root><child>test</child></root>", xml_in_file_name, 256);
    char xml_out_file_name[256];
    create_xml_file("", xml_out_file_name, 256);
    const char *xml_path[] = { "root", "child", NULL };

    ck_assert_int_eq(OS_WriteXML("invalid", xml_out_file_name, xml_path, "test", "test_new"), XMLW_NOIN);
    ck_assert_int_eq(OS_WriteXML(xml_in_file_name, "??invalid<<!!\"\"//\\\\", xml_path, "test", "test_new"), XMLW_NOOUT);

    unlink(xml_in_file_name);
    unlink(xml_out_file_name);
}
Exemplo n.º 2
0
/* Set OSSEC Server IP */
int set_ossec_server(char *ip, HWND hwnd)
{
    char **xml_pt = NULL;
    char *(xml_serverip[])={"ossec_config","client","server-ip", NULL};
    char *(xml_serverhost[])={"ossec_config","client","server-hostname", NULL};


    /* Verifying IP Address */
    if(OS_IsValidIP(ip, NULL) != 1)
    {
        char *s_ip;
        s_ip = OS_GetHost(ip, 0);

        if(!s_ip)
        {
            MessageBox(hwnd, "Invalid Server IP Address.\r\n"
                             "It must be the valid Ipv4 address of the "
                             "OSSEC server or its resolvable hostname.",
                             "Invalid Server IP Address.",MB_OK);
            return(0);
        }
        config_inst.server_type = SERVER_HOST_USED;
        xml_pt = xml_serverhost;
    }
    else
    {
        config_inst.server_type = SERVER_IP_USED;
        xml_pt = xml_serverip;
    }



    /* Reading the XML. Printing error and line number */
    if(OS_WriteXML(CONFIG, NEWCONFIG, xml_pt,
                   NULL, NULL, ip, 0) != 0)
    {
        MessageBox(hwnd, "Unable to set OSSEC Server IP Address.\r\n"
                   "(Internal error on the XML Write).",
                   "Unable to set Server IP Address.",MB_OK);
        return(0);
    }

    /* Renaming config files */
    unlink(LASTCONFIG);
    rename(CONFIG, LASTCONFIG);
    rename(NEWCONFIG, CONFIG);


    return(1);
}
Exemplo n.º 3
0
END_TEST

static void assert_ox_xml_write_eq(const char *xml_str_old, const char *xml_str_new, const char **xml_path, const char *oldval, const char *newval)
{
    char xml_in_file_name[256];
    create_xml_file(xml_str_old, xml_in_file_name, 256);
    char xml_out_file_name[256];
    create_xml_file("", xml_out_file_name, 256);

    ck_assert_int_eq(OS_WriteXML(xml_in_file_name, xml_out_file_name, xml_path, oldval, newval), 0);

    OS_XML xml;
    ck_assert_int_eq(OS_ReadXML(xml_out_file_name, &xml), 0);
    ck_assert_int_eq(OS_ApplyVariables(&xml), 0);
    assert_os_xml_eq_str(&xml, xml_str_new);

    OS_ClearXML(&xml);
    unlink(xml_in_file_name);
    unlink(xml_out_file_name);
}
Exemplo n.º 4
0
/* Set OSSEC Server IP */
int set_ossec_server(char *ip, HWND hwnd)
{
    const char **xml_pt = NULL;
    const char *(xml_serverip[]) = {"ossec_config", "client", "server-ip", NULL};
    const char *(xml_serverhost[]) = {"ossec_config", "client", "server-hostname", NULL};

    char config_tmp[] = CONFIG;
    char *conf_file = basename_ex(config_tmp);

    char tmp_path[strlen(TMP_DIR) + 1 + strlen(conf_file) + 6 + 1];

    snprintf(tmp_path, sizeof(tmp_path), "%s/%sXXXXXX", TMP_DIR, conf_file);

    /* Verify IP Address */
    if (OS_IsValidIP(ip, NULL) != 1) {
        char *s_ip;
        s_ip = OS_GetHost(ip, 0);

        if (!s_ip) {
            MessageBox(hwnd, "Invalid Server IP Address.\r\n"
                       "It must be the valid IPv4 address of the "
                       "OSSEC server or the resolvable hostname.",
                       "Error -- Failure Setting IP", MB_OK);
            return (0);
        }
        config_inst.server_type = SERVER_HOST_USED;
        xml_pt = xml_serverhost;
    } else {
        config_inst.server_type = SERVER_IP_USED;
        xml_pt = xml_serverip;
    }

    /* Create temporary file */
    if (mkstemp_ex(tmp_path) == -1) {
        MessageBox(hwnd, "Could not create temporary file.",
                   "Error -- Failure Setting IP", MB_OK);
        return (0);
    }

    /* Read the XML. Print error and line number. */
    if (OS_WriteXML(CONFIG, tmp_path, xml_pt, NULL, ip) != 0) {
        MessageBox(hwnd, "Unable to set OSSEC Server IP Address.\r\n"
                   "(Internal error on the XML Write).",
                   "Error -- Failure Setting IP", MB_OK);

        if (unlink(tmp_path)) {
            MessageBox(hwnd, "Could not delete temporary file.",
                       "Error -- Failure Deleting Temporary File", MB_OK);
        }

        return (0);
    }

    /* Rename config files */
    if (rename_ex(CONFIG, LASTCONFIG)) {
        MessageBox(hwnd, "Unable to backup configuration.",
                   "Error -- Failure Backing Up Configuration", MB_OK);

        if (unlink(tmp_path)) {
            MessageBox(hwnd, "Could not delete temporary file.",
                       "Error -- Failure Deleting Temporary File", MB_OK);
        }

        return (0);
    }

    if (rename_ex(tmp_path, CONFIG)) {
        MessageBox(hwnd, "Unable rename temporary file.",
                   "Error -- Failure Renaming Temporary File", MB_OK);

        if (unlink(tmp_path)) {
            MessageBox(hwnd, "Could not delete temporary file.",
                       "Error -- Failure Deleting Temporary File", MB_OK);
        }

        return (0);
    }

    return (1);
}
Exemplo n.º 5
0
/* Set OSSEC Server IP */
int set_ossec_server(char *ip, HWND hwnd)
{
    FILE *fp;
    char **xml_pt = NULL;
    char *(xml_serverip[])= {"ossec_config","client","server-ip", NULL};
    char *(xml_serverhost[])= {"ossec_config","client","server-hostname", NULL};
    char *cacls;
    int cmdlen;

    /* Build command line to change permissions */
    cacls = "echo y|cacls \"%s\" /T /G Administrators:f";
    cmdlen = strlen(cacls) + strlen(NEWCONFIG);
    char cmd[cmdlen];
    snprintf(cmd, cmdlen, cacls, NEWCONFIG);

    /* Verifying IP Address */
    if(OS_IsValidIP(ip, NULL) != 1)
    {
        char *s_ip;
        s_ip = OS_GetHost(ip, 0);

        if(!s_ip)
        {
            MessageBox(hwnd, "Invalid Server IP Address.\r\n"
                       "It must be the valid Ipv4 address of the "
                       "OSSEC server or its resolvable hostname.",
                       "Error -- Failure Setting IP",MB_OK);
            return(0);
        }
        config_inst.server_type = SERVER_HOST_USED;
        xml_pt = xml_serverhost;
    }
    else
    {
        config_inst.server_type = SERVER_IP_USED;
        xml_pt = xml_serverip;
    }

    /* Create file */
    fp = fopen(NEWCONFIG, "w");
    if(fp)
    {
        fclose(fp);
    }
    else
    {
        MessageBox(hwnd, "Could not create configuration file.",
                   "Error -- Failure Setting IP",MB_OK);
        return(0);
    }

    /* Change permissions */
    if (run_cmd(cmd, hwnd))
    {
        MessageBox(hwnd, "Unable to set permissions on new configuration file.",
                   "Error -- Failure Setting IP",MB_OK);

        /* Remove config */
        if(unlink(NEWCONFIG))
        {
            MessageBox(hwnd, "Unable to remove new configuration file.",
                       "Error -- Failure Setting IP",MB_OK);
        }

        return(0);
    }

    /* Reading the XML. Printing error and line number. */
    if(OS_WriteXML(CONFIG, NEWCONFIG, xml_pt,
                   NULL, ip) != 0)
    {
        MessageBox(hwnd, "Unable to set OSSEC Server IP Address.\r\n"
                   "(Internal error on the XML Write).",
                   "Error -- Failure Setting IP",MB_OK);
        return(0);
    }

    /* Renaming config files */
    unlink(LASTCONFIG);
    rename(CONFIG, LASTCONFIG);
    rename(NEWCONFIG, CONFIG);

    return(1);
}