[Goodies-commits] r6686 - in thunar-shares-plugin/trunk: . libshares thunar-plugin

Daniel Morales danielm at xfce.org
Sun Feb 15 04:50:47 CET 2009


Author: danielm
Date: 2009-02-15 03:50:46 +0000 (Sun, 15 Feb 2009)
New Revision: 6686

Modified:
   thunar-shares-plugin/trunk/ChangeLog
   thunar-shares-plugin/trunk/configure.in.in
   thunar-shares-plugin/trunk/libshares/libshares-util.c
   thunar-shares-plugin/trunk/libshares/libshares-util.h
   thunar-shares-plugin/trunk/libshares/shares.c
   thunar-shares-plugin/trunk/libshares/shares.h
   thunar-shares-plugin/trunk/thunar-plugin/tsp-page.c
Log:
	* libshares/shares.c: Fixed usershare_acl key.
	* thunar-plugin/tsp-page.c: A couple of tweaks around the 
	changed signal, and error handling.
	* configure.in.in: Added standard headers checks.
	* Added 'owner only' testparam, and folders owner checks. 

Modified: thunar-shares-plugin/trunk/ChangeLog
===================================================================
--- thunar-shares-plugin/trunk/ChangeLog	2009-02-14 23:34:26 UTC (rev 6685)
+++ thunar-shares-plugin/trunk/ChangeLog	2009-02-15 03:50:46 UTC (rev 6686)
@@ -1,3 +1,12 @@
+2009-02-15	Daniel Morales <daniel at daniel.com.uy>
+
+	* libshares/shares.c: Fixed usershare_acl key.
+	* thunar-plugin/tsp-page.c: A couple of tweaks around the 
+	changed signal, and error handling.
+	* configure.in.in: Added standard headers checks.
+
+	* Added 'owner only' testparam, and folders owner checks.
+
 2009-02-14	Daniel Morales <daniel at daniel.com.uy>
 
 	* Changed notification system. Let's use "changed" from thunarx.

Modified: thunar-shares-plugin/trunk/configure.in.in
===================================================================
--- thunar-shares-plugin/trunk/configure.in.in	2009-02-14 23:34:26 UTC (rev 6685)
+++ thunar-shares-plugin/trunk/configure.in.in	2009-02-15 03:50:46 UTC (rev 6686)
@@ -47,6 +47,11 @@
 AC_PROG_INTLTOOL([0.31])
 
 dnl -------------------------------------------------------
+dnl Check headers
+dnl -------------------------------------------------------
+AC_CHECK_HEADERS([string.h sys/types.h sys/wait.h time.h]) 
+
+dnl -------------------------------------------------------
 dnl Packages checks
 dnl -------------------------------------------------------
 XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.12.0])

Modified: thunar-shares-plugin/trunk/libshares/libshares-util.c
===================================================================
--- thunar-shares-plugin/trunk/libshares/libshares-util.c	2009-02-14 23:34:26 UTC (rev 6685)
+++ thunar-shares-plugin/trunk/libshares/libshares-util.c	2009-02-15 03:50:46 UTC (rev 6686)
@@ -304,6 +304,36 @@
   return retval;
 }
 
