Ejemplo n.º 1
1
main()
{
	int	frame,halt=0,storea=0;
	int	a,b,c,y,ya,ysz,ysza,xsc,spd=10,la;
	int	y1,y2,y1a,y2a,ly1a;
	dis_partstart();

	for(a=0;a<200;a++) row[a]=rowdata1[a];
	for(a=0;a<200;a++) row[a+200]=rowdata2[a];

	frame=0;
	ysz=400*16; ysza=-460/6;
	y=0;
	y1=0; y1a=500;
	y2=399*16; y2a=500;
	for(frame=0;frame<512;frame++)
	{	
		if(!halt)
		{
			y1+=y1a;
			y2+=y2a;
	
			y2a+=9;
			if(y2>400*16)
			{
				y2-=y2a;
				y2a=-y2a*5/8;
			}
	
			y1a+=9;
			
			la=a;
			a=(y2-y1)-400*16;
			if((a&0x8000)^(la&0x8000))
			{
				y1a=y1a*5/8;
			}
			y1a+=a/20;
			y2a-=a/20;
		}
		
		if(frame>97) 
		{
			if(y2>=399*16) 
			{
				y2=400*16;
				halt=1;
			}
			y1=y2-400*16;
		}

		framey1[frame]=y1;
		framey2[frame]=y2;
	}

	_asm mov ax,13h
	_asm int 10h	
	inittwk();
	_asm
	{
		mov	dx,3c0h
		mov	al,11h
		out	dx,al
		mov	al,255
		out	dx,al
		mov	al,20h
		out	dx,al
	}

	readp(palette,-1,pic);
	for(y=0;y<400;y++)
	{
		readp(rowbuf,y,pic);
		memcpy(row[y],rowbuf+70,184);
	}
	setpalarea(palette,0,256);
	
	for(y=0;y<400;y++) lasty[y]=lasts[y]=-1;
	dis_waitb();
	scrolly(400);
	dis_waitb();
	for(y=0;y<400;y++)
	{
		linezoom(vram+y*80,row[y],184);
	}
	a=64; y=400*64;
	while(y>0)
	{
		y-=a;
		a+=6;
		if(y<0) y=0;
		scrolly(y/64);
		dis_waitb();
	}
	storea=a;
	dis_waitb();
	doit();
	//_asm mov ax,3
	//_asm int 10h
	//printf("%i\n",storea);
	return(0);
}
Ejemplo n.º 2
0
Archivo: irq.c Proyecto: epicsdeb/rtems
int BSP_rtems_int_disconnect(rtems_irq_number n, rtems_irq_hdl hdl, rtems_irq_hdl_param p)
{
	return doit(BSP_remove_rtems_irq_handler, n, hdl, p);
}
Ejemplo n.º 3
0
int main(void)
{
#ifdef RLIMIT_AS
	doit(RLIMIT_AS);
#endif
	doit(RLIMIT_CORE);
	doit(RLIMIT_CPU);
	doit(RLIMIT_DATA);
	doit(RLIMIT_FSIZE);
#ifdef RLIMT_LOCKS
	doit(RLIMIT_LOCKS);
#endif
#ifdef RLIMT_MEMLOCK
	doit(RLIMIT_MEMLOCK);
#endif
	doit(RLIMIT_NOFILE);
#ifdef RLIMT_NOPROC
	doit(RLIMIT_NOPROC);
#endif
#ifdef RLIMT_RSS
	doit(RLIMIT_RSS);
#endif
#ifdef RLIMT_SBSIZE
	doit(RLIMIT_SBSIZE);
#endif
	doit(RLIMIT_STACK);
#ifdef RLIMT_VMEM
	doit(RLIMIT_VMEM);
#endif
	exit(0);
}
Ejemplo n.º 4
0
	void BoxClass::ExecuteCallbacks(unsigned int flags) {
		doexecute_flags doit(flags);
		std::for_each(callbacks.begin(),callbacks.end(),doit);
	}
