コード例 #1
0
ファイル: grib_diff.c プロジェクト: 0x1mason/GribApi.NET
static int compare_handles(grib_handle* h1,grib_handle* h2,blacklist* bl)
{
  int err = 0;
  const char* name=NULL;
  grib_keys_iterator* iter  = grib_keys_iterator_new(h1,
    GRIB_KEYS_ITERATOR_SKIP_EDITION_SPECIFIC|GRIB_KEYS_ITERATOR_SKIP_DUPLICATES,NULL);

  if (!iter) {
    printf("ERROR: unable to get iterator begin\n");
    exit(1);
  }

  while(grib_keys_iterator_next(iter))
  {
    /* printf("--------------- %s -----------\n",iter->current->name); */
  /* We can also black list with the class*/
/* grib_get_accessor_class_name' */

    name=grib_keys_iterator_get_name(iter);

    if( !in_blacklist(name,bl) && compare_values(h1,h2,name))
      err++;

  }

  grib_keys_iterator_delete(iter);

  return err;
}
コード例 #2
0
void PartedDevices::remove_blacklist()
{
    list<Device*>::iterator iter = list_dev_.begin();
    while( iter != list_dev_.end() )
    {
	char path[PATH_MAX];
	strcpy( path, (*iter)->path() );
	assert( ((*iter)->path()) [0] == '/' );
	assert( ((*iter)->path()) [1] == 'd' );
	assert( ((*iter)->path()) [2] == 'e' );
	assert( ((*iter)->path()) [3] == 'v' );
	assert( ((*iter)->path()) [4] == '/' );

	char* p = strrchr( (*iter)->path(), '/' );
	int len = p - ( (*iter)->path() + 4 ) -1;
	if ( len < 0 )
	    len = strlen( (*iter)->path() ) - 5 ;

	strncpy( path, (*iter)->path() + 5, len );
	path[len+1] = '\0';

	if ( in_blacklist( path ) ) {
	    del(*iter);
	    iter = list_dev_.erase( iter );
	} else {
	    iter ++;
	}
    }
}
コード例 #3
0
ファイル: crash02.c プロジェクト: Nan619/ltp-ddt
void try_one_crash(int try_num)
{
	long int sysno, arg1, arg2, arg3, arg4, arg5, arg6, arg7;

	do {
		sysno = rand() % sysno_max;
	} while (in_blacklist(sysno));

	arg1 = rand_long();
	arg2 = rand_long();
	arg3 = rand_long();
	arg4 = rand_long();
	arg5 = rand_long();
	arg6 = rand_long();
	arg7 = rand_long();

	if (x_opt) {
		if (verbose_level >= 1)
			printf("%04d: syscall(%ld, %#lx, %#lx, %#lx, %#lx, "
			       "%#lx, %#lx, %#lx)\n",
			       try_num, sysno, arg1, arg2, arg3, arg4, arg5,
			       arg6, arg7);
	} else {
		syscall(sysno, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
		record_errno(errno);
	}
}
コード例 #4
0
/* Support routines for remembering -@netgroup and -user entries.
   The names are stored in a single string with `|' as separator. */
static void
blacklist_store_name (const char *name, ent_t *ent)
{
  int namelen = strlen (name);
  char *tmp;

  /* First call, setup cache.  */
  if (ent->blacklist.size == 0)
    {
      ent->blacklist.size = MAX (BLACKLIST_INITIAL_SIZE, 2 * namelen);
      ent->blacklist.data = malloc (ent->blacklist.size);
      if (ent->blacklist.data == NULL)
	return;
      ent->blacklist.data[0] = '|';
      ent->blacklist.data[1] = '\0';
      ent->blacklist.current = 1;
    }
  else
    {
      if (in_blacklist (name, namelen, ent))
	return;			/* no duplicates */

      if (ent->blacklist.current + namelen + 1 >= ent->blacklist.size)
	{
	  ent->blacklist.size += MAX (BLACKLIST_INCREMENT, 2 * namelen);
	  tmp = realloc (ent->blacklist.data, ent->blacklist.size);
	  if (tmp == NULL)
	    {
	      free (ent->blacklist.data);
	      ent->blacklist.size = 0;
	      return;
	    }
	  ent->blacklist.data = tmp;
	}
    }

  tmp = stpcpy (ent->blacklist.data + ent->blacklist.current, name);
  *tmp++ = '|';
  *tmp = '\0';
  ent->blacklist.current += namelen + 1;

  return;
}
コード例 #5
0
ファイル: client.c プロジェクト: mangohero/Network-Lab04
/*thread function which's job is to handle the messages reveived from the server*/
void *handle_msg()
{
	struct YY_MSG rec_buf;
	memset(&rec_buf,0,YY_MSG_HEADER_LENGTH+1024);
	int len;
	while( stcp_client_recv(sockfd,&len,sizeof(int)) && stcp_client_recv(sockfd,&rec_buf,len) )
	{
		if(strncmp(rec_buf.protocol_name,"YYMG",4)!=0)
			continue;
		if(rec_buf.service == 0x16)
		{	/*If the message is not control message,then save it to the history messages!Not include messages sended by the users in the blacklist*/
			if(in_blacklist(rec_buf.send_usr))
				continue;
			int i=0;
			char *p=(char *)&history_msgs[(first_msg+msg_num)%MAX_MSG_NUM];
			char *q=(char *)&rec_buf;
			for(i;i<YY_MSG_HEADER_LENGTH+strlen(rec_buf.msg_content);i++)
				p[i]=q[i];
			if(msg_num==MAX_MSG_NUM)
				first_msg++;
			if(msg_num<MAX_MSG_NUM);
				msg_num++;
			printf("%s(to %s):%s\n",rec_buf.send_usr,rec_buf.rec_usr,rec_buf.msg_content);
			memset(&rec_buf.msg_content,0,1024);
		}
		else	/*If the message is control message,then save it to rec_msg,and set the wait rec_msg.service,then wake up the handle_main thread*/
  		{	int i=0;
			char *p=(char *)&rec_msg;
			char *q=(char *)&rec_buf;
			for(i;i<YY_MSG_HEADER_LENGTH+1024;i++)
			p[i]=q[i];
			pthread_mutex_lock(&wait_mutex);
			wait=rec_msg.service;
			pthread_cond_signal(&wait_cond);
			pthread_mutex_unlock(&wait_mutex);
			memset(&rec_buf.msg_content,0,1024);
		}
	}
	pthread_exit(NULL);
}
コード例 #6
0
static enum nss_status
internal_getgrent_r (ent_t *ent, char *buffer, size_t buflen, const char *user,
		     gid_t group, long int *start, long int *size,
		     gid_t **groupsp, long int limit, int *errnop)
{
  struct parser_data *data = (void *) buffer;
  struct group grpbuf;

  if (!ent->files)
    return getgrent_next_nss (ent, buffer, buflen, user, group,
			      start, size, groupsp, limit, errnop);

  while (1)
    {
      fpos_t pos;
      int parse_res = 0;
      char *p;

      do
	{
	  /* We need at least 3 characters for one line.  */
	  if (__builtin_expect (buflen < 3, 0))
	    {
	    erange:
	      *errnop = ERANGE;
	      return NSS_STATUS_TRYAGAIN;
	    }

	  fgetpos (ent->stream, &pos);
	  buffer[buflen - 1] = '\xff';
	  p = fgets_unlocked (buffer, buflen, ent->stream);
	  if (p == NULL && feof_unlocked (ent->stream))
	    return NSS_STATUS_NOTFOUND;

	  if (p == NULL || __builtin_expect (buffer[buflen - 1] != '\xff', 0))
	    {
	    erange_reset:
	      fsetpos (ent->stream, &pos);
	      goto erange;
	    }

	  /* Terminate the line for any case.  */
	  buffer[buflen - 1] = '\0';

	  /* Skip leading blanks.  */
	  while (isspace (*p))
	    ++p;
	}
      while (*p == '\0' || *p == '#' ||	/* Ignore empty and comment lines. */
	     /* Parse the line.  If it is invalid, loop to
	        get the next line of the file to parse.  */
	     !(parse_res = _nss_files_parse_grent (p, &grpbuf, data, buflen,
						   errnop)));

      if (__builtin_expect (parse_res == -1, 0))
	/* The parser ran out of space.  */
	goto erange_reset;

      if (grpbuf.gr_name[0] != '+' && grpbuf.gr_name[0] != '-')
	/* This is a real entry.  */
	break;

      /* -group */
      if (grpbuf.gr_name[0] == '-' && grpbuf.gr_name[1] != '\0'
	  && grpbuf.gr_name[1] != '@')
	{
	  blacklist_store_name (&grpbuf.gr_name[1], ent);
	  continue;
	}

      /* +group */
      if (grpbuf.gr_name[0] == '+' && grpbuf.gr_name[1] != '\0'
	  && grpbuf.gr_name[1] != '@')
	{
	  if (in_blacklist (&grpbuf.gr_name[1],
			    strlen (&grpbuf.gr_name[1]), ent))
	    continue;
	  /* Store the group in the blacklist for the "+" at the end of
	     /etc/group */
	  blacklist_store_name (&grpbuf.gr_name[1], ent);
	  if (nss_getgrnam_r == NULL)
	    return NSS_STATUS_UNAVAIL;
	  else if (nss_getgrnam_r (&grpbuf.gr_name[1], &grpbuf, buffer,
				   buflen, errnop) != NSS_STATUS_SUCCESS)
	    continue;

	  check_and_add_group (user, group, start, size, groupsp,
			       limit, &grpbuf);

	  return NSS_STATUS_SUCCESS;
	}

      /* +:... */
      if (grpbuf.gr_name[0] == '+' && grpbuf.gr_name[1] == '\0')
	{
	  ent->files = FALSE;
	  return getgrent_next_nss (ent, buffer, buflen, user, group,
				    start, size, groupsp, limit, errnop);
	}
    }

  check_and_add_group (user, group, start, size, groupsp, limit, &grpbuf);

  return NSS_STATUS_SUCCESS;
}
コード例 #7
0
/* Get the next group from NSS  (+ entry). If the NSS module supports
   initgroups_dyn, get all entries at once.  */
static enum nss_status
getgrent_next_nss (ent_t *ent, char *buffer, size_t buflen, const char *user,
		   gid_t group, long int *start, long int *size,
		   gid_t **groupsp, long int limit, int *errnop)
{
  enum nss_status status;
  struct group grpbuf;

  /* if this module does not support getgrent_r and initgroups_dyn,
     abort. We cannot find the needed group entries.  */
  if (nss_getgrent_r == NULL && nss_initgroups_dyn == NULL)
    return NSS_STATUS_UNAVAIL;

  /* Try nss_initgroups_dyn if supported. We also need getgrgid_r.
     If this function is not supported, step through the whole group
     database with getgrent_r.  */
  if (nss_initgroups_dyn && nss_getgrgid_r)
    {
      long int mystart = 0;
      long int mysize = limit <= 0 ? *size : limit;
      gid_t *mygroups = malloc (mysize * sizeof (gid_t));

      if (mygroups == NULL)
	return NSS_STATUS_TRYAGAIN;

      /* For every gid in the list we get from the NSS module,
         get the whole group entry. We need to do this, since we
         need the group name to check if it is in the blacklist.
         In worst case, this is as twice as slow as stepping with
         getgrent_r through the whole group database. But for large
         group databases this is faster, since the user can only be
         in a limited number of groups.  */
      if (nss_initgroups_dyn (user, group, &mystart, &mysize, &mygroups,
			      limit, errnop) == NSS_STATUS_SUCCESS)
	{
	  /* A temporary buffer. We use the normal buffer, until we find
	     an entry, for which this buffer is to small.  In this case, we
	     overwrite the pointer with one to a bigger buffer.  */
	  char *tmpbuf = buffer;
	  size_t tmplen = buflen;
	  int i;

	  for (i = 0; i < mystart; i++)
	    {
	      while ((status = nss_getgrgid_r (mygroups[i], &grpbuf, tmpbuf,
					       tmplen,
					       errnop)) == NSS_STATUS_TRYAGAIN
		     && *errnop == ERANGE)
		if (tmpbuf == buffer)
		  {
		    tmplen *= 2;
		    tmpbuf = __alloca (tmplen);
		  }
		else
		  tmpbuf = extend_alloca (tmpbuf, tmplen, 2 * tmplen);

	      if (!in_blacklist (grpbuf.gr_name,
				 strlen (grpbuf.gr_name), ent))
		check_and_add_group (user, group, start, size, groupsp,
				     limit, &grpbuf);
	    }

	  free (mygroups);

	  return NSS_STATUS_NOTFOUND;
	}

      free (mygroups);
    }

  /* If we come here, the NSS module does not support initgroups_dyn
     and we have to step through the whole list ourself.  */
  do
    {
      if ((status = nss_getgrent_r (&grpbuf, buffer, buflen, errnop)) !=
	  NSS_STATUS_SUCCESS)
	return status;
    }
  while (in_blacklist (grpbuf.gr_name, strlen (grpbuf.gr_name), ent));

  check_and_add_group (user, group, start, size, groupsp, limit, &grpbuf);
  return NSS_STATUS_SUCCESS;
}
コード例 #8
0
ファイル: mod_mail.c プロジェクト: PichuChen/formosa
/**************************************************************
 * 寄信給站上使用者
 **************************************************************/
static int SendMail_Local(char *fname,char *from, const char *to, char *title,
						char ident)
{
	USEREC urcTmp;
	char pathTmp[PATHLEN];
	int retval, fsize;

	retval = CheckMail(&urcTmp, to, FALSE);
	if (retval == -1)
		return -1;
	/* kmwang:20000610:blacklist */
/* bug fixed by lasehu 2002/05/22
	if (in_blacklist(to, from))
		return -1;
		*/
	if (!is_emailaddr(from) && in_blacklist(to, from))
		return -1;
	else if (retval > 0)
	{
		bbslog("SENDMAIL", "from=%s, to=%s, total=%d, stat=ENOSPC",
			from, to, retval);
		return -2;
	}

	/* Auto-Forward */
	if ((urcTmp.flags[0] & FORWARD_FLAG) && is_emailaddr(urcTmp.email))
	{
#ifdef NSYSUBBS
		if (strncmp(urcTmp.email, "bbs@", 4) && !strstr(urcTmp.email, ".."))
		{
#endif
			if (SendMail_Internet(-1, fname, from, urcTmp.email, title, urcTmp.userid) == 0)
				return 0;
#ifdef NSYSUBBS
		}
#endif
		bbslog("ERR", "auto-forward: %s", urcTmp.email);
	}

	setmailfile(pathTmp, to, NULL);
	if (!isdir(pathTmp))
	{
		if (mkdir(pathTmp, 0700) == -1)
			return -1;
	}

	if (!(fsize = get_num_records(fname, sizeof(char))))
		return -2;

	if (fsize > MAX_MAIL_SIZE)
	{
		bbslog("SENDMAIL", "from=%s, to=%s, size=%d, stat=EFBIG",
		       from, to, fsize);
		return -3;
	}

#ifdef USE_THREADING	/* syhu */
	if (append_article(fname, pathTmp, from, title, ident, NULL, FALSE, 0, NULL, -1, -1 ) == -1)		/* syhu */
#else
	if (append_article(fname, pathTmp, from, title, ident, NULL, FALSE, 0, NULL) == -1)
#endif
		return -1;

	return 0;
}
コード例 #9
0
ファイル: compat-initgroups.c プロジェクト: alucas/glibc
/* Get the next group from NSS  (+ entry). If the NSS module supports
   initgroups_dyn, get all entries at once.  */
static enum nss_status
getgrent_next_nss (ent_t *ent, char *buffer, size_t buflen, const char *user,
		   gid_t group, long int *start, long int *size,
		   gid_t **groupsp, long int limit, int *errnop)
{
  enum nss_status status;
  struct group grpbuf;

  /* Try nss_initgroups_dyn if supported. We also need getgrgid_r.
     If this function is not supported, step through the whole group
     database with getgrent_r.  */
  if (! ent->skip_initgroups_dyn)
    {
      long int mystart = 0;
      long int mysize = limit <= 0 ? *size : limit;
      gid_t *mygroups = malloc (mysize * sizeof (gid_t));

      if (mygroups == NULL)
	return NSS_STATUS_TRYAGAIN;

      /* For every gid in the list we get from the NSS module,
	 get the whole group entry. We need to do this, since we
	 need the group name to check if it is in the blacklist.
	 In worst case, this is as twice as slow as stepping with
	 getgrent_r through the whole group database. But for large
	 group databases this is faster, since the user can only be
	 in a limited number of groups.  */
      if (nss_initgroups_dyn (user, group, &mystart, &mysize, &mygroups,
			      limit, errnop) == NSS_STATUS_SUCCESS)
	{
	  status = NSS_STATUS_NOTFOUND;

	  /* If there is no blacklist we can trust the underlying
	     initgroups implementation.  */
	  if (ent->blacklist.current <= 1)
	    for (int i = 0; i < mystart; i++)
	      add_group (start, size, groupsp, limit, mygroups[i]);
	  else
	    {
	      /* A temporary buffer. We use the normal buffer, until we find
		 an entry, for which this buffer is to small.  In this case, we
		 overwrite the pointer with one to a bigger buffer.  */
	      char *tmpbuf = buffer;
	      size_t tmplen = buflen;
	      bool use_malloc = false;

	      for (int i = 0; i < mystart; i++)
		{
		  while ((status = nss_getgrgid_r (mygroups[i], &grpbuf,
						   tmpbuf, tmplen, errnop))
			 == NSS_STATUS_TRYAGAIN
			 && *errnop == ERANGE)
                    {
                      if (__libc_use_alloca (tmplen * 2))
                        {
                          if (tmpbuf == buffer)
                            {
                              tmplen *= 2;
                              tmpbuf = __alloca (tmplen);
                            }
                          else
                            tmpbuf = extend_alloca (tmpbuf, tmplen, tmplen * 2);
                        }
                      else
                        {
                          tmplen *= 2;
                          char *newbuf = realloc (use_malloc ? tmpbuf : NULL, tmplen);

                          if (newbuf == NULL)
                            {
                              status = NSS_STATUS_TRYAGAIN;
			      goto done;
                            }
                          use_malloc = true;
                          tmpbuf = newbuf;
                        }
                    }

		  if (__builtin_expect  (status != NSS_STATUS_NOTFOUND, 1))
		    {
		      if (__builtin_expect  (status != NSS_STATUS_SUCCESS, 0))
		        goto done;

		      if (!in_blacklist (grpbuf.gr_name,
					 strlen (grpbuf.gr_name), ent)
			  && check_and_add_group (user, group, start, size,
						  groupsp, limit, &grpbuf))
			{
			  if (nss_setgrent != NULL)
			    {
			      nss_setgrent (1);
			      ent->need_endgrent = true;
			    }
			  ent->skip_initgroups_dyn = true;

			  goto iter;
			}
		    }
		}

	      status = NSS_STATUS_NOTFOUND;

 done:
	      if (use_malloc)
	        free (tmpbuf);
	    }

	  free (mygroups);

	  return status;
	}

      free (mygroups);
    }

  /* If we come here, the NSS module does not support initgroups_dyn
     or we were confronted with a split group.  In these cases we have
     to step through the whole list ourself.  */
 iter:
  do
    {
      if ((status = nss_getgrent_r (&grpbuf, buffer, buflen, errnop)) !=
	  NSS_STATUS_SUCCESS)
	break;
    }
  while (in_blacklist (grpbuf.gr_name, strlen (grpbuf.gr_name), ent));

  if (status == NSS_STATUS_SUCCESS)
    check_and_add_group (user, group, start, size, groupsp, limit, &grpbuf);

  return status;
}