Exemple #1
0
/**
 *
 * csv_find_string
 *
 * Search a csv list for an entry that matches a specified search string.
 */
char *
csv_find_string(const char *csv_str, const char *search_str)
  {
  int  i;
  int  nitems;
  int  search_length = 0;
  char *cp;

  if (!search_str)
    return(NULL);

  search_length = strlen(search_str);

  nitems = csv_length(csv_str);

  for (i = 0; i < nitems; i++)
    {
    cp = csv_nth(csv_str, i);

    if (cp)
      {
      while (isspace(*cp))
        cp++;

      if ((int)strlen(cp) >= search_length &&
          !isalpha(cp[search_length]) &&
          !strncmp(cp, search_str, search_length))
        {
        return(cp);
        }
      }
    }

  return(NULL);
  }
Exemple #2
0
char *pbs_fbserver(void)
  {
  char *cp;

  pbs_get_server_list();
  server_name[0] = 0;
  cp = csv_nth(server_list, 1); /* get the second item from list */

  if (cp)
    {
    strcpy(fb_server, cp);
    strcpy(server_name, cp);
    }

  return(server_name);
  }
Exemple #3
0
char *pbs_default(void)
  {
  char *cp;

  pbs_get_server_list();
  server_name[0] = 0;
  cp = csv_nth(server_list, 0); /* get the first item from list */

  if (cp)
    {
    strcpy(dflt_server, cp);
    strcpy(server_name, cp);
    }

  return(server_name);
  }
Exemple #4
0
char *pbs_fbserver(void)

  {
  char *cp;

  pbs_get_server_list();
  server_name[0] = 0;
  cp = csv_nth(server_list, 1); /* get the second item from list */

  if (cp)
    {
    snprintf(fb_server, sizeof(fb_server), "%s", cp);
    snprintf(server_name, sizeof(server_name), "%s", cp);
    }

  return(server_name);
  } /* END pbs_fbserver() */
Exemple #5
0
char *pbs_default(void)

  {
  char *cp;

  pbs_get_server_list();
  server_name[0] = '\0';
  cp = csv_nth(server_list, 0); /* get the first item from list */

  if (cp)
    {
    snprintf(dflt_server, sizeof(dflt_server), "%s", cp);
    snprintf(server_name, sizeof(server_name), "%s", cp);
    }

  return(server_name);
  } /* END pbs_default() */
int ck_checkpoint(

  pbs_attribute *pattr,
  void          *pobject, /* not used */
  int            mode) /* not used */

  {
  char *val;
  int field_count;
  int i;
  int len;
  char *str;

  val = pattr->at_val.at_str;

  if (val == NULL)
    {
    /* SUCCESS */

    return(0);
    }

  field_count = csv_length(val);

  for (i = 0; i < field_count; i++)
    {
    str = csv_nth(val, i);

    if (str)
      {
      if ((len = strlen(str)) > 0)
        {
        if (len == 1 && !((str[0] == 'n') || (str[0] == 's') || (str[0] == 'u')))
          {
          return(PBSE_BADATVAL);
          }
        else if (!strncmp(str, "c=", 2))
          {
          if (atoi(&str[2]) <= 0)
            {
            return(PBSE_BADATVAL);
            }

          continue;
          }
        else if (!strcmp(str, "none"))            {}
        else if (!strcmp(str, "periodic"))        {}
        else if (!strcmp(str, "shutdown"))        {}
        else if (!strcmp(str, "enabled"))       {}
        else if (!strncmp(str, "interval=", 9))    {}
        else if (!strncmp(str, "depth=", 6))       {}
        else if (!strncmp(str, "dir=", 4))         {}
        else
          {
          return(PBSE_BADATVAL);
          }
        }
      }
    }

  /* SUCCESS */

  return(0);
  }
Exemple #7
0
int pbs_connect(
    
  char *server_name_ptr)    /* I (optional) */

  {
  int connect = -1;
  int i, list_len;
  char server_name_list[PBS_MAXSERVERNAME*3+1];
  char current_name[PBS_MAXSERVERNAME+1];
  char *tp;

  memset(server_name_list, 0, sizeof(server_name_list));

  /* Use the list from the server_name file.
   * If a server name is passed in, append it at the beginning. */

  if (server_name_ptr && server_name_ptr[0])
    snprintf(server_name_list, sizeof(server_name_list), "%s", server_name_ptr);
  else
    snprintf(server_name_list, sizeof(server_name_list), "%s", pbs_get_server_list());

  if (getenv("PBSDEBUG"))
    fprintf(stderr, "pbs_connect using following server list \"%s\"\n",
        server_name_list);

  list_len = csv_length(server_name_list);

  for (i = 0; i < list_len; i++)  /* Try all server names in the list. */
    {
    tp = csv_nth(server_name_list, i);

    if (tp && tp[0])
      {
      /* Trim any leading space */
      while(isspace(*tp)) tp++;

      memset(current_name, 0, sizeof(current_name));
      snprintf(current_name, sizeof(current_name), "%s", tp);

      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "pbs_connect attempting connection to server \"%s\"\n",
                current_name);
        }

      if ((connect = pbs_original_connect(current_name)) >= 0)
        {
        if (getenv("PBSDEBUG"))
          {
          fprintf(stderr, "pbs_connect: Successful connection to server \"%s\", fd = %d\n", current_name, connect);
          }

        return(connect);  /* Success, we have a connection, return it. */
        }
      else
        print_server_port_to_stderr(current_name);
      }
    }

  return(connect);
  } /* END pbs_connect() */
