Пример #1
0
void
ServiceList::assignSystemServices(void)
{
	struct servent	*entry;

	clearServiceList(true);

	/* Open /etc/services */
	entry = getservent();

	while (entry != NULL) {
		/* Only show protocol tcp and udp. */
		wxString prot = wxString::From8BitData(entry->s_proto);
		if (prot == wxT("tcp") || prot == wxT("udp")) {
			Service *service = new Service(
			    wxString::From8BitData(entry->s_name),
			    entry->s_port,
			    (prot == wxT("tcp") ? Service::TCP : Service::UDP),
			    false);

			addService(service);
		}

		entry = getservent();
	}

	/* Close /etc/services */
	endservent();

	sizeChangeEvent(serviceList_.size());
}
Пример #2
0
struct servent * getservbyport(int port,
		const char *proto) {
	struct servent *se;

	if (proto == NULL) {
		return NULL;
	}

	setservent(1);
	port = htons((unsigned short)port);

	while ((se = getservent()) != NULL) {
		/* same protocol? */
		if (strcmp(proto, se->s_proto) != 0) {
			continue; /* not same. try again */
		}
		/* same port? */
		if (se->s_port == port) {
			break;
		}
		/* nope. try again */
	}

	endservent();

	return se;
}
Пример #3
0
Файл: inet.c Проект: AnthraX1/rk
static int
read_services(void)
{
  struct servent *se;
  struct service *item;

  setservent(1);
  while((se=getservent())) {
	/* Allocate a service entry. */
	item = (struct service *) malloc(sizeof(struct service));
	if (item == NULL) perror("netstat"); 
	item->name = strdup(se->s_name);
	item->number = se->s_port;

	/* Fill it in. */
	if (! strcmp(se->s_proto, "tcp")) {
		add2list(&tcp_name,item);
	} else if (! strcmp(se->s_proto, "udp")) {
		add2list(&udp_name,item);
	} else if (! strcmp(se->s_proto, "raw")) {
		add2list(&raw_name,item);
	}
  }
  endservent();
  return(0);
}
Пример #4
0
static int
services(int argc, char *argv[])
{
	struct servent	*se;
	int		i, rv = RV_OK;

	setservent(1);
	if (argc == 2) {
		while ((se = getservent()) != NULL)
			SERVICESPRINT;
	} else {
		for (i = 2; i < argc; i++) {
			const char	*err;
			long long	id;
			char *proto = strchr(argv[i], '/');

			if (proto != NULL)
				*proto++ = '\0';
			id = strtonum(argv[i], 0, UINT_MAX, &err);
			if (!err)
				se = getservbyport(htons((u_short)id), proto);
			else
				se = getservbyname(argv[i], proto);
			if (se != NULL)
				SERVICESPRINT;
			else {
				rv = RV_NOTFOUND;
				break;
			}
		}
	}
	endservent();
	return rv;
}
struct servent *
getservbyport(
	int port,
	const char *proto)
{
	register struct servent *p;

#ifdef YP
	extern int ___getservbyport_yp;
	extern char *___getservbyproto_yp;

	___getservbyport_yp = port;
	___getservbyproto_yp = (char *)proto;
#endif

	setservent(_serv_stayopen);
	while ( (p = getservent()) ) {
		if (p->s_port != port)
			continue;
		if (proto == 0 || strcmp(p->s_proto, proto) == 0)
			break;
	}
	if (!_serv_stayopen)
		endservent();

#ifdef YP
	___getservbyport_yp = 0;
	___getservbyproto_yp = NULL;
#endif

	return (p);
}
Пример #6
0
struct servent *wp_getservent (void)
{
	struct servent *p;
	if ((p = getservent ()) == NULL)
		wp_warning ("getservent() error");
	return p;
}
Пример #7
0
static long	init_ncl_port()
{
struct hostent	*hp;
char		buf[80];
struct servent	*sp;
int		on = 1;

#ifndef	DEBUG
	if((sp = getservent("oz-ncl", "tcp")) == (struct servent *)NULL) {
		fprintf(stderr, "init_ncl_port: unknown service oz-ncl\n");
		return(0);
	}
	ncl_sin.sin_port	= sp->s_port;
#else
	ncl_sin.sin_port	= (unsigned short)PROVISIONAL_PORT;
#endif
	ncl_sin.sin_family	= AF_INET;

	gethostname(buf, 80);
	if (!(hp = gethostbyname(buf))) {
		fprintf(stderr, "init_ncl_port: %s: unknown host\n", buf);
                return(0);
        }
        bcopy(hp->h_addr, &(ncl_sin.sin_addr.s_addr), sizeof(long));

	return((long)(hp->h_addr));
}
Пример #8
0
void loadFile() 
{
	if (!_loaded)
	{
		while(insert(getservent()));
		_loaded = 1;
	}
}
Пример #9
0
unsigned short * get_tcp_svcs(int * num)
{
  struct nessus_service * ns = NULL;
  int len, num_svc;
  unsigned short * ret;
  int fd, i;
  struct stat st;

  if ((fd = open(NESSUS_SERVICES_TCP, O_RDONLY)) >= 0)
	{
	  if (fstat(fd, &st) < 0)
	    perror("fstat");
	  else
	    {
	      len = st.st_size;
	      num_svc = len / sizeof(struct nessus_service);
          /*if ((ns = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0))== MAP_FAILED ) {
            perror("mmap");
            ns = NULL;
          }*/
	    }
	}

  if (ns == NULL)
    {
	    struct servent  * ent;
	    int n = 0;
        __try {
	    ret = emalloc(sizeof(unsigned short) * 65537);
	    endservent();
	    while ( (ent = getservent()) != NULL )
	    {
		    if(strcmp(ent->s_proto, "tcp") == 0 && ntohs(ent->s_port))
		    {
		    ret[n++] = ntohs(ent->s_port);
		    if(n >= 65537)break;
		    }
	    }
	    endservent();

	    if(num != NULL)
		    *num = n;

	    ret = erealloc(ret, sizeof(unsigned short) * (n+1)); 
	    ret[n] = 0;
        }
        __except (EXCEPTION_EXECUTE_HANDLER) {
         fprintf(stderr, "get_tcp_svcs() causes an exception.\n");
        }
	    return ret;
    }
  else
    {
Пример #10
0
/* Services are represented by the port number portion of the address. Each
 * service is offered on a unique, well-known port number. We can map a
 * service name to a port number with getservbyname(), map a port number to
 * a service name with getservbyport(), or scan the services database
 * sequentially with getservent().
 *
 * #include <netdb.h>
 * void endservent(void);
 * struct servent *getservbyname(const char *name, const char *proto);
 * struct servent *getservbyport(int port, const char *proto);
 * struct servent *getservent(void):
 * void setservent(int stayopen);
 *
 * These functions shall retrieve information about network services.
 *
 * The setservent() function shall open a connection to the database, and
 * set the next entry to the first entry. If the stayopen argument is non-
 * zero, the net database shall not be closed after each call to the
 * getservent() function (either directly, or indirectly through one of the
 * other getserv*() functions).
 *
 * The getservent() function shall read the next entry of the database,
 * opending and closing a connection to the database as necessary.
 *
 * The getservbyname() function shall search the database from the beginning
 * and find the first entry for which the service name specified by name
 * matches the s_name member and the protocol name specified by proto
 * matches the s_proto mumber, opening and closing a connection to the
 * database necessary. If proto is a null pointer, any value of the s_proto
 * member shall be matched. 当 proto 是NULL指针时,将匹配任意的协议名,但是
 * getservbyname()函数还是只返回第一项匹配的指针,不会返回多项.这里的"匹配
 * 任意协议名"应该是指不判断协议名.
 *
 * The getservbyport() function shall search the database from the beginning
 * and find the first entry for which the port specified by port matches the
 * s_port member and the protocol name specified by proto matches the
 * s_proto member, opening and closing a connection to the database as
 * necessary. If proto is a null pointer, any value of the s_proto member
 * shall be matched. The port argument shall be a value obtained by
 * converting a uint16_t in network byte order to int. 即 port 参数的值
 * 是网络字节序的,经过测试,要调用htons()函数来转换得到网络字节序的值,不能
 * 使用htonl()函数, htonl(80) 得到的值是0x50000000, htons(80) 得到的值是
 * 0x5000, 两者的结果是不同的.
 *
 * The endservent() function shall close the database, releasing any open
 * file descriptor.
 *
 * These functions need not be thread-safe.
 *
 * Upon successful completion, getservbyname(), getservbyport(), and
 * getservent() return a pointer to a servent structure if the requested
 * entry was found, and a null pointer if the end of the database was
 * reached or the requested entry was not found. Otherwise, a null pointer
 * is returned. No errors are defined.
 *
 * Linux 中, struct servent 结构体定义如下:
 * struct servent {
 *      char    *s_name;    // official service name
 *      char   **s_aliases; // alias list, terminated by NULL
 *      int      s_port;    // The port number for the service given
 *                          // in network byte order
 *      char     *s_proto;  // protocol to use with this service
 * };
 *
 * 查看执行结果,发现输出的服务名和 /etc/services 文件里面的服务名是一样的.
 */
int main(void)
{
    struct servent *serv;
    int i, port;

    while ((serv = getservent()) != NULL)
        printservent(serv);
    endservent();

    printf("========= getservbyname: name --> echo, proto --> tcp\n");
    if ((serv = getservbyname("echo", "tcp")) != NULL)
        printservent(serv);

    /* 虽然 echo 服务可以使用tcp协议,也可以使用udp协议,但是下面的语句还是
     * 只会返回其中一项的值,指定getservbyname()函数的第二个参数为NULL,并
     * 不会两个echo服务 (使用tcp协议的echo和使用udp协议的echo).
     */
    printf("========= getservbyname: name --> echo, proto --> NULL\n");
    if ((serv = getservbyname("echo", NULL)) != NULL)
        printservent(serv);

    printf("========= getservbyprot: port --> 80, proto --> tcp\n");
    port = htons(80);
    printf("port: host 80 --> network is: %#x\n", port);
    if ((serv = getservbyport(port, "tcp")) != NULL)
        printservent(serv);

    printf("========= setservent() =========\n");
    if ((serv = getservent()) != NULL)
        printservent(serv);
    setservent(0);

    printf("========= after setservent() =========\n");
    for (i = 0; i < 2; ++i)
        if ((serv = getservent()) != NULL)
            printservent(serv);
    endservent();

    return 0;
}
Пример #11
0
struct servent *
getservbyport(int port, const char *proto)
{
    register struct servent *p;

    setservent(_serv_stayopen);
    while (p = getservent()) {
        if (p->s_port != port)
            continue;
        if (proto == 0 || strcmp(p->s_proto, proto) == 0)
            break;
    }
    if (!_serv_stayopen)
        endservent();
    return (p);
}
Пример #12
0
static int
servent_fill_test_data(struct servent_test_data *td)
{
	struct servent *serv;
		
	setservent(1);
	while ((serv = getservent()) != NULL) {
		if (servent_test_correctness(serv, NULL) == 0)
			TEST_DATA_APPEND(servent, td, serv);
		else
			return (-1);
	}
	endservent();
	
	return (0);
}
Пример #13
0
static int
services_mp_lookup_func(char **buffer, size_t *buffer_size, void *mdata)
{
	struct servent *result;

	TRACE_IN(services_mp_lookup_func);
	result = getservent();
	if (result != NULL) {
		services_marshal_func(result, NULL, buffer_size);
		*buffer = malloc(*buffer_size);
		assert(*buffer != NULL);
		services_marshal_func(result, *buffer, buffer_size);
	}

	TRACE_OUT(services_mp_lookup_func);
	return (result == NULL ? NS_NOTFOUND : NS_SUCCESS);
}
Пример #14
0
struct servent *
getservent_r (struct servent *result, char *buffer, int buflen)
{
  struct servent *ret;

  pthread_mutex_lock (&getservby_mutex);

  ret = getservent ();
  if (!ret ||
       convert (ret, result, buffer, buflen) != 0)
  {
    result = NULL;
  }

  pthread_mutex_unlock (&getservby_mutex);
  return result;
}
Пример #15
0
int main (void) {
 struct servent *pht;
 char *pct;
 int i;

 setservent (1);

 while ((pht = getservent ()) != NULL) {
   printf ("Официальное имя сервиса: %s\n", pht->s_name);
   printf ("Альтернативные имена:\n");
   for (i = 0; (pct = pht->s_aliases [i]) != NULL; i++) {
     printf ("  %s\n", pct);
   }
   printf ("Номер порта: %d\n", ntohs ((in_port_t) pht->s_port));
   printf ("Имя протокола: %s\n\n", pht->s_proto);
 }

 if ((pht = getservbyport (htons ((in_port_t) 21), "udp")) != NULL) {
   printf ("Официальное имя сервиса: %s\n", pht->s_name);
   printf ("Альтернативные имена:\n");
   for (i = 0; (pct = pht->s_aliases [i]) != NULL; i++) {
     printf ("  %s\n", pct);
   }
   printf ("Номер порта: %d\n", ntohs ((in_port_t) pht->s_port));
   printf ("Имя протокола: %s\n\n", pht->s_proto);
 } else {
   perror ("GETSERVBYPORT");
 }

 if ((pht = getservbyport (htons ((in_port_t) 21), (char *) NULL)) != NULL) {
   printf ("Официальное имя сервиса: %s\n", pht->s_name);
   printf ("Альтернативные имена:\n");
   for (i = 0; (pct = pht->s_aliases [i]) != NULL; i++) {
     printf ("  %s\n", pct);
   }
   printf ("Номер порта: %d\n", ntohs ((in_port_t) pht->s_port));
   printf ("Имя протокола: %s\n\n", pht->s_proto);
 } else {
   perror ("GETSERVBYPORT");
 }

 endservent ();

 return 0;
}
Пример #16
0
void findservice(int port) {
  struct servent *sep;
  char **cpp;
  int hbo,found=0;
  setservent(1);
  while((sep=getservent())!=NULL) {
    hbo=ntohs(sep->s_port);
    if (hbo==port) {
      printf("%d/%s\t%s",hbo,sep->s_proto,sep->s_name);
      for(cpp=sep->s_aliases;*cpp;++cpp)
	printf(" %s",*cpp);
      putchar('\n');
      found=1;
    }
  }
  endservent();
  if (!found)
    fprintf(stderr,"%s: port %d has no name on this system.\n",progname,port);
} /* void findservice(int port) */
Пример #17
0
SERV_R_RETURN
getservent_r(struct servent *sptr, SERV_R_ARGS) {
	struct servent *se = getservent();
#ifdef SERV_R_SETANSWER
	int n = 0;
	
	if (se == NULL || (n = copy_servent(se, sptr, SERV_R_COPY)) != 0)
		*answerp = NULL;
	else
		*answerp = sptr;

	return (n);
#else
	if (se == NULL)
		return (SERV_R_BAD);

	return (copy_servent(se, sptr, SERV_R_COPY));
#endif
}
Пример #18
0
static void
test_services (void)
{
  struct servent *sptr;

  sptr = getservbyname ("domain", "tcp");
  output_servent ("getservbyname (\"domain\", \"tcp\")", sptr);

  sptr = getservbyname ("domain", "udp");
  output_servent ("getservbyname (\"domain\", \"udp\")", sptr);

  sptr = getservbyname ("domain", NULL);
  output_servent ("getservbyname (\"domain\", NULL)", sptr);

  sptr = getservbyname ("not-existant", NULL);
  output_servent ("getservbyname (\"not-existant\", NULL)", sptr);

  /* This shouldn't return anything.  */
  sptr = getservbyname ("", "");
  output_servent ("getservbyname (\"\", \"\")", sptr);

  sptr = getservbyname ("", "tcp");
  output_servent ("getservbyname (\"\", \"tcp\")", sptr);

  sptr = getservbyport (htons(53), "tcp");
  output_servent ("getservbyport (htons(53), \"tcp\")", sptr);

  sptr = getservbyport (htons(53), NULL);
  output_servent ("getservbyport (htons(53), NULL)", sptr);

  sptr = getservbyport (htons(1), "udp"); /* shouldn't exist */
  output_servent ("getservbyport (htons(1), \"udp\")", sptr);

  setservent (0);
  do
    {
      sptr = getservent ();
      output_servent ("getservent ()", sptr);
    }
  while (sptr != NULL);
  endservent ();
}
Пример #19
0
/*
 * getservbyname() - looks up a service by its name
 */
struct servent *getservbyname(const char *servname, const char *protname)
{
	struct servent *s = NULL;
	int found = false;

	ncbi_ClearErrno();

	if(servname == NULL){
		ncbi_SetErrno(EINVAL);
		goto abort;
	}
  
	if( (strcmp( protname, "tcp") != 0) && ( strcmp( protname, "udp") != 0)){
		ncbi_SetErrno(EINVAL);
		goto abort;
	}
  
	/* Make sure the database is closed */
	endservent();

	while(!found){
		s = getservent();  // get the next entry

		if(s == NULL){
			break;		// did we reach the end?  Guess we return NULL
		}
  	  
		// Do we have a match on the name?
		if(strcmp(s->s_name, servname) == 0){
			// If protocol is "any" or an exact match, then we're done
			if( (protname == NULL) || (strcmp(s->s_proto, protname) == 0)){
				found = true;
			}
  	    }
    }

abort:  
	endservent();
	return(s);
}
Пример #20
0
/*
 * services
 */
static int
services(int argc, char *argv[])
{
	struct servent	*se;
	unsigned long	id;
	char		*proto;
	int		i, rv;

	assert(argc > 1);
	assert(argv != NULL);

#define SERVICESPRINT	printfmtstrings(se->s_aliases, "  ", " ", \
			    "%-16s  %5d/%s", \
			    se->s_name, ntohs(se->s_port), se->s_proto)

	setservent(1);
	rv = RV_OK;
	if (argc == 2) {
		while ((se = getservent()) != NULL)
			SERVICESPRINT;
	} else {
		for (i = 2; i < argc; i++) {
			proto = strchr(argv[i], '/');
			if (proto != NULL)
				*proto++ = '\0';
			if (parsenum(argv[i], &id))
				se = getservbyport(htons((u_short)id), proto);
			else
				se = getservbyname(argv[i], proto);
			if (se != NULL)
				SERVICESPRINT;
			else {
				rv = RV_NOTFOUND;
				break;
			}
		}
	}
	endservent();
	return rv;
}
Пример #21
0
static int read_services(void)
{
    struct servent *se;
    struct protoent *pe;
    struct service *item;

    setservent(1);
    while ((se = getservent())) {
	/* Allocate a service entry. */
	item = (struct service *) xmalloc(sizeof(struct service));
	item->name = strdup(se->s_name);
	item->number = se->s_port;

	/* Fill it in. */
	if (!strcmp(se->s_proto, "tcp")) {
	    add2list(&tcp_name, item);
	} else if (!strcmp(se->s_proto, "udp")) {
	    add2list(&udp_name, item);
	} else if (!strcmp(se->s_proto, "sctp")) {
	    add2list(&sctp_name, item);
	} else if (!strcmp(se->s_proto, "raw")) {
	    add2list(&raw_name, item);
	} else { /* ddp, dccp */
	    free(item->name);
	    free(item);
	}
    }
    endservent();
    setprotoent(1);
    while ((pe = getprotoent())) {
	/* Allocate a service entry. */
	item = (struct service *) xmalloc(sizeof(struct service));
	item->name = strdup(pe->p_name);
	item->number = htons(pe->p_proto);
	add2list(&raw_name, item);
    }
    endprotoent();
    return (0);
}
Пример #22
0
struct servent *
getservbyname(const char *name, const char *proto)
{
	register struct servent *p;
	register char **cp;

	setservent(_serv_stayopen);
	while (p = getservent()) {
		if (strcmp(name, p->s_name) == 0)
			goto gotname;
		for (cp = p->s_aliases; *cp; cp++)
			if (strcmp(name, *cp) == 0)
				goto gotname;
		continue;
gotname:
		if (proto == 0 || strcmp(p->s_proto, proto) == 0)
			break;
	}
	if (!_serv_stayopen)
		endservent();
	return (p);
}
Пример #23
0
/*
 * getservbyport() - looks up a service by its port number
 */
struct servent *getservbyport(int port, const char *protname)
{
  struct servent *s = NULL;
  int found = false;
  
  ncbi_ClearErrno();
  
  if((strcmp(protname, "tcp") != 0) && (strcmp(protname, "udp") != 0))
    {
      ncbi_SetErrno(EINVAL);
      goto abort;
    }
  
  /* Make sure the database is closed */
  endservent();
  
  while(!found)
    {
  	  s = getservent();  /* get the next entry */
  	  
  	  /* did we reach the end?  Guess we return NULL */
  	  if(s == NULL)
  	    break;
  	  
  	  /* Do we have a match on the port? */
  	  if(s->s_port == port)
  	    {
  	      if(protname == NULL)
  	        found = true;  /* any protocol is okay */
  	      else
  	        if(strcmp(s->s_proto, protname) == 0)
  	          found = true;  /* protocol matches */
  	    }
    }

abort:  
  endservent();
  return(s);
}
Пример #24
0
struct servent *
getservbyname(
	const char *name, 
	const char *proto )
{
	register struct servent *p;
	register char **cp;

#ifdef YP
	extern char *___getservbyname_yp;
	extern char *___getservbyproto_yp;

	___getservbyname_yp = (char *)name;
	___getservbyproto_yp = (char *)proto;
#endif

	setservent(_serv_stayopen);
	while ( (p = getservent()) ) {
		if (strcmp(name, p->s_name) == 0)
			goto gotname;
		for (cp = p->s_aliases; *cp; cp++)
			if (strcmp(name, *cp) == 0)
				goto gotname;
		continue;
gotname:
		if (proto == 0 || strcmp(p->s_proto, proto) == 0)
			break;
	}
	if (!_serv_stayopen)
		endservent();

#ifdef YP
	___getservbyname_yp = NULL;
	___getservbyproto_yp = NULL;
#endif

	return (p);
}
Пример #25
0
_WCRTLINK struct servent *getservbyport( int port, const char *proto )
{
    struct servent *ret;

    if( port < 1 ) {
        _RWD_errno = EINVAL;
        return( NULL );
    }

    setservent( 1 );

    do {

        ret = getservent();

    } while( ret != NULL &&
             !( port == ret->s_port &&
               ( proto == NULL || SAFE_SAME_STR( proto, ret->s_proto ) ) ) );

    endservent();

    return( ret );
}
Пример #26
0
/**
 * @brief
 *	pbs_loadconf - Populate the pbs_conf structure
 *
 * @par
 *	Load the pbs_conf structure.  The variables can be filled in
 *	from either the environment or the pbs.conf file.  The
 *	environment gets priority over the file.  If any of the
 *	primary variables are not filled in, the function fails.
 *	Primary vars: pbs_home_path, pbs_exec_path, pbs_server_name
 *
 * @note
 *	Clients can now be multithreaded. So dont call pbs_loadconf with
 *	reload = TRUE. Currently, the code flow ensures that the configuration
 *	is loaded only once (never used with reload true). Thus in the rest of
 *	the code a direct read of the pbs_conf.variables is fine. There is no
 *	race of access of pbs_conf vars against the loading of pbs_conf vars.
 *	However, if pbs_loadconf is called with reload = TRUE, this assumption
 *	will be void. In that case, access to every pbs_conf.variable has to be
 *	synchronized against the reload of those variables.
 *
 * @param[in] reload		Whether to attempt a reload
 *
 * @return int
 * @retval 1 Success
 * @retval 0 Failure
 */
int
pbs_loadconf(int reload)
{
	FILE *fp;
	char buf[256];
	char *conf_name; 		/* the name of the conf parameter */
	char *conf_value;		/* the value from the conf file or env*/
	char *gvalue;			/* used with getenv() */
	unsigned int uvalue;		/* used with sscanf() */
#ifndef WIN32
	struct servent *servent;	/* for use with getservent */
	char **servalias;		/* service alias list */
	unsigned int *pui;		/* for use with identify_service_entry */
#endif

	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return 0;

	/* this section of the code modified the procecss-wide
	 * tcp array. Since multiple threads can get into this
	 * simultaneously, we need to serialize it
	 */
	if (pbs_client_thread_lock_conf() != 0)
		return 0;

	if (pbs_conf.loaded && !reload) {
		(void)pbs_client_thread_unlock_conf();
		return 1;
	}
	else if (pbs_conf.load_failed && !reload) {
		(void)pbs_client_thread_unlock_conf();
		return 0;
	}

	/*
	 * If there are service port definitions available, use them
	 * as the defaults. They may be overridden later by the config
	 * file or environment variables. If not available, retain
	 * whatever we were using before.
	 */
#ifdef WIN32
	/* Windows does not have the getservent() call. */
	pbs_conf.batch_service_port = get_svrport(
		PBS_BATCH_SERVICE_NAME, "tcp",
		pbs_conf.batch_service_port);
	pbs_conf.batch_service_port_dis = get_svrport(
		PBS_BATCH_SERVICE_NAME_DIS, "tcp",
		pbs_conf.batch_service_port_dis);
	pbs_conf.mom_service_port = get_svrport(
		PBS_MOM_SERVICE_NAME, "tcp",
		pbs_conf.mom_service_port);
	pbs_conf.manager_service_port = get_svrport(
		PBS_MANAGER_SERVICE_NAME, "tcp",
		pbs_conf.manager_service_port);
	pbs_conf.scheduler_service_port = get_svrport(
		PBS_SCHEDULER_SERVICE_NAME, "tcp",
		pbs_conf.scheduler_service_port);
	pbs_conf.pbs_data_service_port = get_svrport(
		PBS_DATA_SERVICE_NAME, "tcp",
		pbs_conf.pbs_data_service_port);
#else
	/* Non-Windows uses getservent() for better performance. */
	while ((servent = getservent()) != NULL) {
		if (strcmp(servent->s_proto, "tcp") != 0)
			continue;
		/* First, check the official service name. */
		pui = identify_service_entry(servent->s_name);
		if (pui != NULL) {
			*pui = (unsigned int)ntohs(servent->s_port);
			continue;
		}
		/* Next, check any aliases that may be defined. */
		for (servalias = servent->s_aliases; (servalias != NULL) && (*servalias != NULL); servalias++) {
			pui = identify_service_entry(*servalias);
			if (pui != NULL) {
				*pui = (unsigned int)ntohs(servent->s_port);
				break;
			}
		}
	}
	endservent();
#endif

	/*
	 * Once we determine the location of the pbs.conf file, it never changes.
	 * The fact that it is saved to the pbs_conf global structure means that
	 * we can always see its location when debugging.
	 */
	if (pbs_conf.pbs_conf_file == NULL)
		pbs_conf.pbs_conf_file = pbs_get_conf_file();

	/*
	 * Parse through the configuration file and set variables based
	 * on the contents of the file.
	 */
	if ((fp = fopen(pbs_conf.pbs_conf_file, "r")) != NULL) {
		while (parse_config_line(fp, &conf_name, &conf_value) != NULL) {
			if ((conf_name == NULL) || (*conf_name == '\0'))
				continue;

			if (!strcmp(conf_name, PBS_CONF_START_SERVER)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.start_server = ((uvalue > 0) ? 1 : 0);
			}
			else if (!strcmp(conf_name, PBS_CONF_START_MOM)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.start_mom = ((uvalue > 0) ? 1 : 0);
			}
			else if (!strcmp(conf_name, PBS_CONF_START_SCHED)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.start_sched = ((uvalue > 0) ? 1 : 0);
			}
			else if (!strcmp(conf_name, PBS_CONF_START_COMM)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.start_comm = ((uvalue > 0) ? 1 : 0);
			}
			else if (!strcmp(conf_name, PBS_CONF_LOCALLOG)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.locallog = ((uvalue > 0) ? 1 : 0);
			}
			else if (!strcmp(conf_name, PBS_CONF_SYSLOG)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.syslogfac = ((uvalue <= (23<<3)) ? uvalue : 0);
			}
			else if (!strcmp(conf_name, PBS_CONF_SYSLOGSEVR)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.syslogsvr = ((uvalue <= 7) ? uvalue : 0);
			}
			else if (!strcmp(conf_name, PBS_CONF_BATCH_SERVICE_PORT)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.batch_service_port =
						((uvalue <= 65535) ? uvalue : pbs_conf.batch_service_port);
			}
			else if (!strcmp(conf_name, PBS_CONF_BATCH_SERVICE_PORT_DIS)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.batch_service_port_dis =
						((uvalue <= 65535) ? uvalue : pbs_conf.batch_service_port_dis);
			}
			else if (!strcmp(conf_name, PBS_CONF_MOM_SERVICE_PORT)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.mom_service_port =
						((uvalue <= 65535) ? uvalue : pbs_conf.mom_service_port);
			}
			else if (!strcmp(conf_name, PBS_CONF_MANAGER_SERVICE_PORT)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.manager_service_port =
						((uvalue <= 65535) ? uvalue : pbs_conf.manager_service_port);
			}
			else if (!strcmp(conf_name, PBS_CONF_SCHEDULER_SERVICE_PORT)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.scheduler_service_port =
						((uvalue <= 65535) ? uvalue : pbs_conf.scheduler_service_port);
			}
			else if (!strcmp(conf_name, PBS_CONF_DATA_SERVICE_PORT)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.pbs_data_service_port =
						((uvalue <= 65535) ? uvalue : pbs_conf.pbs_data_service_port);
			}
			else if (!strcmp(conf_name, PBS_CONF_DATA_SERVICE_HOST)) {
				free(pbs_conf.pbs_data_service_host);
				pbs_conf.pbs_data_service_host = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_USE_TCP)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.pbs_use_tcp = ((uvalue > 0) ? 1 : 0);
			}
			else if (!strcmp(conf_name, PBS_CONF_USE_COMPRESSION)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.pbs_use_compression = ((uvalue > 0) ? 1 : 0);
			}
			else if (!strcmp(conf_name, PBS_CONF_USE_MCAST)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.pbs_use_mcast = ((uvalue > 0) ? 1 : 0);
			}
			else if (!strcmp(conf_name, PBS_CONF_FORCE_FT_COMM)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.pbs_use_ft = ((uvalue > 0) ? 1 : 0);
			}
			else if (!strcmp(conf_name, PBS_CONF_LEAF_NAME)) {
				if (pbs_conf.pbs_leaf_name)
					free(pbs_conf.pbs_leaf_name);
				pbs_conf.pbs_leaf_name = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_LEAF_ROUTERS)) {
				if (pbs_conf.pbs_leaf_routers)
					free(pbs_conf.pbs_leaf_routers);
				pbs_conf.pbs_leaf_routers = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_COMM_NAME)) {
				if (pbs_conf.pbs_comm_name)
					free(pbs_conf.pbs_comm_name);
				pbs_conf.pbs_comm_name = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_COMM_ROUTERS)) {
				if (pbs_conf.pbs_comm_routers)
					free(pbs_conf.pbs_comm_routers);
				pbs_conf.pbs_comm_routers = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_COMM_THREADS)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.pbs_comm_threads = uvalue;
			}
			else if (!strcmp(conf_name, PBS_CONF_COMM_LOG_EVENTS)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.pbs_comm_log_events = uvalue;
			}
			else if (!strcmp(conf_name, PBS_CONF_HOME)) {
				free(pbs_conf.pbs_home_path);
				pbs_conf.pbs_home_path = shorten_and_cleanup_path(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_EXEC)) {
				free(pbs_conf.pbs_exec_path);
				pbs_conf.pbs_exec_path = shorten_and_cleanup_path(conf_value);
			}
			/* Check for PBS_DEFAULT for backward compatibility */
			else if (!strcmp(conf_name, PBS_CONF_DEFAULT_NAME)) {
				free(pbs_conf.pbs_server_name);
				pbs_conf.pbs_server_name = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_SERVER_NAME)) {
				free(pbs_conf.pbs_server_name);
				pbs_conf.pbs_server_name = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_RCP)) {
				free(pbs_conf.rcp_path);
				pbs_conf.rcp_path = shorten_and_cleanup_path(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_SCP)) {
				free(pbs_conf.scp_path);
				pbs_conf.scp_path = shorten_and_cleanup_path(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_K5DCELOGIN)) {
				free(pbs_conf.k5dcelogin_path);
				pbs_conf.k5dcelogin_path = shorten_and_cleanup_path(conf_value);
			}
			/* rcp_path can be inferred from pbs_conf.pbs_exec_path - see below */
			/* pbs_demux_path is inferred from pbs_conf.pbs_exec_path - see below */
			else if (!strcmp(conf_name, PBS_CONF_ENVIRONMENT)) {
				free(pbs_conf.pbs_environment);
				pbs_conf.pbs_environment = shorten_and_cleanup_path(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_PRIMARY)) {
				free(pbs_conf.pbs_primary);
				pbs_conf.pbs_primary = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_SECONDARY)) {
				free(pbs_conf.pbs_secondary);
				pbs_conf.pbs_secondary = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_MOM_HOME)) {
				free(pbs_conf.pbs_mom_home);
				pbs_conf.pbs_mom_home = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_CORE_LIMIT)) {
				free(pbs_conf.pbs_core_limit);
				pbs_conf.pbs_core_limit = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_LICENSE_STRING)) {
				free(pbs_conf.pbs_license_file_location);
				pbs_conf.pbs_license_file_location = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_SERVER_HOST_NAME)) {
				free(pbs_conf.pbs_server_host_name);
				pbs_conf.pbs_server_host_name = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_PUBLIC_HOST_NAME)) {
				free(pbs_conf.pbs_public_host_name);
				pbs_conf.pbs_public_host_name = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_MAIL_HOST_NAME)) {
				free(pbs_conf.pbs_mail_host_name);
				pbs_conf.pbs_mail_host_name = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_SMTP_SERVER_NAME)) {
				free(pbs_conf.pbs_smtp_server_name);
				pbs_conf.pbs_smtp_server_name = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_OUTPUT_HOST_NAME)) {
				free(pbs_conf.pbs_output_host_name);
				pbs_conf.pbs_output_host_name = strdup(conf_value);
			}
			else if (!strcmp(conf_name, PBS_CONF_SCHEDULER_MODIFY_EVENT)) {
				if (sscanf(conf_value, "%u", &uvalue) == 1)
					pbs_conf.sched_modify_event = ((uvalue > 0) ? 1 : 0);
			}
			else if (!strcmp(conf_name, PBS_CONF_MOM_NODE_NAME)) {
				free(pbs_conf.pbs_mom_node_name);
				pbs_conf.pbs_mom_node_name = strdup(conf_value);
			}
