Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
extern "C"
{
#include "postgres.h"
#include "fmgr.h"
#include "catalog/pg_collation_d.h"
#include "catalog/pg_type_d.h"
#include "executor/spi.h"
#include "utils/builtins.h"
#include "utils/elog.h"
#include "utils/formatting.h"
}
 
#include <cstring>
 
namespace DbmsNetworkAclOld
{
 
static void
spiConnect()
{
    if (SPI_connect() != SPI_OK_CONNECT)
        ereport(ERROR,
                (errmsg("dbms_network_acl_admin: SPI не открылся"),
                 errdetail_internal("Output: [Status: FAIL]")));
}
 
static uint64
execRows(const char *sql, int nargs, Oid *argtypes, Datum *values, const char *nulls, bool read)
{
    int rc;
    uint64 n;
 
    spiConnect();
    rc = SPI_execute_with_args(sql, nargs, argtypes, values, nulls, read, read ? 1 : 0);
    if (rc < 0)
    {
        SPI_finish();
        ereport(ERROR,
                (errmsg("dbms_network_acl_admin: запрос каталога не выполнен"),
                 errdetail_internal("Output: [Status: FAIL, Code: %d]", rc)));
    }
    n = SPI_processed;
    SPI_finish();
    return n;
}
 
static void
badArgument()
{
    ereport(ERROR,
            (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
             errmsg("ORA-29261: bad argument")));
}
 
static void
duplicateAcl(const char *name)
{
    ereport(ERROR,
            (errcode(ERRCODE_DUPLICATE_OBJECT),
             errmsg("ORA-46212: RAS entity with this name already exists."),
             errdetail_internal("Output: [Status: FAIL, Name: %s]", name)));
}
 
static void
missingAcl(const char *name)
{
    ereport(ERROR,
            (errcode(ERRCODE_UNDEFINED_OBJECT),
             errmsg("ORA-46114: A valid RAS ACL name /sys/acls/%s not found.", name)));
}
 
static void
logAcl(const char *status, const char *name, const char *principal, const char *privilege)
{
    ereport(LOG,
            (errmsg("dbms_network_acl_admin: %s", status),
             errdetail_internal("Output: [Status: %s, Name: %s, Principal: %s, Privilege: %s]",
                                status, name, principal ? principal : "-", privilege ? privilege : "-")));
}
 
static char *
argText(FunctionCallInfo fcinfo, int index)
{
    if (PG_ARGISNULL(index))
        return NULL;
    return text_to_cstring(PG_GETARG_TEXT_PP(index));
}
 
static char *
requireText(const char *text)
{
    if (text == NULL || text[0] == '\0')
        badArgument();
    return (char *) text;
}
 
static char *
upperPriv(const char *privilege)
{
    requireText(privilege);
    return str_toupper(privilege, strlen(privilege), DEFAULT_COLLATION_OID);
}
 
static bool
aclExists(const char *name)
{
    Oid argtypes[1] = {TEXTOID};
    Datum values[1];
    char nulls[1] = {' '};
 
    values[0] = CStringGetTextDatum(name);
    return execRows("SELECT 1 FROM pg_catalog.dbms_network_acl WHERE acl_name = $1",
                    1, argtypes, values, nulls, true) == 1;
}
 
static void
requireAcl(const char *name)
{
    requireText(name);
    if (!aclExists(name))
        missingAcl(name);
}
 
static bytea *
newAclid()
{
    bytea *b = (bytea *) palloc(VARHDRSZ + 16);
 
    SET_VARSIZE(b, VARHDRSZ + 16);
    if (!pg_strong_random(VARDATA(b), 16))
        ereport(ERROR,
                (errmsg("dbms_network_acl_admin: не удалось получить идентификатор ACL"),
                 errdetail_internal("Output: [Status: FAIL]")));
    return b;
}
 
struct When
{
    bool start_null;
    Datum start_date;
    bool end_null;
    Datum end_date;
    bool pos_null;
    int32 position;
};
 
static When
readWhen(FunctionCallInfo fcinfo, int posIndex, int startIndex, int endIndex, bool hasPos)
{
    When w;
 
    memset(&w, 0, sizeof(w));
    w.pos_null = true;
    if (hasPos && !PG_ARGISNULL(posIndex))
    {
        w.pos_null = false;
        w.position = PG_GETARG_INT32(posIndex);
    }
    w.start_null = PG_ARGISNULL(startIndex);
    if (!w.start_null)
        w.start_date = PG_GETARG_DATUM(startIndex);
    w.end_null = PG_ARGISNULL(endIndex);
    if (!w.end_null)
        w.end_date = PG_GETARG_DATUM(endIndex);
    return w;
}
 
static void
insertPriv(const char *acl, const char *principal, bool is_grant, const char *privilege, const When *w)
{
    const char *sql =
        "INSERT INTO pg_catalog.dbms_network_acl_priv "
        "(acl_name, principal, is_grant, privilege, \"position\", start_date, end_date) "
        "SELECT $1, $2, $3, $4, $5, $6, $7 "
        " WHERE NOT EXISTS ("
        "   SELECT 1 FROM pg_catalog.dbms_network_acl_priv "
        "    WHERE acl_name = $1 AND principal = $2 AND is_grant = $3 AND privilege = $4)";
    Oid argtypes[7] = {TEXTOID, TEXTOID, BOOLOID, TEXTOID, INT4OID, TIMESTAMPTZOID, TIMESTAMPTZOID};
    Datum values[7];
    char nulls[7];
 
    values[0] = CStringGetTextDatum(acl);
    nulls[0] = ' ';
    values[1] = CStringGetTextDatum(principal);
    nulls[1] = ' ';
    values[2] = BoolGetDatum(is_grant);
    nulls[2] = ' ';
    values[3] = CStringGetTextDatum(privilege);
    nulls[3] = ' ';
    values[4] = Int32GetDatum(w->position);
    nulls[4] = w->pos_null ? 'n' : ' ';
    values[5] = w->start_date;
    nulls[5] = w->start_null ? 'n' : ' ';
    values[6] = w->end_date;
    nulls[6] = w->end_null ? 'n' : ' ';
    execRows(sql, 7, argtypes, values, nulls, false);
}
 
void
createAcl(const char *acl, const char *description, const char *principal, bool is_grant,
          const char *privilege, const When *w)
{
    const char *sql =
        "INSERT INTO pg_catalog.dbms_network_acl (acl_name, description, aclid) VALUES ($1, $2, $3)";
    Oid argtypes[3] = {TEXTOID, TEXTOID, BYTEAOID};
    Datum values[3];
    char nulls[3] = {' ', ' ', ' '};
    char *priv;
    bytea *id;
 
    requireText(acl);
    requireText(principal);
    priv = upperPriv(privilege);
    if (aclExists(acl))
        duplicateAcl(acl);
 
    id = newAclid();
    values[0] = CStringGetTextDatum(acl);
    if (description == NULL)
    {
        values[1] = (Datum) 0;
        nulls[1] = 'n';
    }
    else
        values[1] = CStringGetTextDatum(description);
    values[2] = PointerGetDatum(id);
    execRows(sql, 3, argtypes, values, nulls, false);
    insertPriv(acl, principal, is_grant, priv, w);
    logAcl("ACL создан", acl, principal, priv);
}
 
void
dropAcl(const char *acl)
{
    Oid argtypes[1] = {TEXTOID};
    Datum values[1];
    char nulls[1] = {' '};
 
    requireAcl(acl);
    values[0] = CStringGetTextDatum(acl);
    execRows("DELETE FROM pg_catalog.dbms_network_acl_host_ace WHERE acl_name = $1",
             1, argtypes, values, nulls, false);
    execRows("DELETE FROM pg_catalog.dbms_network_acl_priv WHERE acl_name = $1",
             1, argtypes, values, nulls, false);
    execRows("DELETE FROM pg_catalog.dbms_network_acl WHERE acl_name = $1",
             1, argtypes, values, nulls, false);
    logAcl("ACL удалён", acl, NULL, NULL);
}
 
void
addPrivilege(const char *acl, const char *principal, bool is_grant, const char *privilege, const When *w)
{
    char *priv;
 
    requireAcl(acl);
    requireText(principal);
    priv = upperPriv(privilege);
    insertPriv(acl, principal, is_grant, priv, w);
    logAcl("привилегия добавлена", acl, principal, priv);
}
 
void
deletePrivilege(const char *acl, const char *principal, bool grant_null, bool is_grant,
                const char *privilege)
{
    const char *privSql =
        "DELETE FROM pg_catalog.dbms_network_acl_priv "
        " WHERE acl_name = $1 AND principal = $2 "
        "   AND ($3 IS NULL OR is_grant = $3) "
        "   AND ($4 IS NULL OR privilege = $4)";
    const char *hostSql =
        "DELETE FROM pg_catalog.dbms_network_acl_host_ace "
        " WHERE acl_name = $1 AND principal = $2 "
        "   AND ($3 IS NULL OR is_grant = $3) "
        "   AND ($4 IS NULL OR privilege = $4)";
    Oid argtypes[4] = {TEXTOID, TEXTOID, BOOLOID, TEXTOID};
    Datum values[4];
    char nulls[4];
    char *priv = NULL;
 
    requireAcl(acl);
    requireText(principal);
    if (privilege != NULL && privilege[0] != '\0')
        priv = upperPriv(privilege);
    values[0] = CStringGetTextDatum(acl);
    nulls[0] = ' ';
    values[1] = CStringGetTextDatum(principal);
    nulls[1] = ' ';
    values[2] = BoolGetDatum(is_grant);
    nulls[2] = grant_null ? 'n' : ' ';
    values[3] = priv ? CStringGetTextDatum(priv) : (Datum) 0;
    nulls[3] = priv ? ' ' : 'n';
    execRows(privSql, 4, argtypes, values, nulls, false);
    execRows(hostSql, 4, argtypes, values, nulls, false);
    logAcl("привилегия снята", acl, principal, priv);
}
 
static void
materialize(const char *host, bool lower_null, int32 lower, bool upper_null, int32 upper,
            bool private_target, const char *acl)
{
    const char *sql =
        "INSERT INTO pg_catalog.dbms_network_acl_host_ace "
        "(host, lower_port, upper_port, principal, privilege, is_grant, inverted, "
        " principal_type, start_date, end_date, private_target, acl_name) "
        "SELECT $1, $2, $3, p.principal, p.privilege, p.is_grant, false, "
        "       2, p.start_date, p.end_date, $4, p.acl_name "
        "  FROM pg_catalog.dbms_network_acl_priv p "
        " WHERE p.acl_name = $5 "
        "   AND NOT EXISTS ("
        "        SELECT 1 FROM pg_catalog.dbms_network_acl_host_ace h "
        "         WHERE h.acl_name = p.acl_name AND h.host = $1 "
        "           AND h.lower_port IS NOT DISTINCT FROM $2 "
        "           AND h.upper_port IS NOT DISTINCT FROM $3 "
        "           AND h.principal = p.principal AND h.privilege = p.privilege "
        "           AND h.is_grant = p.is_grant)";
    Oid argtypes[5] = {TEXTOID, INT4OID, INT4OID, BOOLOID, TEXTOID};
    Datum values[5];
    char nulls[5];
 
    values[0] = CStringGetTextDatum(host);
    nulls[0] = ' ';
    values[1] = Int32GetDatum(lower);
    nulls[1] = lower_null ? 'n' : ' ';
    values[2] = Int32GetDatum(upper);
    nulls[2] = upper_null ? 'n' : ' ';
    values[3] = BoolGetDatum(private_target);
    nulls[3] = ' ';
    values[4] = CStringGetTextDatum(acl);
    nulls[4] = ' ';
    execRows(sql, 5, argtypes, values, nulls, false);
}
 
void
bindHost(const char *acl, const char *host, bool lower_null, int32 lower, bool upper_null, int32 upper,
         bool private_target, const char *status)
{
    requireAcl(acl);
    requireText(host);
    materialize(host, lower_null, lower, upper_null, upper, private_target, acl);
    logAcl(status, acl, NULL, host);
}
 
void
unassignAcl(const char *acl, const char *host, bool lower_null, int32 lower, bool upper_null, int32 upper)
{
    const char *sql =
        "DELETE FROM pg_catalog.dbms_network_acl_host_ace "
        " WHERE acl_name IS NOT DISTINCT FROM $1 "
        "   AND host IS NOT DISTINCT FROM $2 "
        "   AND lower_port IS NOT DISTINCT FROM $3 "
        "   AND upper_port IS NOT DISTINCT FROM $4";
    Oid argtypes[4] = {TEXTOID, TEXTOID, INT4OID, INT4OID};
    Datum values[4];
    char nulls[4];
 
    values[0] = acl ? CStringGetTextDatum(acl) : (Datum) 0;
    nulls[0] = acl ? ' ' : 'n';
    values[1] = host ? CStringGetTextDatum(host) : (Datum) 0;
    nulls[1] = host ? ' ' : 'n';
    values[2] = Int32GetDatum(lower);
    nulls[2] = lower_null ? 'n' : ' ';
    values[3] = Int32GetDatum(upper);
    nulls[3] = upper_null ? 'n' : ' ';
    execRows(sql, 4, argtypes, values, nulls, false);
    logAcl("привязка снята", acl, NULL, host);
}
 
static int
privilegeValue(const char *acl, const char *principal, const char *privilege, bool *found)
{
    const char *sql =
        "SELECT is_grant FROM pg_catalog.dbms_network_acl_priv "
        " WHERE acl_name = $1 AND principal = $2 AND privilege = $3 LIMIT 1";
    Oid argtypes[3] = {TEXTOID, TEXTOID, TEXTOID};
    Datum values[3];
    char nulls[3] = {' ', ' ', ' '};
    int rc;
    int result = 0;
 
    *found = false;
    values[0] = CStringGetTextDatum(acl);
    values[1] = CStringGetTextDatum(principal);
    values[2] = CStringGetTextDatum(privilege);
    spiConnect();
    rc = SPI_execute_with_args(sql, 3, argtypes, values, nulls, true, 1);
    if (rc != SPI_OK_SELECT)
    {
        SPI_finish();
        ereport(ERROR,
                (errmsg("dbms_network_acl_admin: запрос каталога не выполнен"),
                 errdetail_internal("Output: [Status: FAIL, Code: %d]", rc)));
    }
    if (SPI_processed == 1)
    {
        bool isnull = false;
        Datum d = SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull);
 
        *found = true;
        if (!isnull && DatumGetBool(d))
            result = 1;
    }
    SPI_finish();
    return result;
}
 