Exemple #8
0
int pbs_connect(char *server_name_ptr)    /* I (optional) */
  {
  int connect = -1;
  int i, list_len;
  char server_name_list[PBS_MAXSERVERNAME*3+1];
  char current_name[PBS_MAXSERVERNAME+1];
  char *tp;

  memset(server_name_list, 0, sizeof(server_name_list));

  /* If a server name is passed in, use it, otherwise use the list from server_name file. */

  if (server_name_ptr && server_name_ptr[0])
    {
    strncpy(server_name_list, server_name_ptr, sizeof(server_name_list) - 1);

    if (getenv("PBSDEBUG"))
      {
      fprintf(stderr, "pbs_connect called with explicit server name \"%s\"\n",
        server_name_list);
      }
    }
  else
    {
    strncpy(server_name_list, pbs_get_server_list(), sizeof(server_name_list) - 1);

    if (getenv("PBSDEBUG"))
      {
      fprintf(stderr, "pbs_connect using default server name list \"%s\"\n",
        server_name_list);
      }
    }

  list_len = csv_length(server_name_list);

  for (i = 0; i < list_len; i++)  /* Try all server names in the list. */
    {
    tp = csv_nth(server_name_list, i);

    if (tp && tp[0])
      {
      memset(current_name, 0, sizeof(current_name));
      strncpy(current_name, tp, sizeof(current_name) - 1);

      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "pbs_connect attempting connection to server \"%s\"\n",
                current_name);
        }

      if ((connect = pbs_original_connect(current_name)) >= 0)
        {
        if (getenv("PBSDEBUG"))
          {
          fprintf(stderr, "pbs_connect: Successful connection to server \"%s\", fd = %d\n",
                  current_name, connect);
          }

        return(connect);  /* Success, we have a connection, return it. */
        }
      }
    }

  return(connect);
  }
Exemple #9
0
/* validate_server:
 *
 * This function tries to find the currently active
 * pbs_server. If no server can be found the default 
 * server is made the active server */ 
int validate_server(

  char  *active_server_name,
  int    t_server_port,
  char  *ssh_key,
  char **sign_key)

  {
  int rc = PBSE_NONE;
  int sd;
  char server_name_list[PBS_MAXSERVERNAME*3+1];
  char current_name[PBS_MAXSERVERNAME+1];
  char *tp;
  char  log_buf[LOCAL_LOG_BUF_SIZE];

  /* First we try to connect to the pbs_server as 
     indicated in active_server_name. If that fails
     we go through the server list. If that fails
     we stick with the active_server_name. If 
     another server in teh server_name_list responds 
     that will become the active_pbs_server */
  if (active_server_name != NULL)
    rc = trq_simple_connect(active_server_name, t_server_port, &sd);
  else
    rc = PBSE_UNKREQ; /* If we don't have a server name we want to process everyting. */

  if ( rc != PBSE_NONE)
    {
    int           list_len;
    int           i;
    unsigned int  port;
    char         *tmp_server;

    snprintf(server_name_list, sizeof(server_name_list), "%s", pbs_get_server_list());
    list_len = csv_length(server_name_list);

    for (i = 0; i < list_len; i++)  /* Try all server names in the list. */
      {
      tp = csv_nth(server_name_list, i);

      if (tp && tp[0])
        {
        /* Trim any leading space */
        while(isspace(*tp)) tp++; 
        
        memset(current_name, 0, sizeof(current_name));
        snprintf(current_name, sizeof(current_name), "%s", tp);

        if (getenv("PBSDEBUG"))
          {
          fprintf(stderr, "pbs_connect attempting connection to server \"%s\"\n", current_name);
          }

        tmp_server = PBS_get_server(current_name, &port);

        rc = trq_simple_connect(tmp_server, port, &sd);
        if ( rc == PBSE_NONE)
          {
          trq_simple_disconnect(sd);
          fprintf(stderr, "changing active server to %s port %d\n", tmp_server, port);
          snprintf(active_pbs_server, sizeof(active_pbs_server), "%s", tmp_server);
          active_pbs_server_port = port;
          sprintf(log_buf, "Changing active server to %s port %d\n", tmp_server, port);
          log_event(PBSEVENT_CLIENTAUTH | PBSEVENT_FORCE, PBS_EVENTCLASS_TRQAUTHD, __func__, log_buf);
          break;
          }
        }
      }
    }
  else
    trq_simple_disconnect(sd);

  if (rc != PBSE_NONE) /* This only indicates no server is currently active. Go to default */
    {
    fprintf(stderr, "Currently no servers active. Default server will be listed as active server. Error % d\n", rc);
    rc = PBSE_NONE;
    }

  fprintf(stderr, "Active server name: %s  pbs_server port is: %d\n", active_pbs_server, active_pbs_server_port);

  return(rc);
  } /* END validate_server() */