Example #1
0
static int level_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
{
	unsigned int val;

	switch (cmd) {
		case LEVEL_DEV_UNSET_UPLOAD:
			kernel_sec_clear_upload_magic_number();
			return 0;

		case LEVEL_DEV_SET_AUTOTEST:
			kernel_sec_set_autotest();
			return 0;

		case LEVEL_DEV_SET_DEBUGLEVEL:
			set_debug_level();
			return 0;
			
		case LEVEL_DEV_GET_DEBUGLEVEL:
		{
			val = get_debug_level();
			return copy_to_user((unsigned int *)arg, &val, sizeof(val));
		}
		default:
			printk("Unknown Cmd: %x\n", cmd);
			break;
		}
	return -ENOTSUPP;
}
Example #2
0
int main(int argc, char *argv[]) {
  int timeout = 0;
  sock_handlers_t *hdl;
  int udp5353;

  set_debug_level(DBG_GLOBAL, -1000);

  tuni = bind_tcp_listener(8080);
  hdl = cdata_get_handlers(tuni);
  hdl->ev_read = tun_read_ev;

  udp5353 = bind_udp_listener_specific("::", 5353, NULL);
  join_mdns_groups(sock_get_fd(udp5353));
  hdl = cdata_get_handlers(udp5353);
  hdl->ev_read = dns_read_ev;

  LGL = lua_open();
  lua_init_state(LGL);
  if(luaL_dofile(LGL, "example-dns.lua")!=0) {
    fprintf(stderr,"%s\n",lua_tostring(LGL,-1));
    return NULL;
  }


  while(1) {
    if (timeout == 0) { 
      timeout = 1000;
    }
    timeout = sock_one_cycle(timeout, NULL);
  }
}
Example #3
0
/*********************************************************************
 *
 * Function    :  init_log_module
 *
 * Description :  Initializes the logging module to log to stderr.
 *                Can only be called while stderr hasn't been closed
 *                yet and is only supposed to be called once.
 *
 * Parameters  :
 *          1  :  prog_name = The program name.
 *
 * Returns     :  Nothing.
 *
 *********************************************************************/
void init_log_module(void)
{
   lock_logfile();
   logfp = stderr;
   unlock_logfile();
   set_debug_level(debug);
}
Example #4
0
/**
 * @brief Parse configuration file
 */
