Greetings,

  Small patch to move get_grosysid() from catalog/aclchk.c to 
  utils/cache/lsyscache.c where it can be used by other things.  Also
  cleans up both get_usesysid() and get_grosysid() a bit.  This is in
  preparation for 'Group Ownership' support.

        Thanks,

                Stephen
diff -u -u -r1.107 aclchk.c
--- src/backend/catalog/aclchk.c        29 Aug 2004 05:06:41 -0000      1.107
+++ src/backend/catalog/aclchk.c        29 Dec 2004 16:32:57 -0000
@@ -1208,28 +1208,6 @@
        return NULL;                            /* appease compiler */
 }
 
-
-AclId
-get_grosysid(char *groname)
-{
-       HeapTuple       tuple;
-       AclId           id = 0;
-
-       tuple = SearchSysCache(GRONAME,
-                                                  PointerGetDatum(groname),
-                                                  0, 0, 0);
-       if (HeapTupleIsValid(tuple))
-       {
-               id = ((Form_pg_group) GETSTRUCT(tuple))->grosysid;
-               ReleaseSysCache(tuple);
-       }
-       else
-               ereport(ERROR,
-                               (errcode(ERRCODE_UNDEFINED_OBJECT),
-                                errmsg("group \"%s\" does not exist", 
groname)));
-       return id;
-}
-
 /*
  * Convert group ID to name, or return NULL if group can't be found
  */
diff -u -u -r1.118 lsyscache.c
--- src/backend/utils/cache/lsyscache.c 5 Nov 2004 19:16:14 -0000       1.118
+++ src/backend/utils/cache/lsyscache.c 29 Dec 2004 16:32:58 -0000
@@ -25,6 +25,7 @@
 #include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_shadow.h"
+#include "catalog/pg_group.h"
 #include "catalog/pg_statistic.h"
 #include "catalog/pg_type.h"
 #include "nodes/makefuncs.h"
@@ -2032,7 +2033,7 @@
 AclId
 get_usesysid(const char *username)
 {
-       int32           result;
+       AclId           userId;
        HeapTuple       userTup;
 
        userTup = SearchSysCache(SHADOWNAME,
@@ -2043,9 +2044,39 @@
                                (errcode(ERRCODE_UNDEFINED_OBJECT),
                                 errmsg("user \"%s\" does not exist", 
username)));
 
-       result = ((Form_pg_shadow) GETSTRUCT(userTup))->usesysid;
+       userId = ((Form_pg_shadow) GETSTRUCT(userTup))->usesysid;
 
        ReleaseSysCache(userTup);
 
-       return result;
+       return userId;
+}
+
+/*
+ * get_grosysid
+ *
+ *       Given a group name, look up the group's sysid.
+ *       Raises an error if no such group (rather than returning zero,
+ *       which might possibly be a valid grosysid).
+ *
+ */
+AclId
+get_grosysid(char *groname)
+{
+       AclId           groupId;
+       HeapTuple       groupTup;
+
+       groupTup = SearchSysCache(GRONAME,
+                                                  PointerGetDatum(groname),
+                                                  0, 0, 0);
+       if (!HeapTupleIsValid(groupTup))
+               ereport(ERROR,
+                               (errcode(ERRCODE_UNDEFINED_OBJECT),
+                                errmsg("group \"%s\" does not exist", 
groname)));
+
+       groupId = ((Form_pg_group) GETSTRUCT(groupTup))->grosysid;
+
+       ReleaseSysCache(groupTup);
+
+       return groupId;
 }
+
Index: src/include/utils/acl.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/utils/acl.h,v
retrieving revision 1.75
diff -u -u -r1.75 acl.h
--- src/include/utils/acl.h     29 Aug 2004 05:06:58 -0000      1.75
+++ src/include/utils/acl.h     29 Dec 2004 16:32:58 -0000
@@ -245,7 +245,6 @@
  * prototypes for functions in aclchk.c
  */
 extern void ExecuteGrantStmt(GrantStmt *stmt);
-extern AclId get_grosysid(char *groname);
 extern char *get_groname(AclId grosysid);
 
 extern AclMode pg_class_aclmask(Oid table_oid, AclId userid,
Index: src/include/utils/lsyscache.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/utils/lsyscache.h,v
retrieving revision 1.92
diff -u -u -r1.92 lsyscache.h
--- src/include/utils/lsyscache.h       5 Nov 2004 19:16:41 -0000       1.92
+++ src/include/utils/lsyscache.h       29 Dec 2004 16:32:58 -0000
@@ -115,7 +115,8 @@
                                  Datum *values, int nvalues,
                                  float4 *numbers, int nnumbers);
 extern char *get_namespace_name(Oid nspid);
-extern int32 get_usesysid(const char *username);
+extern AclId get_usesysid(const char *username);
+extern AclId get_grosysid(char *groname);
 
 #define is_array_type(typid)  (get_element_type(typid) != InvalidOid)
 
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
      joining column's datatypes do not match

Reply via email to