Ejemplo n.º 5
0
int
main (int argc, char *argv[])
{
    int i = 0;
    time_t t = 0;
    struct sigaction sa;
    unsigned long cachesize = 0;
    char *x = NULL, char_seed[128];

    sa.sa_handler = handle_term;
    sigaction (SIGINT, &sa, NULL);
    sigaction (SIGTERM, &sa, NULL);

    sa.sa_handler = SIG_IGN;
    sigaction (SIGPIPE, &sa, NULL);

    seed_addtime ();
    seed_adduint32 (getpid ());
    seed_adduint32 (getppid ());
    seed_adduint32 (getuid ());
    seed_adduint32 (getgid ());

    seed_addtime ();
    prog = strdup ((x = strrchr (argv[0], '/')) != NULL ?  x + 1 : argv[0]);
    i = check_option (argc, argv);
    argc -= i;
    argv += i;

    if (mode & DAEMON)
    {
        i = fork ();
        if (i == -1)
            err (-1, "could not fork a daemon process");
        if (i > 0)
            return 0;
    }

    time (&t);
    memset (char_seed, 0, sizeof (char_seed));
    strftime (char_seed, sizeof (char_seed), "%b-%d %Y %T", localtime (&t));
    fprintf (stderr, "\n");
    warnx ("version %s: starting: %s\n", VERSION, char_seed);

    read_conf (CFGFILE);

    if ((x = env_get ("DATALIMIT")))
    {
        struct rlimit r;
        unsigned long dlimit = atol (x);

        if (getrlimit (RLIMIT_DATA,  &r) != 0)
            err (-1, "could not get resource RLIMIT_DATA");

        r.rlim_cur = (dlimit <= r.rlim_max) ? dlimit : r.rlim_max;

        if (setrlimit (RLIMIT_DATA, &r) != 0)
            err (-1, "could not set resource RLIMIT_DATA");

        if (debug_level)
            warnx ("DATALIMIT set to `%ld' bytes", r.rlim_cur);
    }

    if (!(x = env_get ("IP")))
        err (-1, "$IP not set");
    if (!ip4_scan (x, myipincoming))
        err (-1, "could not parse IP address `%s'", x);

    seed_addtime ();
    udp53 = socket_udp ();
    if (udp53 == -1)
        err (-1, "could not open UDP socket");
    if (socket_bind4_reuse (udp53, myipincoming, 53) == -1)
        err (-1, "could not bind UDP socket");

    seed_addtime ();
    tcp53 = socket_tcp ();
    if (tcp53 == -1)
        err (-1, "could not open TCP socket");
    if (socket_bind4_reuse (tcp53, myipincoming, 53) == -1)
        err (-1, "could not bind TCP socket");

    if (mode & DAEMON)
    {
        /* redirect stdout & stderr to a log file */
        redirect_to_log (LOGFILE);

        write_pid (PIDFILE);
    }

    seed_addtime ();
    droproot ();
    if (mode & DAEMON)
        /* crerate a new session & detach from controlling tty */
        if (setsid () < 0)
            err (-1, "could not start a new session for the daemon");

    seed_addtime ();
    socket_tryreservein (udp53, 131072);

    memset (char_seed, 0, sizeof (char_seed));
    for (i = 0, x = (char *)seed; i < sizeof (char_seed); i++, x++)
        char_seed[i] = *x;
    dns_random_init (char_seed);

    if (!(x = env_get ("IPSEND")))
        err (-1, "$IPSEND not set");
    if (!ip4_scan (x, myipoutgoing))
        err (-1, "could not parse IP address `%s'", x);

    if (!(x = env_get ("CACHESIZE")))
        err (-1, "$CACHESIZE not set");
    scan_ulong (x, &cachesize);
    if (!cache_init (cachesize))
        err (-1, "could not allocate `%ld' bytes for cache", cachesize);

    if (env_get ("HIDETTL"))
        response_hidettl ();
    if (env_get ("FORWARDONLY"))
        query_forwardonly ();
    if (!roots_init ())
        err (-1, "could not read servers");
    if (socket_listen (tcp53, 20) == -1)
        err (-1, "could not listen on TCP socket");

    doit ();

    return 0;
}
Ejemplo n.º 6
0
int main() {
  printtime("Call only", doit(1, 1, 1));
  printtime("60-by-60-by-2", doit(60, 60, 2));
}
Ejemplo n.º 7
0
int
main(int argc, char *argv[])
{
	extern int __check_rhosts_file;
	struct linger linger;
	int ch, on = 1;
	socklen_t fromlen;
	struct sockaddr_storage from;

	openlog("rshd", LOG_PID | LOG_ODELAY, LOG_DAEMON);

	opterr = 0;
	while ((ch = getopt(argc, argv, OPTIONS)) != -1)
		switch (ch) {
		case 'a':
			check_all = 1;
			break;
		case 'l':
			__check_rhosts_file = 0;
			break;
		case 'n':
			keepalive = 0;
			break;
#ifdef	KERBEROS
		case 'k':
			use_kerberos = 1;
			break;

		case 'v':
			vacuous = 1;
			break;

#ifdef CRYPT
		case 'x':
			doencrypt = 1;
			break;
#endif
#endif
		case 'L':
			log_success = 1;
			break;
		case '?':
		default:
			usage();
			break;
		}

	argc -= optind;
	argv += optind;

#ifdef	KERBEROS
	if (use_kerberos && vacuous) {
		syslog(LOG_ERR, "only one of -k and -v allowed");
		exit(2);
	}
#ifdef CRYPT
	if (doencrypt && !use_kerberos) {
		syslog(LOG_ERR, "-k is required for -x");
		exit(2);
	}
#endif
#endif

	fromlen = sizeof (from);
	if (getpeername(STDIN_FILENO, (struct sockaddr *)&from, &fromlen) < 0) {
		/* syslog(LOG_ERR, "getpeername: %m"); */
		exit(1);
	}
	if (keepalive &&
	    setsockopt(STDIN_FILENO, SOL_SOCKET, SO_KEEPALIVE, (char *)&on,
	    sizeof(on)) < 0)
		syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
	linger.l_onoff = 1;
	linger.l_linger = 60;			/* XXX */
	if (setsockopt(STDIN_FILENO, SOL_SOCKET, SO_LINGER, (char *)&linger,
	    sizeof (linger)) < 0)
		syslog(LOG_WARNING, "setsockopt (SO_LINGER): %m");
	doit((struct sockaddr *)&from);
	/* NOTREACHED */
	exit(0);
}
Ejemplo n.º 8
0
int main(int argc, char *argv[])
{
   int   sock;
   char  *progname;
   int   opt;
   int   fd;
   char  sockname[PATH_MAX];
   int   ret;
   pid_t pid;
   struct sigaction	sa;
   const char *s = NULL;
   glite_renewal_core_context ctx = NULL;

   progname = strrchr(argv[0],'/');
   if (progname) progname++; 
   else progname = argv[0];

   repository = EDG_WLPR_REPOSITORY_ROOT;
   debug = 0;

   while ((opt = getopt_long(argc, argv, "hvdr:c:C:V:AG:t:k:", opts, NULL)) != EOF)
      switch (opt) {
	 case 'h': usage(ctx, progname); exit(0);
	 case 'v': fprintf(stdout, "%s:\t%s\n", progname, rcsid); exit(0);
	 case 'd': debug = 1; break;
         case 'r': repository = optarg; break;
	 case 'c': condor_limit = atoi(optarg); break;
	 case 'C': cadir = optarg; break;
	 case 'V': vomsdir = optarg; break;
	 case 'A': voms_enabled = 1; break;
	 case 'G': vomsconf = optarg; break;
	 case 't': cert = optarg; break;
	 case 'k': key = optarg; break;
	 case '?': usage(ctx, progname); return 1;
      }

   if (optind < argc) {
      usage(ctx, progname);
      exit(1);
   }

   ret = glite_renewal_core_init_ctx(&ctx);
   if (ret) {
      fprintf(stderr, "Cannot initialize context\n");
      exit(1);
   }
   if (debug) {
      ctx->log_level = LOG_DEBUG;
      ctx->log_dst = GLITE_RENEWAL_LOG_STDOUT;
   }
   ctx->voms_conf = vomsconf;

   if (chdir(repository)) {
      glite_renewal_log(ctx, LOG_ERR, "Cannot access repository directory %s (%s)",
	           repository, strerror(errno));
      exit(1);
   }

   globus_module_activate(GLOBUS_GSI_CERT_UTILS_MODULE);
   globus_module_activate(GLOBUS_GSI_PROXY_MODULE);

   if (!debug) {
      /* chdir ? */
      if (daemon(1,0) == -1) {
	 perror("deamon()");
	 exit(1);
      }
      openlog(progname, LOG_PID, LOG_DAEMON);
   }

   if (cert)
      setenv("X509_USER_CERT", cert, 1);

   if (key)
      setenv("X509_USER_KEY", key, 1);

   if (cadir)
      setenv("X509_CERT_DIR", cadir, 1);

   s = getenv("GLITE_PR_TIMEOUT");
   default_timeout = s ? atof(s) : GLITE_PR_TIMEOUT_DEFAULT;

   memset(&sa,0,sizeof(sa));
   sa.sa_handler = catchsig;
   sigaction(SIGINT,&sa,NULL);
   sigaction(SIGQUIT,&sa,NULL);
   sigaction(SIGTERM,&sa,NULL);
   sigaction(SIGCHLD,&sa,NULL);
   sigaction(SIGPIPE,&sa,NULL);

   ret = start_watchdog(ctx, &pid);
   if (ret)
      return 1;
  
   umask(0177);
   snprintf(sockname, sizeof(sockname), "%s%d",
	    DGPR_REG_SOCKET_NAME_ROOT, getuid());
   /* XXX check that the socket is not already active */
   ret = do_listen(ctx, sockname, &sock);
   if (ret)
      return 1;
   glite_renewal_log(ctx, LOG_DEBUG, "Listening at %s", sockname);

   ret = doit(ctx, sock);

   close(sock);
   return ret;
}
Ejemplo n.º 9
0
int
main (int argc, char **argv)
{
    krb5_keytab keytab;
    krb5_error_code ret;
    char **files;
    int port, i;

    krb5_program_setup(&context, argc, argv, args, num_args, NULL);

    if(help_flag)
        krb5_std_usage(0, args, num_args);
    if(version_flag) {
        print_version(NULL);
        exit(0);
    }

    if (config_file == NULL) {
        asprintf(&config_file, "%s/kdc.conf", hdb_db_dir(context));
        if (config_file == NULL)
            errx(1, "out of memory");
    }

    ret = krb5_prepend_config_files_default(config_file, &files);
    if (ret)
        krb5_err(context, 1, ret, "getting configuration files");

    ret = krb5_set_config_files(context, files);
    krb5_free_config_files(files);
    if (ret)
        krb5_err(context, 1, ret, "reading configuration files");

    if(realm_str)
        krb5_set_default_realm(context, realm_str);

    krb5_openlog (context, "kpasswdd", &log_facility);
    krb5_set_warn_dest(context, log_facility);

    if (port_str != NULL) {
        struct servent *s = roken_getservbyname (port_str, "udp");

        if (s != NULL)
            port = s->s_port;
        else {
            char *ptr;

            port = strtol (port_str, &ptr, 10);
            if (port == 0 && ptr == port_str)
                krb5_errx (context, 1, "bad port `%s'", port_str);
            port = htons(port);
        }
    } else
        port = krb5_getportbyname (context, "kpasswd", "udp", KPASSWD_PORT);

    ret = krb5_kt_register(context, &hdb_kt_ops);
    if(ret)
        krb5_err(context, 1, ret, "krb5_kt_register");

    ret = krb5_kt_resolve(context, keytab_str, &keytab);
    if(ret)
        krb5_err(context, 1, ret, "%s", keytab_str);

    kadm5_setup_passwd_quality_check (context, check_library, check_function);

    for (i = 0; i < policy_libraries.num_strings; i++) {
        ret = kadm5_add_passwd_quality_verifier(context,
                                                policy_libraries.strings[i]);
        if (ret)
            krb5_err(context, 1, ret, "kadm5_add_passwd_quality_verifier");
    }
    ret = kadm5_add_passwd_quality_verifier(context, NULL);
    if (ret)
        krb5_err(context, 1, ret, "kadm5_add_passwd_quality_verifier");


    explicit_addresses.len = 0;

    if (addresses_str.num_strings) {
        int j;

        for (j = 0; j < addresses_str.num_strings; ++j)
            add_one_address (addresses_str.strings[j], j == 0);
        free_getarg_strings (&addresses_str);
    } else {
        char **foo = krb5_config_get_strings (context, NULL,
                                              "kdc", "addresses", NULL);

        if (foo != NULL) {
            add_one_address (*foo++, TRUE);
            while (*foo)
                add_one_address (*foo++, FALSE);
        }
    }

#ifdef HAVE_SIGACTION
    {
        struct sigaction sa;

        sa.sa_flags = 0;
        sa.sa_handler = sigterm;
        sigemptyset(&sa.sa_mask);

        sigaction(SIGINT,  &sa, NULL);
        sigaction(SIGTERM, &sa, NULL);
    }
#else
    signal(SIGINT,  sigterm);
    signal(SIGTERM, sigterm);
#endif

    pidfile(NULL);

    return doit (keytab, port);
}
Ejemplo n.º 10
0
int main() {
    doit();
}
Ejemplo n.º 11
0
static void rdft2_apply(dofft_closure *k_, 
			bench_complex *in, bench_complex *out)
{
     dofft_rdft2_closure *k = (dofft_rdft2_closure *)k_;
     bench_problem *p = k->p;
     bench_tensor *totalsz, *pckdsz, *totalsz_swap, *pckdsz_swap;
     bench_tensor *probsz2, *totalsz2, *pckdsz2;
     bench_tensor *probsz2_swap, *totalsz2_swap, *pckdsz2_swap;
     bench_real *ri, *ii, *ro, *io;
     int n2, totalscale;

     totalsz = tensor_append(p->vecsz, p->sz);
     pckdsz = verify_pack(totalsz, 2);
     n2 = tensor_sz(totalsz);
     if (FINITE_RNK(p->sz->rnk) && p->sz->rnk > 0)
	  n2 = (n2 / p->sz->dims[p->sz->rnk - 1].n) * 
	       (p->sz->dims[p->sz->rnk - 1].n / 2 + 1);
     ri = (bench_real *) p->in;
     ro = (bench_real *) p->out;

     if (p->sz->rnk > 0) {
	  probsz2 = tensor_copy_sub(p->sz, p->sz->rnk - 1, 1);
	  totalsz2 = tensor_copy_sub(totalsz, 0, totalsz->rnk - 1);
	  pckdsz2 = tensor_copy_sub(pckdsz, 0, pckdsz->rnk - 1);
     }
     else {
	  probsz2 = mktensor(0);
	  totalsz2 = tensor_copy(totalsz);
	  pckdsz2 = tensor_copy(pckdsz);
     }

     totalsz_swap = tensor_copy_swapio(totalsz);
     pckdsz_swap = tensor_copy_swapio(pckdsz);
     totalsz2_swap = tensor_copy_swapio(totalsz2);
     pckdsz2_swap = tensor_copy_swapio(pckdsz2);
     probsz2_swap = tensor_copy_swapio(probsz2);

     /* confusion: the stride is the distance between complex elements
	when using interleaved format, but it is the distance between
	real elements when using split format */
     if (p->split) {
	  ii = p->ini ? (bench_real *) p->ini : ri + n2;
	  io = p->outi ? (bench_real *) p->outi : ro + n2;
	  totalscale = 1;
     } else {
	  ii = p->ini ? (bench_real *) p->ini : ri + 1;
	  io = p->outi ? (bench_real *) p->outi : ro + 1;
	  totalscale = 2;
     }

     if (p->sign < 0) { /* R2HC */
	  int N, vN, i;
	  cpyr(&c_re(in[0]), pckdsz, ri, totalsz);
	  doit(1, p);
	  if (k->k.recopy_input)
	       cpyr(ri, totalsz_swap, &c_re(in[0]), pckdsz_swap);
	  cpyhc2(ro, io, probsz2, totalsz2, totalscale,
		 &c_re(out[0]), &c_im(out[0]), pckdsz2);
	  N = tensor_sz(p->sz);
	  vN = tensor_sz(p->vecsz);
	  for (i = 0; i < vN; ++i)
	       mkhermitian(out + i*N, p->sz->rnk, p->sz->dims, 1);
     }
     else { /* HC2R */
	  icpyhc2(ri, ii, probsz2, totalsz2, totalscale,
		  &c_re(in[0]), &c_im(in[0]), pckdsz2);
	  doit(1, p);
	  if (k->k.recopy_input)
	       cpyhc2(ri, ii, probsz2_swap, totalsz2_swap, totalscale,
		      &c_re(in[0]), &c_im(in[0]), pckdsz2_swap);
	  mkreal(out, tensor_sz(pckdsz));
	  cpyr(ro, totalsz, &c_re(out[0]), pckdsz);
     }

     tensor_destroy(totalsz);
     tensor_destroy(pckdsz);
     tensor_destroy(totalsz_swap);
     tensor_destroy(pckdsz_swap);
     tensor_destroy(probsz2);
     tensor_destroy(totalsz2);
     tensor_destroy(pckdsz2);
     tensor_destroy(probsz2_swap);
     tensor_destroy(totalsz2_swap);
     tensor_destroy(pckdsz2_swap);
}
Ejemplo n.º 12
0
int
main(int argc, char *argv[])
{
	struct passwd *pw;
	struct servent *sp;
	struct termios tty;
	long omask;
	int argoff, ch, dflag, Dflag, one;
	uid_t uid;
	char *host, *localname, *p, *user, term[1024];
	speed_t ospeed;
	struct sockaddr_storage ss;
	socklen_t sslen;
	size_t len, len2;
	int i;

	argoff = dflag = Dflag = 0;
	one = 1;
	host = localname = user = NULL;

	if ((p = strrchr(argv[0], '/')))
		++p;
	else
		p = argv[0];

	if (strcmp(p, "rlogin"))
		host = p;

	/* handle "rlogin host flags" */
	if (!host && argc > 2 && argv[1][0] != '-') {
		host = argv[1];
		argoff = 1;
	}

#define	OPTIONS	"468DEde:i:l:"
	while ((ch = getopt(argc - argoff, argv + argoff, OPTIONS)) != -1)
		switch(ch) {
		case '4':
			family = PF_INET;
			break;

		case '6':
			family = PF_INET6;
			break;

		case '8':
			eight = 1;
			break;
		case 'D':
			Dflag = 1;
			break;
		case 'E':
			noescape = 1;
			break;
		case 'd':
			dflag = 1;
			break;
		case 'e':
			noescape = 0;
			escapechar = getescape(optarg);
			break;
		case 'i':
			if (getuid() != 0)
				errx(1, "-i user: permission denied");
			localname = optarg;
			break;
		case 'l':
			user = optarg;
			break;
		case '?':
		default:
			usage();
		}
	optind += argoff;

	/* if haven't gotten a host yet, do so */
	if (!host && !(host = argv[optind++]))
		usage();

	if (argv[optind])
		usage();

	if (!(pw = getpwuid(uid = getuid())))
		errx(1, "unknown user id");
	if (!user)
		user = pw->pw_name;
	if (!localname)
		localname = pw->pw_name;

	sp = NULL;
	sp = getservbyname("login", "tcp");
	if (sp == NULL)
		errx(1, "login/tcp: unknown service");

	if ((p = getenv("TERM")) != NULL)
		(void)strlcpy(term, p, sizeof(term));
	len = strlen(term);
	if (len < (sizeof(term) - 1) && tcgetattr(0, &tty) == 0) {
		/* start at 2 to include the / */
		for (ospeed = i = cfgetospeed(&tty), len2 = 2; i > 9; len2++)
			i /= 10;
		if (len + len2 < sizeof(term))
			(void)snprintf(term + len, len2 + 1, "/%d", ospeed);
	}

	(void)get_window_size(0, &winsize);

	(void)signal(SIGPIPE, lostpeer);
	/* will use SIGUSR1 for window size hack, so hold it off */
	omask = sigblock(sigmask(SIGURG) | sigmask(SIGUSR1));
	/*
	 * We set SIGURG and SIGUSR1 below so that an
	 * incoming signal will be held pending rather than being
	 * discarded. Note that these routines will be ready to get
	 * a signal by the time that they are unblocked below.
	 */
	(void)signal(SIGURG, copytochild);
	(void)signal(SIGUSR1, writeroob);

	rem = rcmd_af(&host, sp->s_port, localname, user, term, 0, family);

	if (rem < 0)
		exit(1);

	if (dflag &&
	    setsockopt(rem, SOL_SOCKET, SO_DEBUG, &one, sizeof(one)) < 0)
		warn("setsockopt");
	if (Dflag &&
	    setsockopt(rem, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) < 0)
		warn("setsockopt NODELAY (ignored)");

	sslen = sizeof(ss);
	one = IPTOS_LOWDELAY;
	if (getsockname(rem, (struct sockaddr *)&ss, &sslen) == 0 &&
	    ss.ss_family == AF_INET) {
		if (setsockopt(rem, IPPROTO_IP, IP_TOS, (char *)&one,
			       sizeof(int)) < 0)
			warn("setsockopt TOS (ignored)");
	} else
		if (ss.ss_family == AF_INET)
			warn("setsockopt getsockname failed");

	(void)setuid(uid);
	doit(omask);
	/*NOTREACHED*/
}
Ejemplo n.º 13
0
/* ARGSUSED */
int
main(int argc, char *argv[])
{
	int on = 1;
	socklen_t fromlen;
	struct sockaddr_storage from;
	int fd = -1;

	extern char *optarg;
	char c;
	int tos = -1;
	krb5_context krb_context;
	krb5_keytab keytab = NULL;
	krb5_error_code status;
	char *realm = NULL;
	char *keytab_file = NULL;
	int encr_flag = 0;
	struct sockaddr_storage ouraddr;
	socklen_t ourlen;
#ifdef DEBUG
	int debug_port = 0;
#endif /* DEBUG */
	openlog("rlogind", LOG_PID | LOG_ODELAY, LOG_DAEMON);

	while ((c = getopt(argc, argv, ARGSTR)) != -1) {
		switch (c) {
		case 'k':
		case '5':
			use_auth = KRB5_RECVAUTH_V5;
			break;
		case 'e':
		case 'E':
		case 'x':
		case 'X':
			encr_flag = 1;
			break;
		case 'M':
			realm = (char *)strdup(optarg);
			break;
		case 'S':
			keytab_file = (char *)strdup(optarg);
			break;
		case 'c':
			chksum_flag |= CHKSUM_REQUIRED;
			break;
		case 'i':
			chksum_flag |= CHKSUM_IGNORED;
			break;
		case 's':
			if (optarg == NULL || (tos = atoi(optarg)) < 0 ||
			    tos > 255) {
				syslog(LOG_ERR, "%s: illegal tos value: "
				    "%s\n", argv[0], optarg);
			} else {
				if (tos < 0)
					tos = DEFAULT_TOS;
			}
			break;
#ifdef DEBUG
		case 'D':
			debug_port = atoi(optarg);
			break;
#endif /* DEBUG */
		default:
			syslog(LOG_ERR, "Unrecognized command line option "
			    "(-%c), exiting", optopt);
			exit(EXIT_FAILURE);
		}
	}
	if (use_auth == KRB5_RECVAUTH_V5) {
		status = krb5_init_context(&krb_context);
		if (status) {
			syslog(LOG_ERR, "Error initializing krb5: %s",
			    error_message(status));
			exit(EXIT_FAILURE);
		}
		if (realm != NULL)
			(void) krb5_set_default_realm(krb_context, realm);
		if (keytab_file != NULL) {
			if ((status = krb5_kt_resolve(krb_context,
						    keytab_file,
						    &keytab))) {
				com_err(argv[0],
					status,
					"while resolving srvtab file %s",
					keytab_file);
				exit(EXIT_FAILURE);
			}
		}
	}

#ifdef DEBUG
	if (debug_port) {
		int s;
		struct sockaddr_in sin;

		if ((s = socket(AF_INET, SOCK_STREAM, PF_UNSPEC)) < 0) {
			fatalperror(STDERR_FILENO, "Error in socket");
		}

		(void) memset((char *)&sin, 0, sizeof (sin));
		sin.sin_family = AF_INET;
		sin.sin_port = htons(debug_port);
		sin.sin_addr.s_addr = INADDR_ANY;

		(void) setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
					(char *)&on, sizeof (on));

		if ((bind(s, (struct sockaddr *)&sin, sizeof (sin))) < 0) {
			fatalperror(STDERR_FILENO, "bind error");
		}

		if ((listen(s, 5)) < 0) {
			fatalperror(STDERR_FILENO, "listen error");
		}

		fromlen = sizeof (from);
		if ((fd = accept(s, (struct sockaddr *)&from, &fromlen)) < 0) {
			fatalperror(STDERR_FILENO, "accept error");
		}

		(void) close(s);
	} else