static int parse_config_file() {
    ctx = nfcconf_new ( cfgfile );
    if ( !ctx ) {
        ERR ( "%s", "Error creating conf context" );
        return -1;
    }
    if ( nfcconf_parse ( ctx ) <= 0 ) {
        ERR ( "Error parsing file '%s'", cfgfile );
        return -1;
    }
    /* now parse options */
    root = nfcconf_find_block ( ctx, NULL, "nfc-eventd" );
    if ( !root ) {
        ERR ( "nfc-eventd block not found in config: '%s'", cfgfile );
        return -1;
    }
    debug = nfcconf_get_bool ( root, "debug", debug );
    daemonize = nfcconf_get_bool ( root, "daemon", daemonize );
    polling_time = nfcconf_get_int ( root, "polling_time", polling_time );
    expire_time = nfcconf_get_int ( root, "expire_time", expire_time );

    if ( debug ) set_debug_level ( 1 );

    DBG( "%s", "Looking for specified NFC device." );
    nfcconf_block **device_list, *my_device;
    const char* nfc_device_str = nfcconf_get_str ( root, "nfc_device", "" );
    if (strcmp( nfc_device_str, "") != 0) {
        device_list = nfcconf_find_blocks ( ctx, root, "device", NULL );
        if ( !device_list ) {
            ERR ( "%s", "Device item not found." );
            return -1;
        }
        int i = 0;
        my_device = device_list[i];
        while ( my_device != NULL ) {
            i++;
            if ( strcmp(my_device->name->data, nfc_device_str) == 0 ) {
                INFO("Specified device %s have been found.", nfc_device_str);
                /*connstring = malloc(sizeof(nfc_connstring));
                connstring->pcDriver = (char*)nfcconf_get_str( my_device, "driver", "" );
		char* device_name = (char*)nfcconf_get_str( my_device, "name", "" );
		strncpy(connstring->acDevice, device_name, sizeof(connstring->acDevice));
                char* device_port   = (char*)nfcconf_get_str( my_device, "port", "" );
		strncpy(connstring->acPort, device_port, sizeof(connstring->acPort));
                connstring->uiSpeed  = nfcconf_get_int( my_device, "speed", 9600 );
                connstring->uiBusIndex  = nfcconf_get_int( my_device, "index", 0 );*/
                break;
            }
            my_device = device_list[i];
        }
        DBG( "Found %d device configuration block(s).", i );
        if ( connstring == NULL ) {
            ERR("NFC device have been specified in configuration file but there is no device description. Unable to select specified device: %s.", nfc_device_str);
        }
        free ( device_list );
    }

    return 0;
}
Example #5
0
mapper_module * mapper_module_init(scconf_block *blk,const char *mapper_name) {
#else
mapper_module * krb_mapper_module_init(scconf_block *blk,const char *mapper_name) {
#endif
	mapper_module *pt;
	if( blk) debug = scconf_get_bool(blk,"debug",0);
	set_debug_level(debug);
	pt=init_mapper_st(blk,mapper_name);
	if(pt) DBG("KPN mappper started");
	else DBG("KPN mapper initialization failed");
	return pt;
}
Example #6
0
bool DebugIDManager::
set_debug_level(const char *debugID, int level)
{
	int slen = strlen(debugID);
	if(slen<=0) return false;
	if(debugID[slen-1] == '*')
	{
		for(size_t i=0; i<m_dbgLevelIdentifiers.size(); i++)
		{
			const char *name = m_dbgLevelIdentifiers[i].c_str();
			if(WildcardMatch(name, debugID))
			{
				set_debug_level(crc32(name), level);
				//UG_LOGN(name);
			}
		}
	}
	else if(set_debug_level(crc32(debugID), level) == false)
	{
		UG_LOG("DebugID " << debugID << " not registered.\n");
		return false;
	}
	return true;
}
Example #7
0
mapper_module * mapper_module_init(scconf_block *blk,const char *mapper_name) {
#else
mapper_module * ldap_mapper_module_init(scconf_block *blk,const char *mapper_name) {
#endif
	mapper_module *pt;

    pt = init_mapper_st(blk,mapper_name);

	if (blk) {
		read_config(blk);
	} else {
		set_debug_level(1);
		DBG1("No configuration entry for mapper '%s'. Assume defaults", mapper_name);
	}
    return pt;
}
Example #8
0
int main(int argc, char *argv[]) {
    int timeout;
    sock_handlers_t *hdl;

    set_debug_level(DBG_GLOBAL, 1000);

    tftpi = bind_udp_listener(69);
    hdl = cdata_get_handlers(tftpi);
    hdl->ev_read = tftp_read_ev;
    while(1) {
        if (timeout == 0) {
            timeout = 1000;
        }
        timeout = sock_one_cycle(timeout, NULL);
    }
}
Example #9
0
mapper_module * mapper_module_init(scconf_block *blk,const char *mapper_name) {
#else
mapper_module * uid_mapper_module_init(scconf_block *blk,const char *mapper_name) {
#endif
	mapper_module *pt;
        if (blk) {
		debug= scconf_get_bool(blk,"debug",0);
	mapfile = scconf_get_str(blk,"mapfile",mapfile);
        ignorecase = scconf_get_bool(blk,"ignorecase",ignorecase);
	} else {
		DBG1("No block declaration for mapper '%s'", mapper_name);
	}
        set_debug_level(debug);
	pt= init_mapper_st(blk,mapper_name);
        if(pt) DBG3("UniqueID mapper started. debug: %d, mapfile: %s, icase: %d",debug,mapfile,ignorecase);
	else DBG("UniqueID mapper initialization failed");
        return pt;
}
Example #10
0
mapper_module * mapper_module_init(scconf_block *ctx,const char *mapper_name) {
#else
mapper_module * null_mapper_module_init(scconf_block *ctx,const char *mapper_name) {
#endif
	mapper_module *pt= NULL;
	if (ctx) {
	default_user = scconf_get_str( ctx,"default_user",default_user);
	match = scconf_get_bool( ctx,"default_match",0);
		debug = scconf_get_bool( ctx,"debug",0);
	} else {
		DBG1("No block declaration for mapper '%s'", mapper_name);
	}
	set_debug_level(debug);
	pt = init_mapper_st(ctx,mapper_name);
	if (pt) DBG1("Null mapper match set to '%s'",match?"always":"never");
	else DBG("Null mapper initialization failed");
	return pt;
}
Example #11
0
 SimpleRPC(const std::string & remote_host,
           unsigned short remote_port,
           int debug_level = 0)
 {
     SimpleRPC::debug_level = debug_level;
     if (host != "")
     {
         std::cerr << "SimpleRPC("<<remote_host<<", "<<remote_port<<") ERROR: ";
         std::cerr << "already connecting to "<<host<<":"<<port<<std::endl;
         m_success = false;
     }
     else
     {
         host = remote_host;
         port = remote_port;
         m_success = true;
         success = true;
     }
     set_debug_level(debug_level);
 }
Example #12
0
void parse_option(struct file_system_info *fsinfo, int argc, char **argv, int *index){

    if ((strcmp(argv[*index], OPT_INCREMENTS) == 0) || (strcmp(argv[*index], OPT_INCREMENTS_FULL) == 0)){
		if (set_increments(argc, argv, index) != 0)
			fail(ERR_PARAMETRES);
    }    
    else if ((strcmp(argv[*index], OPT_FULL) == 0) || (strcmp(argv[*index], OPT_FULL_FULL) == 0))
    	structure = STRUCTURE_FULL;
    else if ((strcmp(argv[*index], OPT_LAST) == 0) || (strcmp(argv[*index], OPT_LAST_FULL) == 0)) {
    	layout = LAYOUT_LAST;
        structure = STRUCTURE_FULL;
    }
    else if ((strcmp(argv[*index], OPT_CACHING) == 0) || (strcmp(argv[*index], OPT_CACHING_FULL) == 0)){
    	if (set_caching(argc, argv, index) != 0)
    		fail(ERR_PARAMETRES);
    }
    else if ((strcmp(argv[*index], OPT_DIR) == 0) || (strcmp(argv[*index], OPT_DIR_FULL) == 0)){
    	if (set_directory(argc, argv, index) != 0)
    		fail(ERR_PARAMETRES);
    }
    else if ((strcmp(argv[*index], OPT_VERSION) == 0) || (strcmp(argv[*index], OPT_VERSION_FULL) == 0)) {
		printf(PROGRAM_NAME " - filesystem in userspace for rdiff-backup repositories; version %s\n", PACKAGE_VERSION);
        exit(0);
    }
    else if (strcmp(argv[*index], OPT_DEBUG_FULL) == 0) {
        if (set_debug_level(argc, argv, index) != 0)
            fail(ERR_PARAMETRES);
    }
    else if (strcmp(argv[*index], OPT_FUSE) == 0) {
        if (add_fuse_option(argc, argv, index) != 0)
            fail(ERR_PARAMETRES);
    }
    else if (strcmp(argv[*index], OPT_DIR_LOCAL_TIME_FULL) == 0) 
        fsinfo->rev_dir_time = REV_LOCAL_TIME;
    else 
		fail(ERR_UNKNOWN_OPTION);

};
Example #13
0
/**
 * \brief Main function of unit tests
 */
int main(int argc, char *argv[])
{
	int opt, ret, number_failed;
	SRunner *master_sr = srunner_create(verse_master_suite());
	srunner_add_suite(master_sr, node_create_suite());
	srunner_add_suite(master_sr, node_destroy_suite());
	srunner_add_suite(master_sr, taggroup_create_suite());

	/* When client was started with some arguments */
	if(argc>1) {
		/* Parse all options */
		while( (opt = getopt(argc, argv, "hd:")) != -1) {
			switch(opt) {
				case 'd':
					ret = set_debug_level(optarg);
					if(ret != VRS_SUCCESS) {
						print_help(argv[0]);
						exit(EXIT_FAILURE);
					}
					break;
				case 'h':
					print_help(argv[0]);
					exit(EXIT_SUCCESS);
				case ':':
					exit(EXIT_FAILURE);
				case '?':
					exit(EXIT_FAILURE);
					break;
			}
		}
	}

	srunner_run_all(master_sr, CK_VERBOSE);
	number_failed = srunner_ntests_failed(master_sr);
	srunner_free(master_sr);

	return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
Example #14
0
static ssize_t store_control(struct device *d,
		struct device_attribute *attr, const char *buf, size_t count)
{

	if(!strncmp(buf, "clear", 5)) {
		// clear upload magic number
		kernel_sec_clear_upload_magic_number();
		return count;
	}

	if(!strncmp(buf, "autotest", 8)) {
		// set auto test
		kernel_sec_set_autotest();
		return count;
	}

	if(!strncmp(buf, "set", 3)) {
		// set debug level
		set_debug_level();
		return count;
	}

return count;
}
Example #15
0
void setup() {
  set_debug_level(0);
  set_name("tester");
  set_long("Testing testing 1 2 3");
  reset_drop();
}
Example #16
0
/* parse every config line */
static int
parse_line(char *buff)
{
    char   *token;

    if ((token = strtok(buff, W_SPACE)) == NULL) {
        /* ignore empty lines */
        (void) 0;

    } else if (strstr(token, "mod_")) {
        parse_mod(token);

    } else if (strstr(token, "spec_")) {
        special_mod(token);

    } else if (!strcmp(token, "output_interface")) {
        parse_string(conf.output_interface);

    } else if (!strcmp(token, "output_file_path")) {
        parse_string(conf.output_file_path);

    } else if (!strcmp(token, "output_db_addr")) {
        parse_string(conf.output_db_addr);

    } else if (!strcmp(token, "output_db_mod")) {
        parse_add_string(conf.output_db_mod);

    } else if (!strcmp(token, "output_nagios_mod")) {
        parse_add_string(conf.output_nagios_mod);

    } else if (!strcmp(token, "output_stdio_mod")) {
        parse_add_string(conf.output_stdio_mod);

    } else if (!strcmp(token, "debug_level")) {
        set_debug_level();

    } else if (!strcmp(token, "include")) {
        get_include_conf();

    } else if (!strcmp(token, "server_addr")) {
        parse_string(conf.server_addr);

    } else if (!strcmp(token, "server_port")) {
        parse_int(conf.server_port);

    } else if (!strcmp(token, "cycle_time")) {
        parse_int(conf.cycle_time);

    } else if (!strcmp(token, "send_nsca_cmd")) {
        parse_string(conf.send_nsca_cmd);

    } else if (!strcmp(token, "send_nsca_conf")) {
        parse_string(conf.send_nsca_conf);

    } else if (!strcmp(token, "threshold")) {
        get_threshold();

    } else {
        return 0;
    }
    return 1;
}
Example #17
0
int main(int argc, const char **argv)
{
    int i;
    unsigned int pname;
    const char *params[NUM_PARAMS];

    memset(params, '\0', sizeof(params));

    /* first of all check whether debugging should be enabled */
    for (i = 0; i < argc; i++)
        if (strcmp("debug", argv[i]) == 0) {
            set_debug_level(1);
        }

    for (i = 1; i < argc; i++) {
        for (pname = 0; pname < NUM_PARAMS; pname++) {
            if (param_names[pname][pn_sizes[pname]-2] == '=') {
                if (strncmp(argv[i], param_names[pname], pn_sizes[pname]-1) == 0) {
                    params[pname] = argv[i] + pn_sizes[pname] - 1;
                }
                else if (strncmp(argv[i], param_names[pname], pn_sizes[pname]-2) == 0
                         && argv[i][pn_sizes[pname]-2] == '\0') {
                    params[pname] = (void *)1;
                }
            }
            else {
                if (strcmp(argv[i], param_names[pname]) == 0) {
                    params[pname] = (void *)1;
                }
            }
        }
    }

    for (pname = 0; pname < NUM_PARAMS; pname++) {
        if (params[pname] != NULL)
            break;
    }

    if (pname == NUM_PARAMS) {
        DBG("No correct parameter specified");
        printf("usage: pkcs11_setup [list_modules] [use_module[=<module_name>]]\n"
               "                    [ins_action[=<executable,executable,...>]]\n"
               "                    [rm_action[=<executable,executable,...>]]\n");
    }

    if (params[LIST_MODULES] != NULL) {
        DBG("List modules:");
        return list_modules();
    }
    else {
        if (params[USE_MODULE] == (void *)1) {
            DBG("Print default module:");
            if ((i=print_default_module()) != 0) {
                ERR1("Print default module failed with: %d", i);
                return i;
            }
            return 0;
        }
        else if (params[USE_MODULE] != NULL) {
            DBG1("Set default module: %s", params[USE_MODULE]);
            if ((i=set_default_module(params[USE_MODULE])) != 0) {
                ERR1("Set default module failed with: %d", i);
                return i;
            }
        }
        if (params[INS_ACTION] == (void *)1) {
            DBG("Print card insert action:");
            if ((i=print_card_insert_action()) != 0) {
                ERR1("Print card insert action failed with: %d", i);
                return i;
            }
            return 0;
        }
        else if (params[INS_ACTION] != NULL) {
            DBG1("Set card insert action: %s", params[INS_ACTION]);
            if ((i=set_card_insert_action(params[INS_ACTION])) != 0) {
                ERR1("Set card insert action failed with: %d", i);
                return i;
            }
        }
        if (params[RM_ACTION] == (void *)1) {
            DBG("Print card remove action:");
            if ((i=print_card_remove_action()) != 0) {
                ERR1("Set card remove action failed with: %d", i);
                return i;
            }
            return 0;
        }
        else if (params[RM_ACTION] != NULL) {
            DBG1("Set card remove action: %s", params[RM_ACTION]);
            if ((i=set_card_remove_action(params[RM_ACTION])) != 0) {
                ERR1("Set card remove action failed with: %d", i);
                return i;
            }
        }
    }
    DBG("Process completed");
    return 0;
}
Example #18
0
static int read_config(scconf_block *blk) {
	int debug = scconf_get_bool(blk,"debug",0);
	const char *ssltls;

	ldaphost = scconf_get_str(blk,"ldaphost",ldaphost);
	ldapport = scconf_get_int(blk,"ldapport",ldapport);
	ldapURI = scconf_get_str(blk,"uri",ldapURI);
	scope = scconf_get_int(blk,"scope",scope);
	binddn = scconf_get_str(blk,"binddn",binddn);
	passwd = scconf_get_str(blk,"passwd",passwd);
	base = scconf_get_str(blk,"base",base);
	attribute = scconf_get_str(blk,"attribute",attribute);
	filter = scconf_get_str(blk,"filter",filter);
	ignorecase = scconf_get_bool(blk,"ignorecase",ignorecase);
	searchtimeout = scconf_get_int(blk,"searchtimeout",searchtimeout);

	ssltls =  scconf_get_str(blk,"ssl","off");
	if (! strncasecmp (ssltls, "tls", 3))
		ssl_on = SSL_START_TLS;
	else if( ! strncasecmp (ssltls, "on", 2))
		ssl_on = SSL_LDAPS;
	else if( ! strncasecmp (ssltls, "ssl", 3))
		ssl_on = SSL_LDAPS;

#if defined HAVE_LDAP_START_TLS_S || (defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_X_TLS))
	/* TLS specific options */
	tls_randfile = scconf_get_str(blk,"tls_randfile",tls_randfile);
	tls_cacertfile = scconf_get_str(blk,"tls_cacertfile",tls_cacertfile);
	tls_cacertdir = scconf_get_str(blk,"tls_cacertdir",tls_cacertdir);
	tls_checkpeer=scconf_get_int(blk,"tls_checkpeer",tls_checkpeer);
	tls_ciphers = scconf_get_str(blk,"tls_ciphers",tls_ciphers);
	tls_cert = scconf_get_str(blk,"tls_cert",tls_cert);
	tls_key = scconf_get_str(blk,"tls_key",tls_key);
#endif


	set_debug_level(debug);
DBG1("test ssltls = %s", ssltls);

	DBG("LDAP mapper started.");
	DBG1("debug         = %d", debug);
	DBG1("ignorecase    = %d", ignorecase);
	DBG1("ldaphost      = %s", ldaphost);
	DBG1("ldapport      = %d", ldapport);
	DBG1("ldapURI       = %s", ldapURI);
	DBG1("scope         = %d", scope);
	DBG1("binddn        = %s", binddn);
	DBG1("passwd        = %s", passwd);
	DBG1("base          = %s", base);
	DBG1("attribute     = %s", attribute);
	DBG1("filter        = %s", filter);
	DBG1("searchtimeout = %d", searchtimeout);
	DBG1("ssl_on        = %d", ssl_on);
#if defined HAVE_LDAP_START_TLS_S || (defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_X_TLS))
	DBG1("tls_randfile  = %s", tls_randfile);
	DBG1("tls_cacertfile= %s", tls_cacertfile);
	DBG1("tls_cacertdir = %s", tls_cacertdir);
	DBG1("tls_checkpeer = %d", tls_checkpeer);
	DBG1("tls_ciphers   = %s", tls_ciphers);
	DBG1("tls_cert      = %s", tls_cert);
	DBG1("tls_key       = %s", tls_key);
#endif
	return 1;

}
Example #19
0
int parse_config(GKeyFile *keyfile, Config_t *cfg) {
//  GKeyFileFlags flags;
//  GError *error = NULL;
  Server_t *server;
  char *str;
  int val, k;
  gsize n;
  pMount_t *pm, *pmarray;

  // *** Initialize the data structure to default values ***
  server = &(cfg->server);
  server->max_threads = 64;
  server->max_pending = 16;
  server->min_idle = 60;
  server->stats_size = 5000;
  set_net_timeout(&(server->timeout), 1, 0);  //**Wait 1sec
  server->timeout_secs = 1;
  server->logfile = "ibp.log";
  server->log_overwrite = 0;
  server->log_level = 0;
  server->log_maxsize = 100 * 1024 * 1024;
  server->debug_level = 0;
  server->enable_timestamps = 1;
  server->timestamp_interval = 60;
  server->password = DEFAULT_PASSWORD;
  server->lazy_allocate = 1;
  server->alog_name = "ibp_activity.log";
  server->alog_max_size = 100*1024*1024;
  server->alog_max_history = 1;
  server->alog_host = NULL;
  server->alog_port = 0;
  cfg->dbenv_loc = "/tmp/ibp_dbenv";
  cfg->db_mem = 256;
  cfg->tmpdir = "/etc/ibp";
  cfg->force_resource_rebuild = 0;
  cfg->truncate_expiration = 0;

  // *** Parse the Server settings ***
  char **list = g_key_file_get_string_list(keyfile, "server", "interfaces",  &n, NULL);
  interface_t *iface;
  if (list == NULL) {
     server->iface = (interface_t *)malloc(sizeof(interface_t));
     assert(server->iface != NULL);
     server->n_iface = 1;
     iface = server->iface;
     assert((iface->hostname = (char *)malloc(512)) != NULL);  iface->hostname[511] = '\0';
     gethostname(iface->hostname, 511);
     iface->port = IBP_PORT;
  } else {  //** Cycle through the hosts
     server->iface = (interface_t *)malloc(sizeof(interface_t)*n);
     assert(server->iface != NULL);
     server->n_iface = n;
     char *bstate;
     int fin;
     for (k=0; k<n; k++) {
        iface = &(server->iface[k]);
        iface->hostname = string_token(list[k], ":", &bstate, &fin);
        if (sscanf(string_token(NULL, " ", &bstate, &fin), "%d", &(iface->port)) != 1) {
           iface->port = IBP_PORT;
        }     
     }
  }

//  str = g_key_file_get_string(keyfile, "server", "address", NULL);
//  if (str != NULL) { free(server->hostname); server->hostname = str; }
//  val = g_key_file_get_integer(keyfile, "server", "port", NULL);
//  if (val > 0) server->port = val;
  val = g_key_file_get_integer(keyfile, "server", "threads", NULL);
  if (val > 0) server->max_threads = val;
  val = g_key_file_get_integer(keyfile, "server", "max_pending", NULL);
  if (val > 0) server->max_pending = val;
  val = g_key_file_get_integer(keyfile, "server", "min_idle", NULL);
  if (val > 0) server->min_idle = val;
  val = g_key_file_get_integer(keyfile, "server", "max_network_wait_ms", NULL);
  if (val > 0) {
     int sec = val/1000;
     int us = val - 1000*sec;
     us = us * 1000;  //** Convert from ms->us
     server->timeout_secs = sec;
     set_net_timeout(&(server->timeout), sec, us);  //**Convert it from ms->us
  }
  val = g_key_file_get_integer(keyfile, "server", "stats_size", NULL);
  if (val > 0) server->stats_size = val;
  val = g_key_file_get_integer(keyfile, "server", "timestamp_interval", NULL);
  if (val > 0) server->timestamp_interval = val;
  str = g_key_file_get_string(keyfile, "server", "password", NULL);
  if (str != NULL) server->password = str;
  str = g_key_file_get_string(keyfile, "server", "log_file", NULL);
  if (str != NULL) server->logfile = str;
  val = g_key_file_get_integer(keyfile, "server", "log_level", NULL);
  if (val > 0) server->log_level = val;
  val = g_key_file_get_integer(keyfile, "server", "enable_timestamps", NULL);
  if (val > 0) server->enable_timestamps = val;
  val = g_key_file_get_integer(keyfile, "server", "log_maxsize", NULL);
  if (val > 0) server->log_maxsize = val * 1024 * 1024;
  val = g_key_file_get_integer(keyfile, "server", "debug_level", NULL);
  if (val > 0) server->debug_level = val;
  cfg->tmpdir = g_key_file_get_string(keyfile, "server", "tmpdir", NULL);
  str = g_key_file_get_string(keyfile, "server", "db_env_loc", NULL);
  if (str != NULL) cfg->dbenv_loc = str;
  val = g_key_file_get_integer(keyfile, "server", "db_mem", NULL);
  if (val > 0) cfg->db_mem = val;
  val = g_key_file_get_integer(keyfile, "server", "lazy_allocate", NULL);
  if (val > 0) server->lazy_allocate = val;

  str = g_key_file_get_string(keyfile, "server", "activity_file", NULL);
  if (str != NULL) server->alog_name = str;
  val = g_key_file_get_integer(keyfile, "server", "activity_maxsize", NULL);
  if (val > 0) {
     server->alog_max_size = val * 1024 * 1024;
  } else if (val == -1) {
     server->alog_max_size = -1;
  }

  str = g_key_file_get_string(keyfile, "server", "activity_host", NULL);
  if (str != NULL) server->alog_host = str;
  val = g_key_file_get_integer(keyfile, "server", "activity_max_history", NULL);
  if (val > 0) server->alog_max_history = val;
  val = g_key_file_get_integer(keyfile, "server", "activity_port", NULL);
  if (val > 0) server->alog_port = val;

  val = g_key_file_get_integer(keyfile, "server", "force_resource_rebuild", NULL);
  if (val > 0) cfg->force_resource_rebuild = val;
  val = g_key_file_get_integer(keyfile, "server", "truncate_duration", NULL);
  if (val > 0) cfg->truncate_expiration = val;

  //*** Do some initial config of the log and debugging info ***
  open_log(cfg->server.logfile);            
  set_log_level(cfg->server.log_level);
  set_debug_level(cfg->server.debug_level);
  set_log_maxsize(cfg->server.log_maxsize);

  // *** Now iterate through each resource which is assumed to be all groups beginning with "resource" ***      
  cfg->dbenv = create_db_env(cfg->dbenv_loc, cfg->db_mem, cfg->force_resource_rebuild);
  gsize ngroups, i;
  char **group = g_key_file_get_groups(keyfile, &ngroups);
  cfg->n_resources = 0;
  assert((cfg->res = (Resource_t *)malloc(sizeof(Resource_t)*(ngroups-1))) != NULL);
  assert((pmarray = (pMount_t *)malloc(sizeof(pMount_t)*(ngroups-1))) != NULL);
  for (i=0; i<ngroups; i++) {
      if (strncmp("resource", group[i], 8) == 0) {
         pm = &(pmarray[cfg->n_resources]);
         pm->res = &(cfg->res[cfg->n_resources]);
         pm->res->rl_index = cfg->n_resources;
         pm->keyfile = keyfile;
         pm->group = group[i];
         pm->dbenv = cfg->dbenv;
         pm->force_resource_rebuild = cfg->force_resource_rebuild;
  
         pthread_create(&(pm->thread_id), NULL, parallel_mount_resource, (void *)pm);
//         mount_resource(&(cfg->res[cfg->n_resources]), keyfile, group[i], cfg->dbenv, cfg->force_resource_rebuild);

         cfg->n_resources++;
         
      }
  }  

  //** Wait for all the threads to join **
  void *dummy;
  for (i=0; i<cfg->n_resources; i++) {
     pthread_join(pmarray[i].thread_id, &dummy);
  }

  free(pmarray);

  if (cfg->n_resources < 0) {
     printf("parse_config:  No resources defined!!!!\n");
     abort();
  }

  return(0);
}
Example #20
0
int main(){
	setLogDebugLevel( dbgLevel );
	setLogFile( logFile );
	setLogSilentMode(1);

	writeLog( 0, "Starting remoteAdv Master Client - Version: %s", version );
	
	// Gets a hostent struct containing data about the given host
	struct hostent *server = gethostbyname( server_ip );
	if(server == NULL) {
		herror("ERROR: Host lookup failed");
		exit(1);
	}

	// Create a TCP socket and return a file descriptor for accessing it
	int sockfd = socket(AF_INET, SOCK_STREAM, 0);
	if(sockfd == -1) {
		perror("ERROR: Open socket failed");
		exit(1);
	}

	// Create and initialize a sock_addr struct contianing info about the server to connect to
	struct sockaddr_in server_addr;
	memset( &server_addr , 0 , sizeof(server_addr));
	// Denotes an internet socket
    server_addr.sin_family = AF_INET;
    // Copies several values from the server hostent struct into this one
	memcpy( &server_addr.sin_addr.s_addr, server->h_addr, server->h_length );
    // Sets the server port to the one passed in
    server_addr.sin_port = server_port;

    // Connect to the server
    int connectResult = connect(sockfd,(struct sockaddr*)&server_addr, sizeof(server_addr));
    if(connectResult == -1) {
        perror("ERROR: Connection to server failed");
        exit(1);
    }

    int auth_result = authenticate( sockfd );
    if( auth_result == -1 ) {
        writeLog( -1, "Server authentication failed" );
        exit(1);
    } else {
        writeLog( 2, "Server connection successful" );
        writeLog( 3, "Connected to server at '%s:%d'", server_ip, server_port );
    }

    int end = 0;

    // Wait to send commands
    while( !end ) {
    	printMenu(); // Display options to allow user to see options.

    	int input = 0;
    	scanf( "%d", &input );

    	switch( input ) {
    		case sel_list_slaves:
    			system( "clear" );      // Clear works on unix like enviorments, this will throw an error on windows.
    			list_slaves( sockfd );
    			break;
    		case sel_claim_client:
    			system( "clear" );
    			claim_client( sockfd );
    			break;
    		case sel_release_client:
    			release_client( sockfd );
    			break;
    		case sel_set_debug_level:
    			set_debug_level( sockfd );
    			break;
    		case sel_kill_client:
    			kill_client( sockfd );
    			break;
    		case sel_close:
    			end = 1;
    		default:
    			break;
    	}

    	fflush( stdout );
    	system( "clear" );
    }

    // Close the connection to the server
    close( sockfd );

    return 0;
}
Example #21
0
int main(int argc, const char **argv)
{
    hashtable_p table = NULL;
    int size = START_CAPACITY;
    float best_utilization = 0.0;
    float tmp_utilization = 0.0;

    (void)argc;
    (void)argv;

    pdebug(DEBUG_INFO,"Starting hashtable tests.");

    set_debug_level(DEBUG_SPEW);

    /* create a hashtable */
    pdebug(DEBUG_INFO,"Creating hashtable with at least capacity %d.", START_CAPACITY);
    table = hashtable_create(START_CAPACITY);
    assert(table != NULL);
    assert(hashtable_capacity(table) >= START_CAPACITY);
    assert(hashtable_entries(table) == 0);

    size = hashtable_capacity(table);

    /* insert tests. */
    for(int i=1; i <= INSERT_ENTRIES; i++) {
        int rc = hashtable_put(table, i, (void*)(intptr_t)i);
        assert(rc == PLCTAG_STATUS_OK);

        if(hashtable_capacity(table) != size) {
            pdebug(DEBUG_INFO, "Hashtable expanded from %d entries to %d entries after inserting %d entries.", size, hashtable_capacity(table), hashtable_entries(table));
            size = hashtable_capacity(table);
        }
    }

    tmp_utilization = (float)(hashtable_entries(table))/(float)(hashtable_capacity(table));

    pdebug(DEBUG_INFO, "Current table utilization %f%%", tmp_utilization*100.0);

    if(tmp_utilization > best_utilization) {
        best_utilization = tmp_utilization;
    }

    assert(hashtable_entries(table) == INSERT_ENTRIES);
    pdebug(DEBUG_INFO, "Hash table has correct number of used entries, %d.", hashtable_entries(table));

    pdebug(DEBUG_INFO, "Hashtable using %d entries of %d entries capacity.", hashtable_entries(table), hashtable_capacity(table));

    /* retrieval tests. */
    pdebug(DEBUG_INFO, "Running retrieval tests.");
    for(int i=INSERT_ENTRIES; i > 0; i--) {
        void *res = hashtable_get(table, i);
        assert(res != NULL);

        assert(i == (int)(intptr_t)res);
    }

    /* insert + delete tests. */
    pdebug(DEBUG_INFO, "Running combined insert and delete tests.");
    for(int i=INSERT_ENTRIES+1; i < (INSERT_ENTRIES*2); i++) {
        int rc = hashtable_put(table, i, (void*)(intptr_t)i);
        void *res = NULL;

        assert(rc == PLCTAG_STATUS_OK);

        res = hashtable_remove(table, (i - INSERT_ENTRIES));
        assert((i - INSERT_ENTRIES) == (int)(intptr_t)res);
    }

    assert(hashtable_entries(table) == INSERT_ENTRIES);
    pdebug(DEBUG_INFO, "Hash table has correct number of used entries, %d.", hashtable_entries(table));

    tmp_utilization = (float)(hashtable_entries(table))/(float)(hashtable_capacity(table));

    pdebug(DEBUG_INFO, "Current table utilization %f%%", tmp_utilization*100.0);

    if(tmp_utilization > best_utilization) {
        best_utilization = tmp_utilization;
    }

    pdebug(DEBUG_INFO, "Best table utilization %f%%", best_utilization*100.0);

    hashtable_destroy(table);

    pdebug(DEBUG_INFO, "Done.");
}
Example #22
0
/**
 * @brief Parse command line args
 */
static int parse_args ( int argc, char *argv[] ) {
    int i;
    int res;
    polling_time = DEF_POLLING;
    expire_time = DEF_EXPIRE;
    debug   = 0;
    daemonize  = 0;
    cfgfile = DEF_CONFIG_FILE;
    /* first of all check whether debugging should be enabled */
    for ( i = 0; i < argc; i++ ) {
        if ( ! strcmp ( "debug", argv[i] ) ) set_debug_level ( 1 );
    }
    /* try to find a configuration file entry */
    for ( i = 0; i < argc; i++ ) {
        if ( strstr ( argv[i], "config_file=" ) ) {
            cfgfile = 1 + strchr ( argv[i], '=' );
            break;
        }
    }
    /* parse configuration file */
    if ( parse_config_file() < 0 ) {
        ERR ( "Error parsing configuration file %s", cfgfile );
        exit ( EXIT_FAILURE );
    }

    /* and now re-parse command line to take precedence over cfgfile */
    for ( i = 1; i < argc; i++ ) {
        if ( strcmp ( "daemon", argv[i] ) == 0 ) {
            daemonize = 1;
            continue;
        }
        if ( strcmp ( "nodaemon", argv[i] ) == 0 ) {
            daemonize = 0;
            continue;
        }
        if ( strstr ( argv[i], "polling_time=" ) ) {
            res = sscanf ( argv[i], "polling_time=%d", &polling_time );
            continue;
        }
        if ( strstr ( argv[i], "expire_time=" ) ) {
            res = sscanf ( argv[i], "expire_time=%d", &expire_time );
            continue;
        }
        if ( strstr ( argv[i], "debug" ) ) {
            continue;  /* already parsed: skip */
        }
        if ( strstr ( argv[i], "nodebug" ) ) {
            set_debug_level ( 0 );
            continue;  /* already parsed: skip */
        }
        if ( strstr ( argv[i], "config_file=" ) ) {
            continue; /* already parsed: skip */
        }
        ERR ( "unknown option %s", argv[i] );

        /* arriving here means syntax error */
        printf( "NFC Event Daemon\n" );
        printf( "Usage %s [[no]debug] [[no]daemon] [polling_time=<time>] [expire_time=<limit>] [config_file=<file>]", argv[0] );
        printf( "\nDefaults: debug=0 daemon=0 polltime=%d (ms) expiretime=0 (none) config_file=%s", DEF_POLLING, DEF_CONFIG_FILE );
        exit ( EXIT_FAILURE );
    } /* for */
    /* end of config: return */
    return 0;
}
int main(int argc, char *argv[])
{
  oph_metadb_db_row *db_table = NULL;

  set_debug_level(LOG_DEBUG);
  set_log_prefix(OPH_IO_SERVER_PREFIX);

	int ch;
	unsigned short int instance = 0;
	unsigned short int help = 0;

	while ((ch = getopt(argc, argv, "i:h"))!=-1)
	{
		switch (ch)
		{
			case 'h':
				help = 1;
			break;
			case 'i':
				instance = (unsigned short int)strtol(optarg, NULL, 10);
			break;
		}
	}

	if (help)
	{
		pmesg(LOG_ERROR,__FILE__,__LINE__,"Execute MetaDB Reader: oph_metadb_client -i <instance_number>\n");
		exit(0);
	}
  if(instance == 0){
		pmesg(LOG_WARNING,__FILE__,__LINE__,"Using default (first) instance in configuration file\n");
  }

  HASHTBL *conf_db = NULL;

  //Load params from conf files
  if(oph_server_conf_load(instance, &conf_db)){
		pmesg(LOG_ERROR,__FILE__,__LINE__,"Error while loading configuration file\n");
		//logging(LOG_ERROR,__FILE__,__LINE__,"Error while loading configuration file\n");
    return -1;
  }

  char *dir = 0;

  if(oph_server_conf_get_param(conf_db, OPH_SERVER_CONF_DIR, &dir)){
		pmesg(LOG_WARNING,__FILE__,__LINE__,"Unable to get server dir param\n");
		dir = OPH_IO_SERVER_PREFIX;
  }
  oph_metadb_set_data_prefix(dir);
  
  if(oph_metadb_load_schema (&db_table, 0)){
    printf("Unable to load MetaDB\n");
    oph_metadb_unload_schema (db_table);
    oph_server_conf_unload(&conf_db);
    return -1;
  }

  int i = 0;
  int thread_number = 10;

  pthread_t tid[thread_number];
  int n = 0;

	for (i = 0 ; i < thread_number ; i++)
	{
		pmesg(LOG_DEBUG,__FILE__,__LINE__,"Creating new thread\n");
    if ( (n = pthread_create(&tid[i], NULL, &test_metadb, (void *) db_table)) != 0){
      pmesg(LOG_ERROR,__FILE__,__LINE__,"Error creating thread\n");
    }
	}

  for(i = 0; i < thread_number; i++)
  {
		pmesg(LOG_DEBUG,__FILE__,__LINE__,"Joining thread\n");
	  if ( (n = pthread_join(tid[i], NULL)) != 0){
      pmesg(LOG_WARNING,__FILE__,__LINE__,"Error joining thread\n");
    }
  }

  oph_server_conf_unload(&conf_db);
  oph_metadb_unload_schema (db_table);
    
	return 0;

}
Example #24
0
int main(int argc, const char **argv) {
  int i, rv;
  pkcs11_handle_t *ph;
  struct configuration_st *configuration;
  unsigned int slot_num = 0;
  cert_object_t **certs;
  int cert_count;

  /* first of all check whether debugging should be enabled */
  for (i = 0; i < argc; i++)
    if (strcmp("debug", argv[i]) == 0) {
      set_debug_level(1);
    }

  /* call configure routines */
  configuration = pk_configure(argc - 1, argv + 1);
  if (!configuration ) {
	ERR("Error setting configuration parameters");
	return 1;
  }

  if ((configuration->slot_description != NULL && configuration->slot_num != -1) || (configuration->slot_description == NULL && configuration->slot_num == -1)) {
	ERR("Error setting configuration parameters");
	return 1;
  }

  /* init openssl */
  rv = crypto_init(&configuration->policy);
  if (rv != 0) {
    DBG1("crypto_init() failed: %s", get_error());
    return 1;
  }

  /* load pkcs #11 module */
  DBG("loading pkcs #11 module...");
  rv = load_pkcs11_module(configuration->pkcs11_modulepath, &ph);
  if (rv != 0) {
    ERR2("load_pkcs11_module(%s) failed: %s", configuration->pkcs11_modulepath,
      get_error());
    return 1;
  }

  /* initialise pkcs #11 module */
  DBG("initialising pkcs #11 module...");
  rv = init_pkcs11_module(ph,configuration->support_threads);
  if (rv != 0) {
    release_pkcs11_module(ph);
    DBG1("init_pkcs11_module() failed: %s", get_error());
    return 1;
  }

  /* open pkcs #11 session */
  if (configuration->slot_description != NULL) {
    rv = find_slot_by_slotlabel(ph, configuration->slot_description, &slot_num);
  } else {
    rv = find_slot_by_number(ph, configuration->slot_num, &slot_num);
  }

  if (rv != 0) {
    release_pkcs11_module(ph);
    DBG("no token available");
    return 1;
  }

  rv = open_pkcs11_session(ph, slot_num);
  if (rv != 0) {
    release_pkcs11_module(ph);
    ERR1("open_pkcs11_session() failed: %s", get_error());
    return 1;
  }

  /* not really needed, but.... */
  rv = pkcs11_pass_login(ph,configuration->nullok);
  if (rv != 0) {
    ERR1("pkcs11_pass_login() failed: %s", get_error());
    return 2;
  }

  /* get certificate list (cert space is owned by ph) */
  certs = get_certificate_list(ph, &cert_count);
  if (certs == NULL) {
    close_pkcs11_session(ph);
    release_pkcs11_module(ph);
    ERR1("get_certificates() failed: %s", get_error());
    return 3;
  }

  /* load mapper modules */
  load_mappers(configuration->ctx);

  /* find valid certificates and look for contents */
  DBG1("Found '%d' certificate(s)", cert_count);
  for (i = 0; i < cert_count; i++) {
    X509 *x509 = get_X509_certificate(certs[i]);
    if (x509 != NULL) {
      DBG1("verifying the certificate #%d", i + 1);
      /* verify certificate (date, signature, CRL, ...) */
      rv = verify_certificate(x509, &configuration->policy);
      if (rv < 0) {
        close_pkcs11_session(ph);
        release_pkcs11_module(ph);
	unload_mappers();
        ERR1("verify_certificate() failed: %s", get_error());
        return 1;
      } else if (rv != 1) {
        ERR1("verify_certificate() failed: %s", get_error());
        continue;
      }

      DBG1("Inspecting certificate #%d",i+1);
      inspect_certificate(x509);
    }
  }

  /* unload mappers */
  unload_mappers();

  /* close pkcs #11 session */
  rv = close_pkcs11_session(ph);
  if (rv != 0) {
    release_pkcs11_module(ph);
    ERR1("close_pkcs11_session() failed: %s", get_error());
    return 1;
  }

  /* release pkcs #11 module */
  DBG("releasing pkcs #11 module...");
  release_pkcs11_module(ph);

  DBG("Process completed");
  return 0;
}
Example #25
0
int main(int argc, const char **argv) {
  int i, rv;
  char *user = NULL;
  pkcs11_handle_t *ph;
  struct configuration_st *configuration;
  cert_object_t **certs;
  int cert_count;
  unsigned int slot_num = 0;


  /* first of all check whether debugging should be enabled */
  for (i = 0; i < argc; i++)
    if (strcmp("debug", argv[i]) == 0) {
      set_debug_level(1);
    }

  /* call configure routines */
  configuration = pk_configure(argc - 1, argv + 1);
  if (!configuration ) {
	DBG("Error setting configuration parameters");
	return 1;
  }

  if ((configuration->slot_description != NULL && configuration->slot_num != -1) || (configuration->slot_description == NULL && configuration->slot_num == -1)) {
	ERR("Error setting configuration parameters");
	return 1;
  }

  /* init openssl */
  rv = crypto_init(&configuration->policy);
  if (rv != 0) {
    DBG("Couldn't initialize crypto module ");
    return 1;
  }

  /* load pkcs #11 module */
  DBG("loading pkcs #11 module...");
  rv = load_pkcs11_module(configuration->pkcs11_modulepath, &ph);
  if (rv != 0) {
    DBG1("load_pkcs11_module() failed: %s", get_error());
    return 1;
  }

  /* initialise pkcs #11 module */
  DBG("initialising pkcs #11 module...");
  rv = init_pkcs11_module(ph,configuration->support_threads);
  if (rv != 0) {
    release_pkcs11_module(ph);
    DBG1("init_pkcs11_module() failed: %s", get_error());
    return 1;
  }

  /* open pkcs #11 session */
  if (configuration->slot_description != NULL) {
    rv = find_slot_by_slotlabel(ph,configuration->slot_description, &slot_num);
  } else {
    rv = find_slot_by_number(ph,configuration->slot_num, &slot_num);
  }
  if (rv != 0) {
    release_pkcs11_module(ph);
    DBG("no token available");
    return 1;
  }
  rv = open_pkcs11_session(ph, slot_num);
  if (rv != 0) {
    release_pkcs11_module(ph);
    DBG1("open_pkcs11_session() failed: %s", get_error());
    return 1;
  }

#ifdef HAVE_NSS
  /* not really needed, but... */
  rv = pkcs11_pass_login(ph,configuration->nullok);
  if (rv != 0) {
    DBG1("pkcs11_pass_login() failed: %s", get_error());
    return 2;
  }
#endif

  /* get certificate list */
  certs = get_certificate_list(ph, &cert_count);
  if (certs == NULL) {
    close_pkcs11_session(ph);
    release_pkcs11_module(ph);
    DBG1("get_certificate_list() failed: %s", get_error());
    return 3;
  }

  /* load mapper modules */
  load_mappers(configuration->ctx);

  /* find a valid and matching certificates */
  DBG1("Found '%d' certificate(s)", cert_count);
  for (i = 0; i < cert_count; i++) {
    X509 *x509 = get_X509_certificate(certs[i]);
    if (x509 != NULL) {
      DBG1("verifying the certificate #%d", i + 1);
      /* verify certificate (date, signature, CRL, ...) */
      rv = verify_certificate(x509,&configuration->policy);
      if (rv < 0) {
        close_pkcs11_session(ph);
        release_pkcs11_module(ph);
        unload_mappers();
        DBG1("verify_certificate() failed: %s", get_error());
        return 1;
      } else if (rv != 1) {
        DBG1("verify_certificate() failed: %s", get_error());
        continue;
      }

      DBG("Trying to deduce login from certificate");
      user=find_user(x509);
      if (!user) {
          DBG2("find_user() failed for certificate #%d: %s", i + 1, get_error());
	  continue;	/* with next certificate */
      } else {
          DBG1("Certificate is valid and maps to user %s",user);
	  printf("%s\n",user);
          break;
      }
    }
  }

  unload_mappers(); /* no longer needed */

  /* close pkcs #11 session */
  rv = close_pkcs11_session(ph);
  if (rv != 0) {
    release_pkcs11_module(ph);
    DBG1("close_pkcs11_session() failed: %s", get_error());
    return 1;
  }

  /* release pkcs #11 module */
  DBG("releasing pkcs #11 module...");
  release_pkcs11_module(ph);

  DBG("Process completed");
  return (!user)? 1:0;
}
Example #26
0
Boolean handle_dosemu_keys(Boolean make, t_keysym key) 
{
	Boolean result = TRUE;
	switch(key) {

#ifdef X86_EMULATOR
	case KEY_DOSEMU_X86EMU_DEBUG:
		k_printf("KBD: Ctrl-Alt-PgUp\n");
		if (config.cpuemu) {
			if (debug_level('e') < 2) set_debug_level('e', 4);
			fflush(dbg_fd);
		}
		return 1;
#endif
	/* C-A-D is disabled */
	case KEY_DOSEMU_REBOOT:
		if (make) {
			k_printf("KBD: Ctrl-Alt-Del: rebooting dosemu\n");
			dos_ctrl_alt_del();
		}
		break;
	case KEY_DOSEMU_EXIT:
		if (make) {
			k_printf("KBD: Ctrl-Alt-PgDn: bye bye!\n");
			leavedos(0);
		}
		break;
		
	case KEY_DOSEMU_FREEZE:
		if (make) {
			if (!dosemu_frozen) {
				freeze_dosemu_manual();
			} else {
				unfreeze_dosemu();
			}
		}
		break;

	case KEY_DOSEMU_VT_1: 
	case KEY_DOSEMU_VT_2:
	case KEY_DOSEMU_VT_3:
	case KEY_DOSEMU_VT_4:
	case KEY_DOSEMU_VT_5:
	case KEY_DOSEMU_VT_6:
	case KEY_DOSEMU_VT_7:
	case KEY_DOSEMU_VT_8:
	case KEY_DOSEMU_VT_9:
	case KEY_DOSEMU_VT_10:
	case KEY_DOSEMU_VT_11:
	case KEY_DOSEMU_VT_12:
		if (make) {
			int vc_num;
			vc_num = (key - KEY_DOSEMU_VT_1) +1;
			result = switch_to_console(vc_num);
		}
		break;
			
	case KEY_MOUSE_UP:
	case KEY_MOUSE_DOWN:
	case KEY_MOUSE_LEFT:
	case KEY_MOUSE_RIGHT:
	case KEY_MOUSE_UP_AND_LEFT:
	case KEY_MOUSE_UP_AND_RIGHT:
	case KEY_MOUSE_DOWN_AND_LEFT:
	case KEY_MOUSE_DOWN_AND_RIGHT:
	case KEY_MOUSE_BUTTON_LEFT:
	case KEY_MOUSE_BUTTON_MIDDLE:
	case KEY_MOUSE_BUTTON_RIGHT:
		mouse_keyboard(make, key);        /* mouse emulation keys */
		break;

	case KEY_DOSEMU_HELP:
	case KEY_DOSEMU_REDRAW:
	case KEY_DOSEMU_SUSPEND:
	case KEY_DOSEMU_RESET:
	case KEY_DOSEMU_MONO:
	case KEY_DOSEMU_PAN_UP:
	case KEY_DOSEMU_PAN_DOWN:
	case KEY_DOSEMU_PAN_LEFT:
	case KEY_DOSEMU_PAN_RIGHT:
		if (Keyboard->handle_keys) {
			Keyboard->handle_keys(make, key);
		} else
		{
			result = FALSE;
		}
		break;

#if 0
	case KEY_MOUSE_GRAB:
		if (Keyboard == &Keyboard_X) {
			handle_X_keys(make, key);
		} else {
			result = FALSE;
		}
#endif

	default:
		result = FALSE;
		break;
	}
	return result;
}
Example #27
0
File: main.c Project: tiwoc/liferea
int
main (int argc, char *argv[])
{
	GtkApplication	*app;
	GError		*error = NULL;
	GOptionContext	*context;
	GOptionGroup	*debug;
	gulong		debug_flags = 0;
	LifereaDBus	*dbus = NULL;
	gchar		*feedUri = NULL;
	gint 		status;

	GOptionEntry entries[] = {
		{ "mainwindow-state", 'w', 0, G_OPTION_ARG_STRING, &initialStateOption, N_("Start Liferea with its main window in STATE. STATE may be `shown', `iconified', or `hidden'"), N_("STATE") },
		{ "version", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version, N_("Show version information and exit"), NULL },
		{ "add-feed", 'a', 0, G_OPTION_ARG_STRING, &feedUri, N_("Add a new subscription"), N_("uri") },
		{ NULL, 0, 0, 0, NULL, NULL, NULL }
	};

	GOptionEntry debug_entries[] = {
		{ "debug-all", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of all types"), NULL },
		{ "debug-cache", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages for the cache handling"), NULL },
		{ "debug-conf", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages for the configuration handling"), NULL },
		{ "debug-db", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of the database handling"), NULL },
		{ "debug-gui", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of all GUI functions"), NULL },
		{ "debug-html", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Enables HTML rendering debugging. Each time Liferea renders HTML output it will also dump the generated HTML into ~/.cache/liferea/output.xhtml"), NULL },
		{ "debug-net", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of all network activity"), NULL },
		{ "debug-parsing", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of all parsing functions"), NULL },
		{ "debug-performance", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages when a function takes too long to process"), NULL },
		{ "debug-trace", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages when entering/leaving functions"), NULL },
		{ "debug-update", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of the feed update processing"), NULL },
		{ "debug-vfolder", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of the search folder matching"), NULL },
		{ "debug-verbose", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print verbose debugging messages"), NULL },
		{ NULL, 0, 0, 0, NULL, NULL, NULL }
	};

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

	debug = g_option_group_new ("debug",
				    _("Print debugging messages for the given topic"),
				    _("Print debugging messages for the given topic"),
				    &debug_flags,
				    NULL);
	g_option_group_set_translation_domain(debug, GETTEXT_PACKAGE);
	g_option_group_add_entries (debug, debug_entries);

	context = g_option_context_new (NULL);
	g_option_context_set_summary (context, N_("Liferea, the Linux Feed Reader"));
	g_option_context_set_description (context, N_("For more information, please visit http://lzone.de/liferea/"));
	g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
	g_option_context_set_translation_domain(context, GETTEXT_PACKAGE);
	g_option_context_add_group (context, debug);
	g_option_context_add_group (context, gtk_get_option_group (FALSE));
	g_option_context_add_group (context, g_irepository_get_option_group ());

	g_option_context_parse (context, &argc, &argv, &error);
	g_option_context_free (context);
	if (error) {
		g_print ("Error parsing options: %s\n", error->message);
	}

	set_debug_level (debug_flags);

	/* Configuration necessary for network options, so it
	   has to be initialized before update_init() */
	conf_init ();

	/* We need to do the network initialization here to allow
	   network-manager to be setup before gtk_init() */
	update_init ();

	gtk_init (&argc, &argv);

	/* Single instance checks, also note that we pass or only RPC (add-feed)
	   as activate signal payload as it is simply an URI string. */
	app = gtk_application_new ("net.sourceforge.liferea", G_APPLICATION_HANDLES_OPEN);
	g_signal_connect (app, "activate", G_CALLBACK (on_app_activate), feedUri);
	g_signal_connect (app, "open", G_CALLBACK (on_feed_add), NULL);

	g_set_prgname ("liferea");
	g_set_application_name (_("Liferea"));
	gtk_window_set_default_icon_name ("liferea");	/* GTK theme support */

	debug_start_measurement (DEBUG_DB);

	/* order is important! */
	db_init ();			/* initialize sqlite */
	xml_init ();			/* initialize libxml2 */
#ifdef HAVE_LIBNOTIFY
	notification_plugin_register (&libnotify_plugin);
#endif
	social_init ();			/* initialize social bookmarking */

	dbus = liferea_dbus_new ();

	signal (SIGTERM, signal_handler);
	signal (SIGINT, signal_handler);
	signal (SIGHUP, signal_handler);

	/* Note: we explicitely do not use the gdk_thread_*
	   locking in Liferea because it freezes the program
	   when running Flash applets */

	runState = STATE_STARTING;
	
	debug_end_measurement (DEBUG_DB, "startup");

	status = g_application_run (G_APPLICATION (app), 0, NULL);

	/* Trigger RPCs if we are not primary instance (currently only feed-add) */
	if (feedUri && g_application_get_is_remote (G_APPLICATION (app))) {
		GFile *uris[2];

		uris[0] = g_file_new_for_uri (feedUri);
		uris[1] = NULL;
		g_application_open (G_APPLICATION (app), uris, 1, "feed-add");
		g_object_unref (uris[0]);
	}
	
	g_object_unref (G_OBJECT (dbus));
	g_object_unref (app);

	return status;
}
Example #28
0
PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
  int i, rv;
  const char *user = NULL;
  char *password;
  unsigned int slot_num = 0;
  int is_a_screen_saver = 0;
  struct configuration_st *configuration;
  int pkcs11_pam_fail = PAM_AUTHINFO_UNAVAIL;

  pkcs11_handle_t *ph;
  cert_object_t *chosen_cert = NULL;
  cert_object_t **cert_list;
  int ncert;
  unsigned char random_value[128];
  unsigned char *signature;
  unsigned long signature_length;
  /* enough space to hold an issuer DN */
  char env_temp[256] = "";
  char **issuer, **serial;
  const char *login_token_name = NULL;

  pam_prompt(pamh, PAM_TEXT_INFO , NULL, _("Smartcard authentication starts"));

  /* first of all check whether debugging should be enabled */
  for (i = 0; i < argc; i++)
    if (strcmp("debug", argv[i]) == 0) {
      set_debug_level(1);
    }

  /* call configure routines */
  configuration = pk_configure(argc,argv);
  if (!configuration ) {
	ERR("Error setting configuration parameters");
	return PAM_AUTHINFO_UNAVAIL;
  }

  /* Either slot_description or slot_num, but not both, needs to be used */
  if ((configuration->slot_description != NULL && configuration->slot_num != -1) || (configuration->slot_description == NULL && configuration->slot_num == -1)) {
	ERR("Error setting configuration parameters");
	return PAM_AUTHINFO_UNAVAIL;
  }

  /* fail if we are using a remote server
   * local login: DISPLAY=:0
   * XDMCP login: DISPLAY=host:0 */
  {
	  char *display = getenv("DISPLAY");

	  if (display)
	  {
		  if (strncmp(display, "localhost:", 10) != 0 && (display[0] != ':')
			  && (display[0] != '\0')) {
			  ERR1("Remote login (from %s) is not (yet) supported", display);
			  pam_syslog(pamh, LOG_ERR,
				  "Remote login (from %s) is not (yet) supported", display);
			  return PAM_AUTHINFO_UNAVAIL;
		  }
	  }
  }

#ifdef ENABLE_NLS
  setlocale(LC_ALL, "");
  bindtextdomain(PACKAGE, "/usr/share/locale");
  textdomain(PACKAGE);
#endif

  /* init openssl */
  rv = crypto_init(&configuration->policy);
  if (rv != 0) {
    ERR("Failed to initialize crypto");
    if (!configuration->quiet)
      pam_syslog(pamh,LOG_ERR, "Failed to initialize crypto");
    return PAM_AUTHINFO_UNAVAIL;
  }


  /*
   * card_only means:
   *  1) always get the userid from the certificate.
   *  2) don't prompt for the user name if the card is present.
   *  3) if the token is present, then we must use the cardAuth mechanism.
   *
   * wait_for_card means:
   *  1) nothing if card_only isn't set
   *  2) if logged in, block in pam conversation until the token used for login
   *     is inserted
   *  3) if not logged in, block until a token that could be used for logging in
   *     is inserted
   * right now, logged in means PKC11_LOGIN_TOKEN_NAME is set,
   * but we could something else later (like set some per-user state in
   * a pam session module keyed off uid)
   */
  if (configuration->card_only) {
	char *service;
	if (configuration->screen_savers) {
	    DBG("Is it a screen saver?");
		pam_get_item(pamh, PAM_SERVICE, &service);
	    for (i=0; configuration->screen_savers[i]; i++) {
		if (strcmp(configuration->screen_savers[i], service) == 0) {
		    is_a_screen_saver = 1;
		    break;
		}
	    }
	}

	pkcs11_pam_fail = PAM_CRED_INSUFFICIENT;

	/* look to see if username is already set */
	pam_get_item(pamh, PAM_USER, &user);
	if (user) {
	    DBG1("explicit username = [%s]", user);
	}
  } else {
	rv = pam_get_item(pamh, PAM_USER, &user);
	if (rv != PAM_SUCCESS || user == NULL || user[0] == '\0') {
	  pam_prompt(pamh, PAM_TEXT_INFO, NULL,
		  _("Please insert your %s or enter your username."),
		  _(configuration->token_type));
	  /* get user name */
	  rv = pam_get_user(pamh, &user, NULL);

	  if (rv != PAM_SUCCESS) {
		pam_syslog(pamh, LOG_ERR,
			"pam_get_user() failed %s", pam_strerror(pamh, rv));
		return PAM_USER_UNKNOWN;
	  }
	}
	DBG1("username = [%s]", user);
  }
  login_token_name = getenv("PKCS11_LOGIN_TOKEN_NAME");

  /* if we are using a screen saver, and we didn't log in using the smart card
   * drop to the next pam module.  */
  if (is_a_screen_saver && !login_token_name) {
    return PAM_IGNORE;
  }

  /* load pkcs #11 module */
  DBG("loading pkcs #11 module...");
  rv = load_pkcs11_module(configuration->pkcs11_modulepath, &ph);
  if (rv != 0) {
    ERR2("load_pkcs11_module() failed loading %s: %s",
		configuration->pkcs11_modulepath, get_error());
    if (!configuration->quiet) {
		pam_syslog(pamh, LOG_ERR, "load_pkcs11_module() failed loading %s: %s",
			configuration->pkcs11_modulepath, get_error());
		pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2302: PKCS#11 module failed loading"));
		sleep(configuration->err_display_time);
	}
    return PAM_AUTHINFO_UNAVAIL;
  }

  /* initialise pkcs #11 module */
  DBG("initialising pkcs #11 module...");
  rv = init_pkcs11_module(ph,configuration->support_threads);
  if (rv != 0) {
    release_pkcs11_module(ph);
    ERR1("init_pkcs11_module() failed: %s", get_error());
    if (!configuration->quiet) {
		pam_syslog(pamh, LOG_ERR, "init_pkcs11_module() failed: %s", get_error());
		pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2304: PKCS#11 module could not be initialized"));
		sleep(configuration->err_display_time);
	}
    return PAM_AUTHINFO_UNAVAIL;
  }

  /* open pkcs #11 session */
  if (configuration->slot_description != NULL) {
    rv = find_slot_by_slotlabel_and_tokenlabel(ph,
      configuration->slot_description, login_token_name, &slot_num);
  } else if (configuration->slot_num != -1) {
    rv = find_slot_by_number_and_label(ph, configuration->slot_num,
                                     login_token_name, &slot_num);
  }

  if (rv != 0) {
    ERR("no suitable token available");
    if (!configuration->quiet) {
		pam_syslog(pamh, LOG_ERR, "no suitable token available");
		pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2306: No suitable token available"));
		sleep(configuration->err_display_time);
	}

    if (!configuration->card_only) {
      release_pkcs11_module(ph);
      return PAM_AUTHINFO_UNAVAIL;
    }

    /* we must have a smart card, either because we've configured it as such,
     * or because we used one to log in */
    if (login_token_name || configuration->wait_for_card) {
      if (login_token_name) {
        pam_prompt(pamh, PAM_TEXT_INFO, NULL,
			_("Please insert your smart card called \"%.32s\"."),
			login_token_name);
      } else {
        pam_prompt(pamh, PAM_TEXT_INFO, NULL,
                 _("Please insert your smart card."));
      }

      if (configuration->slot_description != NULL) {
	rv = wait_for_token_by_slotlabel(ph, configuration->slot_description,
          login_token_name, &slot_num);
      } else if (configuration->slot_num != -1) {
        rv = wait_for_token(ph, configuration->slot_num,
                          login_token_name, &slot_num);
      }

      if (rv != 0) {
        release_pkcs11_module(ph);
        return pkcs11_pam_fail;
      }
    } else if (user) {
		if (!configuration->quiet) {
			pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2308: No smartcard found"));
			sleep(configuration->err_display_time);
		}

      /* we have a user and no smart card, go to the next pam module */
      release_pkcs11_module(ph);
      return PAM_AUTHINFO_UNAVAIL;
    } else {
      /* we haven't prompted for the user yet, get the user and see if
       * the smart card has been inserted in the mean time */
      pam_prompt(pamh, PAM_TEXT_INFO, NULL,
	    _("Please insert your %s or enter your username."),
		_(configuration->token_type));
      rv = pam_get_user(pamh, &user, NULL);

      /* check one last time for the smart card before bouncing to the next
       * module */
      if (configuration->slot_description != NULL) {
	rv = find_slot_by_slotlabel(ph, configuration->slot_description,
	  &slot_num);
      } else if (configuration->slot_num != -1) {
        rv = find_slot_by_number(ph, configuration->slot_num, &slot_num);
      }

      if (rv != 0) {
        /* user gave us a user id and no smart card go to next module */
		if (!configuration->quiet) {
			pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2310: No smartcard found"));
			sleep(configuration->err_display_time);
		}

        release_pkcs11_module(ph);
        return PAM_AUTHINFO_UNAVAIL;
      }
    }
  } else {
      pam_prompt(pamh, PAM_TEXT_INFO, NULL,
		  _("%s found."), _(configuration->token_type));
  }
  rv = open_pkcs11_session(ph, slot_num);
  if (rv != 0) {
    ERR1("open_pkcs11_session() failed: %s", get_error());
    if (!configuration->quiet) {
		pam_syslog(pamh, LOG_ERR, "open_pkcs11_session() failed: %s", get_error());
		pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2312: open PKCS#11 session failed"));
		sleep(configuration->err_display_time);
	}
    release_pkcs11_module(ph);
    return pkcs11_pam_fail;
  }

  rv = get_slot_login_required(ph);
  if (rv == -1) {
    ERR1("get_slot_login_required() failed: %s", get_error());
    if (!configuration->quiet) {
		pam_syslog(pamh, LOG_ERR, "get_slot_login_required() failed: %s", get_error());
		pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2314: Slot login failed"));
		sleep(configuration->err_display_time);
	}
    release_pkcs11_module(ph);
    return pkcs11_pam_fail;
  } else if (rv) {
    /* get password */
	pam_prompt(pamh, PAM_TEXT_INFO, NULL,
		_("Welcome %.32s!"), get_slot_tokenlabel(ph));

	/* no CKF_PROTECTED_AUTHENTICATION_PATH */
	rv = get_slot_protected_authentication_path(ph);
	if ((-1 == rv) || (0 == rv))
	{
		char password_prompt[128];

		snprintf(password_prompt,  sizeof(password_prompt), _("%s PIN: "), _(configuration->token_type));
		if (configuration->use_first_pass) {
			rv = pam_get_pwd(pamh, &password, NULL, PAM_AUTHTOK, 0);
		} else if (configuration->try_first_pass) {
			rv = pam_get_pwd(pamh, &password, password_prompt, PAM_AUTHTOK,
					PAM_AUTHTOK);
		} else {
			rv = pam_get_pwd(pamh, &password, password_prompt, 0, PAM_AUTHTOK);
		}
		if (rv != PAM_SUCCESS) {
			if (!configuration->quiet) {
				pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2316: password could not be read"));
				sleep(configuration->err_display_time);
			}
			release_pkcs11_module(ph);
			pam_syslog(pamh, LOG_ERR,
					"pam_get_pwd() failed: %s", pam_strerror(pamh, rv));
			return pkcs11_pam_fail;
		}
#ifdef DEBUG_SHOW_PASSWORD
		DBG1("password = [%s]", password);
#endif

		/* check password length */
		if (!configuration->nullok && strlen(password) == 0) {
			release_pkcs11_module(ph);
			memset(password, 0, strlen(password));
			free(password);
			pam_syslog(pamh, LOG_ERR,
					"password length is zero but the 'nullok' argument was not defined.");
			if (!configuration->quiet) {
				pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2318: Empty smartcard PIN not allowed."));
				sleep(configuration->err_display_time);
			}
			return PAM_AUTH_ERR;
		}
	}
	else
	{
		pam_prompt(pamh, PAM_TEXT_INFO, NULL,
			_("Enter your %s PIN on the pinpad"), _(configuration->token_type));
		/* use pin pad */
		password = NULL;
	}

    /* call pkcs#11 login to ensure that the user is the real owner of the card
     * we need to do thise before get_certificate_list because some tokens
     * can not read their certificates until the token is authenticated */
    rv = pkcs11_login(ph, password);
    /* erase and free in-memory password data asap */
	if (password)
	{
		memset(password, 0, strlen(password));
		free(password);
	}
    if (rv != 0) {
      ERR1("open_pkcs11_login() failed: %s", get_error());
		if (!configuration->quiet) {
			pam_syslog(pamh, LOG_ERR, "open_pkcs11_login() failed: %s", get_error());
			pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2320: Wrong smartcard PIN"));
			sleep(configuration->err_display_time);
		}
      goto auth_failed_nopw;
    }
  }

  cert_list = get_certificate_list(ph, &ncert);
  if (rv<0) {
    ERR1("get_certificate_list() failed: %s", get_error());
    if (!configuration->quiet) {
		pam_syslog(pamh, LOG_ERR, "get_certificate_list() failed: %s", get_error());
		pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2322: No certificate found"));
		sleep(configuration->err_display_time);
	}
    goto auth_failed_nopw;
  }

  /* load mapper modules */
  load_mappers(configuration->ctx);

  /* find a valid and matching certificates */
  for (i = 0; i < ncert; i++) {
    X509 *x509 = (X509 *)get_X509_certificate(cert_list[i]);
    if (!x509 ) continue; /* sanity check */
    DBG1("verifying the certificate #%d", i + 1);
	if (!configuration->quiet) {
		pam_prompt(pamh, PAM_TEXT_INFO, NULL, _("verifying certificate"));
	}

      /* verify certificate (date, signature, CRL, ...) */
      rv = verify_certificate(x509,&configuration->policy);
      if (rv < 0) {
        ERR1("verify_certificate() failed: %s", get_error());
        if (!configuration->quiet) {
          pam_syslog(pamh, LOG_ERR,
                   "verify_certificate() failed: %s", get_error());
			switch (rv) {
				case -2: // X509_V_ERR_CERT_HAS_EXPIRED:
					pam_prompt(pamh, PAM_ERROR_MSG , NULL,
						_("Error 2324: Certificate has expired"));
					break;
				case -3: // X509_V_ERR_CERT_NOT_YET_VALID:
					pam_prompt(pamh, PAM_ERROR_MSG , NULL,
						_("Error 2326: Certificate not yet valid"));
					break;
				case -4: // X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
					pam_prompt(pamh, PAM_ERROR_MSG , NULL,
						_("Error 2328: Certificate signature invalid"));
					break;
				default:
					pam_prompt(pamh, PAM_ERROR_MSG , NULL,
						_("Error 2330: Certificate invalid"));
					break;
			}
			sleep(configuration->err_display_time);
		}
        continue; /* try next certificate */
      } else if (rv != 1) {
        ERR1("verify_certificate() failed: %s", get_error());
        continue; /* try next certificate */
      }

    /* CA and CRL verified, now check/find user */

    if ( is_spaced_str(user) ) {
      /*
	if provided user is null or empty extract and set user
	name from certificate
      */
	DBG("Empty login: try to deduce from certificate");
	user=find_user(x509);
	if (!user) {
          ERR2("find_user() failed: %s on cert #%d", get_error(),i+1);
          if (!configuration->quiet)
            pam_syslog(pamh, LOG_ERR,
                     "find_user() failed: %s on cert #%d",get_error(),i+1);
	  continue; /* try on next certificate */
	} else {
          DBG1("certificate is valid and matches user %s",user);
	  /* try to set up PAM user entry with evaluated value */
	  rv = pam_set_item(pamh, PAM_USER,(const void *)user);
	  if (rv != PAM_SUCCESS) {
	    ERR1("pam_set_item() failed %s", pam_strerror(pamh, rv));
            if (!configuration->quiet) {
				pam_syslog(pamh, LOG_ERR,
                       "pam_set_item() failed %s", pam_strerror(pamh, rv));
				pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2332: setting PAM userentry failed"));
				sleep(configuration->err_display_time);
			}
	    goto auth_failed_nopw;
	}
          chosen_cert = cert_list[i];
          break; /* end loop, as find user success */
      }
    } else {
      /* User provided:
         check whether the certificate matches the user */
        rv = match_user(x509, user);
        if (rv < 0) { /* match error; abort and return */
          ERR1("match_user() failed: %s", get_error());
			if (!configuration->quiet) {
				pam_syslog(pamh, LOG_ERR, "match_user() failed: %s", get_error());
				pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2334: No matching user"));
				sleep(configuration->err_display_time);
			}
	  goto auth_failed_nopw;
        } else if (rv == 0) { /* match didn't success */
          DBG("certificate is valid but does not match the user");
	  continue; /* try next certificate */
        } else { /* match success */
          DBG("certificate is valid and matches the user");
          chosen_cert = cert_list[i];
          break;
      }
    } /* if is_spaced string */
  } /* for (i=0; i<ncerts; i++) */

  /* now myCert points to our found certificate or null if no user found */
  if (!chosen_cert) {
    ERR("no valid certificate which meets all requirements found");
		if (!configuration->quiet) {
			pam_syslog(pamh, LOG_ERR,
				"no valid certificate which meets all requirements found");
		pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2336: No matching certificate found"));
		sleep(configuration->err_display_time);
	}
    goto auth_failed_nopw;
  }


  /* if signature check is enforced, generate random data, sign and verify */
  if (configuration->policy.signature_policy) {
		pam_prompt(pamh, PAM_TEXT_INFO, NULL, _("Checking signature"));


#ifdef notdef
    rv = get_private_key(ph);
    if (rv != 0) {
      ERR1("get_private_key() failed: %s", get_error());
      if (!configuration->quiet)
        pam_syslog(pamh, LOG_ERR,
                 "get_private_key() failed: %s", get_error());
      goto auth_failed_nopw;
    }
#endif

    /* read random value */
    rv = get_random_value(random_value, sizeof(random_value));
    if (rv != 0) {
      ERR1("get_random_value() failed: %s", get_error());
		if (!configuration->quiet){
			pam_syslog(pamh, LOG_ERR, "get_random_value() failed: %s", get_error());
			pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2338: Getting random value failed"));
			sleep(configuration->err_display_time);
		}
      goto auth_failed_nopw;
    }

    /* sign random value */
    signature = NULL;
    rv = sign_value(ph, chosen_cert, random_value, sizeof(random_value),
		    &signature, &signature_length);
    if (rv != 0) {
      ERR1("sign_value() failed: %s", get_error());
		if (!configuration->quiet) {
			pam_syslog(pamh, LOG_ERR, "sign_value() failed: %s", get_error());
			pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2340: Signing failed"));
			sleep(configuration->err_display_time);
		}
      goto auth_failed_nopw;
    }

    /* verify the signature */
    DBG("verifying signature...");
    rv = verify_signature((X509 *)get_X509_certificate(chosen_cert),
             random_value, sizeof(random_value), signature, signature_length);
    if (signature != NULL) {
      free(signature);
    }
    if (rv != 0) {
      close_pkcs11_session(ph);
      release_pkcs11_module(ph);
      ERR1("verify_signature() failed: %s", get_error());
		if (!configuration->quiet) {
			pam_syslog(pamh, LOG_ERR, "verify_signature() failed: %s", get_error());
			pam_prompt(pamh, PAM_ERROR_MSG , NULL, _("Error 2342: Verifying signature failed"));
			sleep(configuration->err_display_time);
		}
      return PAM_AUTH_ERR;
    }

  } else {
      DBG("Skipping signature check");
  }

  /*
   * fill in the environment variables.
   */
  snprintf(env_temp, sizeof(env_temp) - 1,
	   "PKCS11_LOGIN_TOKEN_NAME=%.*s",
	   (int)((sizeof(env_temp) - 1) - strlen("PKCS11_LOGIN_TOKEN_NAME=")),
	   get_slot_tokenlabel(ph));
  rv = pam_putenv(pamh, env_temp);

  if (rv != PAM_SUCCESS) {
    ERR1("could not put token name in environment: %s",
         pam_strerror(pamh, rv));
    if (!configuration->quiet)
      pam_syslog(pamh, LOG_ERR, "could not put token name in environment: %s",
           pam_strerror(pamh, rv));
  }

  issuer = cert_info((X509 *)get_X509_certificate(chosen_cert), CERT_ISSUER,
                     ALGORITHM_NULL);
  if (issuer) {
    snprintf(env_temp, sizeof(env_temp) - 1,
	   "PKCS11_LOGIN_CERT_ISSUER=%.*s",
	   (int)((sizeof(env_temp) - 1) - strlen("PKCS11_LOGIN_CERT_ISSUER=")),
	   issuer[0]);
    rv = pam_putenv(pamh, env_temp);
  } else {
    ERR("couldn't get certificate issuer.");
    if (!configuration->quiet)
      pam_syslog(pamh, LOG_ERR, "couldn't get certificate issuer.");
  }

  if (rv != PAM_SUCCESS) {
    ERR1("could not put cert issuer in environment: %s",
         pam_strerror(pamh, rv));
    if (!configuration->quiet)
      pam_syslog(pamh, LOG_ERR, "could not put cert issuer in environment: %s",
           pam_strerror(pamh, rv));
  }

  serial = cert_info((X509 *)get_X509_certificate(chosen_cert), CERT_SERIAL,
                     ALGORITHM_NULL);
  if (serial) {
    snprintf(env_temp, sizeof(env_temp) - 1,
	   "PKCS11_LOGIN_CERT_SERIAL=%.*s",
	   (int)((sizeof(env_temp) - 1) - strlen("PKCS11_LOGIN_CERT_SERIAL=")),
	   serial[0]);
    rv = pam_putenv(pamh, env_temp);
  } else {
    ERR("couldn't get certificate serial number.");
    if (!configuration->quiet)
      pam_syslog(pamh, LOG_ERR, "couldn't get certificate serial number.");
  }

  if (rv != PAM_SUCCESS) {
    ERR1("could not put cert serial in environment: %s",
         pam_strerror(pamh, rv));
    if (!configuration->quiet)
      pam_syslog(pamh, LOG_ERR, "could not put cert serial in environment: %s",
           pam_strerror(pamh, rv));
  }

  /* unload mapper modules */
  unload_mappers();

  /* close pkcs #11 session */
  rv = close_pkcs11_session(ph);
  if (rv != 0) {
    release_pkcs11_module(ph);
    ERR1("close_pkcs11_session() failed: %s", get_error());
		if (!configuration->quiet) {
			pam_syslog(pamh, LOG_ERR, "close_pkcs11_module() failed: %s", get_error());
			pam_prompt(pamh, PAM_ERROR_MSG , NULL, ("Error 2344: Closing PKCS#11 session failed"));
			sleep(configuration->err_display_time);
		}
    return pkcs11_pam_fail;
  }

  /* release pkcs #11 module */
  DBG("releasing pkcs #11 module...");
  release_pkcs11_module(ph);

  DBG("authentication succeeded");
  return PAM_SUCCESS;

    /* quick and dirty fail exit point */
    memset(password, 0, strlen(password));
    free(password); /* erase and free in-memory password data */

auth_failed_nopw:
    unload_mappers();
    close_pkcs11_session(ph);
    release_pkcs11_module(ph);
    return pkcs11_pam_fail;
}
Example #29
0
/* parse every config line */
static int
parse_line(char *buff)
{
    char   *token;
    int     i; 

    if ((token = strtok(buff, W_SPACE)) == NULL) {
        /* ignore empty lines */
        (void) 0;

    } else if (token[0] == '#') {
        /* ignore comment lines */
        (void) 0;

    } else if (strstr(token, "mod_")) {
        parse_mod(token);

    } else if (strstr(token, "spec_")) {
        special_mod(token);

    } else if (!strcmp(token, "output_interface")) {
        parse_string(conf.output_interface);

    } else if (!strcmp(token, "output_file_path")) {
        parse_string(conf.output_file_path);

    } else if (!strcmp(token, "output_db_addr")) {
        parse_string(conf.output_db_addr);

    } else if (!strcmp(token, "output_db_mod")) {
        parse_add_string(conf.output_db_mod);

    } else if (!strcmp(token, "output_tcp_mod")) {
        parse_add_string(conf.output_tcp_mod);
    } else if (!strcmp(token, "output_tcp_addr")) {
        for(i = 0; i < MAX_TCP_ADDR_NUM; i++){
            parse_string(conf.output_tcp_addr[i]);
            if(conf.output_tcp_addr[i][0] != 0){
                conf.output_tcp_addr_num++;
            } else {
                break;
            }
        }
    } else if (!strcmp(token, "output_tcp_merge")) {
        parse_string(conf.output_tcp_merge);

    } else if (!strcmp(token, "output_nagios_mod")) {
        parse_add_string(conf.output_nagios_mod);

    } else if (!strcmp(token, "output_stdio_mod")) {
        parse_add_string(conf.output_stdio_mod);

    } else if (!strcmp(token, "debug_level")) {
        set_debug_level();

    } else if (!strcmp(token, "include")) {
        get_include_conf();

    } else if (!strcmp(token, "server_addr")) {
        parse_string(conf.server_addr);

    } else if (!strcmp(token, "server_port")) {
        parse_int(&conf.server_port);

    } else if (!strcmp(token, "cycle_time")) {
        parse_int(&conf.cycle_time);

    } else if (!strcmp(token, "max_day")) {
        parse_int(&conf.print_max_day);

    } else if (!strcmp(token, "send_nsca_cmd")) {
        parse_string(conf.send_nsca_cmd);

    } else if (!strcmp(token, "send_nsca_conf")) {
        parse_string(conf.send_nsca_conf);

    } else if (!strcmp(token, "threshold")) {
        get_threshold();

    } else {
        return 0;
    }
    return 1;
}
Example #30
0
static int
common_handle_option (size_t scode, const char *arg, int value)
{
  enum opt_code code = (enum opt_code) scode;

  switch (code)
    {
    /* APPLE LOCAL begin fat builds */
    case OPT_arch:
      /* Ignore for now. */
      break;
    /* APPLE LOCAL end fat builds */

    case OPT__help:
      print_help ();
      exit_after_options = true;
      break;

    case OPT__param:
      handle_param (arg);
      break;

    case OPT__target_help:
      display_target_options ();
      exit_after_options = true;
      break;

    case OPT__version:
      print_version (stderr, "");
      exit_after_options = true;
      break;

    case OPT_G:
      g_switch_value = value;
      g_switch_set = true;
      break;

    case OPT_O:
    case OPT_Os:
      /* Currently handled in a prescan.  */
      break;

    case OPT_W:
      /* For backward compatibility, -W is the same as -Wextra.  */
      set_Wextra (value);
      break;

    case OPT_Wextra:
      set_Wextra (value);
      break;

    case OPT_Wlarger_than_:
      larger_than_size = value;
      warn_larger_than = value != -1;
      break;

    case OPT_Wstrict_aliasing:
    case OPT_Wstrict_aliasing_:
      warn_strict_aliasing = value;
      break;

    case OPT_Wunused:
      set_Wunused (value);
      break;

    case OPT_aux_info:
    case OPT_aux_info_:
      aux_info_file_name = arg;
      flag_gen_aux_info = 1;
      break;

    case OPT_auxbase:
      aux_base_name = arg;
      break;
      
      /* APPLE LOCAL begin LLVM */
    case OPT_mllvm:
      llvm_optns = arg;
      break;
      /* APPLE LOCAL end LLVM */

    case OPT_auxbase_strip:
      {
	char *tmp = xstrdup (arg);
	strip_off_ending (tmp, strlen (tmp));
	if (tmp[0])
	  aux_base_name = tmp;
      }
      break;

    case OPT_d:
      decode_d_option (arg);
      break;

    case OPT_dumpbase:
      dump_base_name = arg;
      break;

/* APPLE LOCAL begin optimization pragmas 3124235/3420242 */
/* APPLE LOCAL end optimization pragmas 3124235/3420242 */
    /* APPLE LOCAL begin falign-jumps-max-skip */
    case OPT_falign_jumps_max_skip_:
      align_jumps_max_skip = value;
      break;

    case OPT_falign_loops_max_skip_:
      align_loops_max_skip = value;
      break;
    /* APPLE LOCAL end falign-jumps-max-skip */

/* APPLE LOCAL begin optimization pragmas 3124235/3420242 */
/* APPLE LOCAL end optimization pragmas 3124235/3420242 */
    /* APPLE LOCAL begin predictive compilation */
    case OPT_fpredictive_compilation:
      predictive_compilation = 0;
      break;

    case OPT_fpredictive_compilation_:
      {
	char* buf = xmalloc (strlen(arg) + 1);
	sprintf (buf, "%d", value);
	if (strcmp(buf, arg))
	  {
	    error ("argument to \"-fpredictive-compilation=\" should be a valid non-negative integer instead of \"%s\"", arg);
	    value = 0;
	  }
	free(buf);
        predictive_compilation = value;
        break;
      }
    /* APPLE LOCAL end predictive compilation */

    case OPT_fbranch_probabilities:
      flag_branch_probabilities_set = true;
      break;

    case OPT_fcall_used_:
      fix_register (arg, 0, 1);
      break;

    case OPT_fcall_saved_:
      fix_register (arg, 0, 0);
      break;

    case OPT_fdiagnostics_show_location_:
      if (!strcmp (arg, "once"))
	diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
      else if (!strcmp (arg, "every-line"))
	diagnostic_prefixing_rule (global_dc)
	  = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
      else
	return 0;
      break;

    case OPT_fdump_:
      if (!dump_switch_p (arg))
	return 0;
      break;

    case OPT_ffast_math:
      set_fast_math_flags (value);
      break;

    case OPT_ffixed_:
      fix_register (arg, 1, 1);
      break;

    case OPT_finline_limit_:
    case OPT_finline_limit_eq:
      set_param_value ("max-inline-insns-single", value / 2);
      set_param_value ("max-inline-insns-auto", value / 2);
      break;

    case OPT_fmessage_length_:
      pp_set_line_maximum_length (global_dc->printer, value);
      break;

    case OPT_fpack_struct_:
      if (value <= 0 || (value & (value - 1)) || value > 16)
	error("structure alignment must be a small power of two, not %d", value);
      else
	{
	  initial_max_fld_align = value;
	  maximum_field_alignment = value * BITS_PER_UNIT;
	}
      break;

    case OPT_fpeel_loops:
      flag_peel_loops_set = true;
      break;

    case OPT_fprofile_arcs:
      profile_arc_flag_set = true;
      break;

    /* APPLE LOCAL begin add fuse-profile */
    case OPT_fuse_profile:
    /* APPLE LOCAL end add fuse-profile */
    case OPT_fprofile_use:
      if (!flag_branch_probabilities_set)
        flag_branch_probabilities = value;
      if (!flag_profile_values_set)
        flag_profile_values = value;
      if (!flag_unroll_loops_set)
        flag_unroll_loops = value;
      if (!flag_peel_loops_set)
        flag_peel_loops = value;
      if (!flag_tracer_set)
        flag_tracer = value;
      if (!flag_value_profile_transformations_set)
        flag_value_profile_transformations = value;
#ifdef HAVE_prefetch
      if (0 && !flag_speculative_prefetching_set)
	flag_speculative_prefetching = value;
#endif
      break;

    /* APPLE LOCAL begin add fcreate-profile */
    case OPT_fcreate_profile:
    /* APPLE LOCAL end add fcreate-profile */
    case OPT_fprofile_generate:
      if (!profile_arc_flag_set)
        profile_arc_flag = value;
      if (!flag_profile_values_set)
        flag_profile_values = value;
      if (!flag_value_profile_transformations_set)
        flag_value_profile_transformations = value;
      if (!flag_unroll_loops_set)
	flag_unroll_loops = value;
#ifdef HAVE_prefetch
      if (0 && !flag_speculative_prefetching_set)
	flag_speculative_prefetching = value;
#endif
      break;

    case OPT_fprofile_values:
      flag_profile_values_set = true;
      break;

    case OPT_fvisibility_:
      {
        if (!strcmp(arg, "default"))
          default_visibility = VISIBILITY_DEFAULT;
        else if (!strcmp(arg, "internal"))
          default_visibility = VISIBILITY_INTERNAL;
        else if (!strcmp(arg, "hidden"))
          default_visibility = VISIBILITY_HIDDEN;
        else if (!strcmp(arg, "protected"))
          default_visibility = VISIBILITY_PROTECTED;
        else
          error ("unrecognised visibility value \"%s\"", arg);
      }
      break;

    case OPT_fvpt:
      flag_value_profile_transformations_set = true;
      break;

    case OPT_fspeculative_prefetching:
      flag_speculative_prefetching_set = true;
      break;

    case OPT_frandom_seed:
      /* The real switch is -fno-random-seed.  */
      if (value)
	return 0;
      flag_random_seed = NULL;
      break;

    case OPT_frandom_seed_:
      flag_random_seed = arg;
      break;

/* APPLE LOCAL begin optimization pragmas 3124235/3420242 */
/* APPLE LOCAL end optimization pragmas 3124235/3420242 */

    case OPT_fsched_stalled_insns_:
      flag_sched_stalled_insns = value;
      if (flag_sched_stalled_insns == 0)
	flag_sched_stalled_insns = -1;
      break;

/* APPLE LOCAL begin optimization pragmas 3124235/3420242 */
/* APPLE LOCAL end optimization pragmas 3124235/3420242 */

    case OPT_fstack_limit:
      /* The real switch is -fno-stack-limit.  */
      if (value)
	return 0;
      stack_limit_rtx = NULL_RTX;
      break;

    case OPT_fstack_limit_register_:
      {
	int reg = decode_reg_name (arg);
	if (reg < 0)
	  error ("unrecognized register name \"%s\"", arg);
	else
	  stack_limit_rtx = gen_rtx_REG (Pmode, reg);
      }
      break;

    case OPT_fstack_limit_symbol_:
      stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
      break;

    case OPT_ftree_vectorizer_verbose_:
      vect_set_verbosity_level (arg);
      break;

    case OPT_ftls_model_:
      if (!strcmp (arg, "global-dynamic"))
	flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
      else if (!strcmp (arg, "local-dynamic"))
	flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
      else if (!strcmp (arg, "initial-exec"))
	flag_tls_default = TLS_MODEL_INITIAL_EXEC;
      else if (!strcmp (arg, "local-exec"))
	flag_tls_default = TLS_MODEL_LOCAL_EXEC;
      else
	warning ("unknown tls-model \"%s\"", arg);
      break;

    case OPT_ftracer:
      flag_tracer_set = true;
      break;

    case OPT_funroll_loops:
      flag_unroll_loops_set = true;
      break;

      /* APPLE LOCAL begin fwritable strings  */
    case OPT_fwritable_strings:
      flag_writable_strings = value;
      break;
      /* APPLE LOCAL end fwritable strings  */

    case OPT_g:
      set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg);
      break;

    case OPT_gcoff:
      set_debug_level (SDB_DEBUG, false, arg);
      break;

    case OPT_gdwarf_2:
      set_debug_level (DWARF2_DEBUG, false, arg);
      break;

    case OPT_ggdb:
      set_debug_level (NO_DEBUG, 2, arg);
      break;

    case OPT_gstabs:
    case OPT_gstabs_:
      set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg);
      break;

    case OPT_gvms:
      set_debug_level (VMS_DEBUG, false, arg);
      break;

    case OPT_gxcoff:
    case OPT_gxcoff_:
      set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg);
      break;

    case OPT_m:
      set_target_switch (arg);
      break;

    case OPT_o:
      asm_file_name = arg;
      break;

    case OPT_pedantic_errors:
      flag_pedantic_errors = pedantic = 1;
      break;

    default:
      /* If the flag was handled in a standard way, assume the lack of
	 processing here is intentional.  */
      /* APPLE LOCAL optimization pragmas 3124235/3420242 */
      if (cl_options[scode].flag_var || cl_options[scode].access_flag)
	break;

      abort ();
    }

  return 1;
}