Exemple #1
0
void get_cmdline_by_pid(struct procinfo *pi)
{
	char cmd_path[128];
	char cmd[256];
	char resolved[256];

	FILE *fp;

	memset(cmd_path, 0, 128);
	memset(cmd, 0, 256);
	sprintf(cmd_path, "/proc/%d/cmdline", pi->pi_pid);
	fp = fopen(cmd_path, "r");
	fgets(cmd, 256, fp);

	/*resolve all symlinks */
	check_target_path((u_char *) cmd, pi->pi_perm);
	memset(cmd, 0, 256);
	memcpy(cmd, pi->pi_perm->p_full_path,
	       strlen((const char *)pi->pi_perm->p_full_path));

	strcpy((char *)pi->pi_perm->p_full_path, realpath(cmd, resolved));
#if 0
	printfd(2, DEBUG "cmdline path : %s\n", cmd_path);
	printfd(2, DEBUG "cmd is : %s\n", pi->pi_perm->p_full_path);
#endif
}
int
sys_epoll_ctl(struct tcb *tcp)
{
	if (entering(tcp)) {
		printfd(tcp, tcp->u_arg[0]);
		tprints(", ");
		printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
		tprints(", ");
		printfd(tcp, tcp->u_arg[2]);
		tprints(", ");
		if (tcp->u_arg[3] == 0)
			tprints("NULL");
		else {
#ifdef HAVE_SYS_EPOLL_H
			struct epoll_event ev;
			if (
#ifdef EPOLL_CTL_DEL
			    (tcp->u_arg[1] != EPOLL_CTL_DEL) &&
#endif
			    umove(tcp, tcp->u_arg[3], &ev) == 0)
				print_epoll_event(&ev);
			else
#endif
				tprintf("%lx", tcp->u_arg[3]);
		}
	}
	return 0;
}
Exemple #3
0
int
sys_sendfile(struct tcb *tcp)
{
	if (entering(tcp)) {
		off_t offset;

		printfd(tcp, tcp->u_arg[0]);
		tprints(", ");
		printfd(tcp, tcp->u_arg[1]);
		tprints(", ");
		if (!tcp->u_arg[2])
			tprints("NULL");
//FIXME: obviously bogus.
//Probably should use explicit long.
//Arches with long long offset param should use
//sys_sendfile64, not this fn.
		else if (umove(tcp, tcp->u_arg[2], &offset) < 0)
			tprintf("%#lx", tcp->u_arg[2]);
		else
#ifdef HAVE_LONG_LONG_OFF_T
			tprintf("[%llu]", offset);
#else
			tprintf("[%lu]", offset);
#endif
		tprintf(", %lu", tcp->u_arg[3]);
	}
	return 0;
}
static void
printpair_fd(struct tcb *tcp, const int i0, const int i1)
{
	tprints("[");
	printfd(tcp, i0);
	tprints(", ");
	printfd(tcp, i1);
	tprints("]");
}
Exemple #5
0
//-----------------------------------------------------------------------------
void USER_IMPL::Run()
{
STG_LOCKER lock(&mutex);

if (stgTime > static_cast<time_t>(lastWriteStat + settings->GetStatWritePeriod()))
    {
    printfd(__FILE__, "USER::WriteStat user=%s\n", GetLogin().c_str());
    WriteStat();
    }
if (creditExpire.ConstData() && creditExpire.ConstData() < stgTime)
    {
    WriteServLog("User: %s. Credit expired.", login.c_str());
    credit = 0;
    creditExpire = 0;
    WriteConf();
    }

if (passive.ConstData()
    && (stgTime % 30 == 0)
    && (passiveTime.ModificationTime() != stgTime))
    {
    passiveTime = passiveTime + (stgTime - passiveTime.ModificationTime());
    printfd(__FILE__, "===== %s: passiveTime=%d =====\n", login.c_str(), passiveTime.ConstData());
    }

if (!authorizedBy.empty())
    {
    if (connected)
        property.Stat().lastActivityTime = stgTime;

    if (!connected && IsInetable())
        Connect();

    if (connected && !IsInetable())
        {
        if (disabled)
            Disconnect(false, "disabled");
        else if (passive)
            Disconnect(false, "passive");
        else
            Disconnect(false, "no cash");
        }

    if (stgTime - lastScanMessages > 10)
        {
        ScanMessage();
        lastScanMessages = stgTime;
        }
    }
else
    {
    if (connected)
        Disconnect(false, "not authorized");
    }

}
Exemple #6
0
//-----------------------------------------------------------------------------
void USER_IMPL::ScanMessage()
{
// No lock `cause we are already locked from caller
// We need not check for the authorizedBy `cause it has already checked by caller

std::list<STG_MSG>::iterator it(messages.begin());
while (it != messages.end())
    {
    if (settings->GetMessageTimeout() > 0 &&
        difftime(stgTime, it->header.creationTime) > settings->GetMessageTimeout())
        {
        // Timeout exceeded
        if (store->DelMessage(it->header.id, login))
            {
            WriteServLog("Error deleting message: '%s'", store->GetStrError().c_str());
            printfd(__FILE__, "Error deleting message: '%s'\n", store->GetStrError().c_str());
            }
        messages.erase(it++);
        continue;
        }
    if (it->GetNextSendTime() <= stgTime)
        {
        if (SendMessage(*it))
            {
            // We need to check all messages in queue for timeout
            ++it;
            continue;
            }
        if (it->header.repeat < 0)
            {
            if (store->DelMessage(it->header.id, login))
                {
                WriteServLog("Error deleting message: '%s'", store->GetStrError().c_str());
                printfd(__FILE__, "Error deleting message: '%s'\n", store->GetStrError().c_str());
                }
            messages.erase(it++);
            }
        else
            {
            if (store->EditMessage(*it, login))
                {
                WriteServLog("Error modifying message: '%s'", store->GetStrError().c_str());
                printfd(__FILE__, "Error modifying message: '%s'\n", store->GetStrError().c_str());
                }
            ++it;
            }
        }
    else
        {
        ++it;
        }
    }
}
static int
do_dup2(struct tcb *tcp, int flags_arg)
{
	printfd(tcp, tcp->u_arg[0]);
	tprints(", ");
	printfd(tcp, tcp->u_arg[1]);
	if (flags_arg >= 0) {
		tprints(", ");
		printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
	}

	return RVAL_DECODED | RVAL_FD;
}
Exemple #8
0
int
sys_sendfile64(struct tcb *tcp)
{
	if (entering(tcp)) {
		printfd(tcp, tcp->u_arg[0]);
		tprints(", ");
		printfd(tcp, tcp->u_arg[1]);
		tprints(", ");
		print_loff_t(tcp, tcp->u_arg[2]);
		tprintf(", %lu", tcp->u_arg[3]);
	}
	return 0;
}
Exemple #9
0
static int
do_dup2(struct tcb *tcp, int flags_arg)
{
	if (entering(tcp)) {
		printfd(tcp, tcp->u_arg[0]);
		tprints(", ");
		printfd(tcp, tcp->u_arg[1]);
		if (flags_arg >= 0) {
			tprints(", ");
			printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
		}
	}
	return 0;
}
static int
print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
{
	if (entering(tcp)) {
		/* addr */
		if (!u_arg[0])
			tprints("NULL, ");
		else
			tprintf("%#lx, ", u_arg[0]);
		/* len */
		tprintf("%lu, ", u_arg[1]);
		/* prot */
		printflags(mmap_prot, u_arg[2], "PROT_???");
		tprints(", ");
		/* flags */
#ifdef MAP_TYPE
		printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
		addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
#else
		printflags(mmap_flags, u_arg[3], "MAP_???");
#endif
		tprints(", ");
		/* fd */
		printfd(tcp, u_arg[4]);
		/* offset */
		tprintf(", %#llx", offset);
	}
	return RVAL_HEX;
}
Exemple #11
0
static int
decode_sockname(struct tcb *tcp)
{
	int ulen, rlen;

	if (entering(tcp)) {
		printfd(tcp, tcp->u_arg[0]);
		tprints(", ");
		if (fetch_socklen(tcp, &ulen, tcp->u_arg[1], tcp->u_arg[2])) {
			set_tcb_priv_ulong(tcp, ulen);
			return 0;
		} else {
			printaddr(tcp->u_arg[1]);
			tprints(", ");
			printaddr(tcp->u_arg[2]);
			return RVAL_DECODED;
		}
	}

	ulen = get_tcb_priv_ulong(tcp);

	if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &rlen) < 0) {
		printaddr(tcp->u_arg[1]);
		tprintf(", [%d]", ulen);
	} else {
		decode_sockaddr(tcp, tcp->u_arg[1], ulen > rlen ? rlen : ulen);
		if (ulen != rlen)
			tprintf(", [%d->%d]", ulen, rlen);
		else
			tprintf(", [%d]", rlen);
	}

	return RVAL_DECODED;
}
static int
do_accept(struct tcb *tcp, int flags_arg)
{
	if (entering(tcp)) {
		printfd(tcp, tcp->u_arg[0]);
		tprints(", ");
		return 0;
	}
	if (!tcp->u_arg[2])
		tprintf("%#lx, NULL", tcp->u_arg[1]);
	else {
		int len;
		if (tcp->u_arg[1] == 0 || syserror(tcp)
		    || umove(tcp, tcp->u_arg[2], &len) < 0) {
			tprintf("%#lx", tcp->u_arg[1]);
		} else {
			printsock(tcp, tcp->u_arg[1], len);
		}
		tprints(", ");
		printnum_int(tcp, tcp->u_arg[2], "%u");
	}
	if (flags_arg >= 0) {
		tprints(", ");
		printflags(sock_type_flags, tcp->u_arg[flags_arg],
			   "SOCK_???");
	}
	return 0;
}
Exemple #13
0
// forced == 1
static void socksserver_disconnect_client(socksserver* srv, int fd, int forced) {
    fdinfo* client = &srv->clients[fdindex(fd)];
    int fdflag = 0;
    if(CONFIG_LOG && srv->log) {
        logstart();
        printfd(fd);
        LOGPUT(1, VARISL(" disconnect, forced: "), VARII(forced), NULL);
    }

    if(forced) rocksockserver_disconnect_client(&srv->serva, fd);
    client->state = SS_DISCONNECTED;
    if(client->data) {
        client->data->state = BS_UNUSED;
        client->data->start = 0;
        client->data->used = 0;
    }

    if(client->target_fd != -1) fdflag = 1;
    fd = client->target_fd;
    client->target_fd = -1;

    if(fdflag) {
        srv->clients[fdindex(fd)].target_fd = -1;
        socksserver_disconnect_client(srv, fd, 1);
    }
}
Exemple #14
0
int
sys_read(struct tcb *tcp)
{
  struct socket_info sockinfo;
  if (entering(tcp)) {
    json_object_object_add(tcp->json, "fd", json_object_new_int((int)tcp->u_arg[0]));
    printfd(tcp, tcp->u_arg[0]);
    tprintf(", ");
    if (output_json) {
      if (get_socket_info(tcp->pid, (int) tcp->u_arg[0], &sockinfo) == 0) {
        append_to_json(tcp->json, &sockinfo);
      } else {
        json_object_object_add(tcp->json, "pid", json_object_new_int(tcp->pid));
      }
    }
  } else {
    /* exiting... */
    if (syserror(tcp)) {
      	tprintf("%#lx", tcp->u_arg[1]);
    } else {
      /* no error */
      if (output_json) {
        json_object_object_add(tcp->json, "content",
            json_object_new_string(readstr(tcp, tcp->u_arg[1], tcp->u_arg[2])));
        json_object_object_add(tcp->json, "length", json_object_new_int(tcp->u_arg[2]));
      } else {
        printstr(tcp, tcp->u_arg[1], tcp->u_rval);
      }
    }
    tprintf(", %lu", tcp->u_arg[2]);
  }
  return 0;
}
Exemple #15
0
static struct ia_circles *_core_mutate(struct ia_circles *circles, int idx)
{
	struct ia_circles *mutated_circles = clone_circles(circles);
	int max_tries = 0;
	//const int ult_max_tries = circles->num_circles * 2;
	const int ult_max_tries = 30;
	while(max_tries < ult_max_tries) {
		printfd("Mutating circle %d/%d\n",
			idx,
			circles->num_circles);
		struct ia_circles *circles_prev = clone_circles(mutated_circles);
		_ia_random_action(&mutated_circles->circles[idx], true);
		refresh_circles(mutated_circles);
		refresh_circles(circles_prev);
		struct img_bitmap *_img = mutated_circles->img;
		struct img_bitmap *_img_prev = circles_prev->img;
		if((_img->score - _img_prev->score) > 0) {
			max_tries++;
			memcpy(&mutated_circles->circles[idx],
			    &circles_prev->circles[idx],
			    sizeof(struct ia_circle));
			refresh_circles(mutated_circles);
		} else {
			max_tries = ult_max_tries;
		}
		free_circles(circles_prev);
		free(circles_prev);
	}
	refresh_circles(mutated_circles);
	return mutated_circles;
}
Exemple #16
0
int
sys_ioctl(struct tcb *tcp)
{
	const struct_ioctlent *iop;

	if (entering(tcp)) {
		printfd(tcp, tcp->u_arg[0]);
		tprints(", ");
		iop = ioctl_lookup(tcp->u_arg[1]);
		if (iop) {
			tprints(iop->symbol);
			while ((iop = ioctl_next_match(iop)))
				tprintf(" or %s", iop->symbol);
		} else
			tprintf("%#lx", tcp->u_arg[1]);
		ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]);
	}
	else {
		int ret = ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]);
		if (!ret)
			tprintf(", %#lx", tcp->u_arg[2]);
		else
			return ret - 1;
	}
	return 0;
}
int
nbd_ioctl(struct tcb *const tcp, const unsigned int code,
	  const kernel_ulong_t arg)
{
	switch (code) {
	case NBD_DISCONNECT:
	case NBD_CLEAR_SOCK:
	case NBD_DO_IT:
	case NBD_CLEAR_QUE:
	case NBD_PRINT_DEBUG:
		return RVAL_IOCTL_DECODED;

	case NBD_SET_SOCK:
		tprints(", ");
		printfd(tcp, arg);
		return RVAL_IOCTL_DECODED;

	case NBD_SET_BLKSIZE:
	case NBD_SET_SIZE:
	case NBD_SET_SIZE_BLOCKS:
	case NBD_SET_TIMEOUT:
		tprints(", ");
		tprintf("%" PRI_klu, arg);
		return RVAL_IOCTL_DECODED;

	case NBD_SET_FLAGS:
		tprints(", ");
		printflags(nbd_ioctl_flags, arg, "NBD_IOC_FLAG_???");
		return RVAL_IOCTL_DECODED;

	default:
		return RVAL_DECODED;
	}
}
Exemple #18
0
int
sys_fanotify_mark(struct tcb *tcp)
{
	unsigned long long mask = 0;
	int argn;

	if (exiting(tcp))
		return 0;

	printfd(tcp, tcp->u_arg[0]);
	tprints(", ");
	printflags(fan_mark_flags, (unsigned) tcp->u_arg[1], "FAN_MARK_???");
	tprints(", ");
	/*
	 * the mask argument is defined as 64-bit,
	 * but kernel uses the lower 32 bits only.
	 */
	argn = getllval(tcp, &mask, 2);
	printflags(fan_event_flags, mask, "FAN_???");
	tprints(", ");
	if ((int) tcp->u_arg[argn] == FAN_NOFD)
		tprints("FAN_NOFD, ");
	else
		print_dirfd(tcp, tcp->u_arg[argn]);
	printpath(tcp, tcp->u_arg[argn + 1]);

	return 0;
}
static bool
print_file_dedupe_range_info(struct tcb *tcp, void *elem_buf,
			     size_t elem_size, void *data)
{
	const struct file_dedupe_range_info *info = elem_buf;
	unsigned int *count = data;

	if (count) {
		if (*count == 0) {
			tprints("...");
			return false;
		}
		--*count;
	}

	if (entering(tcp)) {
		tprints("{dest_fd=");
		printfd(tcp, info->dest_fd);
		tprintf(", dest_offset=%" PRIu64 "}",
			(uint64_t) info->dest_offset);
	} else {
		tprintf("{bytes_deduped=%" PRIu64 ", status=%d}",
			(uint64_t) info->bytes_deduped, info->status);
	}

	return true;
}
static int
do_sockname(struct tcb *tcp, int flags_arg)
{
	if (entering(tcp)) {
		printfd(tcp, tcp->u_arg[0]);
		tprints(", ");
		return 0;
	}

	int len;
	if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
	    umove(tcp, tcp->u_arg[2], &len) < 0) {
		printaddr(tcp->u_arg[1]);
		tprints(", ");
		printaddr(tcp->u_arg[2]);
	} else {
		printsock(tcp, tcp->u_arg[1], len);
		tprintf(", [%d]", len);
	}

	if (flags_arg >= 0) {
		tprints(", ");
		printflags(sock_type_flags, tcp->u_arg[flags_arg],
			   "SOCK_???");
	}
	return 0;
}
Exemple #21
0
//-----------------------------------------------------------------------------
int USER_IMPL::ReadConf()
{
STG_LOCKER lock(&mutex);
USER_CONF conf;

if (store->RestoreUserConf(&conf, login))
    {
    WriteServLog("Cannot read conf for user %s.", login.c_str());
    WriteServLog("%s", store->GetStrError().c_str());
    printfd(__FILE__, "Cannot read conf for user %s.\n", login.c_str());
    printfd(__FILE__, "%s\n", store->GetStrError().c_str());
    return -1;
    }

property.SetConf(conf);

tariff = tariffs->FindByName(tariffName);
if (tariff == NULL)
    {
    WriteServLog("Cannot read user %s. Tariff %s not exist.",
                 login.c_str(), property.tariffName.Get().c_str());
    return -1;
    }

std::vector<STG_MSG_HDR> hdrsList;

if (store->GetMessageHdrs(&hdrsList, login))
    {
    printfd(__FILE__, "Error GetMessageHdrs %s\n", store->GetStrError().c_str());
    WriteServLog("Cannot read user %s. Error reading message headers: %s.",
                 login.c_str(),
                 store->GetStrError().c_str());
    return -1;
    }

std::vector<STG_MSG_HDR>::const_iterator it;
for (it = hdrsList.begin(); it != hdrsList.end(); ++it)
    {
    STG_MSG msg;
    if (store->GetMessage(it->id, &msg, login) == 0)
        {
        messages.push_back(msg);
        }
    }

return 0;
}
Exemple #22
0
//-----------------------------------------------------------------------------
void CHG_IPS_NOTIFIER::Notify(const USER_IPS & from, const USER_IPS & to)
{
printfd(__FILE__, "Change IP from '%s' to '%s'\n", from.GetIpStr().c_str(), to.GetIpStr().c_str());
if (user->connected)
    user->Disconnect(false, "Change IP");
if (!user->authorizedBy.empty() && user->IsInetable())
    user->Connect(false);
}
Exemple #23
0
int
sys_tee(struct tcb *tcp)
{
	if (entering(tcp)) {
		/* int fd_in */
		printfd(tcp, tcp->u_arg[0]);
		tprints(", ");
		/* int fd_out */
		printfd(tcp, tcp->u_arg[1]);
		tprints(", ");
		/* size_t len */
		tprintf("%lu, ", tcp->u_arg[2]);
		/* unsigned int flags */
		printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");
	}
	return 0;
}
int
sys_close(struct tcb *tcp)
{
	if (entering(tcp)) {
		printfd(tcp, tcp->u_arg[0]);
	}
	return 0;
}
int
sys_dup(struct tcb *tcp)
{
	if (entering(tcp)) {
		printfd(tcp, tcp->u_arg[0]);
	}
	return RVAL_FD;
}
Exemple #26
0
void banner(const char *arg)
{
	printfd(1,"Usage : \n"
	       "%s <server IP> <server port> <locale IP> [MTU]\n"
	       ,arg
		);
	exit(0);
}
Exemple #27
0
//-----------------------------------------------------------------------------
int USER_IMPL::WriteDetailStat(bool hard)
{
printfd(__FILE__, "USER::WriteDetailedStat() - saved size = %d\n", traffStatSaved.second.size());

if (!traffStatSaved.second.empty())
    {
    if (store->WriteDetailedStat(traffStatSaved.second, traffStatSaved.first, login))
        {
        printfd(__FILE__, "USER::WriteDetailStat() - failed to write detail stat from queue\n");
        WriteServLog("Cannot write detail stat from queue (of size %d recs) for user %s.", traffStatSaved.second.size(), login.c_str());
        WriteServLog("%s", store->GetStrError().c_str());
        return -1;
        }
    traffStatSaved.second.erase(traffStatSaved.second.begin(), traffStatSaved.second.end());
    }

TRAFF_STAT ts;

    {
    STG_LOCKER lock(&mutex);
    ts.swap(traffStat);
    }

printfd(__FILE__, "USER::WriteDetailedStat() - size = %d\n", ts.size());

if (ts.size() && !disabledDetailStat)
    {
    if (store->WriteDetailedStat(ts, lastWriteDetailedStat, login))
        {
        printfd(__FILE__, "USER::WriteDetailStat() - failed to write current detail stat\n");
        WriteServLog("Cannot write detail stat for user %s.", login.c_str());
        WriteServLog("%s", store->GetStrError().c_str());
        if (!hard)
            {
            printfd(__FILE__, "USER::WriteDetailStat() - pushing detail stat to queue\n");
            STG_LOCKER lock(&mutex);
            traffStatSaved.second.swap(ts);
            traffStatSaved.first = lastWriteDetailedStat;
            }
        return -1;
        }
    }
lastWriteDetailedStat = stgTime;
return 0;
}
Exemple #28
0
//-----------------------------------------------------------------------------
int USER_IMPL::WriteStat()
{
STG_LOCKER lock(&mutex);
USER_STAT stat(property.GetStat());

if (store->SaveUserStat(stat, login))
    {
    WriteServLog("Cannot write stat for user %s.", login.c_str());
    WriteServLog("%s", store->GetStrError().c_str());
    printfd(__FILE__, "Cannot write stat for user %s.\n", login.c_str());
    printfd(__FILE__, "%s\n", store->GetStrError().c_str());
    return -1;
    }

lastWriteStat = stgTime;

return 0;
}
Exemple #29
0
//-----------------------------------------------------------------------------
int USER_IMPL::WriteConf()
{
STG_LOCKER lock(&mutex);
USER_CONF conf(property.GetConf());

printfd(__FILE__, "USER::WriteConf()\n");

if (store->SaveUserConf(conf, login))
    {
    WriteServLog("Cannot write conf for user %s.", login.c_str());
    WriteServLog("%s", store->GetStrError().c_str());
    printfd(__FILE__, "Cannot write conf for user %s.\n", login.c_str());
    printfd(__FILE__, "%s\n", store->GetStrError().c_str());
    return -1;
    }

return 0;
}
Exemple #30
0
//-----------------------------------------------------------------------------
int USER_IMPL::ReadStat()
{
STG_LOCKER lock(&mutex);
USER_STAT stat;

if (store->RestoreUserStat(&stat, login))
    {
    WriteServLog("Cannot read stat for user %s.", login.c_str());
    WriteServLog("%s", store->GetStrError().c_str());
    printfd(__FILE__, "Cannot read stat for user %s.\n", login.c_str());
    printfd(__FILE__, "%s\n", store->GetStrError().c_str());
    return -1;
    }

property.SetStat(stat);

return 0;
}