Exemple #1
0
const char	*_player_see(t_player *player, const t_server *server,
			     void *arg)
{
  unsigned int	i;
  unsigned int	index;
  char		*ret;

  (void)arg;
  ret = "";
  if (!player->is_allowed(player))
    return (NULL);
  i = 0;
  index = 0;
  while (i <= player->level)
    index += LVL_I(i++);
  i = 0;
  ret = my_concat(ret, "{", NULL);
  while (i < index)
    {
      ret = my_concat(ret, egalize(player, server, i), NULL);
      if (i != index - 1)
	ret = my_concat(ret, ",", NULL);
      i++;
    }
  ret = my_concat(ret, "}\n", NULL);
  return (ret);
}
Exemple #2
0
static char	*treat(t_square *sq, const t_server *server, int x, int y)
{
  char		*ret;
  e_ressource	type;

  type = 0;
  ret = "";
  while (type != EMPTY)
    {
      if (sq && sq->content[type] != 0)
	ret = my_concat(ret, " ", get_str(type), NULL);
      type++;
    }
  ret = my_concat(ret,
		  see_player(server,
			     ABS_X(x, server->game->world->width),
			     ABS_Y(y, server->game->world->height)), NULL);
  return (ret);
}
Exemple #3
0
static
const char	*see_player(const t_server *server, int x, int y)
{
  t_list	*tmp;
  char		*ret;

  ret = "";
  tmp = server->game->players;
  while (tmp)
    {
      if (((t_player *)tmp->data)->team &&
	  ((t_player *)tmp->data)->x == x &&
	  ((t_player *)tmp->data)->y == y)
	ret = my_concat(ret, " joueur", NULL);
      tmp = tmp->next;
    }
  return (ret);
}
Exemple #4
0
static char	*egalize(t_player *player, const t_server *server, int i)
{
  t_square	*sq;
  char		*ret;
  int		x;
  int		y;

  ret = "";
  x = player->x + vision[player->direction][i][0];
  y = player->y + vision[player->direction][i][1];
  sq =
    server->game->world->map->
    at(server->game->
       world->map, POS_LIST(ABS_X(x, server->game->
				  world->width),
			    ABS_Y(y, server->
				  game->world->
				  height),
			    server->game->world->width));
  ret = my_concat(ret, treat(sq, server, x, y), NULL);
  return (ret);
}
Exemple #5
0
int	token_replace_home(t_token **list, t_shell *sh)
{
  t_token	*tmp;
  char		*home;
  char		*replace;

  tmp = *list;
  home = explor_env(sh->env, "HOME");
  while (tmp)
    {
      if (tmp->type == WORD && tmp->value_type == STRING
  	  && tmp->value.str[0] == HOME_C)
  	{
  	  if ((replace = my_concat(home, &(tmp->value.str)[1])) == NULL)
	    return (EXIT_FAILURE);
  	  free(tmp->value.str);
  	  tmp->value.str = replace;
  	}
      tmp = tmp->next;
    }
  return (EXIT_SUCCESS);
}
Exemple #6
0
/* We have parsed a 'certif:' attribute from a 'key-cert' object.
 * Now perform the check to make sure the hexid specified in the
 * 'key-cert:' attribute matches the hexid from the 'certif:'
 * attribute.  We perform this check (and others) by adding the
 * 'certif:' attribute/PGP key block to a temp ring and parsing
 * the output from PGP.  Additionally, we check the following:
 *
 *  1. make sure there is only 1 hexid in the key
 *  2. make sure there is at least 1 owner/uid specified
 *  3. make sure we get a 'Successful' return string from PGP
 *  4. call get_fingerprint () to get the key fingerprint
 *     which checks to make sure there is only 1 fingerprint
 *
 * Return:
 *
 *    file name of key certificate file if there were no errors found
 *      - the file can then be used to easily add the PGP key to the
 *        local ring
 *      - the key fingerprint and owner(s)/uid(s) are saved to be
 *        used for the corresponding 'key-cert' auto-generated fields
 *    NULL otherwise
 */
