예제 #1
0
파일: debug.c 프로젝트: UIKit0/mctrl
void
debug_dump(const char* msg, void* addr, size_t n)
{
    DWORD last_error;
    BYTE* bytes = (BYTE*) addr;
    size_t offset = 0;
    size_t count;
    char buffer[32 + 3 * DEBUG_DUMP_PER_LINE];
    char* ptr;
    int i;

    last_error = GetLastError();
    debug_trace(msg);

    while(offset < n) {
        count = MC_MIN(n - offset, DEBUG_DUMP_PER_LINE);

        ptr = buffer;
        ptr += sprintf(ptr, "    %04lx:  ", (ULONG) offset);

        for(i = 0; i < count; i++) {
            ptr += sprintf(ptr, " %02x", bytes[offset + i]);
            if(i == DEBUG_DUMP_PER_LINE/2 - 1)
                ptr += sprintf(ptr, "  ");
        }

        debug_trace(buffer);
        offset += count;
    }

    debug_trace("            (%lu bytes)", (ULONG)n);
    SetLastError(last_error);
}
예제 #2
0
double inverseF(int df1, int df2, double alfa, int verbose) {
  double prob=0.0, minF=0.0, maxF=100.0, halfway=50.0, absdiff=1.0;
  int count=0;
  while ((absdiff>0.001)&&(count<100)) {
    debug_trace("INFO df1:%d df2:%d alpha:%f\n", df1, df2, alfa);
    count++;
    halfway= (maxF+minF)/2.0;
    prob = pbeta(df2/(df2+df1*halfway), df2/2.0, df1/2.0, 1, 0);
    debug_trace("(%f, %f, %f) prob=%f\n", df2/(df2+df1*halfway), df2/2.0, df1/2.0, prob);
    if (prob<alfa) maxF= halfway;
    else minF= halfway;
    absdiff= fabs(prob-alfa);
  }
  if(verbose) Rprintf("INFO: Prob=%.3f Alfa=%f\n", prob, alfa);
  return halfway;
}
/*
 * Class:     org_jnetpcap_packet_JScanner
 * Method:    loadFlags
 * Signature: ([I)V
 */
JNIEXPORT void JNICALL Java_org_jnetpcap_packet_JScanner_loadFlags
(JNIEnv *env, jobject obj, jintArray jflags) {
#ifdef DEBUG
	debug_enter("loadFlags");
#endif

	scanner_t *scanner = (scanner_t *)getJMemoryPhysical(env, obj);
	if (scanner == NULL) {
		return;
	}

	jsize size = env->GetArrayLength(jflags);

#ifdef DEBUG
	debug_trace("load", "loaded %d flags", (int)size);
#endif

	if (size != MAX_ID_COUNT) {
		throwException(env,
				ILLEGAL_ARGUMENT_EXCEPTION,
				"size of array must be MAX_ID_COUNT size");
#ifdef DEBUG
		debug_error("IllegalArgumentException",
				"size of array must be MAX_ID_COUNT size");
#endif
		return;
	}

	env->GetIntArrayRegion(jflags, 0, size, (jint *)scanner->sc_flags);

#ifdef DEBUG
	debug_exit("loadFlags");
#endif
}
예제 #4
0
void
sr_server_term (int sig) {
	sprintf (debug_buf, "sr_server_term received signal %d\n", sig);
	debug_trace (debug_buf);
	if (sig != SIGHUP)
		terminate = 1;
}
예제 #5
0
int
open_auth_listen_port(u_short lport)
{
	int ls = -1, on;
	struct sockaddr_in sin;

	if ((ls = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
                if (verbose) {
                        sprintf (debug_buf, "%s: open_auth_listen_port:couldn't open socket\n", progname);
                        debug_trace (debug_buf);
                        a_syslog(AUTH_FAC|LOG_ERR, "%s: open_auth_listen_port:couldn't open socket", progname);
                }
		exit (3);
	}
	on = 1;
	if (setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof on) == -1) {
                if (verbose) {
                        sprintf (debug_buf, "%s: open_auth_listen_port:couldn't setsockopt\n", progname);
                        debug_trace (debug_buf);
                        a_syslog(AUTH_FAC|LOG_ERR, "%s: open_auth_listen_port:couldn't setsockopt", progname);
                }
		close (ls);
		exit (4);
	}
	memset (&sin, 0, sizeof (sin));
	sin.sin_family = AF_INET;
	sin.sin_port = htons(lport);
	if (bind(ls, (struct sockaddr *)&sin, sizeof sin) == -1) {
        	if (verbose) {
                	sprintf (debug_buf, "%s: open_auth_listen_port:couldn't bind port\n", progname);
                	debug_trace (debug_buf);
                	a_syslog(AUTH_FAC|LOG_ERR, "%s: open_auth_listen_port:couldn't bind port", progname);
        	}
		close (ls);
		exit (5);
	}
	if (listen(ls, n_procs) == -1) {
                if (verbose) {
                        sprintf (debug_buf, "%s: open_auth_listen_port:couldn't bind port\n", progname);
                        debug_trace (debug_buf);
                        a_syslog(AUTH_FAC|LOG_ERR, "%s: open_auth_listen_port:couldn't bind port", progname);
                }
                close (ls);
		exit (6);
	}
	return (ls);
}
예제 #6
0
CL_API_ENTRY cl_int CL_API_CALL INTclIcdGetPlatformIDsKHR(  
             cl_uint num_entries, 
             cl_platform_id *platforms,
             cl_uint *num_platforms) {
  debug_init();
  debug_trace();
  return _GetPlatformIDs(num_entries, platforms, num_platforms);
}
void debug_scan(char *msg, scan_t *scan) {
	debug_trace(msg,
			"id=%s off=%d prefix=%-3d header=%-3d gap=%-3d payload=%-3d post=%-3d "
				"nid=%s buf_len=%-3d wire_len=%-3d flags=%0x",
			id2str(scan->id), scan->offset, scan->hdr_prefix, scan->length,
			scan->hdr_gap, scan->hdr_payload, scan->hdr_postfix, id2str(
					scan->next_id), scan->buf_len, scan->wire_len,
			scan->scanner->sc_flags[scan->id]);
}
예제 #8
0
// Acquire the lock.
// Loops (spins) until the lock is acquired.
// Holding a lock for a long time may cause
// other CPUs to waste time spinning to acquire it.
void
spinlock_acquire(struct spinlock *lk)
{
    if(spinlock_holding(lk))
        panic("Already holding lock.");
    while(xchg(&(lk->locked), 1) != 0)
        pause();
    lk->cpu = cpu_cur();
    debug_trace(read_ebp(), lk->eips);
}
예제 #9
0
파일: umc.c 프로젝트: smallcapp/capp
static int
cmd_enter(int argc, char *argv[])
{
    char *mac   = argv[0];
    char *json  = argv[1];
    
    if (2!=argc) {
        return -EFORMAT;
    }
    else if (false==is_good_macstring(mac)) {
        debug_trace("bad mac %s", mac);

        return -EFORMAT;
    }
    else if (false==is_good_json(json)) {
        debug_trace("bad json %s", json);

        return -EFORMAT;
    }
    
    return umc_handle("enter", argc, argv);
}
예제 #10
0
파일: umc.c 프로젝트: smallcapp/capp
static int
cmd_bind(int argc, char *argv[])
{
    char *mac= argv[0];
    char *ip = argv[1];
    
    if (2!=argc) {
        return -EFORMAT;
    }
    else if (false==is_good_macstring(mac)) {
        debug_trace("bad mac %s", mac);

        return -EFORMAT;
    }
    else if (false==is_good_ipstring(ip)) {
        debug_trace("bad ip %s", ip);

        return -EFORMAT;
    }

    return umc_handle("bind", argc, argv);
}
예제 #11
0
int test_func_debug( int arg,
		const char *file, const char *func, unsigned int line )