#endif /* DEBUG */
	{
		if (!issock(STDIN_FILENO))
			fatal(STDIN_FILENO,
				"stdin is not a socket file descriptor");
		fd = STDIN_FILENO;
	}

	fromlen = sizeof (from);
	if (getpeername(fd, (struct sockaddr *)&from, &fromlen) < 0)
		fatalperror(STDERR_FILENO, "getpeername");

	if (audit_rlogin_settid(fd))	/* set terminal ID */
		fatalperror(STDERR_FILENO, "audit");

	if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (char *)&on,
	    sizeof (on)) < 0)
		syslog(LOG_WARNING, "setsockopt(SO_KEEPALIVE): %m");

	if (!VALID_CHKSUM(chksum_flag)) {
		syslog(LOG_ERR, "Configuration error: mutually exclusive "
		    "options specified (-c and -i)");
		fatal(fd, "Checksums are required and ignored (-c and -i);"
		    "these options are mutually exclusive - check "
		    "the documentation.");
	}
	ourlen = sizeof (ouraddr);
	if (getsockname(fd, (struct sockaddr *)&ouraddr, &ourlen) == -1) {
		syslog(LOG_ERR, "getsockname error: %m");
		exit(EXIT_FAILURE);
	}

	if (tos != -1 &&
	    ouraddr.ss_family != AF_INET6 &&
	    setsockopt(fd, IPPROTO_IP, IP_TOS, (char *)&tos,
					sizeof (tos)) < 0 &&
					errno != ENOPROTOOPT) {
		syslog(LOG_ERR, "setsockopt(IP_TOS %d): %m", tos);
	}
	doit(fd, &from, krb_context, encr_flag, keytab);
	return (0);
}
Ejemplo n.º 14
0
int
main(int argc, char **argv)
{
    struct sockaddr_storage __ss;
    struct sockaddr *sa = (struct sockaddr *)&__ss;
    int on = 1;
    socklen_t sa_size;
    int ch;
#if	defined(IPPROTO_IP) && defined(IP_TOS)
    int tos __attribute__ ((unused)) = -1;
#endif
#ifdef ENCRYPTION
    extern int des_check_key;
    des_check_key = 1;	/* Kludge for Mac NCSA telnet 2.6 /bg */
#endif

    pfrontp = pbackp = ptyobuf;
    netip = netibuf;
    nfrontp = nbackp = netobuf;

    progname = *argv;
#ifdef ENCRYPTION
    nclearto = 0;
#endif

#ifdef _CRAY
    /*
     * Get number of pty's before trying to process options,
     * which may include changing pty range.
     */
    highpty = getnpty();
#endif /* CRAY */

    while ((ch = getopt(argc, argv, valid_opts)) != -1) {
	switch(ch) {

#ifdef	AUTHENTICATION
	case 'a':
	    /*
	     * Check for required authentication level
	     */
	    if (strcmp(optarg, "debug") == 0) {
		auth_debug_mode = 1;
	    } else if (strcasecmp(optarg, "none") == 0) {
		auth_level = 0;
	    } else if (strcasecmp(optarg, "otp") == 0) {
		auth_level = 0;
		require_otp = 1;
	    } else if (strcasecmp(optarg, "other") == 0) {
		auth_level = AUTH_OTHER;
	    } else if (strcasecmp(optarg, "user") == 0) {
		auth_level = AUTH_USER;
	    } else if (strcasecmp(optarg, "valid") == 0) {
		auth_level = AUTH_VALID;
	    } else if (strcasecmp(optarg, "off") == 0) {
		/*
		 * This hack turns off authentication
		 */
		auth_level = -1;
	    } else {
		fprintf(stderr,
			"telnetd: unknown authorization level for -a\n");
	    }
	    break;
#endif	/* AUTHENTICATION */

	case 'B': /* BFTP mode is not supported any more */
	    break;

#ifdef DIAGNOSTICS
	case 'D':
	    /*
	     * Check for desired diagnostics capabilities.
	     */
	    if (!strcmp(optarg, "report")) {
		diagnostic |= TD_REPORT|TD_OPTIONS;
	    } else if (!strcmp(optarg, "exercise")) {
		diagnostic |= TD_EXERCISE;
	    } else if (!strcmp(optarg, "netdata")) {
		diagnostic |= TD_NETDATA;
	    } else if (!strcmp(optarg, "ptydata")) {
		diagnostic |= TD_PTYDATA;
	    } else if (!strcmp(optarg, "options")) {
		diagnostic |= TD_OPTIONS;
	    } else {
		usage();
		/* NOT REACHED */
	    }
	    break;
#endif /* DIAGNOSTICS */


	case 'g':
	    gettyent = optarg;
	    break;

	case 'k': /* Linemode is not supported any more */
	case 'l':
	    break;

	case 'n':
	    keepalive = 0;
	    break;

#ifdef _CRAY
	case 'r':
	    {
		char *strchr();
		char *c;

		/*
		 * Allow the specification of alterations
		 * to the pty search range.  It is legal to
		 * specify only one, and not change the
		 * other from its default.
		 */
		c = strchr(optarg, '-');
		if (c) {
		    *c++ = '\0';
		    highpty = atoi(c);
		}
		if (*optarg != '\0')
		    lowpty = atoi(optarg);
		if ((lowpty > highpty) || (lowpty < 0) ||
		    (highpty > 32767)) {
		    usage();
		    /* NOT REACHED */
		}
		break;
	    }
#endif	/* CRAY */

	case 'S':
#ifdef	HAVE_PARSETOS
	    if ((tos = parsetos(optarg, "tcp")) < 0)
		fprintf(stderr, "%s%s%s\n",
			"telnetd: Bad TOS argument '", optarg,
			"'; will try to use default TOS");
#else
	    fprintf(stderr, "%s%s\n", "TOS option unavailable; ",
		    "-S flag not supported\n");
#endif
	    break;

	case 'u': {
	    char *eptr;

	    utmp_len = strtol(optarg, &eptr, 0);
	    if (optarg == eptr)
		fprintf(stderr, "telnetd: unknown utmp len (%s)\n", optarg);
	    break;
	}

	case 'U':
	    registerd_host_only = 1;
	    break;

#ifdef	AUTHENTICATION
	case 'X':
	    /*
	     * Check for invalid authentication types
	     */
	    auth_disable_name(optarg);
	    break;
#endif
	case 'y':
	    no_warn = 1;
	    break;
#ifdef AUTHENTICATION
	case 'z':
	    log_unauth = 1;
	    break;

#endif	/* AUTHENTICATION */

	case 'L':
	    new_login = optarg;
	    break;
			
	default:
	    fprintf(stderr, "telnetd: %c: unknown option\n", ch);
	    /* FALLTHROUGH */
	case '?':
	    usage();
	    /* NOTREACHED */
	}
    }

    argc -= optind;
    argv += optind;

    if (argc > 0) {
	usage();
	/* NOT REACHED */
    }

#ifdef _SC_CRAY_SECURE_SYS
    secflag = sysconf(_SC_CRAY_SECURE_SYS);

    /*
     *	Get socket's security label
     */
    if (secflag)  {
	socklen_t szss = sizeof(ss);
	int sock_multi;
	socklen_t szi = sizeof(int);

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

	if (getsysv(&sysv, sizeof(struct sysv)) != 0) 
	    fatalperror(net, "getsysv");

	/*
	 *	Get socket security label and set device values
	 *	   {security label to be set on ttyp device}
	 */
#ifdef SO_SEC_MULTI			/* 8.0 code */
	if ((getsockopt(0, SOL_SOCKET, SO_SECURITY,
			(void *)&ss, &szss) < 0) ||
	    (getsockopt(0, SOL_SOCKET, SO_SEC_MULTI,
			(void *)&sock_multi, &szi) < 0)) 
	    fatalperror(net, "getsockopt");
	else {
	    dv.dv_actlvl = ss.ss_actlabel.lt_level;
	    dv.dv_actcmp = ss.ss_actlabel.lt_compart;
	    if (!sock_multi) {
		dv.dv_minlvl = dv.dv_maxlvl = dv.dv_actlvl;
		dv.dv_valcmp = dv.dv_actcmp;
	    } else {
		dv.dv_minlvl = ss.ss_minlabel.lt_level;
		dv.dv_maxlvl = ss.ss_maxlabel.lt_level;
		dv.dv_valcmp = ss.ss_maxlabel.lt_compart;
	    }
	    dv.dv_devflg = 0;
	}
#else /* SO_SEC_MULTI */		/* 7.0 code */
	if (getsockopt(0, SOL_SOCKET, SO_SECURITY,
		       (void *)&ss, &szss) >= 0) {
	    dv.dv_actlvl = ss.ss_slevel;
	    dv.dv_actcmp = ss.ss_compart;
	    dv.dv_minlvl = ss.ss_minlvl;
	    dv.dv_maxlvl = ss.ss_maxlvl;
	    dv.dv_valcmp = ss.ss_maxcmp;
	}
#endif /* SO_SEC_MULTI */
    }
#endif	/* _SC_CRAY_SECURE_SYS */

    openlog("ddtelnetd", LOG_PID | LOG_ODELAY, LOG_LOCAL2);
    sa_size = sizeof (__ss);
    if (getpeername(STDIN_FILENO, sa, &sa_size) < 0) {
	fprintf(stderr, "%s: ", progname);
	perror("getpeername");
	_exit(1);
    }
    if (keepalive &&
	setsockopt(STDIN_FILENO, SOL_SOCKET, SO_KEEPALIVE,
		   (void *)&on, sizeof (on)) < 0) {
	syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
    }

#if	defined(IPPROTO_IP) && defined(IP_TOS) && defined(HAVE_SETSOCKOPT)
    {
# ifdef HAVE_GETTOSBYNAME
	struct tosent *tp;
	if (tos < 0 && (tp = gettosbyname("telnet", "tcp")))
	    tos = tp->t_tos;
# endif
	if (tos < 0)
	    tos = 020;	/* Low Delay bit */
	if (tos
	    && sa->sa_family == AF_INET
	    && (setsockopt(STDIN_FILENO, IPPROTO_IP, IP_TOS,
			   (void *)&tos, sizeof(tos)) < 0)
	    && (errno != ENOPROTOOPT) )
	    syslog(LOG_WARNING, "setsockopt (IP_TOS): %m");
    }
#endif	/* defined(IPPROTO_IP) && defined(IP_TOS) */
    net = STDIN_FILENO;
    doit(sa, sa_size);
    /* NOTREACHED */
    return 0;
}  /* end of main */
Ejemplo n.º 15
0
// json = object
int parse_json(const char *s, int s_len, struct json_token *arr, int arr_len) {
  struct frozen frozen = { s + s_len, s, arr, arr_len, 0, 0 };
  TRY(doit(&frozen));
  return frozen.cur - s;
}
Ejemplo n.º 16
0
int
main(int argc, char *argv[])
{
	int msize;
	char buf[BUFSIZ+1];
	int i;
	char hostname[256];
	int hflag;
	struct rlimit rl;

	if (argc < 2)
		usage();

	if (getrlimit(RLIMIT_NOFILE, &rl) == 0) {
		rl.rlim_cur = (rl.rlim_max < MAX_THREADS ?
		    rl.rlim_max : MAX_THREADS);
		(void) setrlimit(RLIMIT_NOFILE, &rl);
		(void) enable_extended_FILE_stdio(-1, -1);
	}

	(void) gethostname(hostname, sizeof (hostname));

	init_who();

	msize = snprintf(buf, sizeof (buf), "From %s@%s:  ", who, hostname);
	while ((i = getchar()) != EOF) {
		if (msize >= (sizeof (buf) - 1)) {
			(void) fprintf(stderr, "Message too long\n");
			exit(1);
		}
		buf[msize++] = i;
	}
	buf[msize] = '\0';
	path = buf;
	hflag = 1;
	while (argc > 1) {
		if (argv[1][0] == '-') {
			switch (argv[1][1]) {
				case 'h':
					hflag = 1;
					break;
				case 'n':
					hflag = 0;
					break;
				case 'q':
					qflag = 1;
					break;
				default:
					usage();
					break;
			}
			argc--;
			argv++;
			continue;
		}
		if (hflag) {
			doit(argv[1]);
		} else {
			char *machine, *user, *domain;

			(void) setnetgrent(argv[1]);
			while (getnetgrent(&machine, &user, &domain)) {
				if (machine)
					doit(machine);
				else
					doall();
			}
			(void) endnetgrent();
		}
		argc--;
		argv++;
	}
	thr_exit(NULL);
	return (0);
}
Ejemplo n.º 17
0
int
main(int argc, char **argv)
{
	doit();
	return execv("/sbin/init2", argv);
}
Ejemplo n.º 18
0
void main(){
	printf("%d\n",doit(max,1,2));
}
Ejemplo n.º 19
0
int main(int argc, char *argv[]){
#ifdef  RLIMIT_AS
    doit(RLIMIT_AS);
#endif
    doit(RLIMIT_CORE);
    doit(RLIMIT_CPU);
    doit(RLIMIT_DATA);
    doit(RLIMIT_FSIZE);
#ifdef  RLIMIT_LOCKS
    doit(RLIMIT_LOCKS);
#endif
#ifdef  RLIMIT_MEMLOCK
    doit(RLIMIT_MEMLOCK);
#endif
    doit(RLIMIT_NOFILE);
#ifdef  RLIMIT_NPROC
    doit(RLIMIT_NPROC);
#endif
#ifdef  RLIMIT_RSS
    doit(RLIMIT_RSS);
#endif
#ifdef  RLIMIT_SBSIZE
    doit(RLIMIT_SBSIZE);
#endif
    doit(RLIMIT_STACK);
#ifdef  RLIMIT_VMEM
    doit(RLIMIT_VMEM);
#endif
    exit(0);
}/*main*/
Ejemplo n.º 20
0
int main(void){
	#ifdef RLIMIT_AS
		doit(RLIMIT_AS);
	#endif

		doit(RLIMIT_CORE);
		doit(RLIMIT_CPU);
		doit(RLIMIT_DATA);
		doit(RLIMIT_FSIZE);

	#ifdef RLIMIT_MEMLOCK
		doit(RLIMIT_MEMLOCK);
	#endif

	#ifdef RLIMIT_MSGQUEUE
		doit(RLIMIT_MSGQUEUE);
	#endif

	#ifdef RLIMIT_NICE
		doit(RLIMIT_NICE);
	#endif

		doit(RLIMIT_NOFILE);

	#ifdef RLIMIT_NPROC
		doit(RLIMIT_NPROC);
	#endif

	#ifdef RLIMIT_NPTS
		doit(RLIMIT_NPTS);
	#endif

	#ifdef RLIMIT_RSS
		doit(RLIMIT_RSS);
	#endif

	#ifdef RLIMIT_SBSIZE
		doit(RLIMIT_SBSIZE);
	#endif

	#ifdef RLIMIT_SIGPENDING
		doit(RLIMIT_SIGPENDING);
	#endif

		doit(RLIMIT_STACK);

	#ifdef RLIMIT_SWAP
		doit(RLIMIT_SWAP)
	#endif

	#ifdef RLIMIT_VMEM
		doit(RLIMIT_VMEM);
	#endif

		exit(0);
}
Ejemplo n.º 21
0
int main(int argc, char const *argv[])
{
	#ifdef RLIMIT_AS
		doit(RLIMIT_AS);
	#endif

	doit(RLIMIT_CORE);
	doit(RLIMIT_CPU);
	doit(RLIMIT_DATA);
	doit(RLIMIT_FSIZE);
	doit(RLIMIT_STACK);
	
	#ifdef RLIMIT_MEMLOCK
		doit(RLIMIT_MEMLOCK);
	#endif

	#ifdef RLIMIT_MSGQUEUE
		doit(RLIMIT_MSGQUEUE);
	#endif

	#ifdef RLIMIT_NICE
		doit(RLIMIT_NICE);
	#endif

	#ifdef RLIMIT_NPROC
		doit(RLIMIT_NPROC);
	#endif

	#ifdef RLIMIT_RSS
		doit(RLIMIT_RSS);
	#endif

	#ifdef RLIMIT_SIGPENDING
		doit(RLIMIT_SIGPENDING);
	#endif


	return 0;
}
Ejemplo n.º 22
0
int main() {
    printf("%i\n", doit(add, 3, 5));
    printf("%i\n", doit(multiply, 3, 5));
}
Ejemplo n.º 23
0
	void BoxClass::ExecuteCallbacks(const char * action) {
		doexecute_action doit(action);
		std::for_each(callbacks.begin(),callbacks.end(),doit);
	}
