Beispiel #1
0
int init_conf(void)
{
  if (read_configuration_file()) {
    /*
     * make sure we're sane to start if the config
     * file read didn't get everything we need.
     * XXX - should any of these abort the server?
     * TODO: add warning messages
     */
    if (0 == localConf.name || 0 == localConf.numeric)
      return 0;
    if (conf_error)
      return 0;

    if (0 == localConf.location1)
      DupString(localConf.location1, "");
    if (0 == localConf.location2)
      DupString(localConf.location2, "");
    if (0 == localConf.contact)
      DupString(localConf.contact, "");

    return 1;
  }
  return 0;
}
Beispiel #2
0
static VALUE
ServiceModule_do_help(VALUE self, VALUE client, VALUE value, VALUE parv)
{
  struct Service *service = get_service(self);
  struct Client *cclient;
  int argc = 0;
  int i;
  char *cvalue = 0;
  char **argv = 0;
  VALUE tmp;

  Check_OurType(client, cClient);
  cclient = value_to_client(client);

  if(!NIL_P(value))
  {
    Check_Type(value, T_STRING);
    Check_Type(parv, T_ARRAY);

    DupString(cvalue, StringValueCStr(value));

    argc = RARRAY(parv)->len - 1;
    argv = ALLOCA_N(char *, argc);

    for(i = 0; i < argc; ++i)
    {
      tmp = rb_ary_entry(parv, i);
      DupString(argv[i], StringValueCStr(tmp));
    }
  }
Beispiel #3
0
/*
 * check for public repeating and keep/replace appropriate last phrase
 *													-demond
 */
static int check_repeat(struct Client *source_p,
						struct Channel *chptr,
						char *text)
{
	dlink_node *ptr;
	struct Repeat *repeatptr;

	for (ptr = source_p->user->repeat.head; ptr; ptr = ptr->next) {
		repeatptr = ptr->data;
		if (repeatptr->chptr == chptr)
			if (!strcmp(repeatptr->text, text)) {
				return 1;
			} else {
				MyFree(repeatptr->text);
				DupString(repeatptr->text, text);
				repeatptr->lastphrase = CurrentTime;
				return 0;
			}
	}

	repeatptr = (struct Repeat *)MyMalloc(sizeof(struct Repeat));
	repeatptr->chptr = chptr;
	DupString(repeatptr->text, text);
	repeatptr->lastphrase = CurrentTime;

	ptr = make_dlink_node();
	dlinkAdd(repeatptr, ptr, &source_p->user->repeat);

	return 0;
}
Beispiel #4
0
/** Create a Zline structure.
 * @param[in] mask Mask.
 * @param[in] reason Reason for Z-line.
 * @param[in] expire Expiration timestamp.
 * @param[in] lastmod Last modification timestamp.
 * @param[in] flags Bitwise combination of ZLINE_* bits.
 * @return Newly allocated Z-line.
 */
static struct Zline *
make_zline(char *mask, char *reason, time_t expire, time_t lastmod,
	   time_t lifetime, unsigned int flags)
{
  struct Zline *zline;

  assert(0 != expire);

  zline = (struct Zline *)MyMalloc(sizeof(struct Zline)); /* alloc memory */
  assert(0 != zline);

  DupString(zline->zl_reason, reason); /* initialize zline... */
  zline->zl_expire = expire;
  zline->zl_lifetime = lifetime;
  zline->zl_lastmod = lastmod;
  zline->zl_flags = flags & ZLINE_MASK;
  zline->zl_state = ZLOCAL_GLOBAL; /* not locally modified */

  DupString(zline->zl_mask, mask);

  if (ipmask_parse(mask, &zline->zl_addr, &zline->zl_bits)) {
    zline->zl_flags |= ZLINE_IPMASK;
    zline->zl_addr = ipmask_clean(&zline->zl_addr, zline->zl_bits);
  }

  zline->zl_next = GlobalZlineList; /* then link it into list */
  zline->zl_prev_p = &GlobalZlineList;
  if (GlobalZlineList)
    GlobalZlineList->zl_prev_p = &zline->zl_next;
  GlobalZlineList = zline;

  return zline;
}
void
parse_resv_file(FILE * file)
{
	struct ConfItem *aconf;
	char *reason_field;
	char *host_field;
	char line[BUFSIZE];
	char *p;

	while (fgets(line, sizeof(line), file))
	{
		if((p = strpbrk(line, "\r\n")))
			*p = '\0';

		if((*line == '\0') || (line[0] == '#'))
			continue;

		host_field = getfield(line);
		if(EmptyString(host_field))
			continue;

		reason_field = getfield(NULL);
		if(EmptyString(reason_field))
			continue;

		if(IsChannelName(host_field))
		{
			if(hash_find_resv(host_field))
				continue;

			aconf = make_conf();
			aconf->status = CONF_RESV_CHANNEL;
			aconf->port = 0;

			DupString(aconf->name, host_field);
			DupString(aconf->passwd, reason_field);
			add_to_resv_hash(aconf->name, aconf);
		}
		else if(clean_resv_nick(host_field))
		{
			if(find_nick_resv(host_field))
				continue;

			aconf = make_conf();
			aconf->status = CONF_RESV_NICK;
			aconf->port = 0;

			DupString(aconf->name, host_field);
			DupString(aconf->passwd, reason_field);
			dlinkAddAlloc(aconf, &resv_conf_list);
		}
	}
}
Beispiel #6
0
static DOMAIN_PIECE *find_or_add_host_piece(DOMAIN_LEVEL *level_ptr,
				     int flags,char *host_piece)
{
  DOMAIN_PIECE *piece_ptr;
  DOMAIN_PIECE *cur_piece;
  DOMAIN_PIECE *new_ptr;
  DOMAIN_PIECE *last_ptr;
  DOMAIN_PIECE *ptr;
  int index;

  index = *host_piece&(MAX_PIECE_LIST-1);
  piece_ptr = level_ptr->piece_list[index];

  if(piece_ptr == (DOMAIN_PIECE *)NULL)
    {
      cur_piece = (DOMAIN_PIECE *)MyMalloc(sizeof(DOMAIN_PIECE));
      memset((void *)cur_piece,0,sizeof(DOMAIN_PIECE));
      DupString(cur_piece->host_piece,host_piece);
      level_ptr->piece_list[index] = cur_piece;
      cur_piece->flags |= flags;
      return(cur_piece);
    }

  last_ptr = (DOMAIN_PIECE *)NULL;

  for(ptr=piece_ptr; ptr; ptr = ptr->next_piece)
    {
      if(!strcasecmp(ptr->host_piece,host_piece))
	{
	  ptr->flags |= flags;
	  return(ptr);
	}
      last_ptr = ptr;
    }

  if(last_ptr)
    {
      new_ptr = (DOMAIN_PIECE *)MyMalloc(sizeof(DOMAIN_PIECE));
      memset((void *)new_ptr,0,sizeof(DOMAIN_PIECE));
      DupString(new_ptr->host_piece,host_piece);

      last_ptr->next_piece = new_ptr;
      new_ptr->flags |= flags;
      return(new_ptr);
    }
  else
    {
      sendto_realops("Bug: in find_or_add_host_piece. yay.");
      return(NULL);
    }
  /* NOT REACHED */
}
/* conf_add_fields()
 * 
 * inputs       - pointer to config item, host/pass/user/operreason fields
 * output       - NONE
 * side effects - update respective fields with pointers
 */
static void
conf_add_fields(struct ConfItem *aconf,	const char *host_field,
		const char *pass_field,	const char *user_field,
		const char *operreason_field)
{
	if(host_field != NULL)
		DupString(aconf->host, host_field);
	if(pass_field != NULL)
		DupString(aconf->passwd, pass_field);
	if(user_field != NULL)
		DupString(aconf->user, user_field);
	if(operreason_field != NULL)
		DupString(aconf->spasswd, operreason_field);
}
Beispiel #8
0
LPSTR GetGenre(LPSTR lpsz)
{
    int id = atoi(lpsz + 1);
    int i;

    if ((*(lpsz + 1) > '0') && (*(lpsz + 1) < '9'))
    {
        for (i = 0; i < NUMGENRES; i++)
        {
            if (id == ID3Genres[i].id)
                return DupString(ID3Genres[i].name);
        }
    }
    return DupString(lpsz);
}
Beispiel #9
0
static void	DumpBlock(const char *type, struct block_t *blk)
{
	uint32 size = (ReadDword((uint32)&blk->size) - sizeof(*blk) - sizeof(uint32)) & ~7;
	uint32 seq_id = ReadDword((uint32)&blk->seq_id);
	uint32 line = ReadDword((uint32)&blk->line);
	char *file = DupString(ReadDword((uint32)&blk->file));
	char *func = DupString(ReadDword((uint32)&blk->func));
	uint32 ptr = (uint32)blk + sizeof(*blk);

	printf("%s %08x = seq:%5d, size:%5d, %-30.30s (%4d) %s\n",
		type, ptr, seq_id, size, func, line, basename(file));

	free(file);
	free(func);
}
Lut_t *GetLut(int nband, Input_meta_t *meta, Img_coord_int_t *input_size) {
  Lut_t *this;

  /* Create the lookup table data structure */

  this = (Lut_t *)malloc(sizeof(Lut_t));
  if (this == NULL) 
    RETURN_ERROR("allocating Input data structure", "OpenInput", NULL);

  /* Populate the data structure */
  this->nband = nband;
  this->in_fill = meta->fill;
  this->output_fill = OUTPUT_FILL;
  this->in_satu = INPUT_SATU;
  this->output_satu = OUTPUT_SATU;
  this->aerosol_fill = AEROSOL_FILL;
  this->ar_region_size.l = AEROSOL_REGION_NLINE;
  this->ar_region_size.s = AEROSOL_REGION_NSAMP;
  this->ar_size.l = ((input_size->l - 1) / this->ar_region_size.l) + 1;
  this->ar_size.s = ((input_size->s - 1) / this->ar_region_size.s) + 1;
  this->min_valid_sr = MIN_VALID_SR;
  this->max_valid_sr = MAX_VALID_SR;
  this->atmos_opacity_scale_factor= ATMOS_OPACITY_SCALE_FACTOR;
  this->scale_factor=     SCALE_FACTOR;     /* scale factor            */
  this->scale_factor_err= SCALE_FACTOR_ERR; /* scale factor error      */
  this->add_offset=       ADD_OFFSET;       /* add offset              */
  this->add_offset_err=   ADD_OFFSET_ERR;   /* add offset error        */
  this->calibrated_nt=    CALIBRATED_NT;    /* calibrated nt           */

  this->long_name_prefix = DupString(LONG_NAME_PREFIX);
  if (this->long_name_prefix == NULL) {
    free(this);
    RETURN_ERROR("duplicating long name prefix", "GetLut", NULL);
  }

  this->units = DupString(UNITS);
  if (this->units == NULL) {
    free(this);
    RETURN_ERROR("duplicating ref units", "GetLut", NULL);
  }

  if (!InputMetaCopy(meta, nband, &this->meta)) {
    free(this);
    RETURN_ERROR("copying input metadata", "GetLut", NULL);
  }

  return this;
}
Beispiel #11
0
/*
 * m_sxline() - add info ban line
 *
 *	parv[0] = sender prefix
 *	parv[1] =  info banned mask
 */
int	m_sxline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
  {
    aConfItem *aconf;
    char *reason = NULL;
    char *mask;
    int len;

	if (!IsService(sptr) && !IsServer(cptr))
	  {
		sendto_one(sptr, form_str(ERR_NOPRIVILEGES), me.name, parv[0]);
		return 0;
	  }	  
		
	if(parc<3)
	  {
		sendto_one(sptr, form_str(ERR_NEEDMOREPARAMS),
      	  me.name, parv[0], "SXLINE");
        return 0;
	  }
      
    len=atoi(parv[1]);
    mask = parv[2];
    
    if ((strlen(mask) > len) && (mask[len])==':')
      {
        mask[len] = '\0';
        reason = mask+len+1;
      } 
    else
      { /* Bogus */
        return 0;
      }
    
    if (!find_sxline(mask)) /* sxline does not exist */
	  {

		aconf = make_conf();
		DupString(aconf->name, mask);
		DupString(aconf->passwd, reason);
	    aconf->next = sxlines;
		sxlines = aconf;		

        sendto_serv_butone(cptr, ":%s SXLINE %d :%s:%s", sptr->name, len,
                       aconf->name,aconf->passwd);
	  }

	return 0;
  }
Beispiel #12
0
/*
 * ReplaceString - free a string, then allocate new one
 */
void ReplaceString( char **where, const char *str )
{

    MemFree( *where );
    *where = DupString( str );

} /* ReplaceString */
Beispiel #13
0
static void DupList( vlc_value_t *p_val )
{
    int i;
    vlc_list_t *p_list = malloc( sizeof(vlc_list_t) );

    p_list->i_count = p_val->p_list->i_count;
    if( p_val->p_list->i_count )
    {
        p_list->p_values = malloc( p_list->i_count * sizeof(vlc_value_t) );
        p_list->pi_types = malloc( p_list->i_count * sizeof(int) );
    }
    else
    {
        p_list->p_values = NULL;
        p_list->pi_types = NULL;
    }

    for( i = 0; i < p_list->i_count; i++ )
    {
        p_list->p_values[i] = p_val->p_list->p_values[i];
        p_list->pi_types[i] = p_val->p_list->pi_types[i];
        switch( p_val->p_list->pi_types[i] & VLC_VAR_TYPE )
        {
        case VLC_VAR_STRING:

            DupString( &p_list->p_values[i] );
            break;
        default:
            break;
        }
    }

    p_val->p_list = p_list;
}
/*
 * mr_error - unregistered client message handler
 *
 * parv[0] = sender prefix
 * parv[parc-1] = text
 */
int mr_error(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
  const char *para;

  if (!IsHandshake(cptr) && !IsConnecting(cptr))
    return 0; /* ignore ERROR from regular clients */

  para = (parc > 1 && *parv[parc - 1] != '\0') ? parv[parc - 1] : "<>";

  Debug((DEBUG_ERROR, "Received ERROR message from %s: %s", cli_name(sptr), para));

  if (cptr == sptr)
    sendto_opmask_butone(0, SNO_OLDSNO, "ERROR :from %C -- %s", cptr, para);
  else
    sendto_opmask_butone(0, SNO_OLDSNO, "ERROR :from %C via %C -- %s", sptr,
			 cptr, para);

  if (cli_serv(sptr))
  {
    MyFree(cli_serv(sptr)->last_error_msg);
    DupString(cli_serv(sptr)->last_error_msg, para);
  }

  return 0;
}
Beispiel #15
0
/** Send a query to look up the address for a name.
 * @param[in] query Callback information.
 * @param[in] name Hostname to look up.
 * @param[in] request DNS lookup structure (may be NULL).
 * @param[in] type Preferred request type.
 */
static void
do_query_name(dns_callback_f callback, void *ctx, const char *name,
              struct reslist *request, int type)
{
  char host_name[HOSTLEN + 1];

  ircd_strncpy(host_name, name, HOSTLEN);
  add_local_domain(host_name, HOSTLEN);

  if (request == NULL)
  {
    request       = make_request(callback, ctx);
    DupString(request->name, host_name);
#ifdef IPV6
    if (type != T_A)
      request->state = REQ_AAAA;
    else
#endif
    request->state = REQ_A;
  }

  request->type = type;
  Debug((DEBUG_DNS, "Requesting DNS %s %s as %p", (request->state == REQ_AAAA ? "AAAA" : "A"), host_name, request));
  query_name(host_name, C_IN, type, request);
}
Beispiel #16
0
struct ResvChannel *
create_channel_resv(char *name, char *reason, int conf)
{
  struct ResvChannel *resv_p = NULL;
  int len;

  if(find_channel_resv(name))
    return NULL;

  if((len = strlen(reason)) > TOPICLEN)
  {
    reason[TOPICLEN] = '\0';
    len = TOPICLEN;
  }

  resv_p = (struct ResvChannel *)MyMalloc(sizeof(struct ResvChannel));

  strlcpy(resv_p->name, name, sizeof(resv_p->name));
  DupString(resv_p->reason, reason);
  resv_p->conf = conf;

  if(ResvChannelList != NULL)
    ResvChannelList->prev = resv_p;

  resv_p->next = ResvChannelList;
  resv_p->prev = NULL;

  ResvChannelList = resv_p;

  add_to_resv_hash_table(resv_p->name, resv_p);

  return resv_p;
}
Beispiel #17
0
struct ResvNick *
create_nick_resv(char *name, char *reason, int conf)
{
  struct ResvNick *resv_p = NULL;
  int len;

  if(find_nick_resv(name))
    return NULL;

  if((len = strlen(reason)) > TOPICLEN)
  {
    reason[TOPICLEN] = '\0';
    len = TOPICLEN;
  }

  resv_p = (struct ResvNick *)MyMalloc(sizeof(struct ResvNick));

  strlcpy(resv_p->name, name, sizeof(resv_p->name));
  DupString(resv_p->reason, reason);
  resv_p->conf = conf;

  if(ResvNickList)
    ResvNickList->prev = resv_p;

  resv_p->next = ResvNickList;
  resv_p->prev = NULL;

  ResvNickList = resv_p;

  return resv_p;
}
Beispiel #18
0
char *
crypt_pass(char *password, int encode)
{
  EVP_MD_CTX *mdctx;
  const EVP_MD *md;
  unsigned char md_value[EVP_MAX_MD_SIZE];
  char buffer[2*DIGEST_LEN + 1];
  char *ret;
  unsigned int md_len;

  md = EVP_get_digestbyname(DIGEST_FUNCTION);

  mdctx = EVP_MD_CTX_create();
  EVP_MD_CTX_init(mdctx);
  EVP_DigestInit_ex(mdctx, md, NULL);
  EVP_DigestUpdate(mdctx, password, strlen(password));
  EVP_DigestFinal_ex(mdctx, md_value, &md_len);
  EVP_MD_CTX_destroy(mdctx);

  if(encode)
  {
    base16_encode(buffer, sizeof(buffer), (char *)md_value, DIGEST_LEN);
    DupString(ret, buffer);
  }
  else
  {
    ret = MyMalloc(DIGEST_LEN);
    memcpy(ret, md_value, DIGEST_LEN);
  }
  return ret;
}
Beispiel #19
0
/** Find a Z-line for a particular mask, guided by certain flags.
 * Certain bits in \a flags are interpreted specially:
 * <dl>
 * <dt>ZLINE_ANY</dt><dd>Search user Z-lines.</dd>
 * <dt>ZLINE_GLOBAL</dt><dd>Only match global Z-lines.</dd>
 * <dt>ZLINE_LOCAL</dt><dd>Only match local Z-lines.</dd>
 * <dt>ZLINE_LASTMOD</dt><dd>Only match Z-lines with a last modification time.</dd>
 * <dt>ZLINE_EXACT</dt><dd>Require an exact match of Z-line mask.</dd>
 * <dt>anything else</dt><dd>Search user Z-lines.</dd>
 * </dl>
 * @param[in] ipmask Mask to search for.
 * @param[in] flags Bitwise combination of ZLINE_* flags.
 * @return First matching Z-line, or NULL if none are found.
 */
struct Zline *
zline_find(char *ipmask, unsigned int flags)
{
  struct Zline *zline = 0;
  struct Zline *szline;
  char *mask, *t_uh;

  DupString(t_uh, ipmask);
  mask = t_uh;

  zliter(GlobalZlineList, zline, szline) {
    if ((flags & (ZlineIsLocal(zline) ? ZLINE_GLOBAL : ZLINE_LOCAL)) ||
	(flags & ZLINE_LASTMOD && !zline->zl_lastmod))
      continue;
    else if (flags & ZLINE_EXACT) {
      if (((zline->zl_mask && mask && ircd_strcmp(zline->zl_mask, mask) == 0)
           || (!zline->zl_mask && !mask)))
	break;
    } else {
      if (((zline->zl_mask && mask && match(zline->zl_mask, mask) == 0)
           || (!zline->zl_mask && !mask)))
	break;
    }
  }

  MyFree(t_uh);

  return zline;
}
Beispiel #20
0
/*
 * ScreenInit - get screen info
 */
void ScreenInit( void )
{
    CONSOLE_SCREEN_BUFFER_INFO  sbi;
    char                        tmp[256];

    InputHandle = CreateFile( "CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
    SetConsoleMode( InputHandle, ENABLE_MOUSE_INPUT | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_EXTENDED_FLAGS );

    OutputHandle = CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL );
    SetConsoleMode( OutputHandle, 0 );
    // SetConsoleActiveScreenBuffer( OutputHandle );

    GetConsoleScreenBufferInfo( OutputHandle, &sbi );
    EditVars.WindMaxWidth = sbi.dwMaximumWindowSize.X;
    EditVars.WindMaxHeight = sbi.dwMaximumWindowSize.Y;
    BSize.X = EditVars.WindMaxWidth;
    BSize.Y = EditVars.WindMaxHeight;

    EditFlags.Color = true;

    Scrn = malloc( EditVars.WindMaxWidth * EditVars.WindMaxHeight * sizeof( char_info ) );
    ScreenPage( 0 );

    tmp[0] = '\0';
    GetConsoleTitle( tmp, sizeof( tmp ) );
    oldConTitle = DupString( tmp );
    if( !EditFlags.Quiet ) {
        SetConsoleTitle( "Open Watcom vi" );
    }

} /* ScreenInit */
void
parse_x_file(FILE * file)
{
	struct ConfItem *aconf;
	char *gecos_field = NULL;
	char *reason_field = NULL;
	char line[BUFSIZE];
	char *p;

	while (fgets(line, sizeof(line), file))
	{
		if((p = strpbrk(line, "\r\n")))
			*p = '\0';

		if((*line == '\0') || (line[0] == '#'))
			continue;

		gecos_field = getfield(line);
		if(EmptyString(gecos_field))
			continue;

		/* field for xline types, which no longer exist */
		getfield(NULL);

		reason_field = getfield(NULL);
		if(EmptyString(reason_field))
			continue;

		/* sanity checking */
		if((find_xline(gecos_field, 0) != NULL) ||
		   (strchr(reason_field, ':') != NULL))
			continue;

		aconf = make_conf();
		aconf->status = CONF_XLINE;

		DupString(aconf->name, gecos_field);
		DupString(aconf->passwd, reason_field);

		dlinkAddAlloc(aconf, &xline_conf_list);
	}
}
Beispiel #22
0
/** Create a struct Motd and initialize it.
 * @param[in] hostmask Hostmask (or connection class name) to filter on.
 * @param[in] path Path to MOTD file.
 * @param[in] maxcount Maximum number of lines permitted for MOTD.
 */
static struct Motd *
motd_create(const char *hostmask, const char *path, int maxcount, int type)
{
  struct Motd* tmp;

  assert(0 != path);

  /* allocate memory and initialize the structure */
  if (MotdList.freelist)
  {
    tmp = MotdList.freelist;
    MotdList.freelist = tmp->next;
  } else
    tmp = (struct Motd *)MyMalloc(sizeof(struct Motd));
  tmp->next = 0;

  if (hostmask == NULL)
    tmp->type = MOTD_UNIVERSAL;
  else if (type == MOTD_COUNTRY)
    tmp->type = MOTD_COUNTRY;
  else if (type == MOTD_CONTINENT)
    tmp->type = MOTD_CONTINENT;
  else if (find_class(hostmask))
    tmp->type = MOTD_CLASS;
  else if (ipmask_parse(hostmask, &tmp->address, &tmp->addrbits))
    tmp->type = MOTD_IPMASK;
  else
    tmp->type = MOTD_HOSTMASK;

  if (hostmask != NULL)
    DupString(tmp->hostmask, hostmask);
  else
    tmp->hostmask = NULL;

  DupString(tmp->path, path);
  tmp->maxcount = maxcount;
  tmp->cache = 0;

  return tmp;
}
Beispiel #23
0
/** Parse a user\@host mask into username and host or IP parts.
 * If \a host contains no username part, set \a aconf->username to
 * NULL.  If the host part of \a host looks like an IP mask, set \a
 * aconf->addrbits and \a aconf->address to match.  Otherwise, set
 * \a aconf->host, and set \a aconf->addrbits to -1.
 * @param[in,out] aconf Configuration item to set.
 * @param[in] host user\@host mask to parse.
 */
void conf_parse_userhost(struct ConfItem *aconf, char *host)
{
  char *host_part;
  unsigned char addrbits;

  MyFree(aconf->username);
  MyFree(aconf->host);
  host_part = strchr(host, '@');
  if (host_part) {
    *host_part = '\0';
    DupString(aconf->username, host);
    host_part++;
  } else {
    aconf->username = NULL;
    host_part = host;
  }
  DupString(aconf->host, host_part);
  if (ipmask_parse(aconf->host, &aconf->address.addr, &addrbits))
    aconf->addrbits = addrbits;
  else
    aconf->addrbits = -1;
}
Beispiel #24
0
/*
 * setGenericAlias - define an alias/abbreviation
 */
static vi_rc setGenericAlias( const char *what, alias_list **head, alias_list **tail )
{
    alias_list  *curr;
    char        str[MAX_STR];

    what = GetNextWord1( what, str );
    if( *str == '\0' ) {
        return( ERR_INVALID_ALIAS );
    }
    what = SkipLeadingSpaces( what );

    /*
     * see if alias is already in list: if so, and there is expansion data,
     * then replace the data, else delete the item
     */
    for( curr = *head; curr != NULL; curr = curr->next ) {
        if( strcmp( str, curr->alias ) == 0 ) {
            MemFree( curr->expand );
            if( *what == '\0' ) {
                MemFree( curr->alias );
                MemFree( DeleteLLItem( (ss **)head, (ss **)tail, (ss *)curr ) );
            } else {
                curr->expand = DupString( what );
            }
        }
    }

    /*
     * add the new item
     */
    curr = MemAlloc( sizeof( alias_list ) );
    curr->alias = DupString( str );
    curr->expand = DupString( what );

    AddLLItemAtEnd( (ss **)head, (ss **)tail, (ss *)curr );
    Message1( "%s set to \"%s\"", str, what );
    return( DO_NOT_CLEAR_MESSAGE_WINDOW );

} /* setGenericAlias */
static int crule_parsearglist(CRuleNodePtr argrootp, int *next_tokp, const char** ruleptr)
{
  int errcode = CR_NOERR;
  char *argelemp = NULL;
  char currarg[CR_MAXARGLEN];
  int arglen = 0;
  char word[CR_MAXARGLEN];
  int wordlen = 0;

  argrootp->numargs = 0;
  currarg[0] = '\0';
  while (errcode == CR_NOERR)
  {
    switch (*next_tokp)
    {
      case CR_WORD:
        crule_getword(word, &wordlen, CR_MAXARGLEN - 1, ruleptr);
        if (currarg[0] != '\0')
        {
          if ((arglen + wordlen) < (CR_MAXARGLEN - 1))
          {
            strcat(currarg, " ");
            strcat(currarg, word);
            arglen += wordlen + 1;
          }
        }
        else
        {
          strcpy(currarg, word);
          arglen = wordlen;
        }
        errcode = crule_gettoken(next_tokp, ruleptr);
        break;
      default:
#if !defined(CR_DEBUG) && !defined(CR_CHKCONF)
        collapse(currarg);
#endif
        if (!BadPtr(currarg))
        {
          DupString(argelemp, currarg);
          argrootp->arg[argrootp->numargs++] = (void *)argelemp;
        }
        if (*next_tokp != CR_COMMA)
          return (CR_NOERR);
        currarg[0] = '\0';
        errcode = crule_gettoken(next_tokp, ruleptr);
        break;
    }
  }
  return (errcode);
}
Beispiel #26
0
void
check_our_type(VALUE obj, VALUE type)
{
  char *objname;
  char *typename;

  if(CLASS_OF(obj) != type)
  {
    DupString(objname, rb_obj_classname(obj));
    DupString(typename, rb_class2name(type));
    rb_raise(rb_eTypeError, "Argument Exception: Expected type %s got %s", typename, objname);
    MyFree(objname);
    MyFree(typename);
  }
Beispiel #27
0
/** Allocate a new jupe with the given parameters.
 * @param[in] server Server name to jupe.
 * @param[in] reason Reason for jupe.
 * @param[in] expire Expiration time for jupe.
 * @param[in] lastmod Last modification time for jupe.
 * @param[in] flags Flags to set for the jupe.
 */
static struct Jupe *
make_jupe(char *server, char *reason, time_t expire, time_t lastmod,
	  unsigned int flags)
{
  struct Jupe *ajupe;

  ajupe = (struct Jupe*) MyMalloc(sizeof(struct Jupe)); /* alloc memory */
  assert(0 != ajupe);

  memset(ajupe, 0, sizeof(*ajupe));
  DupString(ajupe->ju_server, server); /* copy vital information */
  DupString(ajupe->ju_reason, reason);
  ajupe->ju_expire = expire;
  ajupe->ju_lastmod = lastmod;
  ajupe->ju_flags = flags & JUPE_MASK; /* set jupe flags */

  ajupe->ju_next = GlobalJupeList; /* link it into the list */
  ajupe->ju_prev_p = &GlobalJupeList;
  if (GlobalJupeList)
    GlobalJupeList->ju_prev_p = &ajupe->ju_next;
  GlobalJupeList = ajupe;

  return ajupe;
}
Beispiel #28
0
static VALUE
ServiceModule_register(VALUE self, VALUE commands)
{
  struct Service *ruby_service = get_service(self);
  struct ServiceMessage *generic_msgtab;
  VALUE command;
  long i;

  Check_Type(commands, T_ARRAY);

  for(i = RARRAY(commands)->len-1; i >= 0; --i)
  {
    VALUE name, param_min, param_max, flags, access, hlp_shrt, hlp_long;
    char *tmp;

    command = rb_ary_shift(commands);
    Check_Type(command, T_ARRAY);

    name = rb_ary_shift(command);
    param_min = rb_ary_shift(command);
    param_max = rb_ary_shift(command);
    flags = rb_ary_shift(command);
    access = rb_ary_shift(command);
    hlp_shrt = rb_ary_shift(command);
    hlp_long = rb_ary_shift(command);

    generic_msgtab = MyMalloc(sizeof(struct ServiceMessage));
    DupString(tmp, StringValueCStr(name));

    generic_msgtab->cmd = tmp;
    generic_msgtab->parameters = NUM2INT(param_min);
    generic_msgtab->maxpara = NUM2INT(param_max);
    generic_msgtab->flags = NUM2INT(flags);
    generic_msgtab->access = NUM2INT(access);
    generic_msgtab->help_short = NUM2INT(hlp_shrt);
    generic_msgtab->help_long = NUM2INT(hlp_long);

    generic_msgtab->handler = m_generic;

    mod_add_servcmd(&ruby_service->msg_tree, generic_msgtab);
  }

  return Qnil;
}
Beispiel #29
0
gcc_const
static char *
FindFile(const char *const*list)
{
  for (const char *const* i = list; *i != nullptr; ++i) {
    const char *path = *i;

    if (IsAbsolutePath(path)) {
      if (File::Exists(path))
        return DupString(path);
    } else {
      auto *result = FindInSearchPaths(path);
      if (result != nullptr)
        return result;
    }
  }

  return nullptr;
}
Beispiel #30
0
bool GetSDSDimInfo(int32 sds_id, Myhdf_dim_t *dim, int irank)
/* 
!C******************************************************************************

!Description: 'GetSDSDimInfo' reads information for a specific SDS dimension.
 
!Input Parameters:
 sds_id         SDS id

!Output Parameters:
 dim            Dimension data structure; the following fields are updated:
                   id, nval, type, nattr, name
 (returns)      Status:
                  'true' = okay
		  'false' = error reading the dimension information

!Team Unique Header:

 ! Design Notes:
   1. The HDF file is assumed to be open for SD (Science Data) access.
   2. An dimension name of less than 'DIM_MAX_NCHAR' is expected.
   3. Error messages are handled with the 'RETURN_ERROR' macro.

!END****************************************************************************
*/
{
  char dim_name[DIM_MAX_NCHAR];

  dim->id = SDgetdimid(sds_id, irank);
  if (dim->id == HDF_ERROR) 
    RETURN_ERROR("getting dimension id", "GetSDSDimInfo", false);

  if (SDdiminfo(dim->id, dim_name,
                &dim->nval, &dim->type, 
	        &dim->nattr) == HDF_ERROR)
      RETURN_ERROR("getting dimension information", "GetSDSDimInfo", false);

  dim->name = DupString(dim_name);
  if (dim->name == (char *)NULL)
    RETURN_ERROR("copying dimension name", "GetSDSDimInfo", false);

  return true;
}