v3 containing all suggested changes + copyright and ifdef around packaging
defines for PACKAGE and LOCALEDIR, at least until make file packaging can
be worked out

---

/*
 *   Copyright (C) 2015 Canonical Ltd.
 *
 *   This program is free software; you can redistribute it and/or
 *    modify it under the terms of version 2 of the GNU General Public
 *   License published by the Free Software Foundation.
 */

#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libintl.h>
#define _(s) gettext(s)

#include <sys/apparmor.h>

#ifndef PACKAGE
#define PACKAGE ""
#define LOCALEDIR ""
#endif

void print_help(const char *command)
{
        printf(_("%s: [options]\n"
                 "  options:\n"
                 "  -q | --quiet        Don't print out any messages\n"
                 "  -h | --help         Print help\n"),
               command);
        exit(1);
}

int main(int argc, char **argv)
{
        int enabled;
        int quiet = 0;
        int err = 0;

        setlocale(LC_MESSAGES, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);

        if (argc > 2) {
                printf(_("unknown options\n"));
                print_help(argv[0]);
        } else if (argc == 2) {
                if (strcmp(argv[1], "--quiet") == 0 ||
                    strcmp(argv[1], "-q") == 0) {
                        quiet = 1;
                } else if (strcmp(argv[1], "--help") == 0 ||
                           strcmp(argv[1], "-h") == 0) {
                        print_help(argv[0]);
                } else {
                        printf(_("unknown option '%s'\n"), argv[1]);
                        print_help(argv[0]);
                }
        }

        enabled = aa_is_enabled();
        err = errno;
        if (enabled) {
                if (!quiet)
                        printf(_("Yes\n"));
                return 0;
        }

        if (!quiet) {
                switch(err) {
                case ENOSYS:
                        printf(_("No - not available on this system.\n"));
                        break;
                case ECANCELED:
                        printf(_("No - disabled at boot.\n"));
                        break;
                case ENOENT:
                        printf(_("Maybe - policy interface not available.\n"));
                        break;
                case EPERM:
                case EACCES:
                        printf(_("Maybe - insufficient permissions to determine 
availability.\n"));
                        break;
                default:
                        printf(_("No\n"));
                }
        }

        return err;
}


-- 
AppArmor mailing list
AppArmor@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor

Reply via email to