Example #1
0
static void DeleteTypeContext(Policy *policy, enum typesequence type, const ReportContext *report_context)
{
    switch (type)
    {
    case kp_classes:
        HashVariables(policy, THIS_BUNDLE, report_context);
        break;

    case kp_environments:
        DeleteEnvironmentsContext();
        break;

    case kp_files:

        ConnectionsCleanup();
        break;

    case kp_processes:
        break;

    case kp_storage:
#ifndef __MINGW32__
    {
        Attributes a = { {0} };
        CfOut(cf_verbose, "", " -> Number of changes observed in %s is %d\n", VFSTAB[VSYSTEMHARDCLASS], FSTAB_EDITS);

        if (FSTAB_EDITS && FSTABLIST && !DONTDO)
        {
            if (FSTABLIST)
            {
                SaveItemListAsFile(FSTABLIST, VFSTAB[VSYSTEMHARDCLASS], a, NULL, report_context);
                DeleteItemList(FSTABLIST);
                FSTABLIST = NULL;
            }
            FSTAB_EDITS = 0;
        }

        if (!DONTDO && CF_MOUNTALL)
        {
            CfOut(cf_verbose, "", " -> Mounting all filesystems\n");
            MountAll();
        }
    }
#endif /* !__MINGW32__ */
        break;

    case kp_packages:

        ExecuteScheduledPackages();

        CleanScheduledPackages();
        break;

    default:

        /* Deinitialization is not required */
        ;

    }
}
Example #2
0
static void DeleteTypeContext(Policy *policy, TypeSequence type, const ReportContext *report_context)
{
    switch (type)
    {
    case TYPE_SEQUENCE_CONTEXTS:
        HashVariables(policy, THIS_BUNDLE, report_context);
        break;

    case TYPE_SEQUENCE_ENVIRONMENTS:
        DeleteEnvironmentsContext();
        break;

    case TYPE_SEQUENCE_FILES:

        ConnectionsCleanup();
        break;

    case TYPE_SEQUENCE_PROCESSES:
        break;

    case TYPE_SEQUENCE_STORAGE:
#ifndef __MINGW32__
    {
        Attributes a = { {0} };
        CfOut(OUTPUT_LEVEL_VERBOSE, "", " -> Number of changes observed in %s is %d\n", VFSTAB[VSYSTEMHARDCLASS], FSTAB_EDITS);

        if (FSTAB_EDITS && FSTABLIST && !DONTDO)
        {
            if (FSTABLIST)
            {
                SaveItemListAsFile(FSTABLIST, VFSTAB[VSYSTEMHARDCLASS], a, NULL, report_context);
                DeleteItemList(FSTABLIST);
                FSTABLIST = NULL;
            }
            FSTAB_EDITS = 0;
        }

        if (!DONTDO && CF_MOUNTALL)
        {
            CfOut(OUTPUT_LEVEL_VERBOSE, "", " -> Mounting all filesystems\n");
            MountAll();
        }
    }
#endif /* !__MINGW32__ */
    break;

    case TYPE_SEQUENCE_PACKAGES:

        ExecuteScheduledPackages();

        CleanScheduledPackages();
        break;

    default:

        /* Deinitialization is not required */
        ;

    }
}
Example #3
0
File: nfs.c Project: ouafae31/core
void CleanupNFS(void)
{
    Attributes a = { {0} };
    Log(LOG_LEVEL_VERBOSE, "Number of changes observed in %s is %d", VFSTAB[VSYSTEMHARDCLASS], FSTAB_EDITS);

    if (FSTAB_EDITS && FSTABLIST && !DONTDO)
    {
        if (FSTABLIST)
        {
            SaveItemListAsFile(FSTABLIST, VFSTAB[VSYSTEMHARDCLASS], a);
            DeleteItemList(FSTABLIST);
            FSTABLIST = NULL;
        }
        FSTAB_EDITS = 0;
    }
}
Example #4
0
static PromiseResult SaveSetuid(EvalContext *ctx, Attributes a, Promise *pp)
{
    Attributes b = a;

    b.edits.backup = BACKUP_OPTION_NO_BACKUP;
    b.edits.maxfilesize = 1000000;

    char filename[CF_BUFSIZE];
    snprintf(filename, CF_BUFSIZE, "%s/cfagent.%s.log", GetLogDir(), VSYSNAME.nodename);
    MapName(filename);

    PurgeItemList(ctx, &VSETUIDLIST, "SETUID/SETGID");

    PromiseResult result = PROMISE_RESULT_NOOP;
    if (!CompareToFile(ctx, VSETUIDLIST, filename, a, pp, &result))
    {
        SaveItemListAsFile(VSETUIDLIST, filename, b);
    }

    DeleteItemList(VSETUIDLIST);
    VSETUIDLIST = NULL;

    return result;
}
Example #5
0
void FinishEditContext(EvalContext *ctx, EditContext *ec, Attributes a, const Promise *pp)
{
    if (DONTDO || (a.transaction.action == cfa_warn))
    {
        if (ec && (!CompareToFile(ctx, ec->file_start, ec->filename, a, pp)) && (ec->num_edits > 0))
        {
            cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_WARN, pp, a, "Should edit file '%s' but only a warning promised", ec->filename);
        }
        return;
    }
    else if (ec && (ec->num_edits > 0))
    {
        if (a.haveeditline)
        {
            if (CompareToFile(ctx, ec->file_start, ec->filename, a, pp))
            {
                if (ec)
                {
                    cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, pp, a, "No edit changes to file '%s' need saving", ec->filename);
                }
            }
            else
            {
                if (SaveItemListAsFile(ec->file_start, ec->filename, a))
                {
                    cfPS(ctx, LOG_LEVEL_INFO, PROMISE_RESULT_CHANGE, pp, a, "Edit file '%s'", ec->filename);
                }
                else
                {
                    cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Unable to save file '%s' after editing", ec->filename);
                }
            }
        }

        if (a.haveeditxml)
        {
#ifdef HAVE_LIBXML2
            if (XmlCompareToFile(ec->xmldoc, ec->filename, a.edits))
            {
                if (ec)
                {
                    cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, pp, a, "No edit changes to xml file '%s' need saving", ec->filename);
                }
            }
            else
            {
                if (SaveXmlDocAsFile(ec->xmldoc, ec->filename, a))
                {
                    cfPS(ctx, LOG_LEVEL_INFO, PROMISE_RESULT_CHANGE, pp, a, "Edited xml file '%s'", ec->filename);
                }
                else
                {
                    cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Failed to edit XML file '%s'", ec->filename);
                }
            }
            xmlFreeDoc(ec->xmldoc);