#endif
{
	int rv = arg;

	printf( "rv=%d\n", rv );

#ifdef DEBUG
	if (rv) debug_trace( "test_func", file, func, line );
#endif

	return rv;
}
예제 #12
0
void
sr_server_chld (int sig) {
	unsigned u;
	pid_t pid = wait((int *)0);

	sprintf (debug_buf, "sr_server_chld received signal %d\n", sig);
	debug_trace (debug_buf);
	for (u = 0; u < n_procs; ++u) {
		if (procs[u] == pid) {
			procs[u] = 0;
			break;
		}
	}
}
 MidpError lfpport_textfield_create(MidpItem *itemPtr, MidpDisplayable *ownerPtr, const pcsl_string *label,
                                    int layout, const pcsl_string *text, int maxSize, int constraints,
                                    const pcsl_string *initialInputMode)
 {
   debug_trace();
   debug_dumpdisp(ownerPtr);
   JDisplayable *disp = static_cast<JDisplayable *>(ownerPtr->frame.widgetPtr);
   qDebug() << "Form:" << static_cast<QObject *>(disp->toForm());
   JTextField *tf = new JTextField(itemPtr, disp->toForm(),
                                   pcsl_string2QString(*label), layout, pcsl_string2QString(*text),
                                   maxSize, constraints, pcsl_string2QString(*initialInputMode));
   if (!tf)
     return KNI_ENOMEM;
   return KNI_OK;
 }