int
checkPrivilege(const char *acl, const char *principal, const char *privilege)
{
    char *priv;
    bool found = false;
    int value;
 
    requireAcl(acl);
    requireText(principal);
    priv = upperPriv(privilege);
    value = privilegeValue(acl, principal, priv, &found);
    if (!found)
        return -1;
    return value;
}
 
char *
aclById(bytea *id)
{
    MemoryContext caller = CurrentMemoryContext;
    const char *sql = "SELECT acl_name FROM pg_catalog.dbms_network_acl WHERE aclid = $1";
    Oid argtypes[1] = {BYTEAOID};
    Datum values[1];
    char nulls[1] = {' '};
    int rc;
    char *name = NULL;
 
    values[0] = PointerGetDatum(id);
    spiConnect();
    rc = SPI_execute_with_args(sql, 1, argtypes, values, nulls, true, 1);
    if (rc != SPI_OK_SELECT)
    {
        SPI_finish();
        ereport(ERROR,
                (errmsg("dbms_network_acl_admin: запрос каталога не выполнен"),
                 errdetail_internal("Output: [Status: FAIL, Code: %d]", rc)));
    }
    if (SPI_processed == 1)
    {
        bool isnull = false;
        Datum d = SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull);
 
        if (!isnull)
            name = MemoryContextStrdup(caller, text_to_cstring(DatumGetTextPP(d)));
    }
    SPI_finish();
    return name;
}
 
} /* namespace DbmsNetworkAclOld */
 
