Esempio n. 1
0
				virtual tag_type which(position_interface<types>& pos) {
					std::auto_ptr<position_interface<types> > p = pos.clone();
					if (match_next<0>(*p)) {
						advance_next<0>(*p);
						skip_next(*p);
						if (match_next<0>(*p)) {
							return commands::inc;
						} else if (match_next<1>(*p)) {
							return commands::in;
						} else if (match_next<2>(*p)) {
							return commands::next;
						}
					} else if (match_next<1>(*p)) {
						advance_next<1>(*p);
						skip_next(*p);
						if (match_next<0>(*p)) {
							return commands::out;
						} else if (match_next<1>(*p)) {
							return commands::dec;
						} else if (match_next<2>(*p)) {
							return commands::begin;
						}
					} else if (match_next<2>(*p)) {
						advance_next<2>(*p);
						skip_next(*p);
						if (match_next<0>(*p)) {
							return commands::prior;
						} else if (match_next<1>(*p)) {
							return commands::end;
						}
					}
					return commands::none;
				}
Esempio n. 2
0
int fdset_sweep(fdset_t* fdset, void(*cb)(fdset_t*, int, void*), void *data)
{
	fdset_base_t *base = (fdset_base_t*)fdset;
	if (base == NULL || base->atimes == NULL) {
		return -1;
	}

	/* Get time threshold. */
	timev_t now;
	if (time_now(&now) < 0) {
		return -1;
	}

	/* Inspect all nodes. */
	int sweeped = 0;
	const skip_node_t *n = skip_first(base->atimes);
	while (n != NULL) {
		const skip_node_t* pnext = skip_next(n);

		/* Evaluate */
		timev_t *ts = (timev_t*)n->value;
		if (ts->tv_sec <= now.tv_sec) {
			cb(fdset, (int)(((ssize_t)n->key)), data);
			++sweeped;
		}
		n = pnext;
	}

	return sweeped;
}
Esempio n. 3
0
static int wenv_func(char *arg, int flags)
{
	char *p = arg;
	char *p1;
	int ret = 0;
	int status = 0;
	int i;
	wenv_flags = 0;
	char *cmd_buff;
	if ((cmd_buff = malloc(0x800)) == NULL)
		return 0;

	while ( *p && (arg = p) != NULL)
	{
		if (*arg == '(')
		{
			p = check_Brackets(arg);
			if (p == NULL)
			{
				free(cmd_buff);
				return !(errnum = ERR_BAD_ARGUMENT);
			}
			*p++ = '\0';
			p = skip_next_next_cmd(p,&status,STATUS_NONE);
			ret = wenv_func(++arg,flags);
		}
		else
		{
			#ifdef DEBUG
				printf("wenv_arg:%s\n",arg);
			#endif
			*cmd_buff = '\0';
			p = skip_next_next_cmd(p,&status,STATUS_NONE);
			replace_str(arg,cmd_buff,REPLACE_TRIM | MAX_ENV_LEN); //替换变量
			arg = cmd_buff;
			for (i=0;p_cmd_list[i].name != NULL ;i++)
			{
				if (strcmp_ex(arg, p_cmd_list[i].name) == 0)
				{
					arg = skip_next(0, arg);
					if((unsigned char)*arg < (unsigned char)p_cmd_list[i].flags)
					{
						free(cmd_buff);
						return wenv_help_ex(p_cmd_list[i].flags >> 8);
					}
					break;
				}
			}
			if (p_cmd_list[i].func == NULL)
			{
				if (debug == 2)
					printf("wenv_arg:%s\n",arg);
				free(cmd_buff);
				return !(errnum = ERR_BAD_ARGUMENT);
			}
			ret = p_cmd_list[i].func(arg,flags);
		}
Esempio n. 4
0
static char *skip_next_next_cmd (char *cmd,int *status,int flags)
{
	*status = 0;
	if (cmd == NULL || *cmd == 0)
		return NULL;
	while (*cmd)
	{
		if (*cmd == '(')
			cmd = check_Brackets(cmd);
		cmd = skip_next (0, cmd);
		switch (*(unsigned int *)cmd)
		{//&=0x26;|=0x7c;]=0x5d;!=0x21; ;=0x3b
			case 0x20265d5d://	operator AND "]]&"
				*status = STATUS_AND;
				break;
			case 0x207c5d5d://	operator OR "]]|"
				*status = STATUS_OR;
				break;
			case 0x20215d5d://	]]!
				*status = STATUS_ELSE;
				break;
			case 0x205D5D5D://]]]
				*status = STATUS_QUEUE;
				break;
			default:
				if (*(unsigned short *)cmd != 0x203b)
					continue;
				*status = STATUS_NONE;
				break;
		}
		*(cmd - 1) = '\0';
		cmd = skip_next (0, cmd);
		if (flags == 0 || *status == flags)
		{
			break;
		}
	}
	return cmd;
}
Esempio n. 5
0
  bool Reader::next(Overlap** dst, const ReadSet& reads) {
    if (!has_next()) {
      return false;
    }

    while (next_type() != OVERLAP) {
      skip_next();
      if (!has_next()) {
        return false;
      }
    }

    return overlap_from_buff(dst, reads);
  }
Esempio n. 6
0
				virtual void next(position_interface<types>& pos) {
					switch (which(pos)) {
					case commands::next:
						advance_next<0>(pos);
						skip_next(pos);
						advance_next<2>(pos);
						break;
					case commands::prior:
						advance_next<2>(pos);
						skip_next(pos);
						advance_next<0>(pos);
						break;
					case commands::inc:
						advance_next<0>(pos);
						skip_next(pos);
						advance_next<0>(pos);
						break;
					case commands::dec:
						advance_next<1>(pos);
						skip_next(pos);
						advance_next<1>(pos);
						break;
					case commands::out:
						advance_next<1>(pos);
						skip_next(pos);
						advance_next<0>(pos);
						break;
					case commands::in:
						advance_next<0>(pos);
						skip_next(pos);
						advance_next<1>(pos);
						break;
					case commands::begin:
						advance_next<1>(pos);
						skip_next(pos);
						advance_next<2>(pos);
						break;
					case commands::end:
						advance_next<2>(pos);
						skip_next(pos);
						advance_next<1>(pos);
						break;
					default:
						pos.next();
						break;
					}
				}
Esempio n. 7
0
  bool Reader::next(Read** dst) {
    if (!has_next()) {
      return false;
    }

    while (next_type() != READ) {
      //cerr << "WRONG TYPE" << endl;
      skip_next();
      if (!has_next()) {
        return false;
      }
    }

    //cout << "READ " << buff << endl;
    return read_from_buff(dst);
  }
Esempio n. 8
0
static int
doit(const char *filename, int mergep)
{
    krb5_error_code ret;
    FILE *f;
    char s[8192]; /* XXX should fix this properly */
    char *p;
    int line;
    int flags = O_RDWR;
    struct entry e;
    hdb_entry_ex ent;
    HDB *db = _kadm5_s_get_db(kadm_handle);

    f = fopen(filename, "r");
    if(f == NULL){
	krb5_warn(context, errno, "fopen(%s)", filename);
	return 1;
    }
    ret = kadm5_log_truncate (kadm_handle);
    if (ret) {
	fclose (f);
	krb5_warn(context, ret, "kadm5_log_truncate");
	return 1;
    }

    if(!mergep)
	flags |= O_CREAT | O_TRUNC;
    ret = db->hdb_open(context, db, flags, 0600);
    if(ret){
	krb5_warn(context, ret, "hdb_open");
	fclose(f);
	return 1;
    }
    line = 0;
    ret = 0;
    while(fgets(s, sizeof(s), f) != NULL) {
	ret = 0;
	line++;

	p = s;
	while (isspace((unsigned char)*p))
	    p++;

	e.principal = p;
	for(p = s; *p; p++){
	    if(*p == '\\')
		p++;
	    else if(isspace((unsigned char)*p)) {
		*p = 0;
		break;
	    }
	}
	p = skip_next(p);
	
	e.key = p;
	p = skip_next(p);

	e.created = p;
	p = skip_next(p);

	e.modified = p;
	p = skip_next(p);

	e.valid_start = p;
	p = skip_next(p);

	e.valid_end = p;
	p = skip_next(p);

	e.pw_end = p;
	p = skip_next(p);

	e.max_life = p;
	p = skip_next(p);

	e.max_renew = p;
	p = skip_next(p);

	e.flags = p;
	p = skip_next(p);

	e.generation = p;
	p = skip_next(p);

	e.extensions = p;
	p = skip_next(p);

	memset(&ent, 0, sizeof(ent));
	ret = krb5_parse_name(context, e.principal, &ent.entry.principal);
	if(ret) {
	    fprintf(stderr, "%s:%d:%s (%s)\n", 
		    filename, 
		    line,
		    krb5_get_err_text(context, ret),
		    e.principal);
	    continue;
	}
	
	if (parse_keys(&ent.entry, e.key)) {
	    fprintf (stderr, "%s:%d:error parsing keys (%s)\n",
		     filename, line, e.key);
	    hdb_free_entry (context, &ent);
	    continue;
	}
	
	if (parse_event(&ent.entry.created_by, e.created) == -1) {
	    fprintf (stderr, "%s:%d:error parsing created event (%s)\n",
		     filename, line, e.created);
	    hdb_free_entry (context, &ent);
	    continue;
	}
	if (parse_event_alloc (&ent.entry.modified_by, e.modified) == -1) {
	    fprintf (stderr, "%s:%d:error parsing event (%s)\n",
		     filename, line, e.modified);
	    hdb_free_entry (context, &ent);
	    continue;
	}
	if (parse_time_string_alloc (&ent.entry.valid_start, e.valid_start) == -1) {
	    fprintf (stderr, "%s:%d:error parsing time (%s)\n",
		     filename, line, e.valid_start);
	    hdb_free_entry (context, &ent);
	    continue;
	}
	if (parse_time_string_alloc (&ent.entry.valid_end,   e.valid_end) == -1) {
	    fprintf (stderr, "%s:%d:error parsing time (%s)\n",
		     filename, line, e.valid_end);
	    hdb_free_entry (context, &ent);
	    continue;
	}
	if (parse_time_string_alloc (&ent.entry.pw_end,      e.pw_end) == -1) {
	    fprintf (stderr, "%s:%d:error parsing time (%s)\n",
		     filename, line, e.pw_end);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	if (parse_integer_alloc (&ent.entry.max_life,  e.max_life) == -1) {
	    fprintf (stderr, "%s:%d:error parsing lifetime (%s)\n",
		     filename, line, e.max_life);
	    hdb_free_entry (context, &ent);
	    continue;

	}
	if (parse_integer_alloc (&ent.entry.max_renew, e.max_renew) == -1) {
	    fprintf (stderr, "%s:%d:error parsing lifetime (%s)\n",
		     filename, line, e.max_renew);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	if (parse_hdbflags2int (&ent.entry.flags, e.flags) != 1) {
	    fprintf (stderr, "%s:%d:error parsing flags (%s)\n",
		     filename, line, e.flags);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	if(parse_generation(e.generation, &ent.entry.generation) == -1) {
	    fprintf (stderr, "%s:%d:error parsing generation (%s)\n",
		     filename, line, e.generation);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	if(parse_extensions(e.extensions, &ent.entry.extensions) == -1) {
	    fprintf (stderr, "%s:%d:error parsing extension (%s)\n",
		     filename, line, e.extensions);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	ret = db->hdb_store(context, db, HDB_F_REPLACE, &ent);
	hdb_free_entry (context, &ent);
	if (ret) {
	    krb5_warn(context, ret, "db_store");
	    break;
	}
    }
    db->hdb_close(context, db);
    fclose(f);
    return ret != 0;
}
Esempio n. 9
0
static int
doit(const char *filename, int mergep)
{
    krb5_error_code ret = 0;
    FILE *f;
    char s[8192]; /* XXX should fix this properly */
    char *p;
    int line;
    int flags = O_RDWR;
    struct entry e;
    hdb_entry_ex ent;
    HDB *db = _kadm5_s_get_db(kadm_handle);

    f = fopen(filename, "r");
    if(f == NULL){
	krb5_warn(context, errno, "fopen(%s)", filename);
	return 1;
    }
    /*
     * We don't have a version number in the dump, so we don't know which iprop
     * log entries to keep, if any.  We throw the log away.
     *
     * We could merge the ipropd-master/slave dump/load here as an option, in
     * which case we would first load the dump.
     *
     * If we're merging, first recover unconfirmed records in the existing log.
     */
    if (mergep)
        ret = kadm5_log_init(kadm_handle);
    if (ret == 0)
        ret = kadm5_log_reinit(kadm_handle, 0);
    if (ret) {
	fclose (f);
	krb5_warn(context, ret, "kadm5_log_reinit");
	return 1;
    }

    if(!mergep)
	flags |= O_CREAT | O_TRUNC;
    ret = db->hdb_open(context, db, flags, 0600);
    if(ret){
	krb5_warn(context, ret, "hdb_open");
	fclose(f);
	return 1;
    }
    line = 0;
    ret = 0;
    while(fgets(s, sizeof(s), f) != NULL) {
	line++;

	p = s;
	while (isspace((unsigned char)*p))
	    p++;

	e.principal = p;
	for(p = s; *p; p++){
	    if(*p == '\\')
		p++;
	    else if(isspace((unsigned char)*p)) {
		*p = 0;
		break;
	    }
	}
	p = skip_next(p);

	e.key = p;
	p = skip_next(p);

	e.created = p;
	p = skip_next(p);

	e.modified = p;
	p = skip_next(p);

	e.valid_start = p;
	p = skip_next(p);

	e.valid_end = p;
	p = skip_next(p);

	e.pw_end = p;
	p = skip_next(p);

	e.max_life = p;
	p = skip_next(p);

	e.max_renew = p;
	p = skip_next(p);

	e.flags = p;
	p = skip_next(p);

	e.generation = p;
	p = skip_next(p);

	e.extensions = p;
	skip_next(p);

	memset(&ent, 0, sizeof(ent));
	ret = krb5_parse_name(context, e.principal, &ent.entry.principal);
	if(ret) {
	    const char *msg = krb5_get_error_message(context, ret);
	    fprintf(stderr, "%s:%d:%s (%s)\n",
		    filename, line, msg, e.principal);
	    krb5_free_error_message(context, msg);
	    continue;
	}

	if (parse_keys(&ent.entry, e.key)) {
	    fprintf (stderr, "%s:%d:error parsing keys (%s)\n",
		     filename, line, e.key);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	if (parse_event(&ent.entry.created_by, e.created) == -1) {
	    fprintf (stderr, "%s:%d:error parsing created event (%s)\n",
		     filename, line, e.created);
	    hdb_free_entry (context, &ent);
	    continue;
	}
	if (parse_event_alloc (&ent.entry.modified_by, e.modified) == -1) {
	    fprintf (stderr, "%s:%d:error parsing event (%s)\n",
		     filename, line, e.modified);
	    hdb_free_entry (context, &ent);
	    continue;
	}
	if (parse_time_string_alloc (&ent.entry.valid_start, e.valid_start) == -1) {
	    fprintf (stderr, "%s:%d:error parsing time (%s)\n",
		     filename, line, e.valid_start);
	    hdb_free_entry (context, &ent);
	    continue;
	}
	if (parse_time_string_alloc (&ent.entry.valid_end,   e.valid_end) == -1) {
	    fprintf (stderr, "%s:%d:error parsing time (%s)\n",
		     filename, line, e.valid_end);
	    hdb_free_entry (context, &ent);
	    continue;
	}
	if (parse_time_string_alloc (&ent.entry.pw_end,      e.pw_end) == -1) {
	    fprintf (stderr, "%s:%d:error parsing time (%s)\n",
		     filename, line, e.pw_end);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	if (parse_integer_alloc (&ent.entry.max_life,  e.max_life) == -1) {
	    fprintf (stderr, "%s:%d:error parsing lifetime (%s)\n",
		     filename, line, e.max_life);
	    hdb_free_entry (context, &ent);
	    continue;

	}
	if (parse_integer_alloc (&ent.entry.max_renew, e.max_renew) == -1) {
	    fprintf (stderr, "%s:%d:error parsing lifetime (%s)\n",
		     filename, line, e.max_renew);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	if (parse_hdbflags2int (&ent.entry.flags, e.flags) != 1) {
	    fprintf (stderr, "%s:%d:error parsing flags (%s)\n",
		     filename, line, e.flags);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	if(parse_generation(e.generation, &ent.entry.generation) == -1) {
	    fprintf (stderr, "%s:%d:error parsing generation (%s)\n",
		     filename, line, e.generation);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	if(parse_extensions(e.extensions, &ent.entry.extensions) == -1) {
	    fprintf (stderr, "%s:%d:error parsing extension (%s)\n",
		     filename, line, e.extensions);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	ret = db->hdb_store(context, db, HDB_F_REPLACE, &ent);
	hdb_free_entry (context, &ent);
	if (ret) {
	    krb5_warn(context, ret, "db_store");
	    break;
	}
    }
    (void) kadm5_log_end(kadm_handle);
    db->hdb_close(context, db);
    fclose(f);
    return ret != 0;
}