/**
 * shares_free_share_info_list:
 * @list: List of #ShareInfo structures, or %NULL.
 *
 * Frees a list of #ShareInfo structures as returned by shares_get_share_info_list().
 **/
void
shares_free_share_info_list (GSList *list)
{
	GSList *l;

	for (l = list; l; l = l->next) {
		shares_free_share_info (l->data);
	}

	g_slist_free (list);
}
static gboolean
remove_from_path_hash_cb (gpointer key,
			  gpointer value,
			  gpointer data)
{
	ShareInfo *info;

	info = value;
	shares_free_share_info (info);

	return TRUE;
}
static gboolean
remove_share (const char *path, GError **error)
{
	ShareInfo *old_info;
	char *argv[2];
	GError *real_error;

	/* g_message ("remove_share() start"); */

	if (throw_error_on_remove) {
		g_set_error (error,
			     SHARES_ERROR,
			     SHARES_ERROR_FAILED,
			     "Failed");
		g_message ("remove_share() end FAIL");
		return FALSE;
	}

	old_info = lookup_share_by_path (path);
	if (!old_info) {
		char *display_name;

		display_name = g_filename_display_name (path);
		g_set_error (error,
			     SHARES_ERROR,
			     SHARES_ERROR_NONEXISTENT,
			     _("Cannot remove the share for path %s: that path is not shared"),
			     display_name);
		g_free (display_name);

		g_message ("remove_share() end FAIL: path %s was not in our hashes", path);
		return FALSE;
	}

	argv[0] = "delete";
	argv[1] = old_info->share_name;

	real_error = NULL;
	if (!net_usershare_run (G_N_ELEMENTS (argv), argv, NULL, &real_error)) {
		g_message ("Called \"net usershare delete\" but it failed: %s", real_error->message);
		g_propagate_error (error, real_error);
		g_message ("remove_share() end FAIL");
		return FALSE;
	}

	remove_share_info_from_hashes (old_info);
	shares_free_share_info (old_info);

	/* g_message ("remove_share() end SUCCESS"); */

	return TRUE;
}
Exemple #4
0
static NemoShareStatus 
get_share_status_and_free_share_info (ShareInfo *share_info)
{
  NemoShareStatus result;

  if (!share_info)
    result = NEMO_SHARE_NOT_SHARED;
  else
    {
      if (share_info->is_writable)
	result = NEMO_SHARE_SHARED_RW;
      else
	result = NEMO_SHARE_SHARED_RO;

      shares_free_share_info (share_info);
    }

  return result;
}
Exemple #5
0
/* nemo_property_page_provider_get_pages
 *  
 * This function is called by Nemo when it wants property page
 * items from the extension.
 *
 * This function is called in the main thread before a property page
 * is shown, so it should return quickly.
 * 
 * The function should return a GList of allocated NemoPropertyPage
 * items.
 */
