|
82 | 82 | #include <libgen.h>
|
83 | 83 |
|
84 | 84 | #include <ctype.h>
|
| 85 | +#include <cf3.defs.h> |
| 86 | +#include <compiler.h> |
| 87 | +#include <rlist.h> |
| 88 | +#include <acl_tools.h> |
85 | 89 |
|
86 | 90 | #ifdef HAVE_LIBCURL
|
87 | 91 | #include <curl/curl.h>
|
@@ -654,6 +658,37 @@ static Rlist *GetHostsFromLastseenDB(Seq *host_data, time_t horizon, HostsSeenFi
|
654 | 658 |
|
655 | 659 | /*********************************************************************/
|
656 | 660 |
|
| 661 | +static FnCallResult FnCallGetACLs(ARG_UNUSED EvalContext *ctx, |
| 662 | + ARG_UNUSED const Policy *policy, |
| 663 | + const FnCall *fp, |
| 664 | + const Rlist *final_args) |
| 665 | +{ |
| 666 | + assert(fp != NULL); |
| 667 | + assert(final_args != NULL); |
| 668 | + assert(final_args->next != NULL); |
| 669 | + |
| 670 | + const char *path = RlistScalarValue(final_args); |
| 671 | + const char *type = RlistScalarValue(final_args->next); |
| 672 | + assert(StringEqual(type, "default") || StringEqual(type, "access")); |
| 673 | + |
| 674 | + Rlist *acls = GetACLs(path, StringEqual(type, "access")); |
| 675 | + if (acls == NULL) |
| 676 | + { |
| 677 | + Log((errno != ENOTSUPP) ? LOG_LEVEL_ERR : LOG_LEVEL_VERBOSE, |
| 678 | + "Function %s failed to get ACLs for '%s': %s", |
| 679 | + fp->name, path, GetErrorStr()); |
| 680 | + |
| 681 | + if (errno != ENOTSUPP) |
| 682 | + { |
| 683 | + return FnFailure(); |
| 684 | + } /* else we'll just return an empty list instead */ |
| 685 | + } |
| 686 | + |
| 687 | + return (FnCallResult) { FNCALL_SUCCESS, { acls, RVAL_TYPE_LIST } }; |
| 688 | +} |
| 689 | + |
| 690 | +/*********************************************************************/ |
| 691 | + |
657 | 692 | static FnCallResult FnCallAnd(EvalContext *ctx,
|
658 | 693 | ARG_UNUSED const Policy *policy,
|
659 | 694 | ARG_UNUSED const FnCall *fp,
|
@@ -9754,6 +9789,13 @@ static const FnCallArg AND_ARGS[] =
|
9754 | 9789 | {NULL, CF_DATA_TYPE_NONE, NULL}
|
9755 | 9790 | };
|
9756 | 9791 |
|
| 9792 | +static const FnCallArg GET_ACLS_ARGS[] = |
| 9793 | +{ |
| 9794 | + {CF_ABSPATHRANGE, CF_DATA_TYPE_STRING, "Path to file or directory"}, |
| 9795 | + {"default,access", CF_DATA_TYPE_OPTION, "Whether to get default- or access ACL"}, |
| 9796 | + {NULL, CF_DATA_TYPE_NONE, NULL}, |
| 9797 | +}; |
| 9798 | + |
9757 | 9799 | static const FnCallArg AGO_ARGS[] =
|
9758 | 9800 | {
|
9759 | 9801 | {"0,1000", CF_DATA_TYPE_INT, "Years"},
|
@@ -10791,6 +10833,8 @@ const FnCallType CF_FNCALL_TYPES[] =
|
10791 | 10833 | FNCALL_OPTION_NONE, FNCALL_CATEGORY_FILES, SYNTAX_STATUS_NORMAL),
|
10792 | 10834 | FnCallTypeNew("accumulated", CF_DATA_TYPE_INT, ACCUM_ARGS, &FnCallAccumulatedDate, "Convert an accumulated amount of time into a system representation",
|
10793 | 10835 | FNCALL_OPTION_NONE, FNCALL_CATEGORY_DATA, SYNTAX_STATUS_NORMAL),
|
| 10836 | + FnCallTypeNew("getacls", CF_DATA_TYPE_STRING_LIST, GET_ACLS_ARGS, &FnCallGetACLs, "Get ACLs of a given file", |
| 10837 | + FNCALL_OPTION_NONE, FNCALL_CATEGORY_FILES, SYNTAX_STATUS_NORMAL), |
10794 | 10838 | FnCallTypeNew("ago", CF_DATA_TYPE_INT, AGO_ARGS, &FnCallAgoDate, "Convert a time relative to now to an integer system representation",
|
10795 | 10839 | FNCALL_OPTION_NONE, FNCALL_CATEGORY_DATA, SYNTAX_STATUS_NORMAL),
|
10796 | 10840 | FnCallTypeNew("and", CF_DATA_TYPE_CONTEXT, AND_ARGS, &FnCallAnd, "Calculate whether all arguments evaluate to true",
|
|
0 commit comments