Ejemplo n.º 1
0
void			print_rep(t_op options)
{
	t_files		*tmp;
	int			len;
	t_op		o;

	tmp = options.files;
	len = 0;
	while (tmp != NULL)
	{
		if ((tmp->type == 0 || (tmp->type == 3 && options.flag == 0))
			&& (ft_strcmp(tmp->file_name, ".") != 0 || options.flag == 0)
			&& ft_strcmp(tmp->file_name, "..") != 0)
		{
			copy_options(&o, options, tmp->file_name);
			if (options.flag == 1 || count_files2(options) > 1)
				ft_printf("\n%s:\n", o.path);
			get_rep_files(o.path, &o);
			if (options.maj_r == 1)
			{
				print_rep(o);
				free_options(&o);
			}
		}
		tmp = tmp->next;
	}
}
Ejemplo n.º 2
0
static gboolean
handle_save_file (XdpFileChooser *object,
                  GDBusMethodInvocation *invocation,
                  const gchar *arg_parent_window,
                  const gchar *arg_title,
                  GVariant *arg_options)
{
  Request *request = request_from_invocation (invocation);
  const char *app_id = request->app_id;
  const gchar *sender = g_dbus_method_invocation_get_sender (invocation);
  g_autoptr(GError) error = NULL;
  g_autofree char *impl_handle = NULL;
  GVariantBuilder options;

  g_variant_builder_init (&options, G_VARIANT_TYPE_VARDICT);
  copy_options (arg_options, &options, save_file_options, G_N_ELEMENTS (save_file_options));

  if (!xdp_impl_file_chooser_call_save_file_sync (impl,
                                                  sender, app_id,
                                                  arg_parent_window,
                                                  arg_title,
                                                  g_variant_builder_end (&options),
                                                  &impl_handle,
                                                  NULL, &error))
    {
      g_dbus_method_invocation_return_gerror (invocation, error);
      return TRUE;
    }

  g_object_set_data_full (G_OBJECT (request), "impl-handle", g_strdup (impl_handle), g_free);
  register_handle (impl_handle, request);

  g_signal_connect (request, "handle-close", (GCallback)handle_close, request);

  REQUEST_AUTOLOCK (request);

  request_export (request, g_dbus_method_invocation_get_connection (invocation));

  xdp_file_chooser_complete_open_file (object, invocation, request->id);
  return TRUE;
}
Ejemplo n.º 3
0
/*
    Extern:     rm_sync_image_options
    Purpose:    Propagate ImageInfo values to the Image
    Ref:        SyncImageSettings (in mogrify.c)
*/
void rm_sync_image_options(Image *image, Info *info)
{
    MagickStatusType flags;
    GeometryInfo geometry_info;
    const char *option;

    // The option strings will be set only when their attribute values were
    // set in the optional argument block.
    option = GetImageOption(info,"background");
    if (option)
    {
        image->background_color = info->background_color;
    }

    option = GetImageOption(info,"bordercolor");
    if (option)
    {
        image->border_color = info->border_color;
    }

    if (info->colorspace != UndefinedColorspace)
    {
        image->colorspace = info->colorspace;
    }

    if (info->compression != UndefinedCompression)
    {
        image->compression = info->compression;
    }

    option = GetImageOption(info, "delay");
    if (option)
    {
        image->delay = strtoul(option, NULL, 0);
    }

    if (info->density)
    {
        flags = ParseGeometry(info->density, &geometry_info);
        image->x_resolution = geometry_info.rho;
        image->y_resolution = geometry_info.sigma;
        if ((flags & SigmaValue) == 0)
        {
            image->y_resolution = image->x_resolution;
        }
    }

    if (info->depth != 0)
    {
        image->depth = info->depth;
    }

    option = GetImageOption(info, "dispose");
    if (option)
    {
        image->dispose = rm_dispose_to_enum(option);
    }

    if (info->extract)
    {
        ParseAbsoluteGeometry(info->extract, &image->extract_info);
    }

    if (info->fuzz != 0.0)
    {
        image->fuzz = info->fuzz;
    }

    option = GetImageOption(info, "gravity");
    if (option)
    {
        image->gravity = rm_gravity_to_enum(option);
    }

    if (info->interlace != NoInterlace)
    {
        image->interlace = info->interlace;
    }

    option = GetImageOption(info,"mattecolor");
    if (option)
    {
        image->matte_color = info->matte_color;
    }

    if (info->orientation != UndefinedOrientation)
    {
        image->orientation = info->orientation;
    }

    if (info->page)
    {
        (void)ParseAbsoluteGeometry(info->page, &image->page);
    }

    if (info->quality != 0UL)
    {
        image->quality = info->quality;
    }

    option = GetImageOption(info, "scene");
    if (option)
    {
        image->scene = info->scene;
    }

    option = GetImageOption(info, "tile-offset");
    if (option)
    {
        (void)ParseAbsoluteGeometry(option, &image->tile_offset);
    }

    option = GetImageOption(info, "transparent");
    if (option)
    {
        image->transparent_color = info->transparent_color;
    }

#if defined(HAVE_ST_TYPE)
    if (info->type != UndefinedType)
    {
        image->type = info->type;
    }
#endif

    if (info->units != UndefinedResolution)
    {
        if (image->units != info->units)
        {
            switch (image->units)
            {
              case PixelsPerInchResolution:
              {
                if (info->units == PixelsPerCentimeterResolution)
                {
                    image->x_resolution /= 2.54;
                    image->y_resolution /= 2.54;
                }
                break;
              }
              case PixelsPerCentimeterResolution:
              {
                if (info->units == PixelsPerInchResolution)
                {
                    image->x_resolution *= 2.54;
                    image->y_resolution *= 2.54;
                }
                break;
              }
              default:
                break;
            }
        }

        image->units = info->units;
    }

#if defined(HAVE_SETIMAGEARTIFACT)
    copy_options(image, info);
#endif
}
Ejemplo n.º 4
0
int
copy_options(u_int8_t *inpacket, size_t *inpp, size_t inmax,
	     u_int8_t *outpacket, size_t *outpp, size_t outmax,
	     int copy_top,
	     int (*copy_pd)(u_int8_t *inpacket, size_t ia_data,
			    size_t *inpp, size_t inmax,
			    u_int8_t *outpacket, size_t *outpp, size_t outmax,
			    u_int32_t *validp, int *triplicate_maskp),
	     u_int32_t *validp, int *triplicate_maskp)
{
  OS_VARS;
  int rv;
  size_t outp = *outpp;
  int submax;

  size_t rmlp;
  int rmhl;
  
  /* OS_START sets up for the loop and begins the loop. */
  OS_START;

  /* We handle relay messages specially. */
  if (opcode == OPTION_RELAY_MSG)
    {
      /* We've already consumed the option header here. */
      inp += OPHDR_LEN;

      /* Only if we are copying top-level options, we copy the option
       * header of this option.
       */
      if (copy_top)
	{
	  /* Room? */
	  if (outmax - outp < OPHDR_LEN)
	    return -1;
	  ophdr_store(&outpacket[outp], OPTION_RELAY_MSG);
	  rmlp = outp + OPCODE_LEN;
	  outp += OPHDR_LEN;
	}
       
     /* Figure out how big the header inside the relay message option is. */
      if (inpacket[inp] == RELAY_REPLY)
	rmhl = RELAY_HEADER_SIZE;
      else
	rmhl = CLIENT_HEADER_SIZE;

      /* Copy it. */
      memcpy(&outpacket[outp], &inpacket[inp], rmhl);
      inp += rmhl;
      outp += rmhl;
	  
      /* The subcopy only gets the contents of the option, not the
       * whole packet.
       */
      submax = inp + oplen - rmhl;
      
      /* Recursively descend into the relay message, copying options.
       * If the copy fails, pass the return code up the chain.
       */
      rv = copy_options(inpacket, &inp, submax, outpacket, &outp, outmax,
			1, copy_pd, validp, triplicate_maskp);
      if (rv < 0)
	return rv;
      
      /* Store the length. */
      if (copy_top)
	ophdr_store(&outpacket[rmlp], rv + rmhl);
      
      /* If we are discarding top-level options, we can stop copying,
       * because there shouldn't be more than one Relay Message option
       * in a relay message.
       */
      else
	goto success;
    }
  else
    {
      /* We've already consumed the option header here. */
      inp += OPHDR_LEN;

      if (copy_top)
	{
	  /* No space? */
	  if (outmax - outp < oplen + OPHDR_LEN)
	    return -1;
	  /* Stash the option header. */
	  ophdr_store(&outpacket[outp], opcode);
	  ophdr_store(&outpacket[outp + OPCODE_LEN], oplen);
	  /* Copy the payload. */
	  memcpy(&outpacket[outp + OPHDR_LEN], &inpacket[inp], oplen);
	  outp += oplen + OPHDR_LEN;
	}
      inp += oplen;
    }

  OS_FINISH;

 success:
  /* Return value is the number of bytes copied. */
  rv = outp - *outpp;

  /* Update the caller's version of the input buffer and output buffer
   * pointers.
   */
  *inpp = inp;
  *outpp = outp;
  return rv;

}
Ejemplo n.º 5
0
static void
one_packet(void)
{
  u_int8_t inpacket[MAX_PACKET_SIZE];
  u_int8_t outpacket[MAX_PACKET_SIZE];
  size_t inp;
  size_t outp;
  size_t rmlp;
  u_int16_t rml;

  int result;
  struct sockaddr_in6 from;
  socklen_t fromlen = sizeof from;
  struct sockaddr_in6 dest;
  char buf[100];

  result = recvfrom(sock6fd, inpacket, sizeof inpacket, 0,
		    (struct sockaddr *)&from, &fromlen);
  if (result < 0)
    {
      /* Whenever certain Linux kernels get bogon ICMP port unreachable
       * or ICMP host unreachable packets that implicate the DHCP port,
       * the next recvfrom will return that error, even though there's
       * no way to connect it to anything.   If that happens, just return
       * and we'll loop again.
       */

      if (errno == EHOSTUNREACH || errno == ECONNREFUSED)
	return;

      /* If we got some other error, chances are we are hosed, so exit. */
      else
	{
	  syslog(LOG_CRIT, "Unhandled (fatal) error receiving packet: %m");
	  exit(1);
	}
    }

  /* If we get an 8k message, we're going to assume it's truncated--
   * we should never get a message even close to that size.
   */
  if (result == MAX_PACKET_SIZE)
    {
      syslog(LOG_INFO, "Dropping mobygram");
      return;
    }

  /* This is a packet from the client to the server. */
  if (inpacket[0] == SOLICIT ||
      inpacket[0] == REQUEST ||
      inpacket[0] == CONFIRM ||
      inpacket[0] == RENEW ||
      inpacket[0] == REBIND ||
      inpacket[0] == RELEASE ||
      inpacket[0] == DECLINE ||
      inpacket[0] == RELAY_FORWARD)
    {
      /* Set up and copy encapsulation header into packet. */
      outpacket[0] = RELAY_FORWARD;	/* type */

      /* If this is a RELAY_FORWARD packet, we put the address from which we
       * received the packet in the peer address field, and the copy the link
       * address field from the RELAY_FORWARD.
       */
      if (inpacket[0] == RELAY_FORWARD)
	{
	  /* Malformed packet. */
	  if (result < RELAY_HEADER_SIZE)
	    return;

	  /* Hop count exceeded?   This should never ever happen, so we can
	   * log it.   Most likely reason for it to happen is that the shim
	   * has been misconfigured.
	   */
	  if (inpacket[1] == 255)
	    {
	      inet_ntop(AF_INET6, &from.sin6_addr, buf, sizeof buf);
	      syslog(LOG_INFO, "hop count exceeded from %s", buf);
	      return;
	    }

	  outpacket[1] = inpacket[1] + 1;	/* hop count */

	  /* If the source address is a link-local address, copy in our own
	   * global address; otherwise set the address to zero.
	   */
	  if (!memcmp(&inpacket[2], ll_prefix, 8))
	    memcpy(&outpacket[2], (u_int8_t *)&listen_addr, IPV6_ADDR_SIZE);
	  else
	    memset(&outpacket[2], 0, IPV6_ADDR_SIZE);
	  memcpy(&outpacket[2 + IPV6_ADDR_SIZE],
		 &from.sin6_addr, IPV6_ADDR_SIZE);
	  inp = RELAY_HEADER_SIZE;
	  outp = RELAY_HEADER_SIZE;
	}
      else
	{
	  outpacket[1] = 0;			/* hop count */

	  memcpy(&outpacket[2], (u_int8_t *)&listen_addr, IPV6_ADDR_SIZE);
	  memcpy(&outpacket[2 + IPV6_ADDR_SIZE],
		 &from.sin6_addr, sizeof from.sin6_addr);
	  inp = CLIENT_HEADER_SIZE;
	  outp = RELAY_HEADER_SIZE;
	}
      /* The Relay Message option header goes here, but we don't know how
       * long the relay message option is yet, so we save an index to the
       * relay message length, and remember the length of the input header,
       * so that we can store the right value later.
       */
      ophdr_store(&outpacket[outp], OPTION_RELAY_MSG);
      rmlp = outp + 2;
      rml = inp;
      outp += 4;

      /* Copy in the encapsulated header. */
      memcpy(&outpacket[outp], inpacket, inp);
      outp += inp;

      /* Do recursive descent copy, dropping extra IA_PDs. */
      result = copy_options(inpacket, &inp, result,
			    outpacket, &outp, sizeof outpacket,
			    1, 0, 0, 0);

      /* If the packet was malformed, drop it. */
      if (result < 0)
	return;

      /* Store the Relay Message length, which we now know. */
      ophdr_store(&outpacket[rmlp], rml + result);

      /* Store an interface-id option. */
      ophdr_store(&outpacket[outp], OPTION_INTERFACE_ID);
      ophdr_store(&outpacket[outp + 2], 2);
      outpacket[outp + 4] = from.sin6_scope_id;
      outpacket[outp + 5] = 0;
      outp += 6;

      /* Send packet to server. */
      memset(&dest, 0, sizeof dest);
      memcpy(&dest.sin6_addr, &server_addr, IPV6_ADDR_SIZE);
      dest.sin6_port = htons(DHCPV6_SERVER_PORT);
      dest.sin6_family = AF_INET6;
    }

  /* This is a packet from the server to the client.   All packets
   * from server to client should be encapsulated, because we encapsulated
   * the packet we forwarded.
   */
  else if (inpacket[0] == RELAY_REPLY)
    {
      int ifidp;
      int ifid;
      int ifidl;

      /* Get the destination address from the relay reply. */
      memset(&dest, 0, sizeof dest);
      memcpy(&dest.sin6_addr,
	     &inpacket[2 + IPV6_ADDR_SIZE], sizeof dest.sin6_addr);
      
      /* Skip over the relay reply header. */
      inp = RELAY_HEADER_SIZE;
      outp = 0;

      /* Find the interface ID option, which the server should have
       * returned.
       */
      ifidp = find_option(inpacket, &inp, result,
			  OPTION_INTERFACE_ID, &ifidl, 0);
      if (!ifidp)
	{
	  syslog(LOG_CRIT, "DHCP server did not return interface-id!\n");
	  return;
	}
      if (ifidl != 2)
	{
	  syslog(LOG_CRIT,
		 "DHCP server returned wrong length interface id: %d\n",
		 ifidl);
	  return;
	}
      ifid = inpacket[ifidp];

      /* Recursively descend into the packet.   Skip all the top-level
       * options, because these are relay options the server sent to us,
       * and we don't process relay options.   Upon recursing into the
       * relay message option, we will start copying.   We pass in the
       * triplicate_pd function for copying any IA_PD we encounter, because
       * it will copy it three times, once intact, once modified for VoIP,
       * and once modified for IPTV.   It will also store the valid lifetime
       * through the pointer we pass to expiry.
       */
      if (copy_options(inpacket, &inp, result,
		       outpacket, &outp, sizeof outpacket,
		       0, 0, 0, 0) < 0)
	{
	  return;
	}

      /* If the packet is a RELAY-REPLY, set the destination port to the
       * server port; otherwise to the client port.
       */
      if (outpacket[0] == RELAY_REPLY)
	dest.sin6_port = htons(DHCPV6_SERVER_PORT);
      else
	dest.sin6_port = htons(DHCPV6_CLIENT_PORT);

      /* Use the scope on which we received the packet (which we got back
       * in the interface id option.
       */
      dest.sin6_scope_id = ifid;
      dest.sin6_family = AF_INET6;
    }
  else
    {
      inet_ntop(AF_INET6, &from.sin6_addr, buf, sizeof buf);
      syslog(LOG_INFO, "Discarding packet of type %d from %s",
	     inpacket[0], buf);
      return;
    }

  /* Relay the packet. */
  sendto(sock6fd, outpacket, outp,
	 MSG_DONTWAIT, (struct sockaddr *)&dest, sizeof dest);
}