|
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,43 @@ 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 | +#ifdef _WIN32 |
| 675 | + /* TODO: Policy function to read Windows ACLs (ENT-13019) */ |
| 676 | + Rlist *acls = NULL; |
| 677 | + errno = ENOTSUP; |
| 678 | +#else |
| 679 | + Rlist *acls = GetACLs(path, StringEqual(type, "access")); |
| 680 | +#endif /* _WIN32 */ |
| 681 | + if (acls == NULL) |
| 682 | + { |
| 683 | + Log((errno != ENOTSUP) ? LOG_LEVEL_ERR : LOG_LEVEL_VERBOSE, |
| 684 | + "Function %s failed to get ACLs for '%s': %s", |
| 685 | + fp->name, path, GetErrorStr()); |
| 686 | + |
| 687 | + if (errno != ENOTSUP) |
| 688 | + { |
| 689 | + return FnFailure(); |
| 690 | + } /* else we'll just return an empty list instead */ |
| 691 | + } |
| 692 | + |
| 693 | + return (FnCallResult) { FNCALL_SUCCESS, { acls, RVAL_TYPE_LIST } }; |
| 694 | +} |
| 695 | + |
| 696 | +/*********************************************************************/ |
| 697 | + |
657 | 698 | static FnCallResult FnCallAnd(EvalContext *ctx,
|
658 | 699 | ARG_UNUSED const Policy *policy,
|
659 | 700 | ARG_UNUSED const FnCall *fp,
|
@@ -9776,6 +9817,13 @@ static const FnCallArg AND_ARGS[] =
|
9776 | 9817 | {NULL, CF_DATA_TYPE_NONE, NULL}
|
9777 | 9818 | };
|
9778 | 9819 |
|
| 9820 | +static const FnCallArg GET_ACLS_ARGS[] = |
| 9821 | +{ |
| 9822 | + {CF_ABSPATHRANGE, CF_DATA_TYPE_STRING, "Path to file or directory"}, |
| 9823 | + {"default,access", CF_DATA_TYPE_OPTION, "Whether to get default or access ACL"}, |
| 9824 | + {NULL, CF_DATA_TYPE_NONE, NULL}, |
| 9825 | +}; |
| 9826 | + |
9779 | 9827 | static const FnCallArg AGO_ARGS[] =
|
9780 | 9828 | {
|
9781 | 9829 | {"0,1000", CF_DATA_TYPE_INT, "Years"},
|
@@ -10820,6 +10868,8 @@ const FnCallType CF_FNCALL_TYPES[] =
|
10820 | 10868 | FNCALL_OPTION_NONE, FNCALL_CATEGORY_FILES, SYNTAX_STATUS_NORMAL),
|
10821 | 10869 | FnCallTypeNew("accumulated", CF_DATA_TYPE_INT, ACCUM_ARGS, &FnCallAccumulatedDate, "Convert an accumulated amount of time into a system representation",
|
10822 | 10870 | FNCALL_OPTION_NONE, FNCALL_CATEGORY_DATA, SYNTAX_STATUS_NORMAL),
|
| 10871 | + FnCallTypeNew("getacls", CF_DATA_TYPE_STRING_LIST, GET_ACLS_ARGS, &FnCallGetACLs, "Get ACLs of a given file", |
| 10872 | + FNCALL_OPTION_NONE, FNCALL_CATEGORY_FILES, SYNTAX_STATUS_NORMAL), |
10823 | 10873 | FnCallTypeNew("ago", CF_DATA_TYPE_INT, AGO_ARGS, &FnCallAgoDate, "Convert a time relative to now to an integer system representation",
|
10824 | 10874 | FNCALL_OPTION_NONE, FNCALL_CATEGORY_DATA, SYNTAX_STATUS_NORMAL),
|
10825 | 10875 | FnCallTypeNew("and", CF_DATA_TYPE_CONTEXT, AND_ARGS, &FnCallAnd, "Calculate whether all arguments evaluate to true",
|
|
0 commit comments