예제 #14
0
파일: umc.c 프로젝트: smallcapp/capp
static int
cmd_leave(int argc, char *argv[])
{
    char *mac= argv[0];
    
    if (1!=argc) {
        return -EFORMAT;
    }
    else if (false==is_good_macstring(mac)) {
        debug_trace("bad mac %s", mac);

        return -EFORMAT;
    }

    return umc_handle("leave", argc, argv);
}
예제 #15
0
static cl_int _GetPlatformIDs(  
             cl_uint num_entries, 
             cl_platform_id *platforms,
             cl_uint *num_platforms) {
  debug_trace();
  if( platforms == NULL && num_platforms == NULL )
    return CL_INVALID_VALUE;
  if( num_entries == 0 && platforms != NULL )
    return CL_INVALID_VALUE;
  if( num_master_platforms == 0)
    return CL_PLATFORM_NOT_FOUND_KHR;
  if( num_platforms != NULL ){
    debug(D_LOG, "  asked num_platforms");
    *num_platforms = num_master_platforms; }
  if( platforms != NULL ) {
    debug(D_LOG, "  asked %i platforms", num_entries);
    cl_uint i;
    for( i=0; i<(num_master_platforms<num_entries?num_master_platforms:num_entries); i++)
      platforms[i] = &master_platforms[i];
  }
  return CL_SUCCESS;
}
예제 #16
0
파일: language.c 프로젝트: m4t3uz/yummy
static inline void language_load_menu_utf16(int a, void *b, void **c, int d)
{
	debug_trace();
}
예제 #17
0
파일: language.c 프로젝트: m4t3uz/yummy
static inline void language_dialog_lparam_utf16(int a, void *b, void **c, int d)
{
	debug_trace();
}
예제 #18
0
파일: language.c 프로젝트: m4t3uz/yummy
static inline void language_create_dialog_param(int a, void *b, void **c, int d)
{
	debug_trace();
}
예제 #19
0
파일: language.c 프로젝트: m4t3uz/yummy
static inline void language_shutdown(int a, void *b, void **c, int d)
{
	debug_trace();
}
예제 #20
0
파일: language.c 프로젝트: m4t3uz/yummy
static inline void language_startup(int a, void *b, void **c, int d)
{
	debug_trace();
}
예제 #21
0
파일: language.c 프로젝트: m4t3uz/yummy
static inline void language_get_instance_by_name_utf16(int a, void *b, void **c, int d)
{
	debug_trace();
}
예제 #22
0
파일: language.c 프로젝트: m4t3uz/yummy
static inline void language_get_instance_by_guid(int a, void *b, void **c, int d)
{
	debug_trace();
}
예제 #23
0
파일: language.c 프로젝트: m4t3uz/yummy
static inline void language_get_string_from_guid_utf16(int a, void *b, void **c, int d)
{
	debug_trace();
}
예제 #24
0
파일: language.c 프로젝트: m4t3uz/yummy
static inline void language_get_string(int a, void *b, void **c, int d)
{
	debug_trace();
}
예제 #25
0
파일: language.c 프로젝트: m4t3uz/yummy
static inline void language_load_accelerators_utf16(int a, void *b, void **c, int d)
{
	debug_trace();
}
예제 #26
0
int
get_config_info()
{
	int f, ls = -1, on, n, num_procs, s, stat, rlim_cur, i2;
	char *cp;
	char rmtaddr[16];
	struct sockaddr_in sin;
	char input[64+1];
	struct rlimit rl, *rlp = &rl;
	fd_set readfds, writefds, exceptfds;
	short si;
	int not_configed;
	extern int config_fd;

	if ((ls = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
		if (verbose) {
			sprintf (debug_buf, "get_config_info: socket create failed.\n");
			debug_trace (debug_buf);
		}
		a_syslog(AUTH_FAC|LOG_ERR
			, "%s: config socket create failed: %s"
			, progname, strerror(errno));
		return (-1);
	}

	on = 1;
	if (setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof on) == -1) {
		if (verbose) {
			sprintf (debug_buf, "get_config_info: setsockopt failed.\n");
			debug_trace (debug_buf);
		}
		a_syslog(AUTH_FAC|LOG_ERR
			, "%s: config setsockopt failed: %s"
			, progname, strerror(errno));
		return (-2);
	}
	memset(&sin, 0, sizeof sin);
	sin.sin_family = AF_INET;
	sin.sin_port = htons(listen_port);
	if (bind(ls, (struct sockaddr *)&sin, sizeof sin) == -1) {
		if (verbose) {
			sprintf (debug_buf, "get_config_info: bind failed.\n");
			debug_trace (debug_buf);
		}
		a_syslog(AUTH_FAC|LOG_ERR
			, "%s: config bind failed: %s"
			, progname, strerror(errno));
		return (-3);
	}
	num_procs = 1;
	if (listen(ls, num_procs) == -1) {
		if (verbose) {
			sprintf (debug_buf, "get_config_info: listen failed.\n");
			debug_trace (debug_buf);
		}
		a_syslog(AUTH_FAC|LOG_ERR
			, "%s: config listen failed: %s"
			, progname, strerror(errno));
		return (-4);
	}

	for (f = 3; f < sysconf(_SC_OPEN_MAX); ++f)
		if (f != ls)
			close(f);
	close(0);
	(void) open("/dev/null", 0);
	(void) dup2(2, 1);	/* stdout */

	if (verbose) {
		sprintf (debug_buf, "%s: listening on port %u for config info.\n",
			progname, listen_port);
		debug_trace (debug_buf);
	}

	getrlimit(RLIMIT_NOFILE, rlp);
	rlim_cur = (rl.rlim_cur >= FD_SETSIZE) ? FD_SETSIZE-1 : rl.rlim_cur;
	if (verbose) {
		sprintf (debug_buf, "get_config_info rl.rlim_cur = %d, rlim_cur = %d\n",
			rl.rlim_cur, rlim_cur);
		debug_trace (debug_buf);
	}

	/*
	 *  if the config process fails, stay in waiting-to-be-config'ed state.
	 *  might cause other problems, but...  also, there are some errors that
	 *  will still cause termination of the process.  for one, don't want to
	 *  get caught in a loop.
	 */

#ifdef BE_SENSITIVE
	for (;;) {
#else
	not_configed = 1;
	while (not_configed) {
#endif
		FD_ZERO(&readfds);
		FD_ZERO(&exceptfds);
		FD_SET (ls, &readfds);
		FD_SET (ls, &exceptfds);
		(void) signal(SIGPIPE, sr_server_sigpipe);
		si = select (rlim_cur, &readfds, 0, &exceptfds, 0);
		if (verbose) {
			sprintf (debug_buf,
				"get_config_info select returns with %d, errno=%d, rd=%d, err=%d\n",
				si, errno, FD_ISSET(ls, &readfds), FD_ISSET (ls, &exceptfds));
			debug_trace (debug_buf);
		}
		if (si == -1) {
/*			sprintf (debug_buf, "get_config_info select returns -1, errno = %d\n", errno); */
/*			debug_trace (debug_buf); */
			if (terminate) {
				if (verbose) {
					debug_trace ("SIGTERM, or SIGINT received, exiting\n");
				}
				break;
			}
			continue;
		} else if (si > MAX_FD) {
			if (verbose) {
				sprintf (debug_buf, "get_config_info select got fd (256 max) = %d\n", si);
				debug_trace (debug_buf);
			}
			break;
		}

		if (FD_ISSET(ls, &readfds)) {
			if (verbose) {
				debug_trace ("get_config info: got fd == ls\n");
			}
		} else {
			if (verbose) {
				sprintf (debug_buf, "get_config_info: what? got fd == 0x%08x, ls = %d\n",
					readfds, ls);
				debug_trace (debug_buf);
			}
		}

		n = sizeof sin;
		if ((s = accept(ls, (struct sockaddr *)&sin, &n)) == -1) {
			if (errno != EINTR) {
				if (verbose) {
					sprintf (debug_buf, "get_config_info: unable to accept socket: %s.\n",
						strerror(errno));
					debug_trace (debug_buf);
					a_syslog(AUTH_FAC|LOG_ERR
			  			, "%s: unable to accept new connection: %s"
			  			, progname, strerror(errno));
					return (-5);
				}
			}
			sleep(1);
			continue;
		}

		/*
		 *  make sure it's a local connection
		 */

#ifdef CHECK_LOCALHOST
		memset (rmtaddr, 0, 16);
		cp = inet_ntoa(sin.sin_addr);
		/*
		 *  length of addr shouldn't be more than 15!
		 */
		if ((i2 = strlen(cp)) > 15) {
		    i2 = 15;
		}
		strncpy (rmtaddr, cp, i2);

		if (strcmp(inet_ntoa(sin.sin_addr), "127.0.0.1") != 0) {
		    /*
		     *  see if this address is in the list of "allowed" ones
		     */
			
		    if (!allowed_ipaddress(rmtaddr)) {
			if (verbose) {
				sprintf (debug_buf, "get_config_info: attempted connection from %s.\n",
					inet_ntoa(sin.sin_addr));
				debug_trace (debug_buf);
			}
			close (s);
			a_syslog(AUTH_FAC|LOG_ERR
				, "%s: attempted connection from %s"
				, progname, inet_ntoa(sin.sin_addr));
			return (-6);
		    }
		}
#else
		if (verbose) {
			sprintf (debug_buf, "get_config_info: Connection from %s\n", inet_ntoa(sin.sin_addr));
			debug_trace (debug_buf);
		}
#endif
		
		(void) dup2(s,0);
		(void) dup2(s,1);

		sprintf (debug_buf, "Enter Unix Helper Listen Port [%u]:  ",
			DEFAULT_UNIXHELPER_PORT);
		stat = sr_termio (debug_buf, input, sizeof(input));
		
		if (stat == EOF) {
			if (verbose) {
				sprintf (debug_buf, "get_config_info: Error reading config: listen port.\n");
				debug_trace (debug_buf);
			}
			a_syslog(AUTH_FAC|LOG_ERR
				, "%s: Error reading listen port", progname);
#ifdef BE_SENSITIVE
			return (-7);
#else
			close(s);
			continue;
#endif
		}

		if (stat == 0) {
			lport = DEFAULT_UNIXHELPER_PORT;
			if (verbose) {
				sprintf (debug_buf, "get_config_info: using default=%u as listen port.\n",
					DEFAULT_UNIXHELPER_PORT);
				debug_trace (debug_buf);
			}
		} else {
			if (verbose) {
				sprintf (debug_buf, "get_config_info: received %s as listen port.\n",
					input);
				debug_trace (debug_buf);
			}
			errno = 0;
			lport = (u_short)strtoul(input, (char **)0, 0);
			if (errno) {
				sprintf (debug_buf,
					"get_config_info: Invalid listen port number (%s) specified.\n",
					input);
				if (verbose) {
					debug_trace (debug_buf);
				}
				sr_termout (debug_buf);
				a_syslog(AUTH_FAC|LOG_ERR
					, "%s: Invalid listen port (%s)", progname, input);
#ifdef BE_SENSITIVE
				return (-8);
#else
				close(s);
				continue;
#endif
			}
		}

		auth_rqt_fd = open_auth_listen_port(lport);
		if (auth_rqt_fd < 0) {
			sprintf (debug_buf,
				"get_config_info: Could not open listen port (%d) specified.\n",
				lport);
			if (verbose) {
				debug_trace (debug_buf);
			}
			a_syslog(AUTH_FAC|LOG_ERR
				, "%s: Could not open listen port (%d)", progname, lport);
		}

		sprintf (debug_buf, "Enter Unix Helper Session Timeout [%d]:  ",
			DEFAULT_UNIX_TIMEOUT);
		stat = sr_termio (debug_buf, input, sizeof(input));
		
		if (stat == EOF) {
			if (verbose) {
				sprintf (debug_buf, "get_config_info: Error reading config: session timeout.\n");
				debug_trace (debug_buf);
			}
			a_syslog(AUTH_FAC|LOG_ERR
				, "%s: Error reading session timeout", progname);
#ifdef BE_SENSITIVE
			return (-9);
#else
			close(s);
			continue;
#endif
		}

		if (stat == 0) {
			stimeout = DEFAULT_UNIX_TIMEOUT;
			if (verbose) {
				sprintf (debug_buf, "get_config_info: using default=%d as session timeout.\n",
					DEFAULT_UNIX_TIMEOUT);
				debug_trace (debug_buf);
			}
		} else {
			if (verbose) {
				sprintf (debug_buf, "get_config_info: received %s as session timeout.\n",
					input);
				debug_trace (debug_buf);
			}

			errno = 0;
			stimeout = atoi(input);
			if (errno) {
				sprintf (debug_buf,
					"get_config_info: Invalid session timeout (%s) specified.\n",
					input);
				if (verbose) {
					debug_trace (debug_buf);
				}
				sr_termout (debug_buf);
				a_syslog(AUTH_FAC|LOG_ERR
					, "%s: Invalid session timeout (%s)", progname, input);
#ifdef BE_SENSITIVE
				return (-10);
#else
				close(s);
				continue;
#endif
			}
		}

		sprintf (debug_buf, "Enter Unix Helper Max Sessions [%d]:  ",
			DEFAULT_UNIX_MAX_PROCS);
		stat = sr_termio (debug_buf, input, sizeof(input));
		
		if (stat == EOF) {
			if (verbose) {
				sprintf (debug_buf, "get_config_info: Error reading config: max sessions.\n");
				debug_trace (debug_buf);
			}
			a_syslog(AUTH_FAC|LOG_ERR
				, "%s: Error reading max sessions", progname);
#ifdef BE_SENSITIVE
			return (-11);
#else
			close(s);
			continue;
#endif
		}
		if (stat == 0) {
			n_procs = DEFAULT_UNIX_MAX_PROCS;
			if (verbose) {
				sprintf (debug_buf, "get_config_info: using default=%d as max sessions.\n",
					DEFAULT_UNIX_MAX_PROCS);
				debug_trace (debug_buf);
			}
		} else {
			if (verbose) {
				sprintf (debug_buf, "get_config_info: received %s as max sessions.\n",
					input);
				debug_trace (debug_buf);
			}

			errno = 0;
			n_procs = (u_int)strtoul(input, (char **)0, 0);
			if (errno) {
				sprintf (debug_buf,
					"get_config_info: Invalid max sessions (%s) specified.\n",
					input);
				if (verbose) {
					debug_trace (debug_buf);
				}
				sr_termout (debug_buf);
				a_syslog(AUTH_FAC|LOG_ERR
					, "%s: Invalid max sessions (%s)", progname, input);
#ifdef BE_SENSITIVE
				return (-12);
#else
				close(s);
				continue;
#endif
			}
		}

		sprintf (debug_buf, "get_config_info: %s configured successfully\n",progname);
		if (verbose) {
			debug_trace (debug_buf);
		}
		sr_termout (debug_buf);

		
		close (s);

/*		close (ls); */
		config_fd = ls;
		not_configed = 0;
	}
	return (0);
}

int
do_subsequent_config()
{
	int i, n, s, stat, i2;
	struct sockaddr_in sin;
	char input[64+1];
	struct rlimit rl, *rlp = &rl;
	fd_set readfds, writefds, exceptfds;
	short si;
	extern int config_fd;
	u_short usi;
	u_int ui;
	char *cp;
	char rmtaddr[16];

	n = sizeof sin;
	memset(&sin, 0, n);
	if ((s = accept(config_fd, (struct sockaddr *)&sin, &n)) == -1) {
		if (errno != EINTR) {
			if (verbose) {
				sprintf (debug_buf, "do_subsequent_config: unable to accept socket: %s.\n",
					strerror(errno));
				debug_trace (debug_buf);
				a_syslog(AUTH_FAC|LOG_ERR
		  			, "%s: unable to accept new connection: %s"
		  			, progname, strerror(errno));
				return (-5);
			}
		}
		sleep(1);
	}

	/*
	 *  make sure it's a local connection
	 */

#ifdef CHECK_LOCALHOST
	memset (rmtaddr, 0, 16);
	cp = inet_ntoa(sin.sin_addr);
	/*
	 *  length of addr shouldn't be more than 15!
	 */
	if ((i2 = strlen(cp)) > 15) {
	    i2 = 15;
	}
	strncpy (rmtaddr, cp, i2);

	if (strcmp(inet_ntoa(sin.sin_addr), "127.0.0.1") != 0) {
	    /*
	     *  see if this address is in the list of "allowed" ones
	     */

	    if (!allowed_ipaddress(rmtaddr)) {
		if (verbose) {
			sprintf (debug_buf, "do_subsequent_config: attempted connection from %s.\n",
				inet_ntoa(sin.sin_addr));
			debug_trace (debug_buf);
		}
		close (s);
		a_syslog(AUTH_FAC|LOG_ERR
			, "%s: attempted connection from %s"
			, progname, inet_ntoa(sin.sin_addr));
		return (-6);
	    }
	}
#else
	if (verbose) {
		sprintf (debug_buf, "do_subsequent_config: Connection from %s\n",
			inet_ntoa(sin.sin_addr));
		debug_trace (debug_buf);
	}
#endif
		
	(void) dup2(s,0);
	(void) dup2(s,1);

	if (verbose) {
		sprintf (debug_buf,
			"Subsequent configuration request; lport=%d, stimeout=%d, n_procs=%d\n",
			lport, stimeout, n_procs);
		debug_trace (debug_buf);
	}

	sprintf (debug_buf, "Enter Unix Helper Listen Port [%u]:  ",
		DEFAULT_UNIXHELPER_PORT);
	stat = sr_termio (debug_buf, input, sizeof(input));
		
	if (stat == EOF) {
		if (verbose) {
			sprintf (debug_buf, "do_subsequent_config: Error reading config: listen port.\n");
			debug_trace (debug_buf);
		}
		a_syslog(AUTH_FAC|LOG_ERR
			, "%s: Error reading listen port", progname);
		return (-7);
	}

	if (stat == 0) {
		usi = DEFAULT_UNIXHELPER_PORT;
		if (verbose) {
			sprintf (debug_buf, "do_subsequent_config: using default=%u as listen port.\n",
				DEFAULT_UNIXHELPER_PORT);
			debug_trace (debug_buf);
		}
	} else {
		if (verbose) {
			sprintf (debug_buf, "do_subsequent_config: received %s as listen port.\n",
				input);
			debug_trace (debug_buf);
		}
		errno = 0;
		usi = (u_short)strtoul(input, (char **)0, 0);
		if (errno) {
			sprintf (debug_buf,
				"do_subsequent_config: Invalid listen port number (%s) specified.\n",
				input);
			if (verbose) {
				debug_trace (debug_buf);
			}
			sr_termout (debug_buf);
			a_syslog(AUTH_FAC|LOG_ERR
				, "%s: Invalid listen port (%s)", progname, input);
			return (-8);
		}
	}

	if (usi != lport) {
		sprintf (debug_buf,
			"do_subsequent_config: original lport (%d) remains, not new (%d)\n",
			lport, usi);
		debug_trace (debug_buf);
	}

	sprintf (debug_buf, "Enter Unix Helper Session Timeout [%d]:  ",
		DEFAULT_UNIX_TIMEOUT);
	stat = sr_termio (debug_buf, input, sizeof(input));
		
	if (stat == EOF) {
		if (verbose) {
			sprintf (debug_buf, "do_subsequent_config: Error reading config: session timeout.\n");
			debug_trace (debug_buf);
		}
		a_syslog(AUTH_FAC|LOG_ERR
			, "%s: Error reading session timeout", progname);
		return (-7);
	}

	if (stat == 0) {
		i = DEFAULT_UNIX_TIMEOUT;
		if (verbose) {
			sprintf (debug_buf, "do_subsequent_config: using default=%d as session timeout.\n",
				DEFAULT_UNIX_TIMEOUT);
			debug_trace (debug_buf);
		}
	} else {
		if (verbose) {
			sprintf (debug_buf, "do_subsequent_config: received %s as session timeout.\n",
				input);
			debug_trace (debug_buf);
		}

		errno = 0;
		i = atoi(input);
		if (errno) {
			sprintf (debug_buf,
				"do_subsequent_config: Invalid session timeout (%s) specified.\n",
				input);
			if (verbose) {
				debug_trace (debug_buf);
			}
			sr_termout (debug_buf);
			a_syslog(AUTH_FAC|LOG_ERR
				, "%s: Invalid session timeout (%s)", progname, input);
			return (-8);
		}
	}

	if (i != stimeout) {
		sprintf (debug_buf,
			"do_subsequent_config: original session timeout (%d) remains, not new (%d)\n",
			stimeout, i);
		debug_trace (debug_buf);
	}

	sprintf (debug_buf, "Enter Unix Helper Max Sessions [%d]:  ",
		DEFAULT_UNIX_MAX_PROCS);
	stat = sr_termio (debug_buf, input, sizeof(input));
		
	if (stat == EOF) {
		if (verbose) {
			sprintf (debug_buf, "do_subsequent_config: Error reading config: max sessions.\n");
			debug_trace (debug_buf);
		}
		a_syslog(AUTH_FAC|LOG_ERR
			, "%s: Error reading max sessions", progname);
		return (-7);
	}
	if (stat == 0) {
		ui = DEFAULT_UNIX_MAX_PROCS;
		if (verbose) {
			sprintf (debug_buf, "do_subsequent_config: using default=%d as max sessions.\n",
				DEFAULT_UNIX_MAX_PROCS);
			debug_trace (debug_buf);
		}
	} else {
		if (verbose) {
			sprintf (debug_buf, "do_subsequent_config: received %s as max sessions.\n",
				input);
			debug_trace (debug_buf);
		}

		errno = 0;
		ui = (u_int)strtoul(input, (char **)0, 0);
		if (errno) {
			sprintf (debug_buf,
				"do_subsequent_config: Invalid max sessions (%s) specified.\n",
				input);
			if (verbose) {
				debug_trace (debug_buf);
			}
			sr_termout (debug_buf);
			a_syslog(AUTH_FAC|LOG_ERR
				, "%s: Invalid max sessions (%s)", progname, input);
			return (-8);
		}
	}

	if (ui != n_procs) {
		sprintf (debug_buf,
			"do_subsequent_config: original max sessions (%d) remains, not new (%d)\n",
			n_procs, ui);
		debug_trace (debug_buf);
	}

	sprintf (debug_buf, "get_config_info: %s configured successfully\n",progname);
	if (verbose) {
		debug_trace (debug_buf);
	}
	sprintf (debug_buf, "get_config_info: %s configured successfully\n",progname);
	sr_termout (debug_buf);

	i = close (s);
	return (0);
}
예제 #27
0
int
sr_server () {
	int f, ls = -1, n, on, s, i, rlim_cur, i2;
	u_int u;
	char *what;
	char *cp;
	char rmtaddr[16];
	struct sockaddr_in sin;
	struct rlimit rl, *rlp = &rl;
	fd_set readfds, exceptfds;
	short si;
	extern int config_fd;
	(void) signal(SIGHUP, sr_server_term);
	(void) signal(SIGINT, sr_server_term);
	(void) signal(SIGTERM, sr_server_term);
	(void) sigset(SIGCHLD, sr_server_chld);
	(void) sigset(SIGPIPE, sr_server_sigpipe);

	ls = auth_rqt_fd;

	if ((procs = (int *)calloc(n_procs, sizeof(int))) == (int *)0) {
		a_syslog(AUTH_FAC|LOG_ERR
		  , "%s: unable to allocate %u proc state elements"
		  , progname, n_procs);

                a_syslog(AUTH_FAC|LOG_ERR, "%s: server socket %s failed: %s"
                  , progname, what, strerror(errno));
                if (ls != -1)
                        close(ls);
                return -2;

	}

	for (u = 0; u < n_procs; ++u) {
		procs[u] = 0;
	}

	for (f = 3; f < sysconf(_SC_OPEN_MAX); ++f)
		if ((f != ls) && (f != config_fd))
			close(f);
	close(0);
	(void) open("/dev/null", 0);
	(void) dup2(2, 1);	/* stdout */
	(void) setsid();

	getrlimit(RLIMIT_NOFILE, rlp);
	rlim_cur = (rl.rlim_cur >= FD_SETSIZE) ? FD_SETSIZE-1 : rl.rlim_cur;

	if (verbose) {
		sprintf (debug_buf, "sr_server rl.rlim_cur = %d, rlim_cur = %d\n", rl.rlim_cur, rlim_cur);
		debug_trace (debug_buf);
	}

	for (;;) {
		/* await connection */
		FD_ZERO(&readfds);
		FD_ZERO(&exceptfds);
		FD_SET (ls, &readfds);
		FD_SET (config_fd, &readfds);

		si = select (rlim_cur, &readfds, 0, &exceptfds, 0);
		if (verbose) {
			sprintf (debug_buf, "sr_server select returns with %d\n", si);
			debug_trace (debug_buf);
		}
		if (si == -1) {
			/*
			 *  get an interrupt when the child finishes, and when kill issued.
			 *  check to see if terminate has been set.
			 */
			if (verbose) {
				sprintf (debug_buf, "sr_server select returns -1, errno = %d\n", errno);
				debug_trace (debug_buf);
			}
			if (terminate) {
				if (verbose) {
					debug_trace ("SIGTERM, or SIGINT received, exiting\n");
				}
				break;
			}
			continue;
		} else if (si > MAX_FD) {
			if (verbose) {
				sprintf (debug_buf, "sr_server select got fd (256 max) = %d\n", si);
				debug_trace (debug_buf);
			}
			break;
		}

		if (FD_ISSET(ls, &readfds)) {
			if (verbose) {
				debug_trace ("sr_server info: got fd == ls\n");
			}
		} else if (FD_ISSET(config_fd, &readfds)) {
			if (verbose) {
				debug_trace ("sr_server info: got fd == config_fd\n");
			}
			i = do_subsequent_config();
			if (i) {
				if (verbose) {
					sprintf (debug_buf, "do_subsequent_config returned %d\n", i);
					debug_trace (debug_buf);
				}
				/*
				 *  what to do about this?
				 */
			}
			for (f = 3; f < sysconf(_SC_OPEN_MAX); ++f)
				if ((f != ls) && (f != config_fd))
					close(f);
			close(0);
			(void) open("/dev/null", 0);
			(void) dup2(2, 1);	/* stdout */
			(void) setsid();
			continue;
		} else {
			if (verbose) {
				sprintf (debug_buf, "sr_server: what? got fd == 0x%08x, ls = %d\n",
					readfds, ls);
				debug_trace (debug_buf);
			}
			continue;
		}

		n = sizeof sin;
		if ((s = accept(ls, (struct sockaddr *)&sin, &n)) == -1) {
			if (terminate)
				break;
			if (errno) {
				if (verbose) {
					sprintf (debug_buf, "accept errno=%d\n", errno);
					debug_trace(debug_buf);
				}
			}
			if (errno != EINTR) {
				a_syslog(AUTH_FAC|LOG_ERR
				  , "%s: unable to accept socket: %s"
				  , progname, strerror(errno));
				break;
			}
			sleep(1);	/* give it a rest */
			continue;
		}
/*
printf("newconn: fd==%d, peeraddr==%s,%u\n", s, inet_ntoa(sin.sin_addr)
  , ntohs(sin.sin_port));
*/
		/*
		 *  make sure it's a local connection
		 */

#define CHECK_LOCALHOST 1

#ifdef CHECK_LOCALHOST
		memset (rmtaddr, 0, 16);
		cp = inet_ntoa(sin.sin_addr);
		/*
		 *  length of addr shouldn't be more than 15!
		 */
		if ((i2 = strlen(cp)) > 15) {
		    i2 = 15;
		}
		strncpy (rmtaddr, cp, i2);

		if (strcmp(inet_ntoa(sin.sin_addr), "127.0.0.1") != 0) {
		    /*
		     *  see if this address is in the list of "allowed" ones
		     */
			
		    if (!allowed_ipaddress(rmtaddr)) {
			/*
			 *  don't allow remote connections, since communication is in the clear
			 */
			a_syslog(AUTH_FAC|LOG_ERR, "%s: attempted connection from %s",
				progname, inet_ntoa(sin.sin_addr));
			close(s);
			continue;
		    }
		}
#else
		if (verbose) {
			sprintf (debug_buf, "Connection from %s\n", inet_ntoa(sin.sin_addr));
			debug_trace (debug_buf);
		}
#endif


		/* find a spot for this */
		for (u = 0; u < n_procs; ++u) {
			if (procs[u] == 0) {
				goto found_courtney;
			}
		}

/*		a_syslog(AUTH_FAC|LOG_ERR, "%s: unable to allocate slot for new connection",
	  		progname); */

/*		if (verbose) {
			sprintf(debug_buf, "%s: unable to allocate slot for new connection\n", progname);
			debug_trace (debug_buf);
			sprintf (debug_buf,
				"%s: procs[0]=%d, [1]=%d, [2]=%d, [3]=%d, [4]=%d\n",
				progname, procs[0], procs[1], procs[2], procs[3], procs[4]);
			debug_trace (debug_buf);
		} */

		/*
		 *  check status of children in "process" table
		 */

		for (u = 0; u < n_procs; ++u) {
			if (procs[u]) {
				errno = 0;
				i = kill (procs[u], SIGHUP);
				if (i) {
					if (errno == ESRCH) {
						procs[u] = 0;

						if (verbose) {
							sprintf (debug_buf,
								"%s: process %d actually was INactive\n",
								progname, u);
							debug_trace (debug_buf);
						}
						goto found_courtney;
					} else {
						if (verbose) {
							sprintf (debug_buf,
								"%s: killing process 0x%8x returned errno=%d\n",
								progname, u, errno);
							debug_trace (debug_buf);
						}
					}
				} else {	/* process is busy */
					if (verbose) {
						sprintf (debug_buf,
							"%s: process %d actually was ACTIVE\n",
							progname, u);
						debug_trace (debug_buf);
					}
				}
			}
		}

		if (verbose) {
			sprintf (debug_buf, "closing socket %d\n", s);
			debug_trace (debug_buf);
		}
		close (s);
		continue;

		/* found a hole for this one */
found_courtney:;
		switch (procs[u] = fork()) {
		case -1:		/* trouble */
			a_syslog(AUTH_FAC|LOG_ERR
			  , "%s: unable to fork new process: %s"
			  , progname, strerror(errno));
			procs[u] = 0;
			continue;
		case 0:			/* child */
			(void) sigset(SIGHUP, sr_server_sighup);
			(void) signal(SIGINT, SIG_DFL);
			(void) signal(SIGTERM, SIG_DFL);
			(void) signal(SIGCHLD, SIG_DFL);
			(void) signal(SIGALRM, sr_server_alarm);
			(void) signal(SIGPIPE, sr_server_sigpipe);

			(void) dup2(s, 0);	/* stdin */
			(void) dup2(s, 1);	/* stdout */
			close(ls);
			close(s);
			(void) alarm(stimeout*60);	/* you got 'stimeout' minutes ... */
			return 0;
		}
		/* parent */
		close(s);
	}

	/* gets here if select sez we're suppose to die */
	/* terminate all the child processes */
	(void) kill(0, SIGTERM);
	return (-2);
}
예제 #28
0
파일: language.c 프로젝트: m4t3uz/yummy
static inline void language_get_language_identifier(int a, void *b, void **c, int d)
{
	debug_trace();
}
예제 #29
0
파일: language.c 프로젝트: m4t3uz/yummy
static inline void language_load_resource_from_file(int a, void *b, void **c, int d)
{
	debug_trace();
}
예제 #30
0
void
sr_sig_default (int sig) {
	sprintf (debug_buf, "sr_sig_default received signal %d\n", sig);
	debug_trace (debug_buf);
	return;
}