예제 #1
0
static void read_settings(const char *filename) {
  FILE *fp = NULL;
  char name[4096];
  unsigned int mode;
  float amount;
  setting new_setting;

  free_settings();

  if (filename == NULL) {
    fp = fopen(settings_filename, "r");
  } else {
    fp = fopen(filename, "r");
  }
  if (fp == NULL) {
    perror((filename == NULL) ? settings_filename : filename);
    exit(1);
  }
  while (fscanf(fp, "%4095s %u %f\n", name, &mode, &amount) == 3) {
    new_setting = malloc(sizeof(*new_setting));
    new_setting->name = strdup(name);
    new_setting->mode = mode;
    new_setting->amount = amount;
    new_setting->next = settings;
    settings = new_setting;
  }
  if (ferror(fp)) {
    perror((filename == NULL) ? settings_filename : filename);
    exit(1);
  }
  fclose(fp);
}
예제 #2
0
status_t
unload_driver_settings(void *handle)
{
	if (!check_handle(handle))
		return B_BAD_VALUE;

	free_settings(handle);
	return B_OK;
}
예제 #3
0
파일: settings.c 프로젝트: quickhand/madpdf
void init_settings()
{
    free_settings();
    settings=(progsettings*)malloc(sizeof(progsettings));
    settings->hpan=100;
    settings->vpan=100;
    settings->ltrimpad=0;
    settings->rtrimpad=0;
    settings->zoominc=15;
}
예제 #4
0
/* PAM hook for SESSION closing:
 * other session required pam_globus.so
 */
int
pam_sm_close_session(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
	settings_t *settings = get_settings(pamh, "auth", NULL);
	int result = PAM_SUCCESS;

	msg(settings->ctx, LOG_INFO, "%s@%s: close session for %s@%s",
	    settings->ctx->svc, settings->ctx->uts.nodename, settings->ctx->user, settings->ctx->rhost);
	free_settings(settings);
	return result;
}
예제 #5
0
static void
cmd_end(void)
{
   settings *pcsParent;
   prefix *tag, *tagBegin;

   pcsParent = pcs->next;

   if (pcs->begin_lineno == 0) {
      if (pcsParent == NULL) {
	 /* more ENDs than BEGINs */
	 compile_error_skip(/*No matching BEGIN*/192);
      } else {
	 compile_error_skip(/*END with no matching BEGIN in this file*/22);
      }
      return;
   }

   tagBegin = pcs->tag;

   SVX_ASSERT(pcsParent);
   free_settings(pcs);
   pcs = pcsParent;

   /* note need to read using root *before* BEGIN */
   tag = read_prefix(PFX_SURVEY|PFX_OPT|PFX_ALLOW_ROOT);
   if (tag != tagBegin) {
      if (tag) {
	 if (!tagBegin) {
	    /* "*begin" / "*end foo" */
	    compile_error_skip(-/*Matching BEGIN tag has no prefix*/36);
	 } else {
	    /* tag mismatch */
	    compile_error_skip(-/*Prefix tag doesn’t match BEGIN*/193);
	 }
      } else {
	 /* close tag omitted; open tag given */
	 compile_warning(-/*Closing prefix omitted from END*/194);
      }
   }
}
예제 #6
0
/* PAM hook for AUTH
 * other auth required pam_globus.so
 */
