Esempio n. 1
0
int get_defaults_options(int argc, char **argv,
                         char **defaults,
                         char **extra_defaults,
                         char **group_suffix)
{
  int org_argc= argc, prev_argc= 0;
  *defaults= *extra_defaults= *group_suffix= 0;

  while (argc >= 2 && argc != prev_argc)
  {
    /* Skip program name or previously handled argument */
    argv++;
    prev_argc= argc;                            /* To check if we found */
    if (!*defaults && is_prefix(*argv,"--defaults-file="))
    {
      *defaults= *argv + sizeof("--defaults-file=")-1;
       argc--;
       continue;
    }
    if (!*extra_defaults && is_prefix(*argv,"--defaults-extra-file="))
    {
      *extra_defaults= *argv + sizeof("--defaults-extra-file=")-1;
      argc--;
      continue;
    }
    if (!*group_suffix && is_prefix(*argv, "--defaults-group-suffix="))
    {
      *group_suffix= *argv + sizeof("--defaults-group-suffix=")-1;
      argc--;
      continue;
    }
  }
  return org_argc - argc;
}
Esempio n. 2
0
NOEXPORT void smtp_client(CLI *c) {
    char *line;

    line=str_dup("");
    do { /* copy multiline greeting */
        str_free(line);
        line=fd_getline(c, c->remote_fd.fd);
        fd_putline(c, c->local_wfd.fd, line);
    } while(is_prefix(line, "220-"));

    fd_putline(c, c->remote_fd.fd, "EHLO localhost");
    do { /* skip multiline reply */
        str_free(line);
        line=fd_getline(c, c->remote_fd.fd);
    } while(is_prefix(line, "250-"));
    if(!is_prefix(line, "250 ")) { /* error */
        s_log(LOG_ERR, "Remote server is not RFC 1425 compliant");
        str_free(line);
        longjmp(c->err, 1);
    }

    fd_putline(c, c->remote_fd.fd, "STARTTLS");
    do { /* skip multiline reply */
        str_free(line);
        line=fd_getline(c, c->remote_fd.fd);
    } while(is_prefix(line, "220-"));
    if(!is_prefix(line, "220 ")) { /* error */
        s_log(LOG_ERR, "Remote server is not RFC 2487 compliant");
        str_free(line);
        longjmp(c->err, 1);
    }
    str_free(line);
}
Esempio n. 3
0
File: map.c Progetto: avagin/linux
int map_parse_fd(int *argc, char ***argv)
{
	int fd;

	if (is_prefix(**argv, "id")) {
		unsigned int id;
		char *endptr;

		NEXT_ARGP();

		id = strtoul(**argv, &endptr, 0);
		if (*endptr) {
			p_err("can't parse %s as ID", **argv);
			return -1;
		}
		NEXT_ARGP();

		fd = bpf_map_get_fd_by_id(id);
		if (fd < 0)
			p_err("get map by id (%u): %s", id, strerror(errno));
		return fd;
	} else if (is_prefix(**argv, "pinned")) {
		char *path;

		NEXT_ARGP();

		path = **argv;
		NEXT_ARGP();

		return open_obj_pinned_any(path, BPF_OBJ_MAP);
	}

	p_err("expected 'id' or 'pinned', got: '%s'?", **argv);
	return -1;
}
Esempio n. 4
0
static int
compare_name_info(const void* a, const void* b)
{
	int rc;

	const char *name1 = ((struct ioctlent *) a)->name;
	const char *name2 = ((struct ioctlent *) b)->name;
	const char *info1 = ((struct ioctlent *) a)->info;
	const char *info2 = ((struct ioctlent *) b)->info;

	rc = strcmp(name1, name2);
	if (rc)
		return rc;

	/*
	 * exception from lexicographical order:
	 * "asm/" < "asm-generic/"
	 */
	if (is_prefix("asm/", info1) &&
	    is_prefix("asm-generic/", info2))
		return -1;

	if (is_prefix("asm/", info2) &&
	    is_prefix("asm-generic/", info1))
		return 1;

	return strcmp(info1, info2);
}
Esempio n. 5
0
static int do_attach(int argc, char **argv)
{
	enum bpf_attach_type attach_type;
	int cgroup_fd, prog_fd;
	int attach_flags = 0;
	int ret = -1;
	int i;

	if (argc < 4) {
		p_err("too few parameters for cgroup attach");
		goto exit;
	}

	cgroup_fd = open(argv[0], O_RDONLY);
	if (cgroup_fd < 0) {
		p_err("can't open cgroup %s", argv[1]);
		goto exit;
	}

	attach_type = parse_attach_type(argv[1]);
	if (attach_type == __MAX_BPF_ATTACH_TYPE) {
		p_err("invalid attach type");
		goto exit_cgroup;
	}

	argc -= 2;
	argv = &argv[2];
	prog_fd = prog_parse_fd(&argc, &argv);
	if (prog_fd < 0)
		goto exit_cgroup;

	for (i = 0; i < argc; i++) {
		if (is_prefix(argv[i], "multi")) {
			attach_flags |= BPF_F_ALLOW_MULTI;
		} else if (is_prefix(argv[i], "override")) {
			attach_flags |= BPF_F_ALLOW_OVERRIDE;
		} else {
			p_err("unknown option: %s", argv[i]);
			goto exit_cgroup;
		}
	}

	if (bpf_prog_attach(prog_fd, cgroup_fd, attach_type, attach_flags)) {
		p_err("failed to attach program");
		goto exit_prog;
	}

	if (json_output)
		jsonw_null(json_wtr);

	ret = 0;

exit_prog:
	close(prog_fd);
exit_cgroup:
	close(cgroup_fd);
exit:
	return ret;
}
Esempio n. 6
0
int main() {
  std::vector<int> v1 = { 0, 1, 2 },
                   v2 = { 0, 1, 2, 3 },
                   v3 = { 2, 3, 5 };
  std::cout << "1 <> 2 : " << is_prefix(v1, v2) << std::endl;
  std::cout << "1 <> 3 : " << is_prefix(v1, v3) << std::endl;
  return 0;
}
Esempio n. 7
0
void get_defaults_files(int argc, char **argv,
                        char **defaults, char **extra_defaults)
{
  *defaults=0;
  *extra_defaults=0;
  if (argc >= 2)
  {
    if (is_prefix(argv[1],"--defaults-file="))
      *defaults= argv[1];
    else if (is_prefix(argv[1],"--defaults-extra-file="))
      *extra_defaults= argv[1];
  }
}
Esempio n. 8
0
int main(int argc, char *argv[]){
  if(argc < 3){
    printf("Usage: ./sort method array_length array\n");
    exit(1);
  }
  int method = SORT_QUICK;
  if(argc == 4){
    if(is_prefix(argv[1], "quick")){
      method = SORT_QUICK;
    } else if(is_prefix(argv[1], "merge")){
      method = SORT_MERGE;
    } else if(is_prefix(argv[1], "insertion")){
      method = SORT_INSERTION;
    } else if(is_prefix(argv[1], "radix")){
      method = SORT_RADIX;
    } else {
      fprintf(stderr, "Uknown sorting method %s, using default\n", argv[1]);
    }
    argv++;
  }
  ulong len;
  int err = strtoul_checked(argv[1], &len, NULL);
  if(err){
    perror("strtoul");
    exit(1);
  }
  ulong *arr = read_arr(len, argv[2]);
  if(!arr){
    perror("strtoul");
    exit(1);
  }
  //sort stuff
  switch(method){
    case(SORT_QUICK):      
      qsort_u64(arr,len); break;
    case(SORT_MERGE):
      mergesort_u64(arr,len);break;
    case(SORT_INSERTION):
      insertion_sort_u64(arr,len);break;
    case(SORT_RADIX):
      radix_sort_u64(arr,len);break;
  }
  if(is_sorted(arr,len)){
    printf("Array was sorted\n");
  } else {
    printf("Failed to sort array\n");
  }
  print_arr(arr, len, stdout);
  free(arr);
  return 0;
}
Esempio n. 9
0
NOEXPORT void connect_client(CLI *c) {
    char *line, *encoded;

    if(!c->opt->protocol_host) {
        s_log(LOG_ERR, "protocolHost not specified");
        longjmp(c->err, 1);
    }
    fd_printf(c, c->remote_fd.fd, "CONNECT %s HTTP/1.1",
        c->opt->protocol_host);
    fd_printf(c, c->remote_fd.fd, "Host: %s", c->opt->protocol_host);
    if(c->opt->protocol_username && c->opt->protocol_password) {
        if(!strcasecmp(c->opt->protocol_authentication, "ntlm")) {
#if !defined(OPENSSL_NO_MD4) && OPENSSL_VERSION_NUMBER>=0x0090700fL
            ntlm(c);
#else
            s_log(LOG_ERR, "NTLM authentication is not available");
            longjmp(c->err, 1);
#endif
        } else { /* basic authentication */
            line=str_printf("%s:%s",
                c->opt->protocol_username, c->opt->protocol_password);
            encoded=base64(1, line, strlen(line));
            str_free(line);
            if(!encoded) {
                s_log(LOG_ERR, "Base64 encoder failed");
                longjmp(c->err, 1);
            }
            fd_printf(c, c->remote_fd.fd, "Proxy-Authorization: basic %s",
                encoded);
            str_free(encoded);
        }
    }
    fd_putline(c, c->remote_fd.fd, ""); /* empty line */
    line=fd_getline(c, c->remote_fd.fd);
    if(!is_prefix(line, "HTTP/1.0 2") && !is_prefix(line, "HTTP/1.1 2")) {
        /* not "HTTP/1.x 2xx Connection established" */
        s_log(LOG_ERR, "CONNECT request rejected");
        do { /* read all headers */
            str_free(line);
            line=fd_getline(c, c->remote_fd.fd);
        } while(*line);
        str_free(line);
        longjmp(c->err, 1);
    }
    s_log(LOG_INFO, "CONNECT request accepted");
    do {
        str_free(line);
        line=fd_getline(c, c->remote_fd.fd); /* read all headers */
    } while(*line);
    str_free(line);
}
Esempio n. 10
0
// this is lifted from tabix main.c:
bool
is_tabix_index(const char* f) {

    if (NULL == f) return false;

    // punt on remote case:
    if (is_prefix(f,"ftp://") || is_prefix(f,"http://")) return true;

    std::string idx(f);
    idx += ".tbi";

    struct stat stat_f,stat_idx;
    stat(f, &stat_f);
    stat(idx.c_str(), &stat_idx);
    return ( stat_f.st_mtime <= stat_idx.st_mtime );
}
Esempio n. 11
0
char * my_load_path(char * to, const char *path,
		       const char *own_path_prefix)
{
  char buff[FN_REFLEN];
  int is_cur;
  DBUG_ENTER("my_load_path");
  DBUG_PRINT("enter",("path: %s  prefix: %s",path,
		      own_path_prefix ? own_path_prefix : ""));

  if ((path[0] == FN_HOMELIB && path[1] == FN_LIBCHAR) ||
      test_if_hard_path(path))
    (void) strnmov(buff, path, FN_REFLEN);
  else if ((is_cur=(path[0] == FN_CURLIB && path[1] == FN_LIBCHAR)) ||
	   (is_prefix(path,FN_PARENTDIR)) ||
	   ! own_path_prefix)
  {
    if (is_cur)
      is_cur=2;					/* Remove current dir */
    if (! my_getwd(buff,(uint) (FN_REFLEN-strlen(path)+is_cur),MYF(0)))
      (void) strncat(buff, path+is_cur, FN_REFLEN-1);
    else
      (void) strnmov(buff, path, FN_REFLEN);			/* Return org file name */
  }
  else
    (void) strxnmov(buff, FN_REFLEN, own_path_prefix, path, NullS);
  strnmov(to, buff, FN_REFLEN);
  to[FN_REFLEN-1]= '\0';
  DBUG_PRINT("exit",("to: %s",to));
  DBUG_RETURN(to);
} /* my_load_path */
Esempio n. 12
0
void
gitbot::irc::client::process_line(
	std::string const &_s)
{
	if(
		!is_prefix(
			"PING :",
			_s))
	{
		FCPPT_LOG_DEBUG(
			mylogger,
			fcppt::log::_ 
				<< FCPPT_TEXT("Got a line, but it's not a ping, so doing nothing."));
		return;
	}

	FCPPT_LOG_DEBUG(
		mylogger,
		fcppt::log::_ 
			<< FCPPT_TEXT("Got a ping, sending back pong with: ")
			<< _s.substr(6));
			
	write(
		"PONG :"+
		_s.substr(
			6));
}
Esempio n. 13
0
int codegen_jschema(struct_data *defs, int ndefs, 
  char *prefix, char *suffix, FILE *out) {

  int i;
  int n;
  struct_data *filtered_defs[ndefs];

  for (i = n = 0; i < ndefs; i++) {
    if (is_prefix(defs[i].info.name,prefix) && is_suffix(defs[i].info.name,suffix)) {
      filtered_defs[n] = &defs[i];
      n++;
    }
  }

  fprintf(out,"[\n");

  for (i = 0; i < n; i++) {
    fprintf(out,"{");
    fprintf(out,"\"name\" : \"%s\",",filtered_defs[i]->info.name);
    codegen_jschema_internal(filtered_defs[i],defs,out);
    fprintf(out,"}");
    if (i != (n - 1)) {
      fprintf(out,",");
    }
    fprintf(out,"\n");
  }

  fprintf(out,"]\n");

  return 0;
}
Esempio n. 14
0
void get_words_with_prefix(ucs4_t * word, int p)
{
	int i;
	static ucs4_t buff[DATRIE_WORD_MAX_LENGTH];
	static ucs4_t words_set_char_buff[DATRIE_WORD_MAX_COUNT];
	
	for (i = 0; i < p; i ++)
		buff[i] = word[i];
	buff[p] = 0;
	
	words_set_count = 0;
	for (i = binary_search(buff); i < lexicon_count && is_prefix(buff,lexicon[i].key); i ++)
	{
		if (ucs4cmp(buff,lexicon[i].key) == 0)
			continue;
		words_set_char_buff[words_set_count] = lexicon[i].key[p];
		words_set[words_set_count ++] = i;
	}
	words_set_char_buff[words_set_count] = 0;
	
	qsort(words_set_char_buff, words_set_count, sizeof(words_set_char_buff[0]), wcmp);
	
	ucs4_t * wfp, * wp, last;
	for (last = 0, wfp = words_set_char_buff, wp = words_set_char; *wfp; wfp ++)
	{
		if (*wfp != last)
		{
			last = *wfp;
			*wp = *wfp;
			wp ++;
		}
	}
	*wp = 0;
}
Esempio n. 15
0
int binary_search(const ucs4_t *str)
{
	int a = 0,b = lexicon_count - 1,c;
	while (a + 1 < b)
	{
		c = (a + b) / 2;
		if (ucs4cmp(str,lexicon[c].key) <= 0)
			b = c;
		else
			a = c+1;
	}
	if (is_prefix(str,lexicon[a].key) && (a == 0 || !is_prefix(str,lexicon[a-1].key)))
		return a;
	if (is_prefix(str,lexicon[b].key) && !is_prefix(str,lexicon[b-1].key))
		return b;
	return -1;
}
Esempio n. 16
0
bool is_prefix(const char *prefix, const char *src) {
  if(*prefix == '\0')
    //empty string is always a prefix
    return true;
  else if(*prefix == *src)
    //first two characters match, so recursivly match the remaining characters of prefix and src
    return is_prefix(prefix+1, src+1);
  return false;
}
Esempio n. 17
0
void option_imp<void>::post_process()
{
	if (popt_value) {
		if (is_prefix(option_name, "no-"))
			value = !popt_value;
		else 
			value = popt_value;
	}
}
Esempio n. 18
0
NOEXPORT void smtp_server(CLI *c) {
    char *line;

    s_poll_init(c->fds);
    s_poll_add(c->fds, c->local_rfd.fd, 1, 0);
    switch(s_poll_wait(c->fds, 0, 200)) { /* wait up to 200ms */
    case 0: /* fd not ready to read */
        s_log(LOG_DEBUG, "RFC 2487 detected");
        break;
    case 1: /* fd ready to read */
        s_log(LOG_DEBUG, "RFC 2487 not detected");
        return; /* return if RFC 2487 is not used */
    default: /* -1 */
        sockerror("RFC2487 (s_poll_wait)");
        longjmp(c->err, 1);
    }

    line=fd_getline(c, c->remote_fd.fd);
    if(!is_prefix(line, "220")) {
        s_log(LOG_ERR, "Unknown server welcome");
        str_free(line);
        longjmp(c->err, 1);
    }
    fd_printf(c, c->local_wfd.fd, "%s + stunnel", line);
    str_free(line);
    line=fd_getline(c, c->local_rfd.fd);
    if(!is_prefix(line, "EHLO ")) {
        s_log(LOG_ERR, "Unknown client EHLO");
        str_free(line);
        longjmp(c->err, 1);
    }
    fd_printf(c, c->local_wfd.fd, "250-%s Welcome", line);
    fd_putline(c, c->local_wfd.fd, "250 STARTTLS");
    str_free(line);
    line=fd_getline(c, c->local_rfd.fd);
    if(!is_prefix(line, "STARTTLS")) {
        s_log(LOG_ERR, "STARTTLS expected");
        str_free(line);
        longjmp(c->err, 1);
    }
    fd_putline(c, c->local_wfd.fd, "220 Go ahead");
    str_free(line);
}
Esempio n. 19
0
NOEXPORT void connect_server(CLI *c) {
    char *request, *proto, *header;
    NAME_LIST host_list;

    request=fd_getline(c, c->local_rfd.fd);
    if(!is_prefix(request, "CONNECT ")) {
        fd_putline(c, c->local_wfd.fd, "HTTP/1.0 400 Bad Request Method");
        fd_putline(c, c->local_wfd.fd, "Server: stunnel/" STUNNEL_VERSION);
        fd_putline(c, c->local_wfd.fd, "");
        str_free(request);
        longjmp(c->err, 1);
    }
    proto=strchr(request+8, ' ');
    if(!proto || !is_prefix(proto, " HTTP/")) {
        fd_putline(c, c->local_wfd.fd, "HTTP/1.0 400 Bad Request Protocol");
        fd_putline(c, c->local_wfd.fd, "Server: stunnel/" STUNNEL_VERSION);
        fd_putline(c, c->local_wfd.fd, "");
        str_free(request);
        longjmp(c->err, 1);
    }
    *proto='\0';

    header=str_dup("");
    do { /* ignore any headers */
        str_free(header);
        header=fd_getline(c, c->local_rfd.fd);
    } while(*header); /* not empty */
    str_free(header);

    host_list.name=request+8;
    host_list.next=NULL;
    if(!namelist2addrlist(&c->connect_addr, &host_list, DEFAULT_LOOPBACK)) {
        fd_putline(c, c->local_wfd.fd, "HTTP/1.0 404 Not Found");
        fd_putline(c, c->local_wfd.fd, "Server: stunnel/" STUNNEL_VERSION);
        fd_putline(c, c->local_wfd.fd, "");
        str_free(request);
        longjmp(c->err, 1);
    }
    str_free(request);
    fd_putline(c, c->local_wfd.fd, "HTTP/1.0 200 OK");
    fd_putline(c, c->local_wfd.fd, "Server: stunnel/" STUNNEL_VERSION);
    fd_putline(c, c->local_wfd.fd, "");
}
Esempio n. 20
0
int parse_option(char *opt, char **name, char **value)
{
    static char namebuf[OPTBUF_SIZE];
    static char valbuf[OPTBUF_SIZE];
    int pos = 0;

    if(!is_prefix("--", opt))
        return 0;

    /* Preset outputs to NULL so we don't have to do it in multiple
       places later on
     */
    if(name)  *name = NULL;
    if(value) *value = NULL;

    opt += 2; /* skip past leading '--' */

    /* Scan name into name buffer, stopping at end of string or
       when an '=' is encountered (denoting a value is next)
     */
    while(*opt && *opt != '=' && pos < sizeof(namebuf) - 1) {
        namebuf[pos++] = *opt;
        ++opt;
    }
    namebuf[pos] = '\0'; /* make sure name is terminated */

    /* Send name to output, if possible */
    if(name)
        *name = (char *)&namebuf;

    /* Is there a value to follow? */
    if(*opt == '\0')
        return 1;  /* no, just return a name */

    ++opt;   /* skip past the '=' */
    pos = 0;

    /* Scan value into value buffer, stopping at end of string.
       Note that it is legal for the value to be an empty string;
       this will be returned as a zero-length string, rather than
       as a NULL
     */
    while(*opt && pos < sizeof(valbuf) - 1) {
        valbuf[pos++] = *opt;
        ++opt;
    }
    valbuf[pos] = '\0'; /* make sure value is terminated */

    /* Send value to output, if possible */
    if(value)
        *value = (char *)&valbuf;

    return 1;

} /* end parse_option() */
Esempio n. 21
0
NOEXPORT void nntp_client(CLI *c) {
    char *line;

    line=fd_getline(c, c->remote_fd.fd);
    if(!is_prefix(line, "200 ") && !is_prefix(line, "201 ")) {
        s_log(LOG_ERR, "Unknown server welcome");
        str_free(line);
        longjmp(c->err, 1);
    }
    fd_putline(c, c->local_wfd.fd, line);
    fd_putline(c, c->remote_fd.fd, "STARTTLS");
    str_free(line);
    line=fd_getline(c, c->remote_fd.fd);
    if(!is_prefix(line, "382 ")) {
        s_log(LOG_ERR, "Server does not support TLS");
        str_free(line);
        longjmp(c->err, 1);
    }
    str_free(line);
}
Esempio n. 22
0
static enum bpf_attach_type parse_attach_type(const char *str)
{
	enum bpf_attach_type type;

