Esempio n. 1
0
URegistryKey
ICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale, UBool visible, UErrorCode& status)
{
    return registerInstance(objToAdopt, locale, LocaleKey::KIND_ANY,
                            visible ? LocaleKeyFactory::VISIBLE : LocaleKeyFactory::INVISIBLE,
                            status);
}
Esempio n. 2
0
/* virtual */ SysStatus
ProcessShared<ALLOC>::Factory::create(ProcessRef& outPref, HATRef h, PMRef pm,
                                      ProcessRef caller, const char *name)
{
    // LOCKING: see comment top of ProcessShared.H
    SysStatus rc = 0;
    ProcessShared* newProcess =
	new ProcessShared(h, pm, /*userMode*/ 1, /*isKern*/ 0, name);
    newProcess->factoryRef = (FactoryRef)getRef();
    newProcess->updatedFlagDoNotDestroy = false;

    // Enter Process into the Translation Table
    new typename ProcessShared<ALLOC>::Root(newProcess);
    outPref = (ProcessRef)newProcess->getRef();

    DREF(h)->attachProcess(outPref);

    DREF(pm)->attachRef();

    DREFGOBJ(TheProcessSetRef)->
	addEntry(_SGETUVAL(newProcess->getPID()), (BaseProcessRef&)outPref);

    if (_FAILURE(rc)) {
	newProcess->destroy();
	return rc;
    }

    registerInstance((CORef)outPref); /* FIXME: check return value */

    return 0;
}
Esempio n. 3
0
URegistryKey
ICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale, 
    UBool visible, UErrorCode& status)
{
    Locale loc;
    LocaleUtility::initLocaleFromName(locale, loc);
    return registerInstance(objToAdopt, loc, LocaleKey::KIND_ANY, 
        visible ? LocaleKeyFactory::VISIBLE : LocaleKeyFactory::INVISIBLE, status);
}
Esempio n. 4
0
/* virtual */ SysStatus
ProcessShared<ALLOC>::Factory::createReplacement(CORef ref, CObjRoot *&root)
{
    ProcessShared* newProcess = new ProcessShared();
    newProcess->factoryRef = (FactoryRef)getRef();
    root = new typename ProcessShared<ALLOC>::Root(newProcess, (RepRef)ref,
                                          CObjRoot::skipInstall);
    registerInstance(ref); /* FIXME: check return value */
    return 0;
}
Esempio n. 5
0
URegistryKey
ICULocaleService::registerInstance(UObject* objToAdopt, const Locale& locale, int32_t kind, UErrorCode& status)
{
    return registerInstance(objToAdopt, locale, kind, LocaleKeyFactory::VISIBLE, status);
}
Esempio n. 6
0
URegistryKey
ICUService::registerInstance(UObject* objToAdopt, const UnicodeString& id, UErrorCode& status) 
{
    return registerInstance(objToAdopt, id, TRUE, status);
}
Esempio n. 7
0
int main(int argc, char **argv) {

    struct aXInfo xinfo;
    struct aOpts opts = {
        alock_authmodules[0],
        alock_inputs[0],
        alock_cursors[0],
        alock_backgrounds[0],
    };

#if HAVE_X11_EXTENSIONS_XF86MISC_H
    int xf86misc_major = -1;
    int xf86misc_minor = -1;
#endif

    int arg;
    const char *optarg;
    const char *auth_args = NULL;
    const char *input_args = NULL;
    const char *cursor_args = NULL;
    const char *background_args = NULL;

    /* parse options */
    if (argc > 1) {
        for (arg = 1; arg < argc; arg++) {
            if (!strcmp(argv[arg], "-bg")) {
                optarg = argv[++arg];
                if (optarg != NULL) {

                    struct aBackground **i;
                    if (strcmp(optarg, "list") == 0) {
                        printf("list of available background modules:\n");
                        for (i = alock_backgrounds; *i; ++i) {
                            printf("%s\n", (*i)->name);
                        }
                        exit(EXIT_SUCCESS);
                    }

                    for (i = alock_backgrounds; *i; ++i) {
                        if (strstr(optarg, (*i)->name) == optarg) {
                            background_args = optarg;
                            opts.background = *i;
                            break;
                        }
                    }

                    if (*i == NULL) {
                        fprintf(stderr, "alock: background module not found\n");
                        exit(EXIT_FAILURE);
                    }

                }
                else {
                    fprintf(stderr, "alock: option requires an argument -- '%s'\n", "bg");
                    exit(EXIT_FAILURE);
                }
            }
            else if (!strcmp(argv[arg], "-auth")) {
                optarg = argv[++arg];
                if (optarg != NULL) {

                    struct aAuth **i;
                    if (strcmp(optarg, "list") == 0) {
                        printf("list of available authentication modules:\n");
                        for (i = alock_authmodules; *i; ++i) {
                            printf("%s\n", (*i)->name);
                        }
                        exit(EXIT_SUCCESS);
                    }

                    for (i = alock_authmodules; *i; ++i) {
                        if (strstr(optarg, (*i)->name) == optarg) {
                            auth_args = optarg;
                            opts.auth = *i;
                            break;
                        }
                    }

                    if (*i == NULL) {
                        fprintf(stderr, "alock: authentication module not found\n");
                        exit(EXIT_FAILURE);
                    }

                }
                else {
                    fprintf(stderr, "alock: option requires an argument -- '%s'\n", "auth");
                    exit(EXIT_FAILURE);
                }
            }
            else if (!strcmp(argv[arg], "-cursor")) {
                optarg = argv[++arg];
                if (optarg != NULL) {

                    struct aCursor **i;
                    if (strcmp(argv[arg], "list") == 0) {
                        printf("list of available cursor modules:\n");
                        for (i = alock_cursors; *i; ++i) {
                            printf("%s\n", (*i)->name);
                        }
                        exit(EXIT_SUCCESS);
                    }

                    for (i = alock_cursors; *i; ++i) {
                        if (strstr(optarg, (*i)->name) == optarg) {
                            cursor_args = optarg;
                            opts.cursor = *i;
                            break;
                        }
                    }

                    if (*i == NULL) {
                        fprintf(stderr, "alock: cursor module not found\n");
                        exit(EXIT_FAILURE);
                    }

                }
                else {
                    fprintf(stderr, "alock: option requires an argument -- '%s'\n", "cursor");
                    exit(EXIT_FAILURE);
                }
            }
            else if (!strcmp(argv[arg], "-input")) {
                optarg = argv[++arg];
                if (optarg != NULL) {

                    struct aInput **i;
                    if (strcmp(argv[arg], "list") == 0) {
                        printf("list of available input modules:\n");
                        for (i = alock_inputs; *i; ++i) {
                            printf("%s\n", (*i)->name);
                        }
                        exit(EXIT_SUCCESS);
                    }

                    for (i = alock_inputs; *i; ++i) {
                        if (strstr(optarg, (*i)->name) == optarg) {
                            input_args = optarg;
                            opts.input = *i;
                            break;
                        }
                    }

                    if (*i == NULL) {
                        fprintf(stderr, "alock: input module not found\n");
                        exit(EXIT_FAILURE);
                    }

                }
                else {
                    fprintf(stderr, "alock: option requires an argument -- '%s'\n", "input");
                    exit(EXIT_FAILURE);
                }
            }
            else if (strcmp(argv[arg], "-h") == 0) {
                printf("alock [-h] [-auth type:options] [-bg type:options]"
                       " [-cursor type:options] [-input type:options]\n");
                exit(EXIT_SUCCESS);
            }
            else {
                fprintf(stderr, "alock: invalid option '%s'\n", argv[arg]);
                exit(EXIT_FAILURE);
            }
        }
    }

    /* required for correct input handling */
    setlocale(LC_ALL, "");

    initXInfo(&xinfo);
    if (detectOtherInstance(&xinfo)) {
        fprintf(stderr, "alock: another instance seems to be running\n");
        exit(EXIT_FAILURE);
    }

    if (opts.auth->init(auth_args) == 0) {
        fprintf(stderr, "alock: failed init of [%s] with [%s]\n",
                opts.auth->name, auth_args);
        exit(EXIT_FAILURE);
    }

    /* We can be installed setuid root to support shadow passwords,
       and we don't need root privileges any longer.  --marekm */
    setuid(getuid());

    if (opts.input->init(input_args, &xinfo) == 0) {
        fprintf(stderr, "alock: failed init of [%s] with [%s]\n",
                opts.input->name, input_args);
        exit(EXIT_FAILURE);
    }
    if (opts.background->init(background_args, &xinfo) == 0) {
        fprintf(stderr, "alock: failed init of [%s] with [%s]\n",
                opts.background->name, background_args);
        exit(EXIT_FAILURE);
    }
    if (opts.cursor->init(cursor_args, &xinfo) == 0) {
        fprintf(stderr, "alock: failed init of [%s] with [%s]\n",
                opts.cursor->name, cursor_args);
        exit(EXIT_FAILURE);
    }

    {
        int scr;
        for (scr = 0; scr < xinfo.screens; scr++) {

            XSelectInput(xinfo.display, xinfo.window[scr], KeyPressMask|KeyReleaseMask);
            XMapWindow(xinfo.display, xinfo.window[scr]);
            XRaiseWindow(xinfo.display, xinfo.window[scr]);

        }
    }

    /* try to grab 2 times, another process (windowmanager) may have grabbed
     * the keyboard already */
    if ((XGrabKeyboard(xinfo.display, xinfo.window[0], True, GrabModeAsync, GrabModeAsync,
                          CurrentTime)) != GrabSuccess) {
        sleep(1);
        if ((XGrabKeyboard(xinfo.display, xinfo.window[0], True, GrabModeAsync, GrabModeAsync,
                        CurrentTime)) != GrabSuccess) {
            printf("alock: couldnt grab the keyboard\n");
            exit(EXIT_FAILURE);
        }
    }

#if HAVE_X11_EXTENSIONS_XF86MISC_H
    {
        if (XF86MiscQueryVersion(xinfo.display, &xf86misc_major, &xf86misc_minor) == True) {

            if (xf86misc_major >= 0 &&
                xf86misc_minor >= 5 &&
                XF86MiscSetGrabKeysState(xinfo.display, False) == MiscExtGrabStateLocked) {

                fprintf(stderr, "alock: cant disable xserver hotkeys to remove grabs\n");
                exit(EXIT_FAILURE);
            }

            printf("disabled AllowDeactivateGrabs and AllowClosedownGrabs\n");
        }
    }
#endif

    /* TODO: think about it: do we really need NR_SCREEN cursors ? we grab the
     * pointer on :*.0 anyway ... */
    if (XGrabPointer(xinfo.display, xinfo.window[0], False, None,
                     GrabModeAsync, GrabModeAsync, None, xinfo.cursor[0], CurrentTime) != GrabSuccess) {
        XUngrabKeyboard(xinfo.display, CurrentTime);
        fprintf(stderr, "alock: couldnt grab the pointer\n");
        exit(EXIT_FAILURE);
    }

    registerInstance(&xinfo);
    eventLoop(&opts, &xinfo);
    unregisterInstance(&xinfo);

    opts.auth->deinit();
    opts.input->deinit(&xinfo);
    opts.cursor->deinit(&xinfo);
    opts.background->deinit(&xinfo);

#if HAVE_X11_EXTENSIONS_XF86MISC_H
    if (xf86misc_major >= 0 && xf86misc_minor >= 5) {
        XF86MiscSetGrabKeysState(xinfo.display, True);
        XFlush(xinfo.display);
    }
#endif

    XCloseDisplay(xinfo.display);

    return EXIT_SUCCESS;
}
Esempio n. 8
0
File: alock.c Progetto: mgumz/alock
int main(int argc, char **argv) {


    struct aXInfo xinfo;
    struct aOpts opts;

#if HAVE_XF86MISC
    int xf86misc_major = -1;
    int xf86misc_minor = -1;
#endif

    int arg = 0;
    const char* cursor_args = NULL;
    const char* background_args = NULL;

    opts.auth = NULL;
    opts.cursor = alock_cursors[0];
    opts.background = alock_backgrounds[0];

    /*  parse options */
    if (argc != 1) {
        for(arg = 1; arg <= argc; arg++) {
            if (!strcmp(argv[arg - 1], "-bg")) {
                if (arg < argc) {

                    char* char_tmp;
                    struct aBackground* bg_tmp = NULL;
                    struct aBackground** i;
                    if (strcmp(argv[arg], "list") == 0) {
                        for(i = alock_backgrounds; *i; ++i) {
                            printf("%s\n", (*i)->name);
                        }
                        exit(EXIT_SUCCESS);
                    }

                    for(i = alock_backgrounds; *i; ++i) {
                        char_tmp = strstr(argv[arg], (*i)->name);
                        if(char_tmp && char_tmp == argv[arg]) {
                            background_args = char_tmp;
                            bg_tmp = *i;
                            opts.background = bg_tmp;
                            ++arg;
                            break;
                        }
                    }

                    if (bg_tmp == NULL) {
                        printf("%s", "alock: error, couldnt find the bg-module you specified.\n");
                        exit(EXIT_FAILURE);
                    }

                } else {
                    printf("%s", "alock, error, missing argument\n");
                    displayUsage();
                    exit(EXIT_FAILURE);
                }
            } else if (!strcmp(argv[arg - 1], "-auth")) {
                if (arg < argc) {

                    char* char_tmp;
                    struct aAuth* auth_tmp = NULL;
                    struct aAuth** i;
                    if (!strcmp(argv[arg], "list")) {
                        for(i = alock_authmodules; *i; ++i) {
                            printf("%s\n", (*i)->name);
                        }
                        exit(EXIT_SUCCESS);
                    }

                    for(i = alock_authmodules; *i; ++i) {
                        char_tmp = strstr(argv[arg], (*i)->name);
                        if(char_tmp && char_tmp == argv[arg]) {
                            auth_tmp = (*i);
                            if (auth_tmp->init(argv[arg]) == 0) {
                                printf("alock: error, failed init of [%s].\n", auth_tmp->name);
                                exit(EXIT_FAILURE);
                            }
                            opts.auth = auth_tmp;
                            ++arg;
                            break;
                        }
                    }

                    if (auth_tmp == NULL) {
                        printf("%s", "alock: error, couldnt find the auth-module you specified.\n");
                        exit(EXIT_FAILURE);
                    }

                } else {
                    printf("%s", "alock, error, missing argument\n");
                    displayUsage();
                    exit(EXIT_FAILURE);
                }
            } else if (strcmp(argv[arg - 1], "-cursor") == 0) {
                if (arg < argc) {

                    char* char_tmp;
                    struct aCursor* cursor_tmp = NULL;
                    struct aCursor** i;
                    if (strcmp(argv[arg], "list") == 0) {
                        for(i = alock_cursors; *i; ++i) {
                            printf("%s\n", (*i)->name);
                        }
                        exit(EXIT_SUCCESS);
                    }

                    for(i = alock_cursors; *i; ++i) {
                        char_tmp = strstr(argv[arg], (*i)->name);
                        if(char_tmp && char_tmp == argv[arg]) {
                            cursor_args = char_tmp;
                            cursor_tmp = *i;
                            opts.cursor= cursor_tmp;
                            ++arg;
                            break;
                        }
                    }

                    if (!cursor_tmp) {
                        printf("%s", "alock: error, couldnt find the cursor-module you specified.\n");
                        exit(EXIT_FAILURE);
                    }

                } else {
                    printf("%s", "alock, error, missing argument\n");
                    displayUsage();
                    exit(EXIT_FAILURE);
                }
            } else if (strcmp(argv[arg - 1], "-h") == 0) {
                displayUsage();
                exit(EXIT_SUCCESS);
            } else if (strcmp(argv[arg - 1], "-v") == 0) {
                printf("alock-%s by m.gumz 2005 - 2006\n", VERSION);
                exit(EXIT_SUCCESS);
            }
        }
    }


    initStartTime();
    initXInfo(&xinfo);
    if (detectOtherInstance(&xinfo)) {
        printf("%s", "alock: error, another instance seems to be running\n");
        exit(EXIT_FAILURE);
    }

    if (!opts.auth) {
        printf("%s", "alock: error, no auth-method specified.\n");
        displayUsage();
        exit(EXIT_FAILURE);
    }

    if (opts.background->init(background_args, &xinfo) == 0) {
        printf("alock: error, couldnt init [%s] with [%s].\n",
               opts.background->name,
               background_args);
        exit(EXIT_FAILURE);
    }

    if (opts.cursor->init(cursor_args, &xinfo) == 0) {
        printf("alock: error, couldnt init [%s] with [%s].\n",
               opts.cursor->name,
               cursor_args);
        exit(EXIT_FAILURE);
    }

    {
        int scr;
        for (scr = 0; scr < xinfo.nr_screens; scr++) {

            XSelectInput(xinfo.display, xinfo.window[scr], KeyPressMask|KeyReleaseMask);
            XMapWindow(xinfo.display, xinfo.window[scr]);
            XRaiseWindow(xinfo.display, xinfo.window[scr]);

        }
    }

    /* try to grab 2 times, another process (windowmanager) may have grabbed
     * the keyboard already */
    if ((XGrabKeyboard(xinfo.display, xinfo.window[0], True, GrabModeAsync, GrabModeAsync,
                          CurrentTime)) != GrabSuccess) {
        sleep(1);
        if ((XGrabKeyboard(xinfo.display, xinfo.window[0], True, GrabModeAsync, GrabModeAsync,
                        CurrentTime)) != GrabSuccess) {
            printf("%s", "alock: couldnt grab the keyboard.\n");
            exit(EXIT_FAILURE);
        }
    }

#if HAVE_XF86MISC
    {
        if (XF86MiscQueryVersion(xinfo.display, &xf86misc_major, &xf86misc_minor) == True) {

            if (xf86misc_major >= 0 &&
                xf86misc_minor >= 5 &&
                XF86MiscSetGrabKeysState(xinfo.display, False) == MiscExtGrabStateLocked) {

                printf("%s", "alock: cant disable xserver hotkeys to remove grabs.\n");
                exit(EXIT_FAILURE);
            }

            printf("%s", "disabled AllowDeactivateGrabs and AllowClosedownGrabs\n.");
        }
    }
#endif

    /* TODO: think about it: do we really need NR_SCREEN cursors ? we grab the
     * pointer on :*.0 anyway ... */
    if (XGrabPointer(xinfo.display, xinfo.window[0], False, None,
                     GrabModeAsync, GrabModeAsync, None, xinfo.cursor[0], CurrentTime) != GrabSuccess) {
        XUngrabKeyboard(xinfo.display, CurrentTime);
        printf("%s", "alock: couldnt grab the pointer.\n");
        exit(EXIT_FAILURE);
    }

    registerInstance(&xinfo);
    eventLoop(&opts, &xinfo);
    unregisterInstance(&xinfo);

    opts.auth->deinit();
    opts.cursor->deinit(&xinfo);
    opts.background->deinit(&xinfo);

#if HAVE_XF86MISC
    if (xf86misc_major >= 0 && xf86misc_minor >= 5) {
        XF86MiscSetGrabKeysState(xinfo.display, True);
        XFlush(xinfo.display);
    }
#endif

    XCloseDisplay(xinfo.display);

    return EXIT_SUCCESS;
}
Esempio n. 9
0
File: main.c Progetto: Arkq/alock
int main(int argc, char **argv) {

    int opt;
    struct option longopts[] = {
        {"help", no_argument, NULL, 'h'},
        {"modules", no_argument, NULL, 'm'},
        {"auth", required_argument, NULL, 'a'},
        {"bg", required_argument, NULL, 'b'},
        {"cursor", required_argument, NULL, 'c'},
        {"input", required_argument, NULL, 'i'},
        {0, 0, 0, 0},
    };

    Display *display;
    struct aModules modules;
    int retval;

    const char *args_auth = NULL;
    const char *args_background = NULL;
    const char *args_cursor = NULL;
    const char *args_input = NULL;

    /* set-up default modules */
    modules.auth = alock_modules_auth[0];
    modules.background = alock_modules_background[0];
    modules.cursor = alock_modules_cursor[0];
    modules.input = alock_modules_input[0];

#if WITH_XBLIGHT
    modules.backlight = -1;
#endif

    /* parse options */
    while ((opt = getopt_long_only(argc, argv, "hma:b:c:i:", longopts, NULL)) != -1)
        switch (opt) {
        case 'h':
            printf("%s [-help] [-modules] [-auth type:options] [-bg type:options]"
                    " [-cursor type:options] [-input type:options]\n", argv[0]);
            return EXIT_SUCCESS;

        case 'm': { /* list available modules */

            struct aModuleAuth **ia;
            struct aModuleBackground **ib;
            struct aModuleCursor **ic;
            struct aModuleInput **ii;

            printf("authentication modules:\n");
            for (ia = alock_modules_auth; *ia; ++ia)
                printf("  %s\n", (*ia)->m.name);

            printf("background modules:\n");
            for (ib = alock_modules_background; *ib; ++ib)
                printf("  %s\n", (*ib)->m.name);

            printf("cursor modules:\n");
            for (ic = alock_modules_cursor; *ic; ++ic)
                printf("  %s\n", (*ic)->m.name);

            printf("input modules:\n");
            for (ii = alock_modules_input; *ii; ++ii)
                printf("  %s\n", (*ii)->m.name);

            return EXIT_SUCCESS;
        }

        case 'a': { /* authentication module */

            struct aModuleAuth **i;
            for (i = alock_modules_auth; *i; ++i)
                if (strstr(optarg, (*i)->m.name) == optarg) {
                    args_auth = optarg;
                    modules.auth = *i;
                    break;
                }

            if (*i == NULL) {
                fprintf(stderr, "alock: authentication module `%s` not found\n", optarg);
                return EXIT_FAILURE;
            }

            break;
        }

        case 'b': { /* background module */

            struct aModuleBackground **i;
            for (i = alock_modules_background; *i; ++i)
                if (strstr(optarg, (*i)->m.name) == optarg) {
                    args_background = optarg;
                    modules.background = *i;
                    break;
                }

            if (*i == NULL) {
                fprintf(stderr, "alock: background module `%s` not found\n", optarg);
                return EXIT_FAILURE;
            }

            break;
        }

        case 'c': { /* cursor module */

            struct aModuleCursor **i;
            for (i = alock_modules_cursor; *i; ++i)
                if (strstr(optarg, (*i)->m.name) == optarg) {
                    args_cursor = optarg;
                    modules.cursor = *i;
                    break;
                }

            if (*i == NULL) {
                fprintf(stderr, "alock: cursor module `%s` not found\n", optarg);
                return EXIT_FAILURE;
            }

            break;
        }

        case 'i': { /* input module */

            struct aModuleInput **i;
            for (i = alock_modules_input; *i; ++i)
                if (strstr(optarg, (*i)->m.name) == optarg) {
                    args_input = optarg;
                    modules.input = *i;
                    break;
                }

            if (*i == NULL) {
                fprintf(stderr, "alock: input module `%s` not found\n", optarg);
                return EXIT_FAILURE;
            }

            break;
        }

        default:
            fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
            return EXIT_FAILURE;
        }

    /* required for correct input handling */
    setlocale(LC_ALL, "");

    if ((display = XOpenDisplay(NULL)) == NULL) {
        fprintf(stderr, "error: unable to connect to the X display\n");
        return EXIT_FAILURE;
    }

    /* make sure, that only one instance of alock is running */
    if (registerInstance(display)) {
        fprintf(stderr, "error: another instance seems to be running\n");
        XCloseDisplay(display);
        return EXIT_FAILURE;
    }

#if WITH_DUNST
    /* pause notification daemon */
    system("pkill -x -SIGUSR1 dunst");
#endif

    { /* try to initialize selected modules */

        int rv = 0;

        XrmInitialize();
        const char *data = XResourceManagerString(display);
        XrmDatabase xrdb = XrmGetStringDatabase(data != NULL ? data : "");

        modules.auth->m.loadxrdb(xrdb);
        modules.background->m.loadxrdb(xrdb);
        modules.cursor->m.loadxrdb(xrdb);
        modules.input->m.loadxrdb(xrdb);

#if WITH_XBLIGHT
        XrmValue value;
        char *type;

        if (XrmGetResource(xrdb, "alock.backlight", "ALock.Backlight",
                    &type, &value) && strcmp(value.addr, "true") == 0)
            modules.backlight = getBacklightBrightness();
#endif /* WITH_XBLIGHT */

        XrmDestroyDatabase(xrdb);

        modules.auth->m.loadargs(args_auth);
        modules.background->m.loadargs(args_background);
        modules.cursor->m.loadargs(args_cursor);
        modules.input->m.loadargs(args_input);

        if (modules.auth->m.init(display)) {
            fprintf(stderr, "alock: failed init of [%s] with [%s]\n",
                    modules.auth->m.name, args_auth);
            rv |= 1;
        }

#if ENABLE_PASSWD
        /* We can be installed setuid root to support shadow passwords,
         * and we don't need root privileges any longer.  --marekm */
        if (setuid(getuid()) != 0)
            perror("alock: root privilege drop failed");
#endif

        if (modules.background->m.init(display)) {
            fprintf(stderr, "alock: failed init of [%s] with [%s]\n",
                    modules.background->m.name, args_background);
            rv |= 1;
        }
        if (modules.cursor->m.init(display)) {
            fprintf(stderr, "alock: failed init of [%s] with [%s]\n",
                    modules.cursor->m.name, args_cursor);
            rv |= 1;
        }
        if (modules.input->m.init(display)) {
            fprintf(stderr, "alock: failed init of [%s] with [%s]\n",
                    modules.input->m.name, args_input);
            rv |= 1;
        }

        if (rv) /* initialization failed */
            goto return_failure;

    }

#if HAVE_XMISC
    int xf86misc_major = -1;
    int xf86misc_minor = -1;

    if (XF86MiscQueryVersion(display, &xf86misc_major, &xf86misc_minor) == True) {

        if (xf86misc_major >= 0 && xf86misc_minor >= 5 &&
                XF86MiscSetGrabKeysState(display, False) == MiscExtGrabStateLocked) {

            fprintf(stderr, "error: unable to disable Xorg hotkeys to remove grabs\n");
            goto return_failure;
        }

        fprintf(stderr, "info: disabled AllowDeactivateGrabs and AllowClosedownGrabs\n");
    }
#endif /* HAVE_XMISC */

    /* raise our background window and grab input, if this action has failed,
     * we are not able to lock the screen, then we're f****d... */
    if (lockDisplay(display, &modules))
        goto return_failure;

    debug("entering main event loop");
    eventLoop(display, &modules);

    retval = EXIT_SUCCESS;
    goto return_success;

return_failure:
    retval = EXIT_FAILURE;

return_success:

#if HAVE_XMISC
    if (xf86misc_major >= 0 && xf86misc_minor >= 5) {
        XF86MiscSetGrabKeysState(display, True);
        XFlush(display);
    }
#endif

    modules.auth->m.free();
    modules.cursor->m.free();
    modules.input->m.free();
    modules.background->m.free();

    unregisterInstance(display);
    XCloseDisplay(display);

#if WITH_DUNST
    /* resume notification daemon */
    system("pkill -x -SIGUSR2 dunst");
#endif

    return retval;
}
int ModelExportStrategyRegistry::insertModelExportStrategy(ModelExportStrategy* strategy){
	registerInstance(strategy->getExtension(),strategy);
	return 0;
}
Esempio n. 11
0
int main(int argc, char **argv)
{

	struct aXInfo xinfo;

	struct aOpts opts;

	int arg = 0;
	const char* cursor_args = NULL;
	const char* background_args = NULL;
	int precheck = 0;

	opts.auth = NULL;
	opts.cursor = tlock_cursors[0];
	opts.background = tlock_backgrounds[0];
	opts.flash = 0;
	opts.gids = 0;

	/*  parse options */
	if (argc != 1)
	{
		for (arg = 1; arg <= argc; arg++)
		{
			/**
			 * Background options.
			 */
			if (!strcmp(argv[arg - 1], "-bg"))
			{
				if (arg < argc)
				{

					char* char_tmp;
					struct aBackground* bg_tmp = NULL;
					struct aBackground** i;
					/*
					 * List all the available backgrounds.
					 */
					if (strcmp(argv[arg], "list") == 0)
					{
						for (i = tlock_backgrounds; *i; ++i)
						{
							printf("%s\n", (*i)->name);
						}
						exit(EXIT_SUCCESS);
					}

					/*
					 * Assigning the backgrounds to the option array.
					 */
					for (i = tlock_backgrounds; *i; ++i)
					{
						char_tmp = strstr(argv[arg], (*i)->name);
						if (char_tmp && char_tmp == argv[arg])
						{
							background_args = char_tmp;
							bg_tmp = *i;
							opts.background = bg_tmp;
							++arg;
							break;
						}
					}

					/**
					 * Abort when background is not found.
					 */
					if (bg_tmp == NULL)
					{
						printf("%s", "tlock: error, couldn't find the bg-module you specified.\n");
						exit(EXIT_FAILURE);
					}

				} else
				{
					printf("%s", "tlock, error, missing argument\n");
					displayUsage();
					exit(EXIT_FAILURE);
				}
			} else
				if (!strcmp(argv[arg - 1], "-auth"))
				{
					if (arg < argc)
					{

						char* char_tmp;
						struct aAuth* auth_tmp = NULL;
						struct aAuth** i;

						if (!strcmp(argv[arg], "list"))
						{
							for (i = tlock_authmodules; *i; ++i)
							{
								printf("%s\n", (*i)->name);
							}
							exit(EXIT_SUCCESS);
						}

						for (i = tlock_authmodules; *i; ++i)
						{
							char_tmp = strstr(argv[arg], (*i)->name);
							if (char_tmp && char_tmp == argv[arg])
							{
								auth_tmp = (*i);
								if (auth_tmp->init(argv[arg]) == 0)
								{
									printf("%s.%s: error, failed init of [%s] with arguments [%s].\n",
									__FILE__, __FUNCTION__, auth_tmp->name, argv[arg]);
									exit(EXIT_FAILURE);
								} else
								{
									printf("%s.%s: initialized [%s] with arguments [%s].\n",
									__FILE__, __FUNCTION__, auth_tmp->name, argv[arg]);
								}
								opts.auth = auth_tmp;
								++arg;
								break;
							}
						}

						if (auth_tmp == NULL)
						{
							printf("%s", "tlock: error, couldnt find the auth-module you specified.\n");
							exit(EXIT_FAILURE);
						}

					} else
					{
						printf("%s", "tlock, error, missing argument\n");
						displayUsage();
						exit(EXIT_FAILURE);
					}
				} else
					if (strcmp(argv[arg - 1], "-cursor") == 0)
					{
						if (arg < argc)
						{

							char* char_tmp;
							struct aCursor* cursor_tmp = NULL;
							struct aCursor** i;
							if (strcmp(argv[arg], "list") == 0)
							{
								for (i = tlock_cursors; *i; ++i)
								{
									printf("%s\n", (*i)->name);
								}
								exit(EXIT_SUCCESS);
							}

							for (i = tlock_cursors; *i; ++i)
							{
								char_tmp = strstr(argv[arg], (*i)->name);
								if (char_tmp && char_tmp == argv[arg])
								{
									cursor_args = char_tmp;
									cursor_tmp = *i;
									opts.cursor = cursor_tmp;
									++arg;
									break;
								}
							}

							if (!cursor_tmp)
							{
								printf("%s", "tlock: error, couldn't find the cursor-module you specified.\n");
								exit(EXIT_FAILURE);
							}

						} else
						{
							printf("%s", "tlock, error, missing argument\n");
							displayUsage();
							exit(EXIT_FAILURE);
						}
					} else
					{
						if (strcmp(argv[arg - 1], "-h") == 0)
						{
							displayUsage();
							exit(EXIT_SUCCESS);
						} else
							if (strcmp(argv[arg - 1], "-v") == 0)
							{
								printf("tlock-%s by André 'Bananaman' Kaan\n",
								VERSION);
								exit(EXIT_SUCCESS);
							} else
								if (strcmp(argv[arg - 1], "-pre") == 0)
								{
									precheck = 1;
								}
								else
						if (strcmp(argv[arg - 1], "-flash") == 0)
						{
							opts.flash = 1;
						}
						else
				if (strcmp(argv[arg - 1], "-gids") == 0)
				{
					opts.gids = 1;
				}
					}
		}
	}

	/**
	 *
	 */
	initStartTime();
	/*
	 *
	 */
	initXInfo(&xinfo);
	if (detectOtherInstance(&xinfo))
	{
		printf("%s", "tlock: error, another instance seems to be running\n");
		exit(EXIT_FAILURE);
	}

	/*
	 * List the usage of the authentication.
	 */
	if (!opts.auth)
	{
		printf("%s", "tlock: error, no auth-method specified.\n");
		displayUsage();
		exit(EXIT_FAILURE);
	}

	/*
	 *
	 */
	if (opts.background->init(background_args, &xinfo) == 0)
	{
		printf("tlock: error, couldn't init [%s] with [%s].\n", opts.background->name, background_args);
		exit(EXIT_FAILURE);
	}

	if (opts.cursor->init(cursor_args, &xinfo) == 0)
	{
		printf("tlock: error, couldn't init [%s] with [%s].\n", opts.cursor->name, cursor_args);
		exit(EXIT_FAILURE);
	}

	LOG("initializing screens");
	{
		int scr;
		for (scr = 0; scr < xinfo.nr_screens; scr++)
		{

			XSelectInput(xinfo.display, xinfo.window[scr],
			ButtonReleaseMask | ButtonPressMask);
			XMapWindow(xinfo.display, xinfo.window[scr]);
			XRaiseWindow(xinfo.display, xinfo.window[scr]);

		}
	}

	LOG("initializing keyboard control");
	/* try to grab 2 times, another process (windowmanager) may have grabbed
	 * the keyboard already */
	if ((XGrabKeyboard(xinfo.display, xinfo.window[0], True, GrabModeAsync,
	GrabModeAsync,
	CurrentTime)) != GrabSuccess)
	{
		sleep(1);
		if ((XGrabKeyboard(xinfo.display, xinfo.window[0], True, GrabModeAsync,
		GrabModeAsync,
		CurrentTime)) != GrabSuccess)
		{
			printf("%s", "tlock: couldn't grab the keyboard.\n");
			exit(EXIT_FAILURE);
		}
	}

	/* TODO: think about it: do we really need NR_SCREEN cursors ? we grab the
	 * pointer on :*.0 anyway ... */
	LOG("initializing mouse control");
	if (XGrabPointer(xinfo.display, xinfo.window[0],
	False,
	ButtonPressMask | ButtonReleaseMask,
	// needed for the propagation of the pointer events on window[0]
	      GrabModeAsync,
	      GrabModeAsync,
	      None,
	      xinfo.cursor[0],
	      CurrentTime) != GrabSuccess)
	{
		XUngrabKeyboard(xinfo.display, CurrentTime);
		printf("%s", "tlock: couldn't grab the pointer.\n");
		exit(EXIT_FAILURE);
	}

	openlog("tlock", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
	syslog(LOG_NOTICE, "program started by user %d(%s), accepting groups as '%s' only.",
			getuid(), getenv("USER"), opts.gids ? "id" : "names"	);
	// pre authorization check
	if (precheck == 1)
	{
		if (opts.auth != NULL)
		{
			int ret = opts.auth->auth(NULL, NULL, 0);
			syslog(
			LOG_NOTICE, "%s: %s[exit=%d]\n",
			__FILE__, __FUNCTION__, ret);

			if (ret != 1)
			{

				registerInstance(&xinfo);
				eventLoop(&opts, &xinfo);
				LOG("exiting eventloop, and unregister");
				unregisterInstance(&xinfo);

			}

		}
	} else
	{

		registerInstance(&xinfo);
		eventLoop(&opts, &xinfo);
		LOG("exiting eventloop, and unregister");
		unregisterInstance(&xinfo);

	}

	closelog();

	opts.auth->deinit();
	opts.cursor->deinit(&xinfo);
	opts.background->deinit(&xinfo);

	XCloseDisplay(xinfo.display);

	return EXIT_SUCCESS;
}