static GList *
nemo_share_get_property_pages (NemoPropertyPageProvider *provider,
				   GList *files)
{
  PropertyPage *page;
  GList *pages;
  NemoPropertyPage *np_page;
  NemoFileInfo *fileinfo;
  ShareInfo *share_info;
  gboolean is_shareable;

  /* Only show the property page if 1 file is selected */
  if (!files || files->next != NULL) {
    return NULL;
  }

  fileinfo = NEMO_FILE_INFO (files->data);

  get_share_info_for_file_info (fileinfo, &share_info, &is_shareable);
  if (!is_shareable)
    return NULL;

  page = create_property_page (fileinfo);
  gtk_widget_hide (page->button_cancel);
  
  if (share_info)
    shares_free_share_info (share_info);

  pages = NULL;
  np_page = nemo_property_page_new
    ("NemoShare::property_page",
     gtk_label_new (_("Share")),
     page->main);
  pages = g_list_append (pages, np_page);

  return pages;
}
Exemple #6
0
static PropertyPage *
create_property_page (NemoFileInfo *fileinfo)
{
  PropertyPage *page;
  GError *error;
  ShareInfo *share_info;
  char *share_name;
  gboolean free_share_name;
  const char *comment;
  char *apply_button_label;

  page = g_new0 (PropertyPage, 1);

  page->path = get_fullpath_from_fileinfo(fileinfo);
  page->fileinfo = g_object_ref (fileinfo);

  error = NULL;
  if (!shares_get_share_info_for_path (page->path, &share_info, &error))
    {
      /* We'll assume that there is no share for that path, but we'll still
       * bring up an error dialog.
       */
      GtkWidget *message;

      message = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
					_("There was an error while getting the sharing information"));
      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message), "%s", error->message);
      gtk_widget_show (message);

      share_info = NULL;
      g_error_free (error);
      error = NULL;
    }


  page->xml = gtk_builder_new ();
  gtk_builder_set_translation_domain (page->xml, "nemo-share");
  g_assert (gtk_builder_add_from_file (page->xml,
              INTERFACES_DIR"/share-dialog.ui", &error));

  page->main = GTK_WIDGET (gtk_builder_get_object (page->xml, "vbox1"));
  g_assert (page->main != NULL);

  g_object_set_data_full (G_OBJECT (page->main),
			  "PropertyPage",
			  page,
			  free_property_page_cb);

  page->checkbutton_share_folder = GTK_WIDGET (gtk_builder_get_object (page->xml,"checkbutton_share_folder"));
  page->hbox_share_comment = GTK_WIDGET (gtk_builder_get_object (page->xml,"hbox_share_comment"));
  page->hbox_share_name = GTK_WIDGET (gtk_builder_get_object (page->xml,"hbox_share_name"));
  page->checkbutton_share_rw_ro = GTK_WIDGET (gtk_builder_get_object (page->xml,"checkbutton_share_rw_ro"));
  page->checkbutton_share_guest_ok = GTK_WIDGET (gtk_builder_get_object (page->xml,"checkbutton_share_guest_ok"));
  page->entry_share_name = GTK_WIDGET (gtk_builder_get_object (page->xml,"entry_share_name"));
  page->entry_share_comment = GTK_WIDGET (gtk_builder_get_object (page->xml,"entry_share_comment"));
  page->label_status = GTK_WIDGET (gtk_builder_get_object (page->xml,"label_status"));
  page->button_cancel = GTK_WIDGET (gtk_builder_get_object (page->xml,"button_cancel"));
  page->button_apply = GTK_WIDGET (gtk_builder_get_object (page->xml,"button_apply"));

  /* Sanity check so that we don't screw up the Glade file */
  g_assert (page->checkbutton_share_folder != NULL
	    && page->hbox_share_comment != NULL
	    && page->hbox_share_name != NULL
	    && page->checkbutton_share_rw_ro != NULL
	    && page->checkbutton_share_guest_ok != NULL
	    && page->entry_share_name != NULL
	    && page->entry_share_comment != NULL
	    && page->label_status != NULL
	    && page->button_cancel != NULL
	    && page->button_apply != NULL);

  if (share_info)
    {
      page->was_initially_shared = TRUE;
      page->was_writable = share_info->is_writable;
    }

  /* Share name */

  if (share_info)
    {
      share_name = share_info->share_name;
      free_share_name = FALSE;
    }
  else
    {
      share_name = g_filename_display_basename (page->path);
      free_share_name = TRUE;
    }

  gtk_entry_set_text (GTK_ENTRY (page->entry_share_name), share_name);

  if (free_share_name)
    g_free (share_name);

  /* Comment */

  if (share_info == NULL || share_info->comment == NULL)
    comment = "";
  else
    comment = share_info->comment;

  gtk_entry_set_text (GTK_ENTRY (page->entry_share_comment), comment);

  /* Share toggle */

  if (share_info)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_folder), TRUE);
  else
    {
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_folder), FALSE);
    }

  /* Share name */

  if (g_utf8_strlen(gtk_entry_get_text (GTK_ENTRY (page->entry_share_name)), -1) > 12)
    property_page_set_warning (page);

  /* Permissions */
  if (share_info != NULL && share_info->is_writable)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_rw_ro), TRUE);
  else
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_rw_ro), FALSE);

  /* Guest access */
  if (share_info != NULL && share_info->guest_ok)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_guest_ok), TRUE);
  else
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_guest_ok), FALSE);

  /* Apply button */

  if (share_info)
    apply_button_label = _("Modify _Share");
  else
    apply_button_label = _("Create _Share");

  gtk_button_set_label (GTK_BUTTON (page->button_apply), apply_button_label);
  gtk_button_set_use_underline (GTK_BUTTON (page->button_apply), TRUE);
  gtk_button_set_image (GTK_BUTTON (page->button_apply), gtk_image_new_from_stock (GTK_STOCK_SAVE, GTK_ICON_SIZE_BUTTON));

  gtk_widget_set_sensitive (page->button_apply, FALSE);

  /* Sensitivity */

  property_page_check_sensitivity (page);

  /* Signal handlers */

  g_signal_connect (page->checkbutton_share_folder, "toggled",
                    G_CALLBACK (on_checkbutton_share_folder_toggled),
                    page);

  g_signal_connect (page->checkbutton_share_rw_ro, "toggled",
                    G_CALLBACK (on_checkbutton_rw_ro_toggled),
                    page);

  g_signal_connect (page->checkbutton_share_guest_ok, "toggled",
                    G_CALLBACK (on_checkbutton_guest_ok_toggled),
                    page);

  g_signal_connect (page->entry_share_name, "changed",
                    G_CALLBACK (modify_share_name_text_entry),
                    page);

  g_signal_connect (page->entry_share_comment, "changed",
		    G_CALLBACK (modify_share_comment_text_entry),
		    page);

  g_signal_connect (page->button_apply, "clicked",
		    G_CALLBACK (button_apply_clicked_cb), page);

  if (share_info != NULL)
    shares_free_share_info (share_info);

  return page;
}
static void
add_key_group_to_hashes (GKeyFile *key_file, const char *group)
{
	char *path;
	char *comment;
	char *acl;
	gboolean is_writable;
	char *guest_ok_str;
	gboolean guest_ok;
	ShareInfo *info;
	ShareInfo *old_info;

	/* Remove the old share based on the name */

	old_info = lookup_share_by_share_name (group);
	if (old_info) {
		remove_share_info_from_hashes (old_info);
		shares_free_share_info (old_info);
	}

	/* Start parsing, and remove the old share based on the path */

	path = get_string_from_key_file (key_file, group, KEY_PATH);
	if (!path) {
		g_message ("group '%s' doesn't have a '%s' key!  Ignoring group.", group, KEY_PATH);
		return;
	}

	old_info = lookup_share_by_path (path);
	if (old_info) {
		remove_share_info_from_hashes (old_info);
		shares_free_share_info (old_info);
	}

	/* Finish parsing */

	comment = get_string_from_key_file (key_file, group, KEY_COMMENT);

	acl = get_string_from_key_file (key_file, group, KEY_ACL);
	if (acl) {
		if (strstr (acl, "Everyone:R"))
			is_writable = FALSE;
		else if (strstr (acl, "Everyone:F"))
			is_writable = TRUE;
		else {
			g_message ("unknown format for key '%s/%s' as it contains '%s'.  Assuming that the share is read-only",
				   group, KEY_ACL, acl);
			is_writable = FALSE;
		}

		g_free (acl);
	} else {
		g_message ("group '%s' doesn't have a '%s' key!  Assuming that the share is read-only.", group, KEY_ACL);
		is_writable = FALSE;
	}

	guest_ok_str = get_string_from_key_file (key_file, group, KEY_GUEST_OK);
	if (guest_ok_str) {
		if (strcmp (guest_ok_str, "n") == 0)
			guest_ok = FALSE;
		else if (strcmp (guest_ok_str, "y") == 0)
			guest_ok = TRUE;
		else {
			g_message ("unknown format for key '%s/%s' as it contains '%s'.  Assuming that the share is not guest accessible.",
				   group, KEY_GUEST_OK, guest_ok_str);
			guest_ok = FALSE;
		}

		g_free (guest_ok_str);
	} else {
		g_message ("group '%s' doesn't have a '%s' key!  Assuming that the share is not guest accessible.", group, KEY_GUEST_OK);
		guest_ok = FALSE;
	}

	g_assert (path != NULL);
	g_assert (group != NULL);

	info = g_new (ShareInfo, 1);
	info->path = path;
	info->share_name = g_strdup (group);
	info->comment = comment;
	info->is_writable = is_writable;
	info->guest_ok = guest_ok;

	add_share_info_to_hashes (info);
}