Ejemplo n.º 1
0
/*commit config to kernel*/
int do_commit_config(const char *config_str, unsigned int len)
{
    int ret = -1;
    if (config_str == NULL || len <= 0) {
        return -1;
    }
    if (do_parse_config(config_str, len) != 0) {
        AC_ERROR("do_parse_config failed\n");
        return -1;
    }

    if (s_config.control->rule.updated) {
        struct ac_table_info *table_info = generate_ac_table(&s_config.control->rule);
        display_ac_table(table_info);
        if (table_info) {
            if (do_rule_ipc_set(AC_SO_SET_REPLACE_CONTROL, table_info, table_info->size) != 0) {
                goto out;
            }
        }
    }

    if (s_config.control->set.updated) {
        struct ac_set_info *set_info = generate_ac_set(&s_config.control->set);
        if (set_info) {
            if (do_rule_ipc_set(AC_SO_SET_REPLACE_CONTROL_SET, set_info, set_info->size) != 0) {
                goto out;
            }
        }
    }

    if (s_config.audit->rule.updated) {
        struct ac_table_info *table_info = generate_ac_table(&s_config.audit->rule);
        if (table_info) {
            if (do_rule_ipc_set(AC_SO_SET_REPLACE_AUDIT, table_info, table_info->size) != 0) {
                goto out;
            }
        }
    }

    if (s_config.audit->set.updated) {
        struct ac_set_info *set_info = generate_ac_set(&s_config.audit->set);
        if (set_info) {
            if (do_rule_ipc_set(AC_SO_SET_REPLACE_AUDIT_SET, set_info, set_info->size) != 0) {
                goto out;
            }
        }
    }

    ret = 0;
out:
    free_global_config();
    return ret;
}
Ejemplo n.º 2
0
Archivo: cli.c Proyecto: jhbsz/cpe
  /***********************************************************************
 * Function Name : main
 * Description    : command line main function
 * comparing possibly non-NULL strings.
 * Input         : 
 * Output        : 
 * Return value  : 
 ***********************************************************************/
