* dumpSecLabel * * This routine is used to dump any security labels associated with the * object handed to this routine. The routine takes the object type * and object name (ready to print, except for schema decoration), plus * the namespace and owner of the object (for labeling the ArchiveEntry), * plus catalog ID and subid which are the lookup key for pg_seclabel, * plus the dump ID for t
| 16880 | * calling ArchiveEntry() for the specified object. |
| 16881 | */ |
| 16882 | static void |
| 16883 | dumpSecLabel(Archive *fout, const char *type, const char *name, |
| 16884 | const char *namespace, const char *owner, |
| 16885 | CatalogId catalogId, int subid, DumpId dumpId) |
| 16886 | { |
| 16887 | DumpOptions *dopt = fout->dopt; |
| 16888 | SecLabelItem *labels; |
| 16889 | int nlabels; |
| 16890 | int i; |
| 16891 | PQExpBuffer query; |
| 16892 | |
| 16893 | /* do nothing, if --no-security-labels is supplied */ |
| 16894 | if (dopt->no_security_labels) |
| 16895 | return; |
| 16896 | |
| 16897 | /* Security labels are schema not data ... except blob labels are data */ |
| 16898 | if (strcmp(type, "LARGE OBJECT") != 0) |
| 16899 | { |
| 16900 | if (dopt->dataOnly) |
| 16901 | return; |
| 16902 | } |
| 16903 | else |
| 16904 | { |
| 16905 | /* We do dump blob security labels in binary-upgrade mode */ |
| 16906 | if (dopt->schemaOnly && !dopt->binary_upgrade) |
| 16907 | return; |
| 16908 | } |
| 16909 | |
| 16910 | /* Search for security labels associated with catalogId, using table */ |
| 16911 | nlabels = findSecLabels(fout, catalogId.tableoid, catalogId.oid, &labels); |
| 16912 | |
| 16913 | query = createPQExpBuffer(); |
| 16914 | |
| 16915 | for (i = 0; i < nlabels; i++) |
| 16916 | { |
| 16917 | /* |
| 16918 | * Ignore label entries for which the subid doesn't match. |
| 16919 | */ |
| 16920 | if (labels[i].objsubid != subid) |
| 16921 | continue; |
| 16922 | |
| 16923 | appendPQExpBuffer(query, |
| 16924 | "SECURITY LABEL FOR %s ON %s ", |
| 16925 | fmtId(labels[i].provider), type); |
| 16926 | if (namespace && *namespace) |
| 16927 | appendPQExpBuffer(query, "%s.", fmtId(namespace)); |
| 16928 | appendPQExpBuffer(query, "%s IS ", name); |
| 16929 | appendStringLiteralAH(query, labels[i].label, fout); |
| 16930 | appendPQExpBufferStr(query, ";\n"); |
| 16931 | } |
| 16932 | |
| 16933 | if (query->len > 0) |
| 16934 | { |
| 16935 | PQExpBuffer tag = createPQExpBuffer(); |
| 16936 | |
| 16937 | appendPQExpBuffer(tag, "%s %s", type, name); |
| 16938 | ArchiveEntry(fout, nilCatalogId, createDumpId(), |
| 16939 | ARCHIVE_OPTS(.tag = tag->data, |
no test coverage detected