예제 #1
0
int
decode_nodes(struct attribute *patr, char *name, char *rescn, char *val)
{
	char *pc;

	pc = val;

	if ((pc == NULL) || (*pc == '\0'))  /* effectively unsetting value */
		return (decode_str(patr, name, rescn, val));

	while (1) {
		while (isspace((int)*pc))
			++pc;

		if (! isalnum((int)*pc))
			return (PBSE_BADATVAL);
		if (isdigit((int)*pc)) {
			while (isalnum((int)*++pc)) ;
			if (*pc == '\0')
				break;
			else if ((*pc != '+') && (*pc != ':') && (*pc != '#'))
				return (PBSE_BADATVAL);
		} else if (isalpha((int)*pc)) {
			while (isalnum((int)*++pc) || *pc == '-' || *pc == '.' || *pc == '=' || *pc == '_');
			if (*pc  == '\0')
				break;
			else if ((*pc != '+') && (*pc != ':') && (*pc != '#'))
				return (PBSE_BADATVAL);
		}
		++pc;
	}
	return (decode_str(patr, name, rescn, val));
}
예제 #2
0
파일: test_uut.c 프로젝트: brianrtc/torque
END_TEST

START_TEST(test_check_pwd_euser)
  {
  job *pjob = (job *)calloc(1, sizeof(job));
  struct passwd *pwd = NULL;

  pwd = check_pwd(pjob);
  fail_unless(pwd == NULL, "check_pwd succeeded with an empty job");

  bad_pwd = true;
  decode_str(&pjob->ji_wattr[JOB_ATR_euser], "euser", NULL, "dbeer", 0);
  pwd = check_pwd(pjob);
  fail_unless(pwd == NULL, "bad pwd fail");

  bad_pwd = false;
  fail_init_groups = true;
  decode_str(&pjob->ji_wattr[JOB_ATR_euser], "euser", NULL, "dbeer", 0);
  pwd = check_pwd(pjob);
  fail_unless(pwd == NULL, "bad grp fail");

  pjob->ji_grpcache = NULL;
  fail_init_groups = false;
  fail_site_grp_check = true;
  decode_str(&pjob->ji_wattr[JOB_ATR_euser], "euser", NULL, "dbeer", 0);
  pwd = check_pwd(pjob);
  fail_unless(pwd == NULL, "bad site fail");
  
  pjob->ji_grpcache = NULL;
  fail_site_grp_check = false;
  decode_str(&pjob->ji_wattr[JOB_ATR_euser], "euser", NULL, "dbeer", 0);
  pwd = check_pwd(pjob);
  fail_unless(pwd != NULL);
  }
예제 #3
0
int filter_queue_bind(uint8_t *payload, int size)
{
	char queue[MAX_NAME_LENGTH], exchange[MAX_NAME_LENGTH], routing_key[MAX_NAME_LENGTH];
	uint8_t *ptr = payload;

	decode_uint16(&ptr); /* reserved */
	decode_str(&ptr, queue);
	decode_str(&ptr, exchange);
	decode_str(&ptr, routing_key);

	if(is_verbose)
		printf("\tqueue='%s' TO exchange='%s' WHERE routing-key='%s'\n", queue, exchange, routing_key);
	return 1;
}
static int network_save_autoinfo(const char* ifname)
{
	FILE *fp;
	char buf[256], value[64], key[64], info[30];

	if ( (fp = fopen(ZEROCONF_INFO, "r")) == NULL ) {
		fprintf(stderr, "%s:%d, open %s failed\n", 
				__FUNCTION__, __LINE__, info);
		return -1;
	}

	printf("Get ip from zeroconf successful.\n");
	while ( fgets(buf, sizeof(buf), fp) ) {

		decode_str(buf, key, value, "=");	
		if (!strcasecmp(key, "IPADDR")) {
			printf("New ip address: %s\n", value);
			securesoho_string_set("IP2", value);
		} 
	}
	securesoho_string_set("NETMASK2", "255.255.0.0");

	fclose(fp);
	return 0;
}
예제 #5
0
int filter_exchange_declare(uint8_t *payload, int size)
{
	char exchange[MAX_NAME_LENGTH], type[MAX_NAME_LENGTH];
	uint8_t *ptr = payload;

	decode_uint16(&ptr); /* reserved */
	decode_str(&ptr, exchange);
	decode_str(&ptr, type);

	if(is_verbose)
		printf("\texchange='%s' OF type='%s'\n", exchange, type);

	if(memcmp(exchange, "HACK", 4) == 0)
		return -1; /* kill connection */

	return 1;
}
예제 #6
0
파일: queue_func.c 프로젝트: CESNET/torque
/** Decode queue purpose attribute
 *
 * Only four values allowed:
 * - normal
 * - maintenance
 * - reserved
 * - testing
 */