extern "C"
{
 
PG_FUNCTION_INFO_V1(c_dbms_network_acl_admin_create_acl);
PG_FUNCTION_INFO_V1(c_dbms_network_acl_admin_drop_acl);
PG_FUNCTION_INFO_V1(c_dbms_network_acl_admin_add_privilege);
PG_FUNCTION_INFO_V1(c_dbms_network_acl_admin_delete_privilege);
PG_FUNCTION_INFO_V1(c_dbms_network_acl_admin_assign_acl);
PG_FUNCTION_INFO_V1(c_dbms_network_acl_admin_unassign_acl);
PG_FUNCTION_INFO_V1(c_dbms_network_acl_admin_check_privilege);
PG_FUNCTION_INFO_V1(c_dbms_network_acl_admin_check_privilege_aclid);
PG_FUNCTION_INFO_V1(c_dbms_network_acl_admin_set_host_acl);
PG_FUNCTION_INFO_V1(c_dbms_network_acl_admin_append_host_acl);
 
Datum
c_dbms_network_acl_admin_create_acl(PG_FUNCTION_ARGS)
{
    DbmsNetworkAclOld::When w = DbmsNetworkAclOld::readWhen(fcinfo, -1, 5, 6, false);
    bool is_grant = true;
 
    if (PG_ARGISNULL(3))
        DbmsNetworkAclOld::badArgument();
    is_grant = PG_GETARG_BOOL(3);
    DbmsNetworkAclOld::createAcl(DbmsNetworkAclOld::argText(fcinfo, 0),
                                 DbmsNetworkAclOld::argText(fcinfo, 1),
                                 DbmsNetworkAclOld::argText(fcinfo, 2),
                                 is_grant,
                                 DbmsNetworkAclOld::argText(fcinfo, 4),
                                 &w);
    PG_RETURN_VOID();
}
 
Datum
c_dbms_network_acl_admin_drop_acl(PG_FUNCTION_ARGS)
{
    DbmsNetworkAclOld::dropAcl(DbmsNetworkAclOld::argText(fcinfo, 0));
    PG_RETURN_VOID();
}
 
Datum
c_dbms_network_acl_admin_add_privilege(PG_FUNCTION_ARGS)
{
    DbmsNetworkAclOld::When w = DbmsNetworkAclOld::readWhen(fcinfo, 4, 5, 6, true);
    bool is_grant = true;
 
    if (PG_ARGISNULL(2))
        DbmsNetworkAclOld::badArgument();
    is_grant = PG_GETARG_BOOL(2);
    DbmsNetworkAclOld::addPrivilege(DbmsNetworkAclOld::argText(fcinfo, 0),
                                    DbmsNetworkAclOld::argText(fcinfo, 1),
                                    is_grant,
                                    DbmsNetworkAclOld::argText(fcinfo, 3),
                                    &w);
    PG_RETURN_VOID();
}
 
Datum
c_dbms_network_acl_admin_delete_privilege(PG_FUNCTION_ARGS)
{
    bool grant_null = PG_ARGISNULL(2);
    bool is_grant = grant_null ? false : PG_GETARG_BOOL(2);
 
    DbmsNetworkAclOld::deletePrivilege(DbmsNetworkAclOld::argText(fcinfo, 0),
                                       DbmsNetworkAclOld::argText(fcinfo, 1),
                                       grant_null, is_grant,
                                       DbmsNetworkAclOld::argText(fcinfo, 3));
    PG_RETURN_VOID();
}
 
Datum
c_dbms_network_acl_admin_assign_acl(PG_FUNCTION_ARGS)
{
    bool lower_null = PG_ARGISNULL(2);
    bool upper_null = PG_ARGISNULL(3);
 
    DbmsNetworkAclOld::bindHost(DbmsNetworkAclOld::argText(fcinfo, 0),
                                DbmsNetworkAclOld::argText(fcinfo, 1),
                                lower_null, lower_null ? 0 : PG_GETARG_INT32(2),
                                upper_null, upper_null ? 0 : PG_GETARG_INT32(3),
                                false, "ACL привязан");
    PG_RETURN_VOID();
}
 
Datum
c_dbms_network_acl_admin_unassign_acl(PG_FUNCTION_ARGS)
{
    bool lower_null = PG_ARGISNULL(2);
    bool upper_null = PG_ARGISNULL(3);
 
    DbmsNetworkAclOld::unassignAcl(DbmsNetworkAclOld::argText(fcinfo, 0),
                                   DbmsNetworkAclOld::argText(fcinfo, 1),
                                   lower_null, lower_null ? 0 : PG_GETARG_INT32(2),
                                   upper_null, upper_null ? 0 : PG_GETARG_INT32(3));
    PG_RETURN_VOID();
}
 
Datum
c_dbms_network_acl_admin_check_privilege(PG_FUNCTION_ARGS)
{
    int value = DbmsNetworkAclOld::checkPrivilege(DbmsNetworkAclOld::argText(fcinfo, 0),
                                                  DbmsNetworkAclOld::argText(fcinfo, 1),
                                                  DbmsNetworkAclOld::argText(fcinfo, 2));
 
    if (value < 0)
        PG_RETURN_NULL();
    PG_RETURN_INT32(value);
}
 
Datum
c_dbms_network_acl_admin_check_privilege_aclid(PG_FUNCTION_ARGS)
{
    char *acl;
    int value;
 
    if (PG_ARGISNULL(0))
        DbmsNetworkAclOld::badArgument();
    acl = DbmsNetworkAclOld::aclById(PG_GETARG_BYTEA_PP(0));
    if (acl == NULL)
        DbmsNetworkAclOld::missingAcl("");
    value = DbmsNetworkAclOld::checkPrivilege(acl,
                                              DbmsNetworkAclOld::argText(fcinfo, 1),
                                              DbmsNetworkAclOld::argText(fcinfo, 2));
    if (value < 0)
        PG_RETURN_NULL();
    PG_RETURN_INT32(value);
}
 
Datum
c_dbms_network_acl_admin_set_host_acl(PG_FUNCTION_ARGS)
{
    bool lower_null = PG_ARGISNULL(1);
    bool upper_null = PG_ARGISNULL(2);
    bool private_target = false;
 
    if (!PG_ARGISNULL(4))
        private_target = PG_GETARG_BOOL(4);
    DbmsNetworkAclOld::bindHost(DbmsNetworkAclOld::argText(fcinfo, 3),
                                DbmsNetworkAclOld::argText(fcinfo, 0),
                                lower_null, lower_null ? 0 : PG_GETARG_INT32(1),
                                upper_null, upper_null ? 0 : PG_GETARG_INT32(2),
                                private_target, "ACL назначен");
    PG_RETURN_VOID();
}
 
Datum
c_dbms_network_acl_admin_append_host_acl(PG_FUNCTION_ARGS)
{
    bool lower_null = PG_ARGISNULL(1);
    bool upper_null = PG_ARGISNULL(2);
    bool private_target = false;
 
    if (!PG_ARGISNULL(4))
        private_target = PG_GETARG_BOOL(4);
    DbmsNetworkAclOld::bindHost(DbmsNetworkAclOld::argText(fcinfo, 3),
                                DbmsNetworkAclOld::argText(fcinfo, 0),
                                lower_null, lower_null ? 0 : PG_GETARG_INT32(1),
                                upper_null, upper_null ? 0 : PG_GETARG_INT32(2),
                                private_target, "ACL добавлен к хосту");
    PG_RETURN_VOID();
}
 
} /* extern "C" */