|
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,32 @@ 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(LOG_LEVEL_ERR, "Function %s failed to get ACLs for '%s': %s", |
| 678 | + fp->name, path, GetErrorStr()); |
| 679 | + return FnFailure(); |
| 680 | + } |
| 681 | + |
| 682 | + return (FnCallResult) { FNCALL_SUCCESS, { acls, RVAL_TYPE_LIST } }; |
| 683 | +} |
| 684 | + |
| 685 | +/*********************************************************************/ |
| 686 | + |
657 | 687 | static FnCallResult FnCallAnd(EvalContext *ctx,
|
658 | 688 | ARG_UNUSED const Policy *policy,
|
659 | 689 | ARG_UNUSED const FnCall *fp,
|
@@ -9754,6 +9784,13 @@ static const FnCallArg AND_ARGS[] =
|
9754 | 9784 | {NULL, CF_DATA_TYPE_NONE, NULL}
|
9755 | 9785 | };
|
9756 | 9786 |
|
| 9787 | +static const FnCallArg GET_ACLS_ARGS[] = |
| 9788 | +{ |
| 9789 | + {CF_ABSPATHRANGE, CF_DATA_TYPE_STRING, "Path to file or directory"}, |
| 9790 | + {"default,access", CF_DATA_TYPE_OPTION, "Whether to get default- or access ACL"}, |
| 9791 | + {NULL, CF_DATA_TYPE_NONE, NULL}, |
| 9792 | +}; |
| 9793 | + |
9757 | 9794 | static const FnCallArg AGO_ARGS[] =
|
9758 | 9795 | {
|
9759 | 9796 | {"0,1000", CF_DATA_TYPE_INT, "Years"},
|
@@ -10791,6 +10828,8 @@ const FnCallType CF_FNCALL_TYPES[] =
|
10791 | 10828 | FNCALL_OPTION_NONE, FNCALL_CATEGORY_FILES, SYNTAX_STATUS_NORMAL),
|
10792 | 10829 | FnCallTypeNew("accumulated", CF_DATA_TYPE_INT, ACCUM_ARGS, &FnCallAccumulatedDate, "Convert an accumulated amount of time into a system representation",
|
10793 | 10830 | FNCALL_OPTION_NONE, FNCALL_CATEGORY_DATA, SYNTAX_STATUS_NORMAL),
|
| 10831 | + FnCallTypeNew("getacls", CF_DATA_TYPE_STRING_LIST, GET_ACLS_ARGS, &FnCallGetACLs, "Get ACLs of a given file", |
| 10832 | + FNCALL_OPTION_NONE, FNCALL_CATEGORY_FILES, SYNTAX_STATUS_NORMAL), |
10794 | 10833 | FnCallTypeNew("ago", CF_DATA_TYPE_INT, AGO_ARGS, &FnCallAgoDate, "Convert a time relative to now to an integer system representation",
|
10795 | 10834 | FNCALL_OPTION_NONE, FNCALL_CATEGORY_DATA, SYNTAX_STATUS_NORMAL),
|
10796 | 10835 | FnCallTypeNew("and", CF_DATA_TYPE_CONTEXT, AND_ARGS, &FnCallAnd, "Calculate whether all arguments evaluate to true",
|
|
0 commit comments