#ifdef WIN32
			else if (!strcmp(conf_name, PBS_CONF_REMOTE_VIEWER)) {
				free(pbs_conf.pbs_conf_remote_viewer);
				pbs_conf.pbs_conf_remote_viewer = strdup(conf_value);
			}
#endif
#ifndef WIN32
			else if (!strcmp(conf_name, PBS_CONF_AUTH)) {
				if (!strcasecmp(conf_value, "MUNGE")) {
				   pbs_conf.auth_method = AUTH_MUNGE;
				} else {
					fprintf(stderr, "pbsconf error: illegal value for %s\n",PBS_CONF_AUTH);
					goto err;
				}
			}
#endif
			/* iff_path is inferred from pbs_conf.pbs_exec_path - see below */
		}
		fclose(fp);
		free(pbs_loadconf_buf);
		pbs_loadconf_buf = NULL;
		pbs_loadconf_len = 0;
	}

	/*
	 * Next, check the environment variables and set values accordingly
	 * overriding those that were set in the configuration file.
	 */

	if ((gvalue = getenv(PBS_CONF_START_SERVER)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.start_server = ((uvalue > 0) ? 1 : 0);
	}
	if ((gvalue = getenv(PBS_CONF_START_MOM)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.start_mom = ((uvalue > 0) ? 1 : 0);
	}
	if ((gvalue = getenv(PBS_CONF_START_SCHED)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.start_sched = ((uvalue > 0) ? 1 : 0);
	}
	if ((gvalue = getenv(PBS_CONF_START_COMM)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.start_comm = ((uvalue > 0) ? 1 : 0);
	}
	if ((gvalue = getenv(PBS_CONF_LOCALLOG)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.locallog = ((uvalue > 0) ? 1 : 0);
	}
	if ((gvalue = getenv(PBS_CONF_SYSLOG)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.syslogfac = ((uvalue <= (23<<3)) ? uvalue : 0);
	}
	if ((gvalue = getenv(PBS_CONF_SYSLOGSEVR)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.syslogsvr = ((uvalue <= 7) ? uvalue : 0);
	}
	if ((gvalue = getenv(PBS_CONF_BATCH_SERVICE_PORT)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.batch_service_port =
				((uvalue <= 65535) ? uvalue : pbs_conf.batch_service_port);
	}
	if ((gvalue = getenv(PBS_CONF_BATCH_SERVICE_PORT_DIS)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.batch_service_port_dis =
				((uvalue <= 65535) ? uvalue : pbs_conf.batch_service_port_dis);
	}
	if ((gvalue = getenv(PBS_CONF_MOM_SERVICE_PORT)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.mom_service_port =
				((uvalue <= 65535) ? uvalue : pbs_conf.mom_service_port);
	}
	if ((gvalue = getenv(PBS_CONF_MANAGER_SERVICE_PORT)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.manager_service_port =
				((uvalue <= 65535) ? uvalue : pbs_conf.manager_service_port);
	}
	if ((gvalue = getenv(PBS_CONF_SCHEDULER_SERVICE_PORT)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.scheduler_service_port =
				((uvalue <= 65535) ? uvalue : pbs_conf.scheduler_service_port);
	}
	if ((gvalue = getenv(PBS_CONF_HOME)) != NULL) {
		free(pbs_conf.pbs_home_path);
		pbs_conf.pbs_home_path = shorten_and_cleanup_path(gvalue);
	}
	if ((gvalue = getenv(PBS_CONF_EXEC)) != NULL) {
		free(pbs_conf.pbs_exec_path);
		pbs_conf.pbs_exec_path = shorten_and_cleanup_path(gvalue);
	}
	/* Check for PBS_DEFAULT for backward compatibility */
	if ((gvalue = getenv(PBS_CONF_DEFAULT_NAME)) != NULL) {
		free(pbs_conf.pbs_server_name);
		if ((pbs_conf.pbs_server_name = strdup(gvalue)) == NULL) {
			goto err;
		}
	}
	if ((gvalue = getenv(PBS_CONF_SERVER_NAME)) != NULL) {
		free(pbs_conf.pbs_server_name);
		if ((pbs_conf.pbs_server_name = strdup(gvalue)) == NULL) {
			goto err;
		}
	}
	if ((gvalue = getenv(PBS_CONF_RCP)) != NULL) {
		free(pbs_conf.rcp_path);
		pbs_conf.rcp_path = shorten_and_cleanup_path(gvalue);
	}
	if ((gvalue = getenv(PBS_CONF_SCP)) != NULL) {
		free(pbs_conf.scp_path);
		pbs_conf.scp_path = shorten_and_cleanup_path(gvalue);
	}
	if ((gvalue = getenv(PBS_CONF_K5DCELOGIN)) != NULL) {
		free(pbs_conf.k5dcelogin_path);
		pbs_conf.k5dcelogin_path = shorten_and_cleanup_path(gvalue);
	}
	if ((gvalue = getenv(PBS_CONF_PRIMARY)) != NULL) {
		free(pbs_conf.pbs_primary);
		if ((pbs_conf.pbs_primary = strdup(gvalue)) == NULL) {
			goto err;
		}
	}
	if ((gvalue = getenv(PBS_CONF_SECONDARY)) != NULL) {
		free(pbs_conf.pbs_secondary);
		if ((pbs_conf.pbs_secondary = strdup(gvalue)) == NULL) {
			goto err;
		}
	}
	if ((gvalue = getenv(PBS_CONF_MOM_HOME)) != NULL) {
		free(pbs_conf.pbs_mom_home);
		if ((pbs_conf.pbs_mom_home = strdup(gvalue)) == NULL) {
			goto err;
		}
	}
	if ((gvalue = getenv(PBS_CONF_CORE_LIMIT)) != NULL) {
		free(pbs_conf.pbs_core_limit);
		if ((pbs_conf.pbs_core_limit = strdup(gvalue)) == NULL) {
			goto err;
		}
	}
	if ((gvalue = getenv(PBS_CONF_DATA_SERVICE_HOST)) != NULL) {
		free(pbs_conf.pbs_data_service_host);
		if ((pbs_conf.pbs_data_service_host = strdup(gvalue)) == NULL) {
			goto err;
		}
	}
	if ((gvalue = getenv(PBS_CONF_USE_TCP)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.pbs_use_tcp = ((uvalue > 0) ? 1 : 0);
	}
	if ((gvalue = getenv(PBS_CONF_USE_COMPRESSION)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.pbs_use_compression = ((uvalue > 0) ? 1 : 0);
	}
	if ((gvalue = getenv(PBS_CONF_USE_MCAST)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.pbs_use_mcast = ((uvalue > 0) ? 1 : 0);
	}
	if ((gvalue = getenv(PBS_CONF_FORCE_FT_COMM)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.pbs_use_ft = ((uvalue > 0) ? 1 : 0);
	}
	if ((gvalue = getenv(PBS_CONF_LEAF_NAME)) != NULL) {
		if (pbs_conf.pbs_leaf_name)
			free(pbs_conf.pbs_leaf_name);
		pbs_conf.pbs_leaf_name = strdup(gvalue);
	}
	if ((gvalue = getenv(PBS_CONF_LEAF_ROUTERS)) != NULL) {
		if (pbs_conf.pbs_leaf_routers)
			free(pbs_conf.pbs_leaf_routers);
		pbs_conf.pbs_leaf_routers = strdup(gvalue);
	}
	if ((gvalue = getenv(PBS_CONF_COMM_NAME)) != NULL) {
		if (pbs_conf.pbs_comm_name)
			free(pbs_conf.pbs_comm_name);
		pbs_conf.pbs_comm_name = strdup(gvalue);
	}
	if ((gvalue = getenv(PBS_CONF_COMM_ROUTERS)) != NULL) {
		if (pbs_conf.pbs_comm_routers)
			free(pbs_conf.pbs_comm_routers);
		pbs_conf.pbs_comm_routers = strdup(gvalue);
	}
	if ((gvalue = getenv(PBS_CONF_COMM_THREADS)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.pbs_comm_threads = uvalue;
	}
	if ((gvalue = getenv(PBS_CONF_COMM_LOG_EVENTS)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.pbs_comm_log_events = uvalue;
	}
	if ((gvalue = getenv(PBS_CONF_DATA_SERVICE_PORT)) != NULL) {
		if (sscanf(gvalue, "%u", &uvalue) == 1)
			pbs_conf.pbs_data_service_port =
				((uvalue <= 65535) ? uvalue : pbs_conf.pbs_data_service_port);
	}
	if ((gvalue = getenv(PBS_CONF_SERVER_HOST_NAME)) != NULL) {
		free(pbs_conf.pbs_server_host_name);
		pbs_conf.pbs_server_host_name = strdup(gvalue);
	}
	if ((gvalue = getenv(PBS_CONF_PUBLIC_HOST_NAME)) != NULL) {
		free(pbs_conf.pbs_public_host_name);
		pbs_conf.pbs_public_host_name = strdup(gvalue);
	}
	if ((gvalue = getenv(PBS_CONF_MAIL_HOST_NAME)) != NULL) {
		free(pbs_conf.pbs_mail_host_name);
		pbs_conf.pbs_mail_host_name = strdup(gvalue);
	}
	if ((gvalue = getenv(PBS_CONF_SMTP_SERVER_NAME)) != NULL) {
		free(pbs_conf.pbs_smtp_server_name);
		pbs_conf.pbs_smtp_server_name = strdup(gvalue);
	}
	if ((gvalue = getenv(PBS_CONF_OUTPUT_HOST_NAME)) != NULL) {
		free(pbs_conf.pbs_output_host_name);
		pbs_conf.pbs_output_host_name = strdup(gvalue);
	}

	/* support PBS_MOM_NODE_NAME to tell MOM natural node name on server */
	if ((gvalue = getenv(PBS_CONF_MOM_NODE_NAME)) != NULL) {
		free(pbs_conf.pbs_mom_node_name);
		pbs_conf.pbs_mom_node_name = strdup(gvalue);
	}

	/* rcp_path is inferred from pbs_conf.pbs_exec_path - see below */
	/* pbs_demux_path is inferred from pbs_conf.pbs_exec_path - see below */
	if ((gvalue = getenv(PBS_CONF_ENVIRONMENT)) != NULL) {
		free(pbs_conf.pbs_environment);
		pbs_conf.pbs_environment = shorten_and_cleanup_path(gvalue);
	}

#ifdef WIN32
	if ((gvalue = getenv(PBS_CONF_REMOTE_VIEWER)) != NULL) {
		free(pbs_conf.pbs_conf_remote_viewer);
		pbs_conf.pbs_conf_remote_viewer = strdup(gvalue);
	}
	
#endif

	/* iff_path is inferred from pbs_conf.pbs_exec_path - see below */

	/*
	 * Now that we have parsed through the configuration file and the
	 * environment variables, check to make sure that all the critical
	 * items are set.
	 */

	buf[0] = '\0';
	if (pbs_conf.pbs_home_path == NULL)
		sprintf(buf, "%s %s", buf, PBS_CONF_HOME);
	if (pbs_conf.pbs_exec_path == NULL)
		sprintf(buf, "%s %s", buf, PBS_CONF_EXEC);
	if (pbs_conf.pbs_server_name == NULL)
		sprintf(buf, "%s %s", buf, PBS_CONF_SERVER_NAME);
	if (buf[0] != '\0') {
		fprintf(stderr, "pbsconf error: pbs conf variables not found: %s\n", buf);
		goto err;
	}

	/*
	 * Perform sanity checks on PBS_*_HOST_NAME values and PBS_CONF_SMTP_SERVER_NAME.
	 * See IDD for SPID 4534.
	 */
	buf[0] = '\0';
	if ((pbs_conf.pbs_server_host_name != NULL) &&
			(strchr(pbs_conf.pbs_server_host_name, ':') != NULL))
		strcpy(buf, PBS_CONF_SERVER_HOST_NAME);
	else if ((pbs_conf.pbs_public_host_name != NULL) &&
			(strchr(pbs_conf.pbs_public_host_name, ':') != NULL))
		strcpy(buf, PBS_CONF_PUBLIC_HOST_NAME);
	else if ((pbs_conf.pbs_mail_host_name != NULL) &&
			(strchr(pbs_conf.pbs_mail_host_name, ':') != NULL))
		strcpy(buf, PBS_CONF_MAIL_HOST_NAME);
	else if ((pbs_conf.pbs_smtp_server_name != NULL) &&
			(strchr(pbs_conf.pbs_smtp_server_name, ':') != NULL))
		strcpy(buf, PBS_CONF_SMTP_SERVER_NAME);
	else if ((pbs_conf.pbs_output_host_name != NULL) &&
			(strchr(pbs_conf.pbs_output_host_name, ':') != NULL))
		strcpy(buf, PBS_CONF_OUTPUT_HOST_NAME);
	else if ((pbs_conf.pbs_mom_node_name != NULL) &&
			(strchr(pbs_conf.pbs_mom_node_name, ':') != NULL))
		strcpy(buf, PBS_CONF_MOM_NODE_NAME);

	if (buf[0] != '\0') {
		fprintf(stderr, "pbsconf error: illegal value for: %s\n", buf);
		goto err;
	}

	/*
	 * Finally, fill in the blanks for variables with inferred values.
	 */

	if (pbs_conf.pbs_environment == NULL) {
		/* a reasonable default for the pbs_environment file is in pbs_home */
		/* strlen("/pbs_environment") + '\0' == 16 + 1 == 17 */
		if ((pbs_conf.pbs_environment =
			malloc(strlen(pbs_conf.pbs_home_path) + 17)) != NULL) {
			sprintf(pbs_conf.pbs_environment, "%s/pbs_environment",
				pbs_conf.pbs_home_path);
#ifdef WIN32
			back2forward_slash(pbs_conf.pbs_environment);
#endif
		} else {
			goto err;
		}
	}

	free(pbs_conf.iff_path);
	/* strlen("/sbin/pbs_iff") + '\0' == 13 + 1 == 14 */
	if ((pbs_conf.iff_path =
		malloc(strlen(pbs_conf.pbs_exec_path) + 14)) != NULL) {
		sprintf(pbs_conf.iff_path, "%s/sbin/pbs_iff", pbs_conf.pbs_exec_path);
#ifdef WIN32
		back2forward_slash(pbs_conf.iff_path);
#endif
	} else {
		goto err;
	}

	if (pbs_conf.rcp_path == NULL) {
		if ((pbs_conf.rcp_path =
			malloc(strlen(pbs_conf.pbs_exec_path) + 14)) != NULL) {
			sprintf(pbs_conf.rcp_path, "%s/sbin/pbs_rcp", pbs_conf.pbs_exec_path);
#ifdef WIN32
			back2forward_slash(pbs_conf.rcp_path);
#endif
		} else {
			goto err;
		}
	}

	free(pbs_conf.pbs_demux_path);
	/* strlen("/sbin/pbs_demux") + '\0' == 15 + 1 == 16 */
	if ((pbs_conf.pbs_demux_path =
		malloc(strlen(pbs_conf.pbs_exec_path) + 16)) != NULL) {
		sprintf(pbs_conf.pbs_demux_path, "%s/sbin/pbs_demux",
			pbs_conf.pbs_exec_path);
#ifdef WIN32
		back2forward_slash(pbs_conf.pbs_demux_path);
#endif
	} else {
		goto err;
	}

	if ((gvalue = getenv(PBS_CONF_LICENSE_STRING)) != NULL) {
		free(pbs_conf.pbs_license_file_location);
		if ((pbs_conf.pbs_license_file_location = strdup(gvalue)) == NULL) {
			goto err;
		}
	}

#ifndef WIN32
	if ((gvalue = getenv(PBS_CONF_AUTH)) != NULL) {
		if (!strcasecmp(gvalue, "MUNGE")) {
			pbs_conf.auth_method = AUTH_MUNGE;
		} else {
			fprintf(stderr, "pbsconf error: illegal value for %s\n",PBS_CONF_AUTH);
			goto err;
		}
	}
#endif

	pbs_conf.pbs_tmpdir = pbs_get_tmpdir();

	/* if routers has null value populate with server name as the default */
	if (pbs_conf.pbs_leaf_routers == NULL) {
		if (pbs_conf.pbs_primary && pbs_conf.pbs_secondary) {
			pbs_conf.pbs_leaf_routers = malloc(strlen(pbs_conf.pbs_primary) + strlen(pbs_conf.pbs_secondary) + 2);
			if (pbs_conf.pbs_leaf_routers == NULL) {
				fprintf(stderr, "Out of memory\n");
				goto err;
			}
			sprintf(pbs_conf.pbs_leaf_routers, "%s,%s", pbs_conf.pbs_primary, pbs_conf.pbs_secondary);
		} else {
			if (pbs_conf.pbs_server_host_name) {
				pbs_conf.pbs_leaf_routers = strdup(pbs_conf.pbs_server_host_name);
			} else if (pbs_conf.pbs_server_name) {
				pbs_conf.pbs_leaf_routers = strdup(pbs_conf.pbs_server_name);
			} else {
				fprintf(stderr, "PBS server undefined\n");
				goto err;
			}
			if (pbs_conf.pbs_leaf_routers == NULL) {
				fprintf(stderr, "Out of memory\n");
				goto err;
			}
		}
	}

	if (pbs_conf.pbs_use_tcp == 0) {
		pbs_conf.pbs_use_compression = 0;
		pbs_conf.pbs_use_mcast = 0;
		pbs_conf.pbs_use_ft = 0;
	}
	pbs_conf.loaded = 1;

	if (pbs_client_thread_unlock_conf() != 0)
		return 0;

	return 1;		/* success */

err:
	if (pbs_conf.pbs_conf_file) {
		free(pbs_conf.pbs_conf_file);
		pbs_conf.pbs_conf_file = NULL;
	}
	if (pbs_conf.pbs_data_service_host) {
		free(pbs_conf.pbs_data_service_host);
		pbs_conf.pbs_data_service_host = NULL;
	}
	if (pbs_conf.pbs_home_path) {
		free(pbs_conf.pbs_home_path);
		pbs_conf.pbs_home_path = NULL;
	}
	if (pbs_conf.pbs_exec_path) {
		free(pbs_conf.pbs_exec_path);
		pbs_conf.pbs_exec_path = NULL;
	}
	if (pbs_conf.pbs_server_name) {
		free(pbs_conf.pbs_server_name);
		pbs_conf.pbs_server_name = NULL;
	}
	if (pbs_conf.rcp_path) {
		free(pbs_conf.rcp_path);
		pbs_conf.rcp_path = NULL;
	}
	if (pbs_conf.scp_path) {
		free(pbs_conf.scp_path);
		pbs_conf.scp_path = NULL;
	}
	if (pbs_conf.k5dcelogin_path) {
		free(pbs_conf.k5dcelogin_path);
		pbs_conf.k5dcelogin_path = NULL;
	}
	if (pbs_conf.pbs_environment) {
		free(pbs_conf.pbs_environment);
		pbs_conf.pbs_environment = NULL;
	}
	if (pbs_conf.pbs_primary) {
		free(pbs_conf.pbs_primary);
		pbs_conf.pbs_primary = NULL;
	}
	if (pbs_conf.pbs_secondary) {
		free(pbs_conf.pbs_secondary);
		pbs_conf.pbs_secondary = NULL;
	}
	if (pbs_conf.pbs_mom_home) {
		free(pbs_conf.pbs_mom_home);
		pbs_conf.pbs_mom_home = NULL;
	}
	if (pbs_conf.pbs_core_limit) {
		free(pbs_conf.pbs_core_limit);
		pbs_conf.pbs_core_limit = NULL;
	}
	if (pbs_conf.pbs_license_file_location) {
		free(pbs_conf.pbs_license_file_location);
		pbs_conf.pbs_license_file_location = NULL;
	}

	pbs_conf.load_failed = 1;
	(void)pbs_client_thread_unlock_conf();
	return 0;
}
Пример #27
0
struct servent *
nw_getservent(void) 
{
    return (struct servent *) getservent();
}
Пример #28
0
/* ----------------------------- ports parsing ------------------------------ */
static int parse_ports(struct portinfo *pi, char *ports)
{
	char *args[32], *p = strdup(ports);
	int argc, j, i;

	if (!p) {
		fprintf(stderr, "Out of memory");
		return 1;
	}
	argc = strftok(",", ports, args, 32);
	for (j = 0; j < argc; j++) {
		int neg = 0;
		char *a = args[j];

		/* ports negation */
		if (a[0] == '!') {
			neg = 1;
			a++;
		}
		/* range */
		if (strchr(a, '-')) {
			char *range[2];
			int low, high;

			strftok("-", a, range, 2);
			if (!strisnum(range[0]) || !strisnum(range[1]))
				goto err; /* syntax error */
			low = strtol(range[0], NULL, 0);
			high = strtol(range[1], NULL, 0);
			if (low > high) {
				int t;
				t = high;
				high = low;
				low = t;
			}
			for (i = low; i <= high; i++)
				pi[i].active = !neg;
		/* all the ports */
		} else if (!strcmp(a, "all")) {
			for (i = 0; i <= MAXPORT; i++)
				pi[i].active = !neg;
		/* /etc/services ports */
		} else if (!strcmp(a, "known")) {
			struct servent *se;
			setservent(0);
			while((se = getservent()) != NULL) {
				int port = ntohs(se->s_port);
				if (port < 0 || port > MAXPORT)
					continue;
				pi[port].active = !neg;
			}
		/* a single port */
		} else {
			int port;
			if (!strisnum(a))
				goto err; /* syntax error */
			port = strtol(a, NULL, 0);
			if (port < 0 || port > MAXPORT)
				goto err; /* syntax error */
			pi[port].active = !neg;
		}
	}
	free(p);
	return 0;
err:
	free(p);
	return 1;
}