#else
            cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Cannot edit XML files without LIBXML2");
#endif
        }
    }
    else
    {
        if (ec)
        {
            cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, pp, a, "No edit changes to file '%s' need saving", ec->filename);
        }
    }

    if (ec != NULL)
    {
        DeleteItemList(ec->file_start);
    }
}
Example #6
0
void FinishEditContext(EvalContext *ctx, EditContext *ec, Attributes a, Promise *pp)
{
    Item *ip;

    EDIT_MODEL = false;

    if (DONTDO || (a.transaction.action == cfa_warn))
    {
        if (ec && (!CompareToFile(ctx, ec->file_start, ec->filename, a, pp)) && (ec->num_edits > 0))
        {
            cfPS(ctx, OUTPUT_LEVEL_ERROR, CF_WARN, "", pp, a, " -> Should edit file %s but only a warning promised", ec->filename);
        }
        return;
    }
    else if (ec && (ec->num_edits > 0))
    {
        if (a.haveeditline)
        {
            if (CompareToFile(ctx, ec->file_start, ec->filename, a, pp))
            {
                if (ec)
                {
                    cfPS(ctx, OUTPUT_LEVEL_VERBOSE, CF_NOP, "", pp, a, " -> No edit changes to file %s need saving", ec->filename);
                }
            }
            else
            {
                SaveItemListAsFile(ctx, ec->file_start, ec->filename, a, pp);
            }
        }

        if (a.haveeditxml)
        {
#ifdef HAVE_LIBXML2
            if (XmlCompareToFile(ctx, ec->xmldoc, ec->filename, a, pp))
            {
                if (ec)
                {
                    cfPS(ctx, OUTPUT_LEVEL_VERBOSE, CF_NOP, "", pp, a, " -> No edit changes to xml file %s need saving", ec->filename);
                }
            }
            else
            {
                SaveXmlDocAsFile(ctx, ec->xmldoc, ec->filename, a, pp);
            }
            xmlFreeDoc(ec->xmldoc);
#else
            cfPS(ctx, OUTPUT_LEVEL_ERROR, CF_FAIL, "", pp, a, " !! Cannot edit XML files without LIBXML2\n");
#endif
        }
    }
    else
    {
        if (ec)
        {
            cfPS(ctx, OUTPUT_LEVEL_VERBOSE, CF_NOP, "", pp, a, " -> No edit changes to file %s need saving", ec->filename);
        }
    }

    if (ec != NULL)
    {
        for (ip = ec->file_classes; ip != NULL; ip = ip->next)
        {
            EvalContextHeapAddSoft(ctx, ip->name, PromiseGetNamespace(pp));
        }

        DeleteItemList(ec->file_classes);
        DeleteItemList(ec->file_start);
    }
}