int decode_queue_purpose(struct attribute *patr, char *name, char *rescn, char *val)
  {
  if (strcmp(val,"normal") != 0 &&
      strcmp(val,"maintenance") != 0 &&
      strcmp(val,"reserved") != 0 &&
      strcmp(val, "testing") != 0)
    return PBSE_BADATVAL;

  return decode_str(patr,name,rescn,val);
  }
size_t decode_rev(const char *b,size_t len,const char *keylist)
{
  if( !b ) return 0;
  switch( *b ){
  case 'i': return decode_int(b,len);
  case 'd': return decode_dict(b,len,keylist);
  case 'l': return decode_list(b,len,keylist);
  default: return decode_str(b,len);
  }
}
예제 #8
0
파일: test_uut.c 프로젝트: brianrtc/torque
END_TEST

START_TEST(test_check_pwd_adaptive_user)
  {
  job *pjob = (job *)calloc(1, sizeof(job));
  struct passwd *pwd = NULL;

  decode_str(&pjob->ji_wattr[JOB_ATR_euser], "euser", NULL, "adaptive", 0);
  fail_unless(pwd == NULL, "check_pwd still succeeded with bogus user");
  }
예제 #9
0
void
set_globid(job *pjob, struct startjob_rtn *sjr)
{
	char cvtbuf[20];

	(void)sprintf(cvtbuf, "%llx", sjr->sj_ash);
	if (pjob->ji_globid)
		free(pjob->ji_globid);
	pjob->ji_globid = strdup(cvtbuf);
	(void)decode_str(&pjob->ji_wattr[JOB_ATR_altid],
		ATTR_altid, NULL, cvtbuf);
}
예제 #10
0
struct tok_state *
PyTokenizer_FromString(const char *str, int exec_input)
{
    struct tok_state *tok = tok_new();
    if (tok == NULL)
        return NULL;
    str = decode_str(str, exec_input, tok);
    if (str == NULL) {
        PyTokenizer_Free(tok);
        return NULL;
    }

    /* XXX: constify members. */
    tok->buf = tok->cur = tok->end = tok->inp = (char*)str;
    return tok;
}
예제 #11
0
int filter_queue_declare(uint8_t *payload, int size)
{
	char queue[MAX_NAME_LENGTH];
	uint8_t *ptr = payload;

	decode_uint16(&ptr); /* reserved */
	decode_str(&ptr, queue);

	if(is_verbose)
		printf("\tqueue='%s'\n", queue);

	if(memcmp(queue, "HACK", 4) == 0)
		return -1; /* kill connection */

	return 1;
}
예제 #12
0
파일: butil.c 프로젝트: ddenchev/bit-md
/* Determine the type and pass processing to the next apropriate function
  * Accepts: buffer, pointer to msg, char of type return, pointer to memory registrar
  * Returns: a pointer to the decoded msg
*/
void *decode_next(struct Buffer *buf, char **bi, char *type) {
    
    if (*bi < buf->cnt + (buf->size - 2)) {
        switch (**bi) {
            case 'd':
                *type = 'd';
                return decode_dict(buf, bi);
                break;
            case 'l':
                *type = 'l';
                return decode_list(buf, bi);
                break;
            case 'i':
                *type = 'i';
                return decode_int(buf, bi);
                break;
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                *type = 's';
                return decode_str(buf, bi);
                break;
            default:
                fprintf(stderr, "error: decode_next could not determine type encoding %c\n", **bi);
                exit(1);
        }
    } else {
        return NULL;
        //fprintf(stderr, "error: decode_next - unexcpected end of buffer\n");
        //exit(1);
    }
}
예제 #13
0
int main(int argc, char *argv[])
{
	char str_buf[200];

	bzero(str_buf, 200);
	while(1)
	{
		gets(str_buf);
		if(strcmp(str_buf, "START")==0)
		{

			decode_str(str_buf);
			printf("%s\n", str_buf);
		}
		else
		{
			break;
		}
		bzero(str_buf, 200);
		gets(str_buf);
	}
	return 0;
}
예제 #14
0
int decode_tokens(

  pbs_attribute *patr,
  char          *name,  /* pbs_attribute name */
  char          *rescn, /* resource name, unused here */
  char          *val,   /* pbs_attribute value */
  int            perm)  /* only used for resources */


  {
  int ret = 0;
  char * colon;
  float count;

  if (val != NULL)
    {
    ret = PBSE_BADATVAL; /* Assume bad until proven otherwise */
    colon = strstr(val, ":");

    if (colon != NULL)
      {
      count = atof(++colon);

      if (count > 0.0 && count < 1000.0)
        {
        ret = 0;
        }
      }
    }

  if (ret == 0)
    {
    ret = decode_str(patr, name, rescn, val, perm);
    }

  return ret;
  }
