[liboobs] Increase OOBS_[UG]ID_MAX to G_MAXINT32 when possible and install oobs-defines.h



commit 8ec0644df51477bde544a12ebcb8d70948423544
Author: Milan Bouchet-Valat <nalimilan club fr>
Date:   Sat Dec 5 16:41:10 2009 +0100

    Increase OOBS_[UG]ID_MAX to G_MAXINT32 when possible and install oobs-defines.h
    
    The system-tools-backends use an int32 to store [UG]IDs, so we need to respect these limits even if we and the system support it. But using a hard-coded limit of 65,535 makes no sense. If uid_t and gid_t are big enough, we need to allow these values, else we could destroy the system's configuration. Use a custom computing method to get the max value [ug]id_t can hold, since no system constant exists for that.

 oobs/Makefile.am    |    1 +
 oobs/oobs-defines.h |   16 +++++++++++++---
 oobs/oobs.h         |    1 +
 3 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/oobs/Makefile.am b/oobs/Makefile.am
index cf4dbb4..8f691bf 100644
--- a/oobs/Makefile.am
+++ b/oobs/Makefile.am
@@ -17,6 +17,7 @@ oobsinclude_HEADERS= 	\
 	oobs-session.h		\
 	oobs-object.h		\
 	oobs-list.h		\
+	oobs-defines.h		\
 	oobs-share.h		\
 	oobs-smbconfig.h	\
 	oobs-share-smb.h	\
diff --git a/oobs/oobs-defines.h b/oobs/oobs-defines.h
index e9864a6..f2f9f17 100644
--- a/oobs/oobs-defines.h
+++ b/oobs/oobs-defines.h
@@ -15,8 +15,18 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  *
- * Authors: Carlos Garnacho Parro  <carlosg gnome org>
+ * Authors: Carlos Garnacho Parro  <carlosg gnome org>,
+ *          Milan Bouchet-Valat <nalimilan club fr>.
  */
 
-#define OOBS_MAX_UID 65534
-#define OOBS_MAX_GID 65534
+#include <math.h>
+
+/* The system-tools-backends protocol is using an int32
+ * to store [UG]IDs, thus we can't go beyond this,
+ * even if the system supports it.
+ *
+ * Computing the size of [ug]id_t is tricky, because
+ * no system constant exists for that.*/
+
+#define OOBS_MAX_UID MIN (G_MAXINT32, pow (2, 8 * sizeof (uid_t) - 1))
+#define OOBS_MAX_GID MIN (G_MAXINT32, pow (2, 8 * sizeof (gid_t) - 1))
diff --git a/oobs/oobs.h b/oobs/oobs.h
index 30914a5..31f676a 100644
--- a/oobs/oobs.h
+++ b/oobs/oobs.h
@@ -25,6 +25,7 @@
 #include <oobs/oobs-object.h>
 #include <oobs/oobs-session.h>
 #include <oobs/oobs-list.h>
+#include <oobs/oobs-defines.h>
 #include <oobs/oobs-selfconfig.h>
 #include <oobs/oobs-share.h>
 #include <oobs/oobs-share-smb.h>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]