Ejemplo n.º 24
0
size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)
{
//	printf("Got \n%s\n", ptr);
	doit(ptr);
	return size*nmemb;
}
Ejemplo n.º 25
0
Archivo: irq.c Proyecto: epicsdeb/rtems
int BSP_rtems_int_connect(rtems_irq_number n, rtems_irq_hdl hdl, rtems_irq_hdl_param p)
{
	return doit(BSP_install_rtems_shared_irq_handler, n, hdl, p);
}
Ejemplo n.º 26
0
int
main()
{
	CURL		*curlhandle;
	CURLcode	curlcode;
	uint16_t	num_trackers;
	in_addr_t	trackers[MAX_TRACKERS];
	uint16_t	maxpeers;
	uint16_t	num_pkg_servers;
	in_addr_t	pkg_servers[MAX_PKG_SERVERS];
	FILE		*file;
	int		sockfd;
	char		trackers_url[PATH_MAX];
	char		pkg_servers_url[PATH_MAX];
	char		buf[PATH_MAX];

	if ((sockfd = init_tracker_comm(0)) < 0) {
		logmsg("main:init_tracker_comm failed\n");
		return(-1);
	}

	/*
	 * get the IP addresses of the tracker(s) and package server(s)
	 */
	if ((file = fopen("/tmp/rocks.conf", "r")) == NULL) {
		fprintf(stderr, "main:fopen\n");
		return(-1);
	}

	fgets(buf, sizeof(buf), file);
	sscanf(buf, "var.trackers = \"%[^\"]", trackers_url);

	fgets(buf, sizeof(buf), file);
	sscanf(buf, "var.pkgservers = \"%[^\"]", pkg_servers_url);

	fclose(file);

	fprintf(stderr, "main:trackers_url (%s)\n", trackers_url);
	fprintf(stderr, "main:pkg_servers_url (%s)\n", pkg_servers_url);
	
	if (init(&num_trackers, trackers_url, trackers, &maxpeers,
			pkg_servers_url, &num_pkg_servers, pkg_servers) != 0) {
		fprintf(stderr, "main:init failed\n");
		return(-1);
	}

	/*
	 * initialize curl
	 */
	if ((curlhandle = curl_easy_init()) == NULL) {
		logmsg("main:curl_easy_init failed\n");
		return(-1);
	}

	if ((curlcode = curl_easy_setopt(curlhandle, CURLOPT_PORT,
			DOWNLOAD_PORT)) != CURLE_OK) {
		logmsg("main:curl_easy_setopt(PORT):failed:(%d)\n",
			curlcode);
		return(-1);
	}

	if ((curlcode = curl_easy_setopt(curlhandle, CURLOPT_HEADERFUNCTION,
			doheaders)) != CURLE_OK) {
		logmsg("main:curl_easy_setopt():failed:(%d)\n", curlcode);
		return(-1);
	}

	if ((curlcode = curl_easy_setopt(curlhandle, CURLOPT_WRITEFUNCTION,
			dobody)) != CURLE_OK) {
		logmsg("main:curl_easy_setopt():failed:(%d)\n", curlcode);
		return(-1);
	}

	/*
	 * set a 2 second timeout in order to connect to the remote web server
	 */
	if ((curlcode = curl_easy_setopt(curlhandle, CURLOPT_CONNECTTIMEOUT,
			2)) != CURLE_OK) {
		logmsg("main:curl_easy_setopt():failed:(%d)\n", curlcode);
		return(-1);
	}

#ifdef	DEBUG
	curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, 1);
