88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.91 2003/06 /2700:33:25 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.92 2003/07 /2704:53:02 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -90,8 +90,12 @@ getid(const char *s, char *n)
9090else
9191{
9292if (len >=NAMEDATALEN - 1 )
93- elog (ERROR ,"identifier must be less than %d characters" ,
94- NAMEDATALEN );
93+ ereport (ERROR ,
94+ (errcode (ERRCODE_NAME_TOO_LONG ),
95+ errmsg ("identifier too long" ),
96+ errdetail ("Identifier must be less than %d characters." ,
97+ NAMEDATALEN )));
98+
9599n [len ++ ]= * s ;
96100}
97101}
@@ -157,26 +161,34 @@ aclparse(const char *s, AclItem *aip)
157161Assert (s && aip );
158162
159163#ifdef ACLDEBUG
160- elog (LOG ,"aclparse: input ='%s' " ,s );
164+ elog (LOG ,"aclparse: input =\"%s\" " ,s );
161165#endif
162166idtype = ACL_IDTYPE_UID ;
163167s = getid (s ,name );
164168if (* s != '=' )
165169{
166170/* we just read a keyword, not a name */
167- if (strncmp (name ,ACL_IDTYPE_GID_KEYWORD , sizeof ( name ) )== 0 )
171+ if (strcmp (name ,ACL_IDTYPE_GID_KEYWORD )== 0 )
168172idtype = ACL_IDTYPE_GID ;
169- else if (strncmp (name ,ACL_IDTYPE_UID_KEYWORD ,sizeof (name ))!= 0 )
170- elog (ERROR ,"aclparse: bad keyword, must be [group|user]" );
173+ else if (strcmp (name ,ACL_IDTYPE_UID_KEYWORD )!= 0 )
174+ ereport (ERROR ,
175+ (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
176+ errmsg ("unrecognized keyword: \"%s\"" ,name ),
177+ errhint ("ACL keyword must be \"group\" or \"user\"." )));
171178s = getid (s ,name );/* move s to the name beyond the keyword */
172179if (name [0 ]== '\0' )
173- elog (ERROR ,"aclparse: a name must follow the [group|user] keyword" );
180+ ereport (ERROR ,
181+ (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
182+ errmsg ("missing name" ),
183+ errhint ("A name must follow the [group|user] keyword." )));
174184}
175185if (name [0 ]== '\0' )
176186idtype = ACL_IDTYPE_WORLD ;
177187
178188if (* s != '=' )
179- elog (ERROR ,"aclparse: expecting \"=\" sign" );
189+ ereport (ERROR ,
190+ (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
191+ errmsg ("missing \"=\" sign" )));
180192
181193privs = goption = ACL_NO_RIGHTS ;
182194
@@ -221,8 +233,10 @@ aclparse(const char *s, AclItem *aip)
221233read = ACL_CREATE_TEMP ;
222234break ;
223235default :
224- elog (ERROR ,"aclparse: mode flags must use \"%s\"" ,
225- ACL_ALL_RIGHTS_STR );
236+ ereport (ERROR ,
237+ (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
238+ errmsg ("invalid mode character: must be one of \"%s\"" ,
239+ ACL_ALL_RIGHTS_STR )));
226240}
227241
228242privs |=read ;
@@ -247,14 +261,18 @@ aclparse(const char *s, AclItem *aip)
247261{
248262s = getid (s + 1 ,name2 );
249263if (name2 [0 ]== '\0' )
250- elog (ERROR ,"aclparse: a name must follow the \"/\" sign" );
264+ ereport (ERROR ,
265+ (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
266+ errmsg ("a name must follow the \"/\" sign" )));
251267
252268aip -> ai_grantor = get_usesysid (name2 );
253269}
254270else
255271{
256272aip -> ai_grantor = BOOTSTRAP_USESYSID ;
257- elog (WARNING ,"defaulting grantor to %u" ,BOOTSTRAP_USESYSID );
273+ ereport (WARNING ,
274+ (errcode (ERRCODE_INVALID_GRANTOR ),
275+ errmsg ("defaulting grantor to %u" ,BOOTSTRAP_USESYSID )));
258276}
259277
260278ACLITEM_SET_PRIVS_IDTYPE (* aip ,privs ,goption ,idtype );
@@ -280,7 +298,7 @@ allocacl(int n)
280298Size size ;
281299
282300if (n < 0 )
283- elog (ERROR ,"allocacl: invalid size: %d" ,n );
301+ elog (ERROR ,"invalid size: %d" ,n );
284302size = ACL_N_SIZE (n );
285303new_acl = (Acl * )palloc0 (size );
286304new_acl -> size = size ;
@@ -311,7 +329,10 @@ aclitemin(PG_FUNCTION_ARGS)
311329while (isspace ((unsignedchar )* s ))
312330++ s ;
313331if (* s )
314- elog (ERROR ,"aclitemin: extra garbage at end of specification" );
332+ ereport (ERROR ,
333+ (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
334+ errmsg ("extra garbage at the end of the ACL specification" )));
335+
315336PG_RETURN_ACLITEM_P (aip );
316337}
317338
@@ -373,8 +394,8 @@ aclitemout(PG_FUNCTION_ARGS)
373394case ACL_IDTYPE_WORLD :
374395break ;
375396default :
376- elog (ERROR ,"aclitemout: bad idtype: %d" ,
377- ACLITEM_GET_IDTYPE (* aip ));
397+ elog (ERROR ,"unrecognized idtype: %d" ,
398+ ( int ) ACLITEM_GET_IDTYPE (* aip ));
378399break ;
379400}
380401while (* p )
@@ -482,7 +503,7 @@ acldefault(GrantObjectType objtype, AclId ownerid)
482503owner_default = ACL_ALL_RIGHTS_NAMESPACE ;
483504break ;
484505default :
485- elog (ERROR ,"acldefault: bogus objtype %d" , (int )objtype );
506+ elog (ERROR ,"unrecognized objtype: %d" , (int )objtype );
486507world_default = ACL_NO_RIGHTS ;/* keep compiler quiet */
487508owner_default = ACL_NO_RIGHTS ;
488509break ;
@@ -644,7 +665,10 @@ recursive_revoke(Acl *acl,
644665AclItem mod_acl ;
645666
646667if (behavior == DROP_RESTRICT )
647- elog (ERROR ,"dependent privileges exist (use CASCADE to revoke them too)" );
668+ ereport (ERROR ,
669+ (errcode (ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST ),
670+ errmsg ("dependent privileges exist" ),
671+ errhint ("Use CASCADE to revoke them too." )));
648672
649673mod_acl .ai_grantor = grantee ;
650674mod_acl .ai_grantee = aip [i ].ai_grantee ;
@@ -718,7 +742,9 @@ aclremove(PG_FUNCTION_ARGS)
718742new_aip = ACL_DAT (new_acl );
719743if (dst == 0 )
720744{/* start */
721- elog (ERROR ,"aclremove: removal of the world ACL??" );
745+ ereport (ERROR ,
746+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
747+ errmsg ("cannot remove the world ACL" )));
722748}
723749else if (dst == old_num - 1 )
724750{/* end */
@@ -784,7 +810,9 @@ makeaclitem(PG_FUNCTION_ARGS)
784810}
785811else if (u_grantee != 0 && g_grantee != 0 )
786812{
787- elog (ERROR ,"cannot specify both user and group" );
813+ ereport (ERROR ,
814+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
815+ errmsg ("cannot specify both user and group" )));
788816}
789817else if (u_grantee != 0 )
790818{
@@ -840,7 +868,9 @@ convert_priv_string(text *priv_type_text)
840868if (strcasecmp (priv_type ,"TEMPORARY" )== 0 )
841869return ACL_CREATE_TEMP ;
842870
843- elog (ERROR ,"invalid privilege type %s" ,priv_type );
871+ ereport (ERROR ,
872+ (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
873+ errmsg ("unrecognized privilege type: \"%s\"" ,priv_type )));
844874return ACL_NO_RIGHTS ;/* keep compiler quiet */
845875}
846876
@@ -1063,8 +1093,9 @@ convert_table_priv_string(text *priv_type_text)
10631093if (strcasecmp (priv_type ,"TRIGGER WITH GRANT OPTION" )== 0 )
10641094return ACL_GRANT_OPTION_FOR (ACL_TRIGGER );
10651095
1066- elog (ERROR ,"has_table_privilege: invalid privilege type %s" ,
1067- priv_type );
1096+ ereport (ERROR ,
1097+ (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
1098+ errmsg ("unrecognized privilege type: \"%s\"" ,priv_type )));
10681099return ACL_NO_RIGHTS ;/* keep compiler quiet */
10691100}
10701101
@@ -1237,7 +1268,9 @@ convert_database_name(text *databasename)
12371268
12381269oid = get_database_oid (dbname );
12391270if (!OidIsValid (oid ))
1240- elog (ERROR ,"database \"%s\" does not exist" ,dbname );
1271+ ereport (ERROR ,
1272+ (errcode (ERRCODE_UNDEFINED_DATABASE ),
1273+ errmsg ("database \"%s\" does not exist" ,dbname )));
12411274
12421275return oid ;
12431276}
@@ -1272,8 +1305,9 @@ convert_database_priv_string(text *priv_type_text)
12721305if (strcasecmp (priv_type ,"TEMP WITH GRANT OPTION" )== 0 )
12731306return ACL_GRANT_OPTION_FOR (ACL_CREATE_TEMP );
12741307
1275- elog (ERROR ,"has_database_privilege: invalid privilege type %s" ,
1276- priv_type );
1308+ ereport (ERROR ,
1309+ (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
1310+ errmsg ("unrecognized privilege type: \"%s\"" ,priv_type )));
12771311return ACL_NO_RIGHTS ;/* keep compiler quiet */
12781312}
12791313
@@ -1448,7 +1482,9 @@ convert_function_name(text *functionname)
14481482CStringGetDatum (funcname )));
14491483
14501484if (!OidIsValid (oid ))
1451- elog (ERROR ,"function \"%s\" does not exist" ,funcname );
1485+ ereport (ERROR ,
1486+ (errcode (ERRCODE_UNDEFINED_FUNCTION ),
1487+ errmsg ("function \"%s\" does not exist" ,funcname )));
14521488
14531489return oid ;
14541490}
@@ -1473,8 +1509,9 @@ convert_function_priv_string(text *priv_type_text)
14731509if (strcasecmp (priv_type ,"EXECUTE WITH GRANT OPTION" )== 0 )
14741510return ACL_GRANT_OPTION_FOR (ACL_EXECUTE );
14751511
1476- elog (ERROR ,"has_function_privilege: invalid privilege type %s" ,
1477- priv_type );
1512+ ereport (ERROR ,
1513+ (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
1514+ errmsg ("unrecognized privilege type: \"%s\"" ,priv_type )));
14781515return ACL_NO_RIGHTS ;/* keep compiler quiet */
14791516}
14801517
@@ -1649,7 +1686,9 @@ convert_language_name(text *languagename)
16491686CStringGetDatum (langname ),
165016870 ,0 ,0 );
16511688if (!OidIsValid (oid ))
1652- elog (ERROR ,"language \"%s\" does not exist" ,langname );
1689+ ereport (ERROR ,
1690+ (errcode (ERRCODE_UNDEFINED_OBJECT ),
1691+ errmsg ("language \"%s\" does not exist" ,langname )));
16531692
16541693return oid ;
16551694}
@@ -1674,8 +1713,9 @@ convert_language_priv_string(text *priv_type_text)
16741713if (strcasecmp (priv_type ,"USAGE WITH GRANT OPTION" )== 0 )
16751714return ACL_GRANT_OPTION_FOR (ACL_USAGE );
16761715
1677- elog (ERROR ,"has_language_privilege: invalid privilege type %s" ,
1678- priv_type );
1716+ ereport (ERROR ,
1717+ (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
1718+ errmsg ("unrecognized privilege type: \"%s\"" ,priv_type )));
16791719return ACL_NO_RIGHTS ;/* keep compiler quiet */
16801720}
16811721
@@ -1850,7 +1890,9 @@ convert_schema_name(text *schemaname)
18501890CStringGetDatum (nspname ),
185118910 ,0 ,0 );
18521892if (!OidIsValid (oid ))
1853- elog (ERROR ,"schema \"%s\" does not exist" ,nspname );
1893+ ereport (ERROR ,
1894+ (errcode (ERRCODE_UNDEFINED_SCHEMA ),
1895+ errmsg ("schema \"%s\" does not exist" ,nspname )));
18541896
18551897return oid ;
18561898}
@@ -1880,7 +1922,8 @@ convert_schema_priv_string(text *priv_type_text)
18801922if (strcasecmp (priv_type ,"USAGE WITH GRANT OPTION" )== 0 )
18811923return ACL_GRANT_OPTION_FOR (ACL_USAGE );
18821924
1883- elog (ERROR ,"has_schema_privilege: invalid privilege type %s" ,
1884- priv_type );
1925+ ereport (ERROR ,
1926+ (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
1927+ errmsg ("unrecognized privilege type: \"%s\"" ,priv_type )));
18851928return ACL_NO_RIGHTS ;/* keep compiler quiet */
18861929}