+/**
+ * libshares_check_owner:
+ * @info: FileInfo
+ *
+ * Checks the owner only param, and the owner of the file.
+ *
+ * Return value: #TRUE is shareable.
+ **/
+gboolean
+libshares_check_owner (ThunarxFileInfo *info)
+{
+  ThunarVfsInfo *vfsinfo;
+  gboolean retval = TRUE;
+  gboolean owner_only;
+
+  if (shares_has_owner_only (&owner_only, NULL))
+  {
+    if (owner_only)
+    {
+      vfsinfo = thunarx_file_info_get_vfs_info (info);
+
+      retval = (geteuid () == vfsinfo->uid);
+
+      thunar_vfs_info_unref (vfsinfo);
+    }
+  }
+
+  return retval;
+}
+
 /* Asks to the user if we can change the permissions of the folder */
 static gboolean
 tsp_ask_perms (gboolean  need_r,

Modified: thunar-shares-plugin/trunk/libshares/libshares-util.h
===================================================================
--- thunar-shares-plugin/trunk/libshares/libshares-util.h	2009-02-14 23:34:26 UTC (rev 6685)
+++ thunar-shares-plugin/trunk/libshares/libshares-util.h	2009-02-15 03:50:46 UTC (rev 6686)
@@ -43,6 +43,8 @@
 
 gboolean   libshares_is_shareable   (ThunarxFileInfo *info);
 
+gboolean   libshares_check_owner    (ThunarxFileInfo *info);
+
 gboolean   libshares_shares_unshare (const gchar     *path);
 
 ShareInfo *libshares_shares_share   (const gchar     *file_local,

Modified: thunar-shares-plugin/trunk/libshares/shares.c
===================================================================
--- thunar-shares-plugin/trunk/libshares/shares.c	2009-02-14 23:34:26 UTC (rev 6685)
+++ thunar-shares-plugin/trunk/libshares/shares.c	2009-02-15 03:50:46 UTC (rev 6686)
@@ -1,5 +1,4 @@
-/* nautilus-share -- Nautilus File Sharing Extension
- *
+/*
  * Sebastien Estienne <sebastien.estienne at gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -17,13 +16,26 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
  * (C) Copyright 2005 Ethium, Inc.
+ * (C) Copyright 2008-2009 Daniel Morales <daniel at daniel.com.uy>
  */
 
+#ifdef HAVE_CONFIG_H
 #include <config.h>
+#endif
+
+#ifdef HAVE_STRING_H
 #include <string.h>
+#endif
+#ifdef HAVE_TIME_H
 #include <time.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
+
 #include <glib/gi18n-lib.h>
 #include "shares.h"
 
@@ -386,9 +398,9 @@
 
 	acl = get_string_from_key_file (key_file, group, KEY_ACL);
 	if (acl) {
-		if (strcmp (acl, "Everyone:R") == 0)
+		if (strncmp (acl, "Everyone:R", 10) == 0)
 			is_writable = FALSE;
-		else if (strcmp (acl, "Everyone:F") == 0)
+		else if (strncmp (acl, "Everyone:F", 10) == 0)
 			is_writable = TRUE;
 		else {
 #ifdef G_ENABLE_DEBUG
@@ -547,21 +559,8 @@
 	return copy;
 }
 
-/**
- * shares_supports_guest_ok:
- * @supports_guest_ok_ret: Location to store whether "usershare allow guests"
- * is enabled.
- * @error: Location to store error, or #NULL.
- *
- * Determines whether the option "usershare allow guests" is enabled in samba
- * config as shown by testparm.
- *
- * Return value: #TRUE if if the info could be queried successfully, #FALSE
- * otherwise.  If this function returns #FALSE, an error code will be returned
- * in the @error argument, and *@ret_info_list will be set to #FALSE.
- **/
-gboolean
-shares_supports_guest_ok (gboolean *supports_guest_ok_ret, GError **error)
+static gboolean
+test_param (const gchar *testparam, gboolean *supports_test_ret, GError **error)
 {
 	gboolean retval;
 	gboolean result;
@@ -570,9 +569,9 @@
 	int exit_status;
 	int exit_code;
 
-	*supports_guest_ok_ret = FALSE;
+	*supports_test_ret = FALSE;
 
-	result = g_spawn_command_line_sync ("testparm -s --parameter-name='usershare allow guests'",
+	result = g_spawn_command_line_sync (testparam,
 					    &stdout_contents,
 					    &stderr_contents,
 					    &exit_status,
@@ -629,7 +628,7 @@
 	}
 
 	retval = TRUE;
-	*supports_guest_ok_ret = (g_ascii_strncasecmp (stdout_contents, "Yes", 3) == 0);
+	*supports_test_ret = (g_ascii_strncasecmp (stdout_contents, "Yes", 3) == 0);
 
  out:
 	g_free (stdout_contents);
@@ -638,6 +637,49 @@
 	return retval;
 }
 
+/**
+ * shares_supports_guest_ok:
+ * @supports_guest_ok_ret: Location to store whether "usershare allow guests"
+ * is enabled.
+ * @error: Location to store error, or #NULL.
+ *
+ * Determines whether the option "usershare allow guests" is enabled in samba
+ * config as shown by testparm.
+ *
+ * Return value: #TRUE if if the info could be queried successfully, #FALSE
+ * otherwise.  If this function returns #FALSE, an error code will be returned
+ * in the @error argument, and *@supports_guest_ok_ret will be set to #FALSE.
++ **/
+gboolean
+shares_supports_guest_ok (gboolean *supports_guest_ok_ret, GError **error)
+{
+	return test_param ("testparm -s --parameter-name='usershare allow guests'",
+						supports_guest_ok_ret,
+						error);
+}
+
+/**
+ * shares_has_owner_only:
+ * @supports_owner_only_ret: Location to store whether "usershare owner only"
+ * is enabled.
+ * @error: Location to store error, or #NULL.
+ *
+ * Determines whether the option "usershare usershare owner only" is enabled in samba
+ * config as shown by testparm.
+ *
+ * Return value: #TRUE if if the info could be queried successfully, #FALSE
+ * otherwise.  If this function returns #FALSE, an error code will be returned
+ * in the @error argument, and *@supports_owner_only_ret will be set to #FALSE.
+ **/
+gboolean
+shares_has_owner_only (gboolean *supports_owner_only_ret, 
+					   GError **error)
+{
+	return test_param ("testparm -s --parameter-name='usershare owner only'",
+						supports_owner_only_ret,
+						error);
+}
+
 static gboolean
 add_share (ShareInfo *info, GError **error)
 {

Modified: thunar-shares-plugin/trunk/libshares/shares.h
===================================================================
--- thunar-shares-plugin/trunk/libshares/shares.h	2009-02-14 23:34:26 UTC (rev 6685)
+++ thunar-shares-plugin/trunk/libshares/shares.h	2009-02-15 03:50:46 UTC (rev 6686)
@@ -62,6 +62,9 @@
 gboolean shares_supports_guest_ok (gboolean *supports_guest_ok_ret, 
 				   GError **error);
 
+gboolean shares_has_owner_only (gboolean *supports_owner_only_ret, 
+				   GError **error);
+
 void shares_set_debug (gboolean error_on_refresh,
 		       gboolean error_on_add,
 		       gboolean error_on_modify,

Modified: thunar-shares-plugin/trunk/thunar-plugin/tsp-page.c
===================================================================
--- thunar-shares-plugin/trunk/thunar-plugin/tsp-page.c	2009-02-14 23:34:26 UTC (rev 6685)
+++ thunar-shares-plugin/trunk/thunar-plugin/tsp-page.c	2009-02-15 03:50:46 UTC (rev 6686)
@@ -66,6 +66,7 @@
                                     gboolean         sens);
 static void tsp_page_set_error     (TspPage         *tsp_page,
                                     const char      *msg);
+static void tsp_page_reset_error   (TspPage         *tsp_page);
 
 static gboolean tsp_check_changes  (TspPage         *page);
 
@@ -359,6 +360,14 @@
   g_free (uri);
   g_free (file_local);
 
+  /* Check folder owner */
+  if (!libshares_check_owner (tsp_page->file))
+  {
+    tsp_page_set_error (tsp_page, _("You are not the owner of the folder."));
+
+    return;
+  }
+
   /* Check error */
   if (!result)
   {
@@ -371,6 +380,9 @@
     return;
   }
 
+  /* Reset error */
+  tsp_page_reset_error (tsp_page);
+
   /* Check if shared */
   if (share_info)
   {
@@ -489,31 +501,39 @@
     {
       tsp_update_default (tsp_page, share_info);
       shares_free_share_info (share_info);
+
+      thunarx_file_info_changed (tsp_page->file);
     }
   } else {
     /* Un-share the folder */
     if (libshares_shares_unshare (local_file))
     {
       tsp_update_default (tsp_page, NULL);
+
+      thunarx_file_info_changed (tsp_page->file);
     }
   }
-  
-  thunarx_file_info_changed (tsp_page->file);
 
   g_free (local_file);
 }
 
 static void
+tsp_page_reset_error (TspPage *tsp_page)
+{
+  gtk_label_set_markup (GTK_LABEL (tsp_page->label_status), NULL);
+
+  gtk_widget_set_sensitive (GTK_WIDGET (tsp_page), TRUE);
+}
+
+static void
 tsp_page_set_error (TspPage    *tsp_page,
                     const char *msg)
 {
   gchar *errormsg = g_strdup_printf ("<span color='red'>%s</span>", msg);
 
   gtk_label_set_markup (GTK_LABEL (tsp_page->label_status), errormsg);
-  tsp_page_sensibility (tsp_page, FALSE);
-  tsp_update_default (tsp_page, NULL);
-  gtk_widget_set_sensitive (tsp_page->cb_share_folder, FALSE);
-  g_free (errormsg);
+
+  gtk_widget_set_sensitive (GTK_WIDGET (tsp_page), FALSE);
 }
 
 




More information about the Goodies-commits mailing list