int main(int argc, char **argv)
{
    CLI *pCli;
    int telnet = 0;
    int status;
    //int eof;
    int logon = FALSE;
    char *accessMode;

    int fin = STD_IN;
    //Deleted by Mario Huang
    int fout = STD_OUT;
	int nvram_exist = 0;
    pCli = cliInit();
    cliIoDevSet(pCli, fin, fout);

    /* Disable int, trap and abort */
    init_signals();
    /* [email protected] */
    setenv("PATH", "/sbin:/usr/sbin:/bin:/usr/bin", 1);
    if ((accessMode = getenv("ACCESS_MODE")) != NULL)
    {
        if (!strcmp(accessMode, "telnet"))
            telnet = 1;
    }

	//check nvram work?
    nvram_exist = nvram_workable();
    if(!nvram_exist)
	{
		uiPrintf("System booting, please wait...");
		sleep(5);
	}

	while(!nvram_workable())
	{
		sleep(5);
	}

	//load config to ram
	init_global_config();

	//print config
	debug_global_config();
	
  login:

	do
    {
        logon = cliLoginRead(pCli, telnet);
		if(!logon)
			exit(0);
    }while(!logon);

    for (;;)
    {
        status = parser(pCli, fin, cmdTbl);
        if (status == CLI_PARSE_QUIT)
        {
            /*
             * CLI super user can exit to shell,
             * and others cannot but login again.
             * add by Tony 2008.3.12
             */
        	if (telnet || g_su)
                exit(0);
        	else
                goto login;
        }

		if (status == CLI_PARSE_ACCESS_LINUX)
		{
			break;
		}
		
        if ((tokenCount(pCli) > 2) || (status == CLI_PARSE_TOO_MANY))
        {
            uiPrintf("Too many parameters!\n");
        }
        else if (status == CLI_PARSE_TOO_FEW)
        {
            uiPrintf("Not enough parameters!\n");
        }
        else if (status == CLI_PARSE_INVALID_PARAMETER)
        {
            uiPrintf("Invalid parameter!\n");
        }
        else if (status == CLI_PARSE_INPUT_ERROR)
        {
            uiPrintf("Invalid input characters!\n");
        }
        else if (status == CLI_PARSE_NO_VALUE)
        {
            uiPrintf("No parameter specified!\n");
        }
//TODO:Modified by Mario Huang
        //else if ((tokenCount(pCli) >= 1) && (cTimeofZone == 0))
        else if (tokenCount(pCli) >= 1)
        {
            uiPrintf("Too many parameters!\n");
        }
    }

	//free config
	free_global_config();
	
    return 0;
}
Ejemplo n.º 3
0
/*
	Parse json string to c data structure, and then store them in global config
*/
int do_parse_config(const char *json_str, unsigned int size)
{
    int ret = -1;
    char *json_str_cpy = NULL;
    const nx_json *js = NULL, *js_elem = NULL;

    if (json_str == NULL || size <= 0) {
        AC_ERROR("invalid parameters.");
        return -1;
    }

    json_str_cpy = malloc(sizeof(char) * (size + 1));
    if (json_str_cpy == NULL) {
        goto out;
    }
    bzero(json_str_cpy, size + 1);
    memcpy(json_str_cpy, json_str, size);
    js = nx_json_parse_utf8(json_str_cpy);
    if (js == NULL) {
        AC_ERROR("config parse failed.\n");
        goto out;
    }

    if (nx_json_verify(js) != 0) {
        AC_ERROR("nxjson verify failed.\n");
        goto out;
    }

    init_global_config();

    /*parse control set*/
    js_elem = nx_json_get(js, CONTROL_SET_KEY);
    if (js_elem->type != NX_JSON_NULL) {
        if (do_parse_control_set(js_elem, &s_config.control->set) == 0) {
            display_control_set(&s_config.control->set);
        }
    }

    /*parse audit set*/
    js_elem = nx_json_get(js, AUDIT_SET_KEY);
    if (js_elem->type != NX_JSON_NULL) {
        if (do_parse_audit_set(js_elem, &s_config.audit->set) == 0) {
            display_audit_set(&s_config.audit->set);
        }
    }

    /*parse control rule*/
    js_elem = nx_json_get(js, CONTROL_RULE_KEY);
    if (js_elem->type != NX_JSON_NULL) {
        if (do_parse_control_rule(js_elem, &s_config.control->rule) == 0) {
            display_control_rule(&s_config.control->rule);
        }
        else {
            goto out;
        }
    }

    /*parse audit rule*/
    js_elem = nx_json_get(js, AUDIT_RULE_KEY);
    if (js_elem->type != NX_JSON_NULL) {
        if (do_parse_audit_rule(js_elem, &s_config.audit->rule) == 0) {
            display_audit_rule(&s_config.audit->rule);
        }
        else {
            goto out;
        }
    }

    ret = 0;
out:
    if (js != NULL) {
        nx_json_free(js);
    }
    if (json_str_cpy) {
        free(json_str_cpy);
    }
    if (ret != 0) {
        free_global_config();
    }
    return ret;
}
Ejemplo n.º 4
0
int main(int argc, char *argv[], char *env[])
{
    int i;
    const char* desktop_name;
    char *file;

    setlocale(LC_CTYPE, "");

#if !GLIB_CHECK_VERSION(2, 32, 0)
    g_thread_init(NULL);
#endif
/*    gdk_threads_init();
    gdk_threads_enter(); */

    gtk_init(&argc, &argv);

#ifdef ENABLE_NLS
    bindtextdomain ( GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR );
    bind_textdomain_codeset ( GETTEXT_PACKAGE, "UTF-8" );
    textdomain ( GETTEXT_PACKAGE );
#endif

    XSetLocaleModifiers("");
    XSetErrorHandler((XErrorHandler) panel_handle_x_error);

    resolve_atoms();

    desktop_name = g_getenv("XDG_CURRENT_DESKTOP");
    is_in_lxde = desktop_name && (0 == strcmp(desktop_name, "LXDE"));

    for (i = 1; i < argc; i++) {
        if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
            usage();
            exit(0);
        } else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
            printf("lxpanel %s\n", version);
            exit(0);
        } else if (!strcmp(argv[i], "--log")) {
            i++;
            if (i == argc) {
                g_critical( "lxpanel: missing log level");
                usage();
                exit(1);
            } else {
                /* deprecated */
            }
        } else if (!strcmp(argv[i], "--configure") || !strcmp(argv[i], "-C")) {
            config = 1;
        } else if (!strcmp(argv[i], "--profile") || !strcmp(argv[i], "-p")) {
            i++;
            if (i == argc) {
                g_critical( "lxpanel: missing profile name");
                usage();
                exit(1);
            } else {
                cprofile = g_strdup(argv[i]);
            }
        } else {
            printf("lxpanel: unknown option - %s\n", argv[i]);
            usage();
            exit(1);
        }
    }

    /* Add a gtkrc file to be parsed too. */
    file = _user_config_file_name("gtkrc", NULL);
    gtk_rc_parse(file);
    g_free(file);

    /* Check for duplicated lxpanel instances */
    if (!check_main_lock() && !config) {
        printf("There is already an instance of LXPanel.  Now to exit\n");
        exit(1);
    }

    _ensure_user_config_dirs();

    /* Add our own icons to the search path of icon theme */
    gtk_icon_theme_append_search_path( gtk_icon_theme_get_default(), PACKAGE_DATA_DIR "/images" );

    fbev = fb_ev_new();

    is_restarting = FALSE;

    /* init LibFM */
    fm_gtk_init(NULL);

    /* prepare modules data */
    lxpanel_prepare_modules();
    init_static_plugins();

    load_global_config();

    /* NOTE: StructureNotifyMask is required by XRandR
     * See init_randr_support() in gdkscreen-x11.c of gtk+ for detail.
     */
    gdk_window_set_events(gdk_get_default_root_window(), GDK_STRUCTURE_MASK |
            GDK_SUBSTRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK);
    gdk_window_add_filter(gdk_get_default_root_window (), (GdkFilterFunc)panel_event_filter, NULL);

    if( G_UNLIKELY( ! start_all_panels() ) )
        g_warning( "Config files are not found.\n" );
/*
 * FIXME: configure??
    if (config)
        configure();
*/
    gtk_main();

    XSelectInput (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), GDK_ROOT_WINDOW(), NoEventMask);
    gdk_window_remove_filter(gdk_get_default_root_window (), (GdkFilterFunc)panel_event_filter, NULL);

    /* destroy all panels */
    g_slist_foreach( all_panels, (GFunc) gtk_widget_destroy, NULL );
    g_slist_free( all_panels );
    all_panels = NULL;
    g_free( cfgfile );

    free_global_config();

    lxpanel_unload_modules();
    fm_gtk_finalize();

    /* gdk_threads_leave(); */

    g_object_unref(fbev);

    if (!is_restarting)
        return 0;
    if (strchr(argv[0], G_DIR_SEPARATOR))
        execve(argv[0], argv, env);
    else
        execve(g_find_program_in_path(argv[0]), argv, env);
    return 1;
}