Exemplo n.º 1
0
CanSocket::CanSocket(const char* interface_str) noexcept :
Socket(SocketType::CAN),
m_can_init(FALSE)
{
    AR::boolean sock_created = is_socket_initialized();

    if ( interface_str != NULL_PTR && sock_created == TRUE )
    {
        AR::boolean interface_exists = check_interface(interface_str);

        // socket creation successful and interface exists
        if ( interface_exists == TRUE )
        {
            AR::boolean bind_success = bind_if_socket();

            if ( bind_success == TRUE )
            {
                m_can_init = TRUE;
            }
            else
            {
                m_can_init = FALSE;
            }
        }
        else
        {
            m_can_init = FALSE;
        }
    }
    else
    {
        m_can_init = FALSE;
    }
}
Exemplo n.º 2
0
Bool SignerReal::notarize( PublicKey pubkey, Signature signature, Digest hash, Monitor& monitor )
{
	if (!check_interface(monitor)) return false;

	eprovider::TheKey thepubkey = creator.getCreatureCurrentTheKey(pubkey);
	Size hashsize;
	RECOVER_CALL(hashsize = iface->getMaxHashSize(thepubkey, error));
	
	Padder curpad = padder;
	if (pubkey.getPadder(Monitor()))
	{
		curpad = pubkey.getPadder(monitor);
	} else if (signature.getPadder(Monitor()))
	{
		curpad = signature.getPadder(monitor);
	} else {
		//TODO: find default padder
	}

	if (curpad.ok() && hashsize.bits()) hash = curpad.pad(hash, hashsize, monitor); if (!monitor) return Bool();
	Data hashblock = hash.asData();
	
	Image signimage = signature.encode(monitor);
	Snapshot signblock = signimage.snapshot();

	Bool result;
	
	RECOVER_CALL( (result = iface->notarizeHash(session,hashblock.get(), hashblock.size(), signblock.get(), signblock.size(), signblock.encid(), thepubkey, error)) );

	return result;
}
Exemplo n.º 3
0
Signature SignerReal::sign( PrivateKey privkey, Digest hash, Monitor& monitor )
{
	if (!check_interface(monitor)) return Signature();

	Parameters params = privkey.getAlgParams(acSign, Monitor());
	if (params) setAlgParams(params,monitor);

	Padder curpad = padder;
	if (privkey.getPadder(Monitor()))
	{
		curpad = privkey.getPadder(monitor);
	} else {
		//TODO: find default padder
	}

	Error error;
	if (random)
	{
		IRef<eprovider::ProviderInterface> randomer = creator.getCreatureCurrentInterface(random);
		if (randomer) iface->setRandom(session, randomer.cast<eprovider::RandomGenerator>().get(), error);
	}

	eprovider::TheKey thekey = creator.getCreatureCurrentTheKey(privkey);

	Size hashsize = iface->getMaxHashSize(thekey, error);
	if (curpad.ok() && hashsize.bits()) hash = curpad.pad(hash, hashsize, monitor); if (!monitor) return Signature();
	Data hashblock = hash.asData();

	eprovider::Block binsign;
	RECOVER_CALL( (binsign = iface->signHash(session, hashblock.get(), hashblock.size(), thekey, error)) );

	Snapshot snapshot = creator.createSnapshot(binsign.get(), binsign.size(), binsign.encid(), iface->getKeyId(kcSignature));
	return snapshot.reviveSignature(monitor);
}
static jint check(JNIEnv *env, jobject thiz, jstring jName)
{
    const char *name = jName ? env->GetStringUTFChars(jName, NULL) : NULL;
    if (!name) {
        jniThrowNullPointerException(env, "name");
        return 0;
    }
    int flags = check_interface(name);
    env->ReleaseStringUTFChars(jName, name);
    return flags;
}
Exemplo n.º 5
0
int 
main(int count, char **options) {
        int 		res;
        
        if (strcmp(options[1], "-d") != 0) {
            res = daemon(0, 0);
            printf("return value: %s\n", res);        
        }
        res_init();
        _res.retrans = 4;
        _res.retry = 2;
        int 		running = 1;
        if (parse_config()) {
            printf("error reading configuration!\n");
            return 1;
        }
        if (open_status_socket())
            printf("error opening status socket; no status will be provided\n");
        stat(config_file, &config_last_mod);
        printf("last config modified time: %s\n", ctime(&config_last_mod.st_mtime));
        while (running) {
            struct config_interfaces *cur = config;
            printf("checking if conf file has changed\n");
            if (config_changed()) {
                printf("modifying:\n");
                clear_config(config);
                cur = 0;
                if (parse_config())
                   printf("error reading configuration!\n");
                else
                    cur = config;
            }
            while (cur) {
                if (check_interface(cur)) {
                    printf("media type: %s\n", mediatype(cur->if_name));
                    if (strcmp(mediatype(cur->if_name), "Ethernet") == 0) {
                        if (setup_ethernetinterface(cur))
                            break;
                    } else if (strcmp(mediatype(cur->if_name), "IEEE802.11") == 0) {
                        if (setup_wlaninterface(cur))
                            break;
                    }
                }
                cur = cur->next;
            }
            printf("Sleeping... waiting %d seconds\n", poll_wait);
            sleep(poll_wait);
            printf("restarto\n");
        }
        return 0;
}
Exemplo n.º 6
0
static int check_sysfs(char *sysfspath)
{
  char dirbuf[FILENAME_MAX];
  int len = strlen(sysfspath);
  DIR *dir;
  struct dirent *dent;
  regex_t r;
  int ret;
  int look_closer = 0;

  dir = opendir(sysfspath);
  if (!dir)
    return -1;

  strcpy(dirbuf, sysfspath);
  dirbuf[len++] = '/';

  /* Check for dirs that identify interfaces */
  ret = regcomp(&r, "^[0-9]+-[0-9]+(\\.[0-9])*\\:[0-9]+\\.[0-9]+$", REG_EXTENDED | REG_NOSUB);
  if (ret) {
    closedir(dir);
    return -1;
  }

  while ((dent = readdir(dir))) {
    struct stat st;
    int ret;

    /* No need to check those beginning with a period */
    if (dent->d_name[0] == '.')
      continue;

    strncpy(dirbuf + len, dent->d_name, FILENAME_MAX - len);
    dirbuf[FILENAME_MAX - 1] = '\0'; /* Sentinel */
    ret = lstat(dirbuf, &st);
    if (ret)
      continue;

    /* Look closer at dirs that may be interfaces */
    if (S_ISDIR(st.st_mode)) {
      if (!regexec(&r, dent->d_name, 0, 0, 0))
      if (check_interface(dirbuf) > 0)
	/* potential MTP interface! */
	look_closer = 1;
    }
  }

  regfree(&r);
  closedir(dir);
  return look_closer;
}
Exemplo n.º 7
0
static char* get_interface(struct mode_list_elem *data)
{
  char *interface = NULL;
  int check = 0;

  /* check main configuration before using
     the information from the specific mode */
  interface = (char *)get_network_interface();
  /* no interface override specified, let's use the one
     from the mode config */
  if(data && !interface)
  {
	if(data->network_interface)
	{	
		interface = strdup(data->network_interface);
	}
  }

  if(interface != NULL)
	check = check_interface(interface);

  if(interface == NULL || check != 0)
  {
	if(interface != NULL)
		free((char *)interface);
	/* no known interface configured and existing, falling back to usb0 */
	interface = malloc(sizeof(default_interface)*sizeof(char));
	strncpy(interface, default_interface, sizeof(default_interface));
  }

  check = check_interface(interface);
  if(check)
	log_warning("Configured interface is incorrect, nor does usb0 exists. Check your config!\n");
  /* TODO: Make it so that interface configuration gets skipped when no usable interface exists */

  log_debug("interface = %s\n", interface);
  return interface;
}
Exemplo n.º 8
0
Bool SignerReal::notarize( PublicKey pubkey, Signature signature, const void* data, Size size, Monitor& monitor )
{
	if (!check_interface(monitor)) return false;

	eprovider::TheKey thepubkey = creator.getCreatureCurrentTheKey(pubkey);

	Image signimage = signature.encode(monitor);
	Snapshot signblock = signimage.snapshot();

	Bool result;

	RECOVER_CALL( (iface->notarizeStart(session, signblock.get(), signblock.size(), signblock.encid(), thepubkey, error)) );
	RECOVER_CALL( (iface->notarizeProcess(session, data, size, error)) );
	RECOVER_CALL( (result = iface->notarizeStop(session, error)) );

	return result;

}
Exemplo n.º 9
0
Signature SignerReal::sign( PrivateKey privkey, const void* data, Size size, Monitor& monitor )
{
	if (!check_interface(monitor)) return Signature();
	if (!hasher)
	{
		// TODO: find default hasher for this sign algid
	}

	if (hasher)
	{
		Digest digest = hasher.hash(data,size,monitor);
		return sign(privkey,data,size,monitor);
	} else {
		eprovider::TheKey thekey = creator.getCreatureCurrentTheKey(privkey);

		eprovider::Block binsign;
		RECOVER_CALL( (iface->signStart(session, thekey, error)) );
		RECOVER_CALL( (iface->signProcess(session, data, size, error)) );
		RECOVER_CALL( (binsign = iface->signStop(session, error)) );

		Snapshot snapshot = creator.createSnapshot(binsign.get(), binsign.size(), binsign.encid(), iface->getKeyId(kcSignature));
		return snapshot.reviveSignature(monitor);
	}
}
Exemplo n.º 10
0
void LPC17XX_Ethernet::on_second_tick(void *) {
    check_interface();
}
Exemplo n.º 11
0
int collect_thread(void)
{
        //int ret, ret1, ret2, ret3, ret4, ret5, ret6, ret7;
        pthread_t thread_id, thread_id1, thread_id2, thread_id3, thread_id4, thread_id5, thread_id6, thread_id7, thread_id8;

	//pthread_mutex_init(&mutex, NULL);
	//pthread_cond_init(&cond, NULL);

//	struct pthread_para *para;
//	para = malloc(sizeof(struct pthread_para));

	int len = 50;
	
	para_conf_s->interface_status1 = 0;
	para_conf_s->interface_status1 = 0;

	//strcpy( para_conf_s->interface0, para_conf_s->interface1);
	//strcpy( para_conf_s->interface1, para_conf_s->interface2);
	
	if(check_interface(para_conf_s->interface1) == 3) { para_conf_s->interface_status1 = 1; }
	if(check_interface(para_conf_s->interface2) == 3) { para_conf_s->interface_status2 = 1; }

//	printf("the para_conf_s->interface_status1: %d===\n", para_conf_s->interface_status1);

//	printf("the para_conf_s->interface_status0 is %d===\n", para_conf_s->interface_status0);
//	printf("the para_conf_s->interface_status1 is %d===\n", para_conf_s->interface_status1);


//当send_json_base和send_json_net同时在各自线程中执行时。就会提示:
//sh: -c: line 30: unexpected EOF while looking for matching `''
//sh: -c: line 31: syntax error: unexpected end of file
//但各自分别单独作为一个线程执行时就没有这个问题。


//	pthread_create(&thread_id,   NULL, (void *)send_json_disk_raw,	(void *)para );
//	pthread_create(&thread_id,   NULL, (void *)send_json_disk_all,	(void *)para );

#ifndef MODE_DEBUG
        pthread_create(&thread_id,  NULL, (void *)send_json_disk_iostat,(void *)para_conf_s ); 
        pthread_create(&thread_id1, NULL, (void *)send_json_common,	(void *)para_conf_s ); 
        pthread_create(&thread_id2, NULL, (void *)send_json_base,	(void *)para_conf_s ); 

	pthread_create(&thread_id3, NULL, (void *)send_json_cpu,	(void *)para_conf_s );
	pthread_create(&thread_id4, NULL, (void *)send_json_interval_240,(void *)para_conf_s );


	if(para_conf_s->interface_status1) { pthread_create(&thread_id5, NULL, (void *)send_json_net, (void *)(para_conf_s->interface1) ); }
	if(para_conf_s->interface_status2) { pthread_create(&thread_id6, NULL, (void *)send_json_net, (void *)(para_conf_s->interface2) ); }
	
	pthread_create(&thread_id7, NULL, (void *)send_json_proc, 	(void *)para_conf_s );
	
	if(strcmp("2", shell("netstat -antp |grep LIST |grep mysql")) !=0) {
		pthread_create(&thread_id8, NULL, (void *)send_json_mysql, (void *)para_conf_s );
	}	


	//线程回收 
        pthread_join(thread_id , NULL); 
        pthread_join(thread_id1, NULL);
        pthread_join(thread_id2, NULL);

        pthread_join(thread_id3, NULL);
	pthread_join(thread_id4, NULL);
	

	if(para_conf_s->interface_status1) { pthread_join(thread_id5, NULL); }
	if(para_conf_s->interface_status2) { pthread_join(thread_id6, NULL); }

	pthread_join(thread_id7, NULL);
	if(strcmp("2", shell("netstat -antp |grep LIST |grep mysql")) !=0) {
		pthread_join(thread_id8, NULL);
	}

#endif

//finished=======================================
	//root about Private and Private_IPCS
	//send_json_common((void *)para_conf_s);

	//user monitor group of disk
//	send_json_base((void *)para_conf_s);

	//user monitor
//	send_json_interval_240((void *)para_conf_s);

	//user monitor
//	send_json_net((void *)(para_conf_s->interface2) );

	//user monitor
//	send_json_cpu((void *)para_conf_s);
	
	//user monitor group of disk
//	send_json_disk_iostat((void *)para_conf_s);
	
//	if(strcmp("2", shell("netstat -antp |grep LIST |grep mysql")) !=0) { send_json_mysql((void *)para_conf_s); }

	//user root of iptables
//	send_json_proc((void *)para_conf_s);


        //free(para);

	//防止debug模式时,出现死循环
	sleep(1);

        return 0;
}