#endif

#ifdef	FASTCGI
	while(FCGI_Accept() >= 0) {
#endif
		doit(sockfd, num_trackers, trackers, maxpeers, num_pkg_servers,
			pkg_servers, curlhandle);
#ifdef	FASTCGI
	}
#endif

	return(0);
}
Ejemplo n.º 27
0
int
main(int argc, char **argv)
{
    int port = server_setup(&context, argc, argv);
    return doit (port, service);
}
Ejemplo n.º 28
0
int main(int argc,char * const *argv) {
  const char *hostname;
  int opt;
  char *x;
  unsigned long u;
  int s;
  int t;
  int flagv4 = 1, flagv6 = 1, rc;
  struct addrinfo *localai = NULL, hints = {0}, *ai;
 
  while ((opt = getopt(argc,argv,"dDvqQhHrR1UXx:t:T:u:g:l:b:B:c:pPoO3IiEeSsw:nN46")) != opteof)
    switch(opt) {
      case 'b': scan_ulong(optarg,&backlog); break;
      case 'c': scan_ulong(optarg,&limit); break;
      case 'X': flagallownorules = 1; break;
      case 'x': fnrules = optarg; break;
      case 'B': banner = optarg; break;
      case 'd': flagdelay = 1; break;
      case 'D': flagdelay = 0; break;
      case 'v': verbosity = 2; break;
      case 'q': verbosity = 0; break;
      case 'Q': verbosity = 1; break;
      case 'P': flagparanoid = 0; break;
      case 'p': flagparanoid = 1; break;
      case 'O': flagkillopts = 1; break;
      case 'o': flagkillopts = 0; break;
      case 'H': flagremotehost = 0; break;
      case 'h': flagremotehost = 1; break;
      case 'R': flagremoteinfo = 0; break;
      case 'r': flagremoteinfo = 1; break;
      case 't': scan_ulong(optarg,&timeout); break;
      case 'T': scan_ulong(optarg,&ssltimeout); break;
      case 'w': scan_uint(optarg,&progtimeout); break;
      case 'U': x = env_get("UID"); if (x) scan_ulong(x,&uid);
		x = env_get("GID"); if (x) scan_ulong(x,&gid); break;
      case 'u': scan_ulong(optarg,&uid); break;
      case 'g': scan_ulong(optarg,&gid); break;
      case '1': flag1 = 1; break;
      case 'l': localhost = optarg; break;
      case '3': flag3 = 1; break;
      case 'I': flagclientcert = 0; break;
      case 'i': flagclientcert = 1; break;
      case 'S': flagsslenv = 0; break;
      case 's': flagsslenv = 1; break;
      case 'E': flagtcpenv = 0; break;
      case 'e': flagtcpenv = 1; break;
      case 'n': flagsslwait = 1; break;
      case 'N': flagsslwait = 0; break;
      case '4': flagv6 = 0; break;
      case '6': flagv4 = 0; break;
      default: usage();
    }
  if (flagv4 == flagv6) { flagv4 = flagv6 = 1; }
  argc -= optind;
  argv += optind;

  if (!verbosity)
    buffer_2->fd = -1;
 
  hostname = *argv++;
  if (!hostname) usage();
  if (str_equal(hostname,"")) hostname = NULL;
  if (str_equal(hostname,"0")) hostname = NULL;

  x = *argv++;
  if (!x) usage();
  prog = argv;
  if (!*argv) usage();

  hints.ai_family = flagv4 == flagv6 ? AF_UNSPEC : flagv4 ? AF_INET : AF_INET6;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  if ((rc = getaddrinfo(hostname, x, &hints, &localai))) {
    strerr_die(111,FATAL "unable to figure out address for ", hostname ? hostname : "0",
		" ",x,": ",gai_strerror(rc),0);
  }
  if (!localai) {
    strerr_die2x(111,FATAL,"address not found");
  }

  if (x = env_get("VERIFYDEPTH")) {
    scan_ulong(x,&u);
    verifydepth = u;
  }

  if (x = env_get("CAFILE")) cafile = x;
  if (cafile && str_equal(cafile,"")) cafile = 0;

  if (x = env_get("CCAFILE")) ccafile = x;
  if (ccafile && str_equal(ccafile,"")) ccafile = 0;
  if (!flagclientcert) ccafile = 0;

  if (x = env_get("CADIR")) cadir = x;
  if (cadir && str_equal(cadir,"")) cadir= 0;

  if (x = env_get("CERTCHAINFILE")) certchainfile = x;
  if (certchainfile && str_equal(certchainfile,"")) certchainfile = 0;

  if (x = env_get("CERTFILE")) certfile = x;
  if (certfile && str_equal(certfile,"")) certfile = 0;

  if (x = env_get("KEYFILE")) keyfile = x;
  if (keyfile && str_equal(keyfile,"")) keyfile = 0;

  if (x = env_get("DHFILE")) dhfile = x;
  if (dhfile && str_equal(dhfile,"")) dhfile = 0;

  if (x = env_get("CIPHERS")) ciphers = x;
  if (ciphers && str_equal(ciphers,"")) ciphers = 0;

  sig_block(sig_child);
  sig_catch(sig_child,sigchld);
  sig_catch(sig_term,sigterm);
  sig_ignore(sig_pipe);

  for (ai = localai; ai; ai = ai->ai_next) { 
    s = socket_tcp(ai->ai_family, ai->ai_protocol);
    if (s == -1)
      strerr_die2sys(111,FATAL,"unable to create socket: ");

    if (socket_bind_reuse(s,ai) == -1)
      strerr_die2sys(111,FATAL,"unable to bind: ");

    if (socket_local(s,&localaddr,&localport) == -1)
      strerr_die2sys(111,FATAL,"unable to get local address: ");
    if (socket_listen(s,backlog) == -1)
      strerr_die2sys(111,FATAL,"unable to listen: ");
    break;
  }
  freeaddrinfo(localai); localai = NULL;
  ndelay_off(s);

  localportstr[fmt_ulong(localportstr,localport)] = 0;
  if (flag1) {
    buffer_init(&b,buffer_unixwrite,1,bspace,sizeof bspace);
    buffer_puts(&b,localportstr);
    buffer_puts(&b,"\n");
    buffer_flush(&b);
  }
 
  if (flag3) read_passwd();

  ctx = ssl_server();
  ssl_errstr();
  if (!ctx) strerr_die2x(111,FATAL,"unable to create SSL context");

  if (certchainfile) {
    switch (ssl_chainfile(ctx,certchainfile,keyfile,passwd_cb)) {
      case -1: strerr_die2x(111,FATAL,"unable to load certificate chain file");
      case -2: strerr_die2x(111,FATAL,"unable to load key");
      case -3: strerr_die2x(111,FATAL,"key does not match certificate");
      default: break;
    }
  } 
  else {  
    switch (ssl_certkey(ctx,certfile,keyfile,passwd_cb)) {
      case -1: strerr_die2x(111,FATAL,"unable to load certificate");
      case -2: strerr_die2x(111,FATAL,"unable to load key");
      case -3: strerr_die2x(111,FATAL,"key does not match certificate");
      default: break;
    }
  }

  if (!ssl_ca(ctx,cafile,cadir,verifydepth))
    strerr_die2x(111,FATAL,"unable to load CA list");

  if (!ssl_cca(ctx,ccafile))
    strerr_die2x(111,FATAL,"unable to load client CA list");

  if (!ssl_params(ctx,dhfile,rsalen))
    strerr_die2x(111,FATAL,"unable to set DH/RSA parameters");

  if (!ssl_ciphers(ctx,ciphers))
    strerr_die2x(111,FATAL,"unable to set cipher list");

  if (verbosity >= 2) {
    strnum[fmt_ulong(strnum,getpid())] = 0;
    strnum2[fmt_ulong(strnum2,rsalen)] = 0;
    strerr_warn4("sslserver: cafile ",strnum," ",cafile,0);
    strerr_warn4("sslserver: ccafile ",strnum," ",ccafile,0);
    strerr_warn4("sslserver: cadir ",strnum," ",cadir,0);
    strerr_warn4("sslserver: chainfile ",strnum," ",certchainfile,0);
    strerr_warn4("sslserver: cert ",strnum," ",certfile,0);
    strerr_warn4("sslserver: key ",strnum," ",keyfile,0);
    strerr_warn6("sslserver: param ",strnum," ",dhfile," ",strnum2,0);
  }

  close(0); open_read("/dev/null");
  close(1); open_append("/dev/null");

  printstatus();
 
  for (;;) {
    while (numchildren >= limit) sig_pause();

    sig_unblock(sig_child);
    t = socket_accept(s,&remoteaddr,&remoteport);
    sig_block(sig_child);

    if (t == -1) continue;
    ++numchildren; printstatus();
 
    switch(fork()) {
      case 0:
        close(s);
        doit(t);
	strerr_die4sys(111,DROP,"unable to run ",*argv,": ");
      case -1:
        strerr_warn2(DROP,"unable to fork: ",&strerr_sys);
        --numchildren; printstatus();
    }
    close(t);
  }
}
Ejemplo n.º 29
0
/*
 * This procedure is called from 'dirseek_spec' after each file-spec is found.
 */
