Giter Club home page Giter Club logo

rot13authplugin's Introduction

ROT13AuthPlugin
---------------

Overview: This is a very simple example of plugin for the Authorization
API that shows the most basic way to write a plugin. This plugin will
read the password that the user typed in and perform a ROT13 on it. The
password is read from the HINTS.

Warning: You should determine what the ROT13 of your password is before
making these changes. Failure to do so may require you to boot the
system into single user mode.

Use:

1.	Compile the project
2.	Copy the resulting bundle to the auth plugins directory:

	sudo cp -R $BUILDDIR/rot13.bundle /Library/Security/SecurityAgentPlugins
	
3.	Make a copy of the existing /etc/authorization file:

	sudo cp /etc/authorization /etc/authorization-orig
	
4.	Add a line to /etc/authorization to call the bundle. To do this
	for testing, use your favorite editor, e.g.

		sudo pico /etc/authorization
		
	then look for "system.login.console". A few lines below this key,
	you can add the line:
	
		<key>mechanisms</key>
		<array>
				<string>builtin:smartcard-sniffer,privileged</string>
				<string>loginwindow:login</string>
				<string>builtin:reset-password,privileged</string>
+				<string>rot13:rot13</string>
				<string>builtin:auto-login,privileged</string>
				<string>builtin:authenticate,privileged</string>
				<string>loginwindow:success</string>
				...
				
	The new line is marked with a "+" (don't include the "+" sign in the
	file, though). The first occurence of "rot13" is the bundle name,
	the second is the mechanism ID. See the code in "mechanismCreate"
	for where this is used.

5.	If you have fast user switching enabled, you can quickly see
	the results by selecting a different user from the user menu.

Note: The preferred way to modify the /etc/authorization file is to use
the Authorization APIs in <Security/AuthorizationDB.h>. This is always
how it should be done in shipping products, as there may have been other
modifications to the /etc/authorization file. A code snippet to do this
is:

#include <CoreFoundation/CoreFoundation.h>
#include <Security/AuthorizationDB.h>

#define LOGIN_RIGHT "system.login.console"

int main(int argc, char *argv[])
{
    CFDictionaryRef login_dict;
    OSStatus status;
    AuthorizationRef authRef;

    status = AuthorizationCreate(NULL, NULL, 0, &authRef);
    if (status) exit(1);

    status = AuthorizationRightGet(LOGIN_RIGHT, &login_dict);
    if (status) exit(1);

    CFArrayRef arrayRef;
    if (!CFDictionaryGetValueIfPresent(login_dict, CFSTR("mechanisms"),
    	&arrayRef))
        exit(1);

    CFMutableArrayRef newMechanisms = CFArrayCreateMutableCopy(NULL, 0,
    	arrayRef);
    if (!newMechanisms)
        exit(1);

    CFIndex index = CFArrayGetFirstIndexOfValue(newMechanisms,
    	CFRangeMake(0, CFArrayGetCount(newMechanisms)), CFSTR("authinternal"));

    if (index == -1)
        exit(1);

    CFArraySetValueAtIndex(newMechanisms, index, CFSTR("newmech"));

    CFMutableDictionaryRef new_login_dict 
    	= CFDictionaryCreateMutableCopy(NULL, 0, login_dict);

    CFDictionarySetValue(new_login_dict, CFSTR("mechanisms"), newMechanisms);

    status = AuthorizationRightSet(authRef, LOGIN_RIGHT, new_login_dict,
    	NULL, NULL, NULL);

    if (status) exit(1);
}

rot13authplugin's People

Contributors

stevemoser avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.