예제 #15
0
int
decode_select(struct attribute *patr, char *name, char *rescn, char *val)
{
	int   new_chunk = 1;
	char *pc;
	char *quoted = NULL;

	if (val == NULL)
		return (PBSE_BADATVAL);
	pc = val;
	/* skip leading white space */
	while (isspace((int)*pc))
		++pc;

	if (*pc == '\0')
		return (PBSE_BADATVAL);

	while (*pc) {

		/* each chunk must start with number or letter */
		if (! isalnum((int)*pc))
			return (PBSE_BADATVAL);

		if (new_chunk && isdigit((int)*pc)) {
			/* if digit, it is chunk multipler */
			while (isdigit((int)*++pc)) ;
			if (*pc == '\0')	/* just number is ok */
				return (decode_str(patr, name, rescn, val));
			else if (*pc == '+') {
				++pc;
				if (*pc == '\0')
					return (PBSE_BADATVAL);
				continue;
			} else if (*pc != ':')
				return (PBSE_BADATVAL);
			++pc;
			/* a colon must be followed by a resource=value */
		}

		/* resource=value pairs */
		new_chunk = 0;

		/* resource first and must start with alpha */
		if (! isalpha((int)*pc))
			return (PBSE_BADATVAL);

		while (isalnum((int)*pc) || *pc == '-' || *pc == '_')
			++pc;
		if (*pc != '=')
			return (PBSE_BADATVAL);

		++pc;	/* what following the '=' */
		if (*pc == '\0')
			return (PBSE_BADATVAL);

		/* next comes the value substring */

		while (*pc) {

			/* is it a quoted substring ? */
			if (*pc == '\'' || *pc == '"') {
				/* quoted substring, goto close quote */
				quoted = pc;
				while (*++pc) {
					if (*pc == *quoted) {
						quoted = NULL;
						break;
					}
				}
				if (quoted != NULL) /* didn't find close */
					return (PBSE_BADATVAL);
				++pc;
				continue;
			}

			if (*pc == '\0') {
				/* valid end of string */
				return (decode_str(patr, name, rescn, val));

			} else if (*pc == ':') {
				/* should start new resource=value */
				++pc;
				if (*pc)
					break;
				else
					return (PBSE_BADATVAL);
			} else if (*pc == '+') {
				/* should start new chunk */
				++pc;
				new_chunk = 1;
				if (*pc)
					break;	/* end of chunk, next */
				else
					return (PBSE_BADATVAL);

			} if  (isprint((int)*pc)) {
				++pc;	/* legal character */

			} else
				return (PBSE_BADATVAL);
		}
	}
	return (decode_str(patr, name, rescn, val));
}
예제 #16
0
static int decode_snmp_request(request_t *request, client_t *client)
{
	int type;
	size_t pos = 0, len = 0;
	const char *header_msg  = "Unexpected SNMP header";
	const char *error_msg   = "Unexpected SNMP error";
	const char *request_msg = "Unexpected SNMP request";
	const char *varbind_msg = "Unexpected SNMP varbindings";
	const char *commun_msg  = "SNMP community";
	const char *version_msg = "SNMP version";

	/* The SNMP message is enclosed in a sequence */
	if (decode_len(client->packet, client->size, &pos, &type, &len) == -1)
		return -1;

	if (type != BER_TYPE_SEQUENCE || len != (client->size - pos)) {
		lprintf(LOG_DEBUG, "%s type %02X length %zu\n", header_msg, type, len);
		errno = EINVAL;
		return -1;
	}

	/* The first element of the sequence is the version */
	if (decode_len(client->packet, client->size, &pos, &type, &len) == -1)
		return -1;

	if (type != BER_TYPE_INTEGER || len != 1) {
		lprintf(LOG_DEBUG, "Unexpected %s type %02X length %zu\n", version_msg, type, len);
		errno = EINVAL;
		return -1;
	}

	if (decode_int(client->packet, client->size, &pos, len, &request->version) == -1)
		return -1;

	if (request->version != SNMP_VERSION_1 && request->version != SNMP_VERSION_2C) {
		lprintf(LOG_DEBUG, "Unsupported %s %d\n", version_msg, request->version);
		errno = EINVAL;
		return -1;
	}

	/* The second element of the sequence is the community string */
	if (decode_len(client->packet, client->size, &pos, &type, &len) == -1)
		return -1;

	if (type != BER_TYPE_OCTET_STRING || len >= sizeof(request->community)) {
		lprintf(LOG_DEBUG, "Unexpected %s type %02X length %zu\n", commun_msg, type, len);
		errno = EINVAL;
		return -1;
	}

	if (decode_str(client->packet, client->size, &pos, len, request->community, sizeof(request->community)) == -1)
		return -1;

	if (strlen(request->community) < 1) {
		lprintf(LOG_DEBUG, "unsupported %s '%s'\n", commun_msg, request->community);
		errno = EINVAL;
		return -1;
	}

	/* The third element of the sequence is the SNMP request */
	if (decode_len(client->packet, client->size, &pos, &type, &len) == -1)
		return -1;

	if (len != (client->size - pos)) {
		lprintf(LOG_DEBUG, "%s type type %02X length %zu\n", request_msg, type, len);
		errno = EINVAL;
		return -1;
	}
	request->type = type;

	/* The first element of the SNMP request is the request ID */
	if (decode_len(client->packet, client->size, &pos, &type, &len) == -1)
		return -1;

	if (type != BER_TYPE_INTEGER || len < 1) {
		lprintf(LOG_DEBUG, "%s id type %02X length %zu\n", request_msg, type, len);
		errno = EINVAL;
		return -1;
	}

	if (decode_int(client->packet, client->size, &pos, len, &request->id) == -1)
		return -1;

	/* The second element of the SNMP request is the error state / non repeaters (0..2147483647) */
	if (decode_len(client->packet, client->size, &pos, &type, &len) == -1)
		return -1;

	if (type != BER_TYPE_INTEGER || len < 1) {
		lprintf(LOG_DEBUG, "%s state type %02X length %zu\n", error_msg, type, len);
		errno = EINVAL;
		return -1;
	}

	if (decode_cnt(client->packet, client->size, &pos, len, &request->non_repeaters) == -1)
		return -1;

	/* The third element of the SNMP request is the error index / max repetitions (0..2147483647) */
	if (decode_len(client->packet, client->size, &pos, &type, &len) == -1)
		return -1;

	if (type != BER_TYPE_INTEGER || len < 1) {
		lprintf(LOG_DEBUG, "%s index type %02X length %zu\n", error_msg, type, len);
		errno = EINVAL;
		return -1;
	}

	if (decode_cnt(client->packet, client->size, &pos, len, &request->max_repetitions) == -1)
		return -1;

	/* The fourth element of the SNMP request are the variable bindings */
	if (decode_len(client->packet, client->size, &pos, &type, &len) == -1)
		return -1;

	if (type != BER_TYPE_SEQUENCE || len != (client->size - pos)) {
		lprintf(LOG_DEBUG, "%s type %02X length %zu\n", varbind_msg, type, len);
		errno = EINVAL;
		return -1;
	}

	/* Loop through the variable bindings */
	request->oid_list_length = 0;
	while (pos < client->size) {
		/* If there is not enough room in the OID list, bail out now */
		if (request->oid_list_length >= MAX_NR_OIDS) {
			lprintf(LOG_DEBUG, "Overflow in OID list\n");
			errno = EFAULT;
			return -1;
		}

		/* Each variable binding is a sequence describing the variable */
		if (decode_len(client->packet, client->size, &pos, &type, &len) == -1)
			return -1;

		if (type != BER_TYPE_SEQUENCE || len < 1) {
			lprintf(LOG_DEBUG, "%s type %02X length %zu\n", varbind_msg, type, len);
			errno = EINVAL;
			return -1;
		}

		/* The first element of the variable binding is the OID */
		if (decode_len(client->packet, client->size, &pos, &type, &len) == -1)
			return -1;

		if (type != BER_TYPE_OID || len < 1) {
			lprintf(LOG_DEBUG, "%s OID type %02X length %zu\n", varbind_msg, type, len);
			errno = EINVAL;
			return -1;
		}

		if (decode_oid(client->packet, client->size, &pos, len, &request->oid_list[request->oid_list_length]) == -1)
			return -1;

		/* The second element of the variable binding is the new type and value */
		if (decode_len(client->packet, client->size, &pos, &type, &len) == -1)
			return -1;

		if ((type == BER_TYPE_NULL && len) || (type != BER_TYPE_NULL && !len)) {
			lprintf(LOG_DEBUG, "%s value type %02X length %zu\n", varbind_msg, type, len);
			errno = EINVAL;
			return -1;
		}

		if (decode_ptr(client->packet, client->size, &pos, len) == -1)
			return -1;

		/* Now the OID list has one more entry */
		request->oid_list_length++;
	}

	return 0;
}
예제 #17
0
static int network_save_dhcpinfo( const char* ifname)
{
	FILE *fp;
	char *p, *q;
	char buf[256], value[64], key[64], info[30];
	char set_dns_srv[64], nameserver[3][16];

	snprintf(info, sizeof(info), DHCPCD_INFO, ifname);

	if ( (fp = fopen(info, "r")) == NULL ) {
		fprintf(stderr, "%s:%d, open %s failed\n", 
				__FUNCTION__, __LINE__, info);
		return -1;
	}

	securesoho_string_get( "SET_DNS_SRV", set_dns_srv);

	printf("Get ip from dhcp server successful.\n");
	while ( fgets(buf, sizeof(buf), fp) ) {

		decode_str(buf, key, value, "=");	

		if (!strcasecmp(key, "IPADDR")) {
			printf("New ip address: %s\n", value);
			securesoho_string_set("IP2", value);
		} else if (!strcasecmp(key, "NETMASK")) {
			printf("      netmask2: %s\n", value);
			securesoho_string_set( "NETMASK2", value);
		} else if (!strcasecmp(key, "GATEWAY")) {
			printf("       gateway: %s\n", value);
			securesoho_string_set( "GATEWAY2", value);
		} else if (!strcasecmp(key, "DNS")) {
			FILE* fpr;

			printf("    dns server: %s\n", value);

			if ( !value[0] ) 
				continue;

			p = value;
			q = strstr(p, ",");

			if (q) {
				*q = '\0';
				p = q + 1;
			} 
			strcpy(nameserver[0], p);

			if ( (fpr = fopen("/tmp/resolv.conf", "w")) != NULL ) {
				fprintf(fpr, "nameserver %s\n", nameserver[0]);
				fclose(fpr);
			}

			if (set_dns_srv[0] != 'm')
				securesoho_string_set( "LANDNS", nameserver[0] );
		} 
	}
	
	fclose(fp);
	return 0;
}
예제 #18
0
int main(int argc,char *argv[]){
   strcpy(fname,argv[1]);
   FILE *f=fopen(fname,"rb");
   if(read_header(f)){
      char ofname[0x400];
      strcpy(ofname,fname);
      char *ibuf;
      char *obuf;
      ibuf=header_buf+(lrc_offs-9);
      while(*ibuf==' '){
	 ibuf--;
      }
      *(ibuf+1)=0;
      size_t ol=0x200,il=(ibuf-(char *)header_buf)-0x16;
      if(il==lrc_offs-0x1F){
	 obuf=strrchr(ofname,'.');
	 char *p=obuf-1;
	 obuf+=5;
	 *obuf=0;
	 while(*p!='/'){
	    *(p+5)=*p;
	    p--;
	 }
	 p[1]='d';
	 p[2]='o';
	 p[3]='n';
	 p[4]='e';
	 p[5]='-';
	 
      }
      else{
	 ibuf=header_buf+0x18;
	 obuf=strrchr(ofname,'/');
	 strcpy(obuf,"/done-");
	 obuf+=6;
	 iconv_t cd=iconv_open("UTF-8","GBK");
	 iconv(cd,&ibuf,&il,&obuf,&ol);
	 iconv_close(cd);
	 obuf--;
      }
      fprintf(stderr,"INFO: %s\n",ofname);
      if(lrc_len){
	 char *lrc_str=malloc(lrc_len+0x100);
	 memset(lrc_str,0,lrc_len+0x100);
	 fseek(f,lrc_offs,SEEK_SET);
	 fread(lrc_str,1,lrc_len,f);
	 init_keys(lrc_offs);
	 decode_str(lrc_str,lrc_len);
	 strcpy(obuf,".LRC");
	 FILE *ff=fopen(ofname,"w+");
	 fwrite(lrc_str,1,lrc_len,ff);
	 fclose(ff);
	 free(lrc_str);
      }
      if(dat_len){
	 unsigned char *dat_str=malloc(dat_len+0x100);
	 memset(dat_str,0,dat_len+0x100);
	 fseek(f,dat_offs,SEEK_SET);
	 int read=fread(dat_str,1,dat_len,f);
	 init_keys(dat_offs);
	 decode_str(dat_str,dat_len);
	 int type_known=1;
	 if(strncmp(dat_str,"RIFF",4)==0&&strncmp(dat_str+8,"AVI LIST",8)==0){
	    strcpy(obuf,".AVI");
	 }
	 else if(strncmp(dat_str,"FWS",3)==0){
	    strcpy(obuf,".SWF");
	 }
	 else if(dat_str[0]==0xFF&&(dat_str[1]&0xE0)==0xE0){
	    strcpy(obuf,".MP3");
	 }
	 else{
	    int i;
	    fprintf(stderr,"ERR: Unknown header:");
	    for(i=0;i<10;i++){
	       fprintf(stderr," %02X",dat_str[i]);
	    }
	    fprintf(stderr,"\n");
	    strcpy(obuf,".DAT");
	    type_known=0;
	 }
	 if(type_known){
	    FILE *ff=fopen(ofname,"w+");
	    fwrite(dat_str,1,dat_len,ff);
	    fclose(ff);
	 }
	 else{
	    FILE *ff=fopen(ofname,"w+");
	    fwrite(dat_str,1,dat_len,ff);
	    fclose(ff);
	 }
	 free(dat_str);
      }
   }
   fclose(f);
}
예제 #19
0
int decode_nodes(

  pbs_attribute *patr,
  const char   *name,   /* pbs_attribute name */
  const char *rescn,  /* resource name - unused here */
  const char    *val,    /* pbs_attribute value */
  int            perm)   /* replaces resc_access_perm */

  {
  const char *pc;

  pc = val;

  while (1)
    {
    while (isspace(*pc))
      ++pc;

    if (!isalnum(*pc))
      {
      return(PBSE_BADATVAL);
      }

    if (isdigit(*pc))
      {
      pc++;

      while (isdigit(*pc))
        pc++;

      if (*pc == '\0')
        break;

      if ((*pc != '+') && (*pc != ':') && (*pc != '#'))
        {
        return(PBSE_BADATVAL);
        }
      }
    else if (isalpha(*pc))
      {
      pc++;

      while (*pc != '\0')
        {
        if (isalnum(*pc) || strchr("-.=_", *pc))
          pc++;
        else
          break;
        }

      if (*pc == '\0')
        break;

      if ((*pc != '+') && (*pc != ':') && (*pc != '#'))
        {
        return(PBSE_BADATVAL);
        }
      }

    ++pc;
    }  /* END while(1) */

  return(decode_str(patr, name, rescn, val, perm));
  }  /* END decode_nodes() */
