* GetUserMapping - look up the user mapping. * * If no mapping is found for the supplied user, we also look for * PUBLIC mappings (userid == InvalidOid). */
| 299 | * PUBLIC mappings (userid == InvalidOid). |
| 300 | */ |
| 301 | UserMapping * |
| 302 | GetUserMapping(Oid userid, Oid serverid) |
| 303 | { |
| 304 | Datum datum; |
| 305 | HeapTuple tp; |
| 306 | bool isnull; |
| 307 | UserMapping *um; |
| 308 | |
| 309 | tp = SearchSysCache2(USERMAPPINGUSERSERVER, |
| 310 | ObjectIdGetDatum(userid), |
| 311 | ObjectIdGetDatum(serverid)); |
| 312 | |
| 313 | if (!HeapTupleIsValid(tp)) |
| 314 | { |
| 315 | /* Not found for the specific user -- try PUBLIC */ |
| 316 | tp = SearchSysCache2(USERMAPPINGUSERSERVER, |
| 317 | ObjectIdGetDatum(InvalidOid), |
| 318 | ObjectIdGetDatum(serverid)); |
| 319 | } |
| 320 | |
| 321 | if (!HeapTupleIsValid(tp)) |
| 322 | ereport(ERROR, |
| 323 | (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 324 | errmsg("user mapping not found for \"%s\"", |
| 325 | MappingUserName(userid)))); |
| 326 | |
| 327 | um = (UserMapping *) palloc(sizeof(UserMapping)); |
| 328 | um->umid = ((Form_pg_user_mapping) GETSTRUCT(tp))->oid; |
| 329 | um->userid = userid; |
| 330 | um->serverid = serverid; |
| 331 | |
| 332 | /* Extract the umoptions */ |
| 333 | datum = SysCacheGetAttr(USERMAPPINGUSERSERVER, |
| 334 | tp, |
| 335 | Anum_pg_user_mapping_umoptions, |
| 336 | &isnull); |
| 337 | if (isnull) |
| 338 | um->options = NIL; |
| 339 | else |
| 340 | um->options = untransformRelOptions(datum); |
| 341 | |
| 342 | ReleaseSysCache(tp); |
| 343 | |
| 344 | return um; |
| 345 | } |
| 346 | |
| 347 | List * |
| 348 | GetForeignServerSegsByRelId(Oid relid) |
no test coverage detected