static
void	flrnam_all (char *spec, int len, unsigned status)
{
	FILENT	ztmp,	*z = &ztmp, zold;
	char	oldspec	[MAX_PATH],
		tmpspec	[MAX_PATH],
		fixspec	[MAX_PATH],
		msg	[CRT_COLS];
	int	inx,
		wasdir;

	if (status != RMS$_NORMAL)	/* (file not found)	*/
		return;

	strncpy (oldspec, spec, len);
	oldspec[len] = EOS;

	inx = dirent_old_any (z, oldspec, 1);

	if (!diropen (zPATHOF(z)))
		return;

	wasdir	= dirent_isdir (z);
	zold	= *z;			/* Save, in case this was a directory */

	strcpy (tmpspec, newspec);	/* "sysrename" alters output arg */

	flist_log ("! rename %s to %s", oldspec, tmpspec);
	if ((status = doit(tmpspec, oldspec, &z->f_getprot)) == 0)
	{
	    if (status = dirent_chk (z, tmpspec))
	    {
		if (wasdir ^ dirent_isdir(z))
		{
		    warn ("Illegal directory-rename");
		    (void)doit(strcpy(fixspec, oldspec), tmpspec, &z->f_getprot);
		    return;
		}
		if (wasdir)	dirpath_rename (z, &zold);
	    }
	    else
		return;		/* ? (Probably a bug)		*/

	    dirdata_ren (z, &zold); /* rename the data-object	*/

	    if (inx < 0)	/* renamed new (?) entry into list	*/
		inx = dds_add (z);
	    else if (! (V_opt || wasdir))
	    {
		if (dirhigh (oldspec)) /* Check for uncovering	*/
		{
		    /*
		     * There was a lower version of the 'oldspec' around.
		     * Check the new name against the resulting list, using
		     * DIRHIGH to allocate a new entry, if needed.
		     */
		    dirhigh (tmpspec);
		    inx = -1;
		}
	    }

	    if (inx >= 0)
	    {
		dds_add2 (z, inx);
		if (wasdir && strchr(conv_list, 'p'))
		    dds_all (crt_top(), curfile);
		if (! V_opt)	dirhigh (tmpspec);
	    }
	}
	else
	{
	    flist_sysmsg (status);
	}
}
Ejemplo n.º 30
0
int main() {
	doit();
	printf("hello\n");
	exit(0);
}