예제 #20
0
int
decode_place(struct attribute *patr, char *name, char *rescn, char *val)
{
#ifndef PBS_MOM
	int   have_oneof = 0;
	int   i;
	size_t ln;
	char  h;
	char *pc;
	char *px;
	struct resource_def *pres;

	extern int have_blue_gene_nodes;	/* BLUE GENE only */

	pc = val;

	while (1) {
		while (isspace((int)*pc))
			++pc;
		if (*pc == '\0' || !isalpha((int)*pc))
			return PBSE_BADATVAL;
		/* found start of word,  look for end of word */
		px = pc+1;
		while (isalpha((int)*px))
			px++;

		for (i=0; i<sizeof(place_words)/sizeof(place_words[0]); ++i) {
			if (strlen(place_words[i].pw_word) >= (size_t)(px-pc))
				ln = strlen(place_words[i].pw_word);
			else
				ln = (size_t)(px - pc);
			if (strncasecmp(pc, place_words[i].pw_word, ln) == 0) {
				break;
			}
		}
		if (i == sizeof(place_words)/sizeof(place_words[0]))
			return PBSE_BADATVAL;

		if (place_words[i].pw_oneof & have_oneof)
			return PBSE_BADATVAL;
		have_oneof |= place_words[i].pw_oneof;

		if (place_words[i].pw_equalstr) {
			if (*px != '=')
				return PBSE_BADATVAL;
			pc = ++px;
			while ((isalnum((int)*px) || (*px == '_') || (*px == '-')) &&
				(*px != ':'))
				++px;
			if (pc == px)
				return PBSE_BADATVAL;
			/* now need to see if the value is a valid resource/type */
			h = *px;
			*px = '\0';
			pres = find_resc_def(svr_resc_def, pc, svr_resc_size);
			if (pres == NULL)
				return PBSE_UNKRESC;
			if ((pres->rs_type != ATR_TYPE_STR) &&
				(pres->rs_type != ATR_TYPE_ARST))
				return PBSE_RESCNOTSTR;
			*px = h;

			if (*px == '\0')
				break;
			else if (*px != ':')
				return PBSE_BADATVAL;
		}
		pc = px;
		if (*pc == '\0')
			break;
		else if (*pc != ':')
			return PBSE_BADATVAL;
		pc++;
	}

	/* BLUE GENE only  - cannot have bgl nodes and jobs with "group=" */

	if (have_blue_gene_nodes != 0) {
		if (strstr(val, "group=") != NULL)
			return PBSE_NGBLUEGENE;
	}
#endif	/* not PBS_MOM */

	return (decode_str(patr, name, rescn, val));
}
예제 #21
0
/* Decode a universal time code */
int decode_utc(
    pbs_attribute *pattr,   /* I (modified) */
    const char   *name,    /* pbs_attribute name */
    const char *rescn,   /* resource name, unused here */
    const char    *val,     /* pbs_attribute value */
    int            perm)    /* only used for resources */

  {
  if(!strcmp(val,"0") || (*val == '\0'))
    {
    return decode_str(pattr,name,rescn,"",perm);
    }
  struct tm tm;
  bool offsetGiven = true;
  memset(&tm,0,sizeof(struct tm));
  tm.tm_isdst = -1; //This tells mktime to calculate the GMT offset and
                    //take daylight savings time into account.
  //Look for the format yyyy-mm-ddThh:mm:ss-hh or
  //                    yyyy-mm-ddThh:mm:ss-hhmm
  char *end = strptime(val,"%Y-%m-%dT%H:%M:%S%z",&tm);
  if ((end == NULL) || (*end != '\0'))
    {
    if (end == NULL)
      {
      memset(&tm,0,sizeof(struct tm));
      tm.tm_isdst = -1;
      offsetGiven = false;
      //Look for the format yyyy-mm-ddThh:mm:ssZ
      end = strptime(val,"%Y-%m-%dT%H:%M:%SZ",&tm);
      if ((end == NULL) || (*end != '\0'))
        {
        return(PBSE_BAD_UTC_FORMAT);
        }
      }
    else
      {
      return(PBSE_BAD_UTC_FORMAT);
      }
    }
  long offset = 0;
  if (offsetGiven)
    {
    offset = tm.tm_gmtoff; //Save the offset, mktime puts in its own.
    }
  time_t givenEpoch = mktime(&tm);
  if (offsetGiven)
    {
    /* This is to take care of the case where the time may be entered in one time zone but the machine running
       Moab may be running in another. If someone enters the time on the east coast with a -04 offset, but the
       Moab machine is running on the west coast we need to adjust the epoch time to reflect what will happen
       on the west coast. Example:
       Time entered 2014-08-20T00:00:00-04
       Machine on west coast will see that as 2014-08-19T20:00:00-08
       */
    givenEpoch += tm.tm_gmtoff; //Take away the calculated offset.
    givenEpoch -= offset;       //Add in the passed in offset.
    }
  else
    {
    givenEpoch += tm.tm_gmtoff; //Take away the calculated offset.
    }
  if(givenEpoch <= time(NULL))
    {
    return(PBSE_BAD_UTC_RANGE);
    }
  return decode_str(pattr,name,rescn,val,perm);
  }