int
pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
	settings_t *settings = get_settings(pamh, "auth", NULL);
	int result = PAM_AUTH_ERR;  /* Default to failure in case of bugs */
	int rc;
	bool already = false;
	const char *user, *pass;

	msg(settings->ctx, LOG_INFO, "%s@%s: authenticate %s@%s",
	    settings->ctx->svc, settings->ctx->uts.nodename, settings->ctx->user, settings->ctx->rhost);

	rc = pam_get_user(pamh, &user, "Globus Username: "******"%s@%s: cannot obtain username",
		    settings->ctx->svc, settings->ctx->uts.nodename);
		return rc;
	}

	rc = pam_set_item(pamh, PAM_USER, user);
	if (rc != PAM_SUCCESS) {
		msg(settings->ctx, LOG_ERR, "%s@%s: cannot set username",
		    settings->ctx->svc, settings->ctx->uts.nodename);
		return PAM_AUTHINFO_UNAVAIL;
	}

	//msg(settings->ctx, LOG_INFO, "checkpoint 1");

	/* If options request using inherited authentication tokens: */
	if (settings->use_first || settings->try_first) {
		/* Get current authentication token, if present. */
		pam_get_item(pamh, PAM_AUTHTOK, (const void **)&pass);

	//msg(settings->ctx, LOG_INFO, "checkpoint 2");

		/* If authtok exists, try to authenticate with the old authtok. */
		if (pass) {
			rc = globus_authenticate(NEXUSBASE, user, pass);
			//msg(settings->ctx, LOG_INFO, "auth: %d", rc);
			if (rc == PAM_SUCCESS)
				return PAM_SUCCESS;
		}

	//msg(settings->ctx, LOG_INFO, "checkpoint 3");

		/* If we required inherited authtoks, fail now. */
		if (settings->use_first)
			return rc;

		already = true;  /* already prompted user */
	}

	//msg(settings->ctx, LOG_INFO, "checkpoint 4");

	/* Prompt for a token and try it. */
	{
		struct pam_message      pmsg, *pmsgp;
		struct pam_response    *resp;
		const struct pam_conv  *conv;

		pmsg.msg_style = PAM_PROMPT_ECHO_OFF;
		pmsg.msg = already ? "Globus Password: "******"Password: "******"checkpoint 5");

		rc = pam_get_item(pamh, PAM_CONV, (const void **)&conv);
		if (rc != PAM_SUCCESS) {
			free_settings(settings);
			return rc;
		}

		//msg(settings->ctx, LOG_INFO, "checkpoint 6");

		conv->conv(1, (const struct pam_message **)&pmsgp, &resp, conv->appdata_ptr);
		if (resp == NULL) {
			free_settings(settings);
			return PAM_CONV_ERR;
		}

		//msg(settings->ctx, LOG_INFO, "checkpoint 7");

		if ((flags & PAM_DISALLOW_NULL_AUTHTOK) && resp[0].resp == NULL) {
			free(resp);
			free_settings(settings);
			return PAM_AUTHTOK_ERR;
		}

		//msg(settings->ctx, LOG_INFO, "checkpoint 8");

		rc = globus_authenticate(NEXUSBASE, user, resp[0].resp);
		//msg(settings->ctx, LOG_INFO, "auth: %d", rc);
		if (rc == PAM_SUCCESS) {
			rc = pam_set_item(pamh, PAM_AUTHTOK, resp[0].resp);
			result = rc;
		}

		//msg(settings->ctx, LOG_INFO, "checkpoint 9");

		resp[0].resp = NULL;
		free(resp);
	}

	//msg(settings->ctx, LOG_INFO, "checkpoint 10");

	free_settings(settings);
	return result;
}
예제 #7
0
파일: main.c 프로젝트: dolfly/nmdb
int main(int argc, char **argv)
{
	struct cache *cd;
	struct queue *q;
	struct db_conn *db;
	pid_t pid;
	pthread_t *dbthread;

	if (!load_settings(argc, argv))
		return 1;

	if (!log_init()) {
		perror("Error opening log file");
		return 1;
	}

	stats_init(&stats);

	cd = cache_create(settings.numobjs, 0);
	if (cd == NULL) {
		errlog("Error creating cache");
		return 1;
	}
	cache_table = cd;

	q = queue_create();
	if (q == NULL) {
		errlog("Error creating queue");
		return 1;
	}
	op_queue = q;

	db = db_open(settings.backend, settings.dbname, 0);
	if (db == NULL) {
		errlog("Error opening DB");
		return 1;
	}
	wlog("Opened database \"%s\" with %s backend\n", settings.dbname,
		be_str_from_type(settings.backend));

	if (!settings.foreground) {
		pid = fork();
		if (pid > 0) {
			/* parent exits */
			return 0;
		} else if (pid < 0) {
			errlog("Error in fork()");
			return 1;
		}

		close(0);
		setsid();
	}

	wlog("Starting nmdb\n");

	write_pid();

	dbthread = db_loop_start(db);

	net_loop();

	db_loop_stop(dbthread);

	db->close(db);

	queue_free(q);

	cache_free(cd);

	if (settings.pidfile)
		unlink(settings.pidfile);

	free_settings();

	return 0;
}
예제 #8
0
파일: madpdf.c 프로젝트: quickhand/madpdf
int main ( int argc, char ** argv )
{	

    
    Ewl_Widget *vbox=NULL;
    Ewl_Widget *statbar=NULL;
    char *homedir;
    char *configfile;
    if(argc<2)
        return 1;
    
    if ( !ewl_init ( &argc, argv ) )
    {
        return 1;
    }

    //setlocale(LC_ALL, "");
    //textdomain("elementpdf");
    ewl_theme_theme_set(get_theme_file());
    
    homedir=getenv("HOME");
    configfile=(char *)calloc(strlen(homedir)+21 + 1, sizeof(char));
    strcat(configfile,homedir);
    strcat(configfile,"/.madpdf");
    
    if(!file_exists(configfile))
    {
        mkdir (configfile,S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
        
    }
    
    strcat(configfile,"/settings.xml");
    
    
    
    load_settings(configfile);
    
    win = ewl_window_new();
    ewl_window_title_set ( EWL_WINDOW ( win ), "EWL_WINDOW" );
    ewl_window_name_set ( EWL_WINDOW ( win ), "EWL_WINDOW" );
    ewl_window_class_set ( EWL_WINDOW ( win ), "EWLWindow" );
    ewl_object_size_request ( EWL_OBJECT ( win ), 600, 800 );
    ewl_callback_append ( win, EWL_CALLBACK_DELETE_WINDOW, destroy_cb, NULL );
    ewl_callback_append(win, EWL_CALLBACK_KEY_DOWN, cb_key_down, NULL);
    ewl_widget_name_set(win,"mainwindow");
    ewl_widget_show ( win );
 
    vbox=ewl_vbox_new();
    ewl_container_child_append(EWL_CONTAINER(win),vbox);
    ewl_object_fill_policy_set(EWL_OBJECT(vbox), EWL_FLAG_FILL_FILL);
    ewl_widget_show(vbox);
    
    scrollpane=ewl_scrollpane_new();
    ewl_container_child_append(EWL_CONTAINER(vbox),scrollpane);
    ewl_callback_append(scrollpane,EWL_CALLBACK_REVEAL,cb_scrollpane_revealed,NULL);
    ewl_scrollpane_hscrollbar_flag_set(EWL_SCROLLPANE(scrollpane),EWL_SCROLLPANE_FLAG_ALWAYS_HIDDEN);
    ewl_scrollpane_vscrollbar_flag_set(EWL_SCROLLPANE(scrollpane),EWL_SCROLLPANE_FLAG_ALWAYS_HIDDEN);
    //ewl_object_fill_policy_set(EWL_OBJECT(scrollpane), EWL_FLAG_FILL_FILL);
    //ewl_theme_data_str_set(EWL_WIDGET(scrollpane),"/scrollpane/group","ewl/blank");
    ewl_widget_show(scrollpane);
    
    trimpane=ewl_scrollpane_new();
    ewl_container_child_append(EWL_CONTAINER(scrollpane),trimpane);
    ewl_object_alignment_set(EWL_OBJECT(trimpane),EWL_FLAG_ALIGN_LEFT|EWL_FLAG_ALIGN_TOP);
    ewl_scrollpane_hscrollbar_flag_set(EWL_SCROLLPANE(trimpane),EWL_SCROLLPANE_FLAG_ALWAYS_HIDDEN);
    ewl_scrollpane_vscrollbar_flag_set(EWL_SCROLLPANE(trimpane),EWL_SCROLLPANE_FLAG_ALWAYS_HIDDEN);
    //ewl_theme_data_str_set(EWL_WIDGET(trimpane),"/scrollpane/group","ewl/blank");
    ewl_widget_show(trimpane);
    
    statbar=ewl_hbox_new();
    ewl_container_child_append(EWL_CONTAINER(vbox),statbar);
    ewl_theme_data_str_set(EWL_WIDGET(statbar),"/hbox/group","ewl/menu/oi_menu");
    ewl_object_fill_policy_set(EWL_OBJECT(statbar),EWL_FLAG_FILL_HFILL|EWL_FLAG_FILL_VSHRINKABLE);
    ewl_widget_show(statbar);
    
    statlabel1=ewl_label_new();   
    //ewl_statusbar_left_append(EWL_STATUSBAR(statbar),statlabel1);
    ewl_container_child_append(EWL_CONTAINER(statbar),statlabel1);
    ewl_theme_data_str_set(EWL_WIDGET(statlabel1),"/label/group","ewl/oi_statbar_label_left");
    ewl_theme_data_str_set(EWL_WIDGET(statlabel1),"/label/textpart","ewl/oi_statbar_label_left/text");
    ewl_object_fill_policy_set(EWL_OBJECT(statlabel1),EWL_FLAG_FILL_HSHRINKABLE);
    ewl_widget_show(statlabel1);
    
    statlabel2=ewl_label_new();   
    //ewl_statusbar_right_append(EWL_STATUSBAR(statbar),statlabel2);
    ewl_container_child_append(EWL_CONTAINER(statbar),statlabel2);
    ewl_theme_data_str_set(EWL_WIDGET(statlabel2),"/label/group","ewl/oi_statbar_label_right");
    ewl_theme_data_str_set(EWL_WIDGET(statlabel2),"/label/textpart","ewl/oi_statbar_label_right/text");
    ewl_object_fill_policy_set(EWL_OBJECT(statlabel2),EWL_FLAG_FILL_HFILL);
    ewl_widget_show(statlabel2);
    
    
    pdfwidget = ewl_pdf_new();
    ewl_pdf_file_set (EWL_PDF (pdfwidget), argv[1]);
    ewl_container_child_append(EWL_CONTAINER(trimpane),pdfwidget);
    ewl_object_alignment_set(EWL_OBJECT(pdfwidget),EWL_FLAG_ALIGN_LEFT|EWL_FLAG_ALIGN_TOP);
    ewl_widget_name_set(pdfwidget,"pdfwidget");
    ewl_callback_append (pdfwidget, EWL_CALLBACK_CONFIGURE, cb_pdfwidget_resized, NULL );
    ewl_widget_show (pdfwidget);
    
    //set up menu
    menu=ewl_context_menu_new();
    
    ewl_callback_append(menu, EWL_CALLBACK_KEY_DOWN, cb_menu_key_down, NULL);
    ewl_theme_data_str_set(EWL_WIDGET(menu),"/menu/group","ewl/menu/oi_menu");
    ewl_context_menu_attach(EWL_CONTEXT_MENU(menu), statbar);
    
    Ewl_Widget *temp=ewl_menu_new();
    ewl_container_child_append(EWL_CONTAINER(menu),temp);
    ewl_widget_name_set(temp,"menuitem1");
    ewl_button_label_set(EWL_BUTTON(temp),"1. Go to page...");
    ewl_widget_show(temp);

    goto_entry=ewl_entry_new();
    ewl_container_child_append(EWL_CONTAINER(temp),goto_entry);
    ewl_object_custom_w_set(EWL_OBJECT(goto_entry),50);
    ewl_callback_append(goto_entry, EWL_CALLBACK_KEY_DOWN, cb_goto_key_down, NULL);
    ewl_widget_show(goto_entry);
    
    
    temp=ewl_menu_item_new();
    ewl_widget_name_set(temp,"menuitem2");
    ewl_container_child_append(EWL_CONTAINER(menu),temp);
    ewl_button_label_set(EWL_BUTTON(temp),"2. Preferences...");
    ewl_widget_show(temp);

        
    
    
    ewl_main();
    save_settings(configfile);
    free(configfile);
    free_settings();
    return 0;
}