char *hexid_check (parse_info_t *o) {
#ifdef PGP
  char pgpinfn[256], tmp_pgp_dir[256], ebuf[1024];
  FILE *pgpin;
  char_list_t *p;
  pgp_data_t pdat;
  int pgp_errors = 0, fd;
#endif

  /* If we don't have PGP installed then there is nothing to do. */
#ifndef PGP
    error_msg_queue (o, "PGP is not installed on the system.  Cannot perform operation.", ERROR_MSG);
    return NULL;
#else

  /* make a tmp directory for the pgp rings */
  umask (0022);
  strcpy (tmp_pgp_dir, "/var/tmp/pgp.XXXXXX");
  if (mkdtemp (tmp_pgp_dir) == NULL) {
    error_msg_queue (o, "Internal error.  Couldn't create temp directory for PGP\n", ERROR_MSG);
    return NULL;
  }

  /* create a file and put the key certificate into it */
  strcpy (pgpinfn, "/var/tmp/irrsyntax.XXXXXX");
  fd = mkstemp (pgpinfn);
  if ((pgpin = fdopen (fd, "w")) == NULL) {
    error_msg_queue (o, 
"Internal error.  Could not check 'key-cert:' temp file creation error", ERROR_MSG);
    goto pgp_errors_jump;
  }
  fwrite (o->u.kc.certif, sizeof (char), strlen (o->u.kc.certif), pgpin);
  fclose (pgpin);

  /* add the certificate to a temp ring */
  if (!pgp_add (default_trace, tmp_pgp_dir, pgpinfn, &pdat)) {
    error_msg_queue (o, "Couldn't add key-cert to ring.  Didn't get successful reply from PGP", ERROR_MSG);
    goto pgp_errors_jump;
  }

  /* certificate checks */

  /* do we have more than 1 hex ID? */
  if (pdat.hex_cnt > 1) {
    error_msg_queue (o, "Too many public keys in certificate", ERROR_MSG);
    pgp_errors = 1;
  }
  /* does the hex ID of the 'key-cert' attr match the certificate hex ID ? */
  else if (strcmp (pdat.hex_first->key, o->u.kc.kchexid)) {
    snprintf (ebuf, 1024, "Hex-ID mistmatch: 'key-cert:' (%s)  'certif:' (%s)\n",
	     o->u.kc.kchexid, pdat.hex_first->key);
    error_msg_queue (o, ebuf, ERROR_MSG);
    pgp_errors = 1;
  }
  /* owner check */
  else if (pdat.owner_first == NULL) {
    error_msg_queue (o, "No uid's/owners found in certificate", ERROR_MSG);
    pgp_errors = 1;
  }
  /* grab all the owners */
  else {
    o->u.kc.owner_count = pdat.owner_cnt;
    for (p = pdat.owner_first; p != NULL; p = p->next)
      o->u.kc.owner = my_concat (o->u.kc.owner, p->key, 0);
  }

  /* get the key fingerprint */
  if (!pgp_errors && 
      !get_fingerprint (o, tmp_pgp_dir, &pdat)) 
    pgp_errors = 1;

  if (o->u.kc.owner != NULL)
    if (verbose) fprintf (dfile, 
	     "owner count (%d) owner (%s)\n", o->u.kc.owner_count, o->u.kc.owner);
  if (o->u.kc.fingerpr != NULL)
    if (verbose) fprintf (dfile, "fingerpr (%s)\n", o->u.kc.fingerpr);

  /* end debug */

  /* clean up */
  pgp_free (&pdat);

  /* if we have errors then we won't need the key file */
  if (pgp_errors) {
pgp_errors_jump:
    rm_tmpdir (tmp_pgp_dir);  /* can get rid of temporary directory */
    remove (pgpinfn); 
    return NULL;
  }

  rm_tmpdir (tmp_pgp_dir);  /* can get rid of temporary directory */

  /* leave pgp key for possible addition to local ring */
  return strdup (pgpinfn);
#endif
}