	for (type = 0; type < __MAX_BPF_ATTACH_TYPE; type++) {
		if (attach_type_strings[type] &&
		    is_prefix(str, attach_type_strings[type]))
			return type;
	}

	return __MAX_BPF_ATTACH_TYPE;
}
Esempio n. 23
0
File: request.c Progetto: dmt4/ne
char *complete_filename(const char *start_prefix) {

	/* This might be NULL if the current directory has been unlinked, or it is not readable.
		in that case, we end up moving to the completion directory. */
	char * const cur_dir_name = ne_getcwd(CUR_DIR_MAX_SIZE);

	char * const dir_name = str_dup(start_prefix);
	if (dir_name) {
		char * const p = (char *)file_part(dir_name);
		*p = 0;
		if (p != dir_name && chdir(tilde_expand(dir_name)) == -1) {
			free(dir_name);
			return NULL;
		}
	}

	start_prefix = file_part(start_prefix);
	bool is_dir, unique = true;
	char *cur_prefix = NULL;
	DIR * const d = opendir(CURDIR);

	if (d) {
		for(struct dirent * de; !stop && (de = readdir(d)); ) {
			if (is_prefix(start_prefix, de->d_name))
				if (cur_prefix) {
					cur_prefix[max_prefix(cur_prefix, de->d_name)] = 0;
					unique = false;
				}
				else {
					cur_prefix = str_dup(de->d_name);
					is_dir = is_directory(de->d_name);
				}
		}

		closedir(d);
	}

	char * result = NULL;

	if (cur_prefix) {
		result = malloc(strlen(dir_name) + strlen(cur_prefix) + 2);
		strcat(strcat(strcpy(result, dir_name), cur_prefix), unique && is_dir ? "/" : "");
	}

	if (cur_dir_name != NULL) {
		chdir(cur_dir_name);
		free(cur_dir_name);
	}
	free(dir_name);
	free(cur_prefix);

	return result;
}
Esempio n. 24
0
NOEXPORT void pop3_server(CLI *c) {
    char *line;

    line=fd_getline(c, c->remote_fd.fd);
    fd_printf(c, c->local_wfd.fd, "%s + stunnel", line);
    str_free(line);
    line=fd_getline(c, c->local_rfd.fd);
    if(is_prefix(line, "CAPA")) { /* client wants RFC 2449 extensions */
        fd_putline(c, c->local_wfd.fd, "+OK Stunnel capability list follows");
        fd_putline(c, c->local_wfd.fd, "STLS");
        fd_putline(c, c->local_wfd.fd, ".");
        str_free(line);
        line=fd_getline(c, c->local_rfd.fd);
    }
    if(!is_prefix(line, "STLS")) {
        s_log(LOG_ERR, "Client does not want TLS");
        str_free(line);
        longjmp(c->err, 1);
    }
    str_free(line);
    fd_putline(c, c->local_wfd.fd, "+OK Stunnel starts TLS negotiation");
}
Esempio n. 25
0
NOEXPORT void imap_client(CLI *c) {
    char *line;

    line=fd_getline(c, c->remote_fd.fd);
    if(!is_prefix(line, "* OK")) {
        s_log(LOG_ERR, "Unknown server welcome");
        str_free(line);
        longjmp(c->err, 1);
    }
    fd_putline(c, c->local_wfd.fd, line);
    fd_putline(c, c->remote_fd.fd, "stunnel STARTTLS");
    str_free(line);
    line=fd_getline(c, c->remote_fd.fd);
    if(!is_prefix(line, "stunnel OK")) {
        fd_putline(c, c->local_wfd.fd,
            "* BYE stunnel: Server does not support TLS");
        s_log(LOG_ERR, "Server does not support TLS");
        str_free(line);
        longjmp(c->err, 2); /* don't reset */
    }
    str_free(line);
}
Esempio n. 26
0
static void pre_bm_gs(const char* pattern, int pattern_length, int* table_gs) {
	int last_prefix_pos = pattern_length;
	for(int i=pattern_length-1; i>=0; i--) {
		if(is_prefix(pattern,pattern_length,i+1))
			last_prefix_pos=i+1;
		table_gs[pattern_length-i-1]=last_prefix_pos + pattern_length - i - 1;
	
	}
	for(int i=0; i<pattern_length-1; i++) {
		int suff_len = suffix_length(pattern,pattern_length,i);
		table_gs[suff_len] = pattern_length + suff_len - i - 1;
	}
}
Esempio n. 27
0
void handle_cmd_input(D_SOCKET *dsock, char *argument)
{
  D_MOBILE *dMob;
  char command[MAX_BUFFER];
  bool found_cmd = FALSE;
  int i;

  if ((dMob = dsock->player) == NULL)
    return;
    /*
     * Strip leading spaces.
     */
    while (isspace(*argument))
        argument++;
    if (argument[0] == '\0')
        return;
    if (!isalpha(argument[0]) && !isdigit(argument[0])) {
        command[0] = argument[0];
        command[1] = '\0';
        argument++;
        while (isspace(*argument))
            argument++;
    } else {

  argument = one_argument(argument, command);
    }

  for (i = 0; tabCmd[i].cmd_name[0] != '\0' && !found_cmd; i++)
  {
    if (tabCmd[i].level > dMob->level) continue;

    if (is_prefix(command, tabCmd[i].cmd_name))
    {
      found_cmd = TRUE;
      (*tabCmd[i].cmd_funct)(dMob, argument);
    }
  }

  if( !found_cmd
#ifdef IMC
        &&   !imc_command_hook( dMob, command, argument )
#endif
     )
    text_to_mobile(dMob, "No such command.\n\r");
}
Esempio n. 28
0
int substring_position(const char *substr, const char *src) {
  //if the substring is a prefix of the src then we can just return 0
  if(is_prefix(substr, src)) {
    return 0;
  } else if(*src == '\0') {
    //if we reach the end of src without finding the substr thenwe return -1
    return -1;
  } else {
    //effectively chop off the first character of the src and try again
    //NOTE that as soon as we get a -1 we must return -1 all the way up the stack to the original call (rather than just keep addng 1 as we go up the stack which works for finding the substring position)
    int shift_char_position = substring_position(substr, src+1);
    if(shift_char_position == -1) {
      return -1;
    } else {
      return 1+shift_char_position;
    }
  }
}
Esempio n. 29
0
static void
check_arguments(int line, char *args[], int count, mipv6_conf_item_t *item)
{
	int i;

	for (i = 0; i < count; i++) {
		switch (item->params[i]) {
		case MIPV6_PARAM_T_INT:
			check_argument(is_int(args[i + 1]), "integer", args[0],
				       i, line);
			break;
		case MIPV6_PARAM_T_BOOLEAN:
			check_argument(is_boolean(args[i + 1]), "boolean",
				       args[0], i, line);
			break;
		case MIPV6_PARAM_T_ONOFF:
			check_argument(is_onoff(args[i + 1]), "on/off",
				       args[0], i, line);
			break;
		case MIPV6_PARAM_T_IDENTIFIER:
			check_argument(is_identifier(args[i + 1]), "identifier",
				       args[0], i, line);
			break;
		case MIPV6_PARAM_T_ADDRESS:
			check_argument(is_address(args[i + 1]), "address",
				       args[0], i, line);
			break;
		case MIPV6_PARAM_T_PREFIX:
			check_argument(is_prefix(args[i + 1]), "prefix",
				       args[0], i, line);
			break;
		case MIPV6_PARAM_T_DOMAIN:
			check_argument(is_domain(args[i + 1], 0), "domain name"
				       " or address", args[0], i, line);
			break;
		case MIPV6_PARAM_T_NAI:
			check_argument(is_nai(args[i + 1]), "NAI", args[0], i,
				       line);
			break;
		default:
			break;
		}
	}
}
Esempio n. 30
0
static void
ioctlsort(struct ioctlent *ioctls, size_t nioctls)
{
	size_t i;

	qsort(ioctls, nioctls, sizeof(ioctls[0]), compare_name_info);

	for (i = 1; i < nioctls; ++i)
		if (!strcmp(ioctls[i-1].name, ioctls[i].name)) {
			/*
			 * If there are multiple definitions for the same
			 * name, keep the first one and mark all the rest
			 * for deletion.
			 */
			ioctls[i].info = NULL;
		}

	for (i = 1; i < nioctls; ++i)
		if (!ioctls[i].info) {
			/*
			 * Change ioctl code of marked elements
			 * to make them sorted to the end of array.
			 */
			ioctls[i].dir =
			ioctls[i].type_nr =
			ioctls[i].size = 0xffffffffu;
		}

	qsort(ioctls, nioctls, sizeof(ioctls[0]), compare_code_name);

	puts("/* Generated by ioctlsort. */");
	for (i = 0; i < nioctls; ++i) {
		if (!ioctls[i].info) {
			/*
			 * We've reached the first element marked for deletion.
			 */
			break;
		}
		if (i == 0 || code(&ioctls[i-1]) != code(&ioctls[i]) ||
		    !is_prefix(ioctls[i-1].name, ioctls[i].name))
			printf("{ \"%s\", %#010x },\n",
				ioctls[i].name, code(ioctls+i));
	}
}