├── OSXSimpleAuth.xcodeproj ├── TemplateIcon.icns └── project.pbxproj ├── OSXSimpleAuth_Prefix.pch ├── README.rst ├── OSXSimpleAuth.m └── OSXSimpleAuth.1 /OSXSimpleAuth.xcodeproj/TemplateIcon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelvobrien/OSXSimpleAuth/HEAD/OSXSimpleAuth.xcodeproj/TemplateIcon.icns -------------------------------------------------------------------------------- /OSXSimpleAuth_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'OSXSimpleAuth' target in the 'OSXSimpleAuth' project. 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | SYNOPSIS 2 | ========= 3 | 4 | This code was written to show how to use 5 | ``AuthorizationExecuteWithPrivileges`` in a simple and straightforward 6 | example. It is probably not secure, but it gets the job done for 7 | demonstration purposes. Look at OSXSlightlyBetterAuth example for 8 | more details. 9 | 10 | 11 | REQUIREMENTS 12 | ============= 13 | 14 | * Mac OS X Leopard (10.5) 15 | * Xcode 3.1 16 | 17 | 18 | COPYRIGHT 19 | ========== 20 | 21 | The MIT License 22 | 23 | Copyright (c) 2009 Michael V. O'Brien 24 | 25 | Permission is hereby granted, free of charge, to any person obtaining a copy 26 | of this software and associated documentation files (the "Software"), to deal 27 | in the Software without restriction, including without limitation the rights 28 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 29 | copies of the Software, and to permit persons to whom the Software is 30 | furnished to do so, subject to the following conditions: 31 | 32 | The above copyright notice and this permission notice shall be included in 33 | all copies or substantial portions of the Software. 34 | 35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 38 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 40 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 41 | THE SOFTWARE. 42 | -------------------------------------------------------------------------------- /OSXSimpleAuth.m: -------------------------------------------------------------------------------- 1 | /* 2 | * OSXSimpleAuth.m 3 | * 4 | * Created by Michael V. O'Brien on 02/07/2009. 5 | * 6 | * This code was written to show how to use 7 | * AuthorizationExecuteWithPrivileges in a simple and straightforward 8 | * example. It is probably not secure, but it gets the job done for 9 | * demonstration purposes. Look at OSXSlightlyBetterAuth example for 10 | * more details. 11 | */ 12 | 13 | 14 | #import 15 | // Add Security.framework to the Xcode project 16 | 17 | int main (int argc, const char * argv[]) { 18 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 19 | 20 | // Create authorization reference 21 | AuthorizationRef authorizationRef; 22 | OSStatus status; 23 | 24 | status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorizationRef); 25 | 26 | // Run the tool using the authorization reference 27 | char *tool = "/sbin/dmesg"; 28 | char *args[] = {NULL}; 29 | FILE *pipe = NULL; 30 | 31 | status = AuthorizationExecuteWithPrivileges(authorizationRef, tool, kAuthorizationFlagDefaults, args, &pipe); 32 | 33 | // Print to standard output 34 | char readBuffer[128]; 35 | if (status == errAuthorizationSuccess) { 36 | for (;;) { 37 | int bytesRead = read(fileno(pipe), readBuffer, sizeof(readBuffer)); 38 | if (bytesRead < 1) break; 39 | write(fileno(stdout), readBuffer, bytesRead); 40 | } 41 | } else { 42 | NSLog(@"Authorization Result Code: %d", status); 43 | } 44 | 45 | [pool drain]; 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /OSXSimpleAuth.1: -------------------------------------------------------------------------------- 1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. 2 | .\"See Also: 3 | .\"man mdoc.samples for a complete listing of options 4 | .\"man mdoc for the short list of editing options 5 | .\"/usr/share/misc/mdoc.template 6 | .Dd 7/19/09 \" DATE 7 | .Dt OSXSimpleAuth 1 \" Program name and manual section number 8 | .Os Darwin 9 | .Sh NAME \" Section Header - required - don't modify 10 | .Nm OSXSimpleAuth, 11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key 12 | .\" words here as the database is built based on the words here and in the .ND line. 13 | .Nm Other_name_for_same_program(), 14 | .Nm Yet another name for the same program. 15 | .\" Use .Nm macro to designate other names for the documented program. 16 | .Nd This line parsed for whatis database. 17 | .Sh SYNOPSIS \" Section Header - required - don't modify 18 | .Nm 19 | .Op Fl abcd \" [-abcd] 20 | .Op Fl a Ar path \" [-a path] 21 | .Op Ar file \" [file] 22 | .Op Ar \" [file ...] 23 | .Ar arg0 \" Underlined argument - use .Ar anywhere to underline 24 | arg2 ... \" Arguments 25 | .Sh DESCRIPTION \" Section Header - required - don't modify 26 | Use the .Nm macro to refer to your program throughout the man page like such: 27 | .Nm 28 | Underlining is accomplished with the .Ar macro like this: 29 | .Ar underlined text . 30 | .Pp \" Inserts a space 31 | A list of items with descriptions: 32 | .Bl -tag -width -indent \" Begins a tagged list 33 | .It item a \" Each item preceded by .It macro 34 | Description of item a 35 | .It item b 36 | Description of item b 37 | .El \" Ends the list 38 | .Pp 39 | A list of flags and their descriptions: 40 | .Bl -tag -width -indent \" Differs from above in tag removed 41 | .It Fl a \"-a flag as a list item 42 | Description of -a flag 43 | .It Fl b 44 | Description of -b flag 45 | .El \" Ends the list 46 | .Pp 47 | .\" .Sh ENVIRONMENT \" May not be needed 48 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1 49 | .\" .It Ev ENV_VAR_1 50 | .\" Description of ENV_VAR_1 51 | .\" .It Ev ENV_VAR_2 52 | .\" Description of ENV_VAR_2 53 | .\" .El 54 | .Sh FILES \" File used or created by the topic of the man page 55 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact 56 | .It Pa /usr/share/file_name 57 | FILE_1 description 58 | .It Pa /Users/joeuser/Library/really_long_file_name 59 | FILE_2 description 60 | .El \" Ends the list 61 | .\" .Sh DIAGNOSTICS \" May not be needed 62 | .\" .Bl -diag 63 | .\" .It Diagnostic Tag 64 | .\" Diagnostic informtion here. 65 | .\" .It Diagnostic Tag 66 | .\" Diagnostic informtion here. 67 | .\" .El 68 | .Sh SEE ALSO 69 | .\" List links in ascending order by section, alphabetically within a section. 70 | .\" Please do not reference files that do not exist without filing a bug report 71 | .Xr a 1 , 72 | .Xr b 1 , 73 | .Xr c 1 , 74 | .Xr a 2 , 75 | .Xr b 2 , 76 | .Xr a 3 , 77 | .Xr b 3 78 | .\" .Sh BUGS \" Document known, unremedied bugs 79 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner -------------------------------------------------------------------------------- /OSXSimpleAuth.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 45; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4CC795371013E06D00F3D43A /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CC795361013E06D00F3D43A /* Security.framework */; }; 11 | 8DD76F9A0486AA7600D96B5E /* OSXSimpleAuth.m in Sources */ = {isa = PBXBuildFile; fileRef = 08FB7796FE84155DC02AAC07 /* OSXSimpleAuth.m */; settings = {ATTRIBUTES = (); }; }; 12 | 8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08FB779EFE84155DC02AAC07 /* Foundation.framework */; }; 13 | 8DD76F9F0486AA7600D96B5E /* OSXSimpleAuth.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6859EA3029092ED04C91782 /* OSXSimpleAuth.1 */; }; 14 | /* End PBXBuildFile section */ 15 | 16 | /* Begin PBXCopyFilesBuildPhase section */ 17 | 8DD76F9E0486AA7600D96B5E /* CopyFiles */ = { 18 | isa = PBXCopyFilesBuildPhase; 19 | buildActionMask = 8; 20 | dstPath = /usr/share/man/man1/; 21 | dstSubfolderSpec = 0; 22 | files = ( 23 | 8DD76F9F0486AA7600D96B5E /* OSXSimpleAuth.1 in CopyFiles */, 24 | ); 25 | runOnlyForDeploymentPostprocessing = 1; 26 | }; 27 | /* End PBXCopyFilesBuildPhase section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | 08FB7796FE84155DC02AAC07 /* OSXSimpleAuth.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSXSimpleAuth.m; sourceTree = ""; }; 31 | 08FB779EFE84155DC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; 32 | 32A70AAB03705E1F00C91783 /* OSXSimpleAuth_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSXSimpleAuth_Prefix.pch; sourceTree = ""; }; 33 | 4CC795361013E06D00F3D43A /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = /System/Library/Frameworks/Security.framework; sourceTree = ""; }; 34 | 8DD76FA10486AA7600D96B5E /* OSXSimpleAuth */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = OSXSimpleAuth; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | C6859EA3029092ED04C91782 /* OSXSimpleAuth.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = OSXSimpleAuth.1; sourceTree = ""; }; 36 | /* End PBXFileReference section */ 37 | 38 | /* Begin PBXFrameworksBuildPhase section */ 39 | 8DD76F9B0486AA7600D96B5E /* Frameworks */ = { 40 | isa = PBXFrameworksBuildPhase; 41 | buildActionMask = 2147483647; 42 | files = ( 43 | 8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */, 44 | 4CC795371013E06D00F3D43A /* Security.framework in Frameworks */, 45 | ); 46 | runOnlyForDeploymentPostprocessing = 0; 47 | }; 48 | /* End PBXFrameworksBuildPhase section */ 49 | 50 | /* Begin PBXGroup section */ 51 | 08FB7794FE84155DC02AAC07 /* OSXSimpleAuth */ = { 52 | isa = PBXGroup; 53 | children = ( 54 | 08FB7795FE84155DC02AAC07 /* Source */, 55 | C6859EA2029092E104C91782 /* Documentation */, 56 | 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */, 57 | 1AB674ADFE9D54B511CA2CBB /* Products */, 58 | ); 59 | name = OSXSimpleAuth; 60 | sourceTree = ""; 61 | }; 62 | 08FB7795FE84155DC02AAC07 /* Source */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 32A70AAB03705E1F00C91783 /* OSXSimpleAuth_Prefix.pch */, 66 | 08FB7796FE84155DC02AAC07 /* OSXSimpleAuth.m */, 67 | 4CC795361013E06D00F3D43A /* Security.framework */, 68 | ); 69 | name = Source; 70 | sourceTree = ""; 71 | }; 72 | 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 08FB779EFE84155DC02AAC07 /* Foundation.framework */, 76 | ); 77 | name = "External Frameworks and Libraries"; 78 | sourceTree = ""; 79 | }; 80 | 1AB674ADFE9D54B511CA2CBB /* Products */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | 8DD76FA10486AA7600D96B5E /* OSXSimpleAuth */, 84 | ); 85 | name = Products; 86 | sourceTree = ""; 87 | }; 88 | C6859EA2029092E104C91782 /* Documentation */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | C6859EA3029092ED04C91782 /* OSXSimpleAuth.1 */, 92 | ); 93 | name = Documentation; 94 | sourceTree = ""; 95 | }; 96 | /* End PBXGroup section */ 97 | 98 | /* Begin PBXNativeTarget section */ 99 | 8DD76F960486AA7600D96B5E /* OSXSimpleAuth */ = { 100 | isa = PBXNativeTarget; 101 | buildConfigurationList = 1DEB927408733DD40010E9CD /* Build configuration list for PBXNativeTarget "OSXSimpleAuth" */; 102 | buildPhases = ( 103 | 8DD76F990486AA7600D96B5E /* Sources */, 104 | 8DD76F9B0486AA7600D96B5E /* Frameworks */, 105 | 8DD76F9E0486AA7600D96B5E /* CopyFiles */, 106 | ); 107 | buildRules = ( 108 | ); 109 | dependencies = ( 110 | ); 111 | name = OSXSimpleAuth; 112 | productInstallPath = "$(HOME)/bin"; 113 | productName = OSXSimpleAuth; 114 | productReference = 8DD76FA10486AA7600D96B5E /* OSXSimpleAuth */; 115 | productType = "com.apple.product-type.tool"; 116 | }; 117 | /* End PBXNativeTarget section */ 118 | 119 | /* Begin PBXProject section */ 120 | 08FB7793FE84155DC02AAC07 /* Project object */ = { 121 | isa = PBXProject; 122 | buildConfigurationList = 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "OSXSimpleAuth" */; 123 | compatibilityVersion = "Xcode 3.1"; 124 | hasScannedForEncodings = 1; 125 | mainGroup = 08FB7794FE84155DC02AAC07 /* OSXSimpleAuth */; 126 | projectDirPath = ""; 127 | projectRoot = ""; 128 | targets = ( 129 | 8DD76F960486AA7600D96B5E /* OSXSimpleAuth */, 130 | ); 131 | }; 132 | /* End PBXProject section */ 133 | 134 | /* Begin PBXSourcesBuildPhase section */ 135 | 8DD76F990486AA7600D96B5E /* Sources */ = { 136 | isa = PBXSourcesBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | 8DD76F9A0486AA7600D96B5E /* OSXSimpleAuth.m in Sources */, 140 | ); 141 | runOnlyForDeploymentPostprocessing = 0; 142 | }; 143 | /* End PBXSourcesBuildPhase section */ 144 | 145 | /* Begin XCBuildConfiguration section */ 146 | 1DEB927508733DD40010E9CD /* Debug */ = { 147 | isa = XCBuildConfiguration; 148 | buildSettings = { 149 | ALWAYS_SEARCH_USER_PATHS = NO; 150 | COPY_PHASE_STRIP = NO; 151 | GCC_DYNAMIC_NO_PIC = NO; 152 | GCC_ENABLE_FIX_AND_CONTINUE = YES; 153 | GCC_MODEL_TUNING = G5; 154 | GCC_OPTIMIZATION_LEVEL = 0; 155 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 156 | GCC_PREFIX_HEADER = OSXSimpleAuth_Prefix.pch; 157 | INSTALL_PATH = /usr/local/bin; 158 | PRODUCT_NAME = OSXSimpleAuth; 159 | }; 160 | name = Debug; 161 | }; 162 | 1DEB927608733DD40010E9CD /* Release */ = { 163 | isa = XCBuildConfiguration; 164 | buildSettings = { 165 | ALWAYS_SEARCH_USER_PATHS = NO; 166 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 167 | GCC_MODEL_TUNING = G5; 168 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 169 | GCC_PREFIX_HEADER = OSXSimpleAuth_Prefix.pch; 170 | INSTALL_PATH = /usr/local/bin; 171 | PRODUCT_NAME = OSXSimpleAuth; 172 | }; 173 | name = Release; 174 | }; 175 | 1DEB927908733DD40010E9CD /* Debug */ = { 176 | isa = XCBuildConfiguration; 177 | buildSettings = { 178 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 179 | GCC_C_LANGUAGE_STANDARD = c99; 180 | GCC_OPTIMIZATION_LEVEL = 0; 181 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 182 | GCC_WARN_UNUSED_VARIABLE = YES; 183 | ONLY_ACTIVE_ARCH = YES; 184 | PREBINDING = NO; 185 | SDKROOT = macosx10.5; 186 | }; 187 | name = Debug; 188 | }; 189 | 1DEB927A08733DD40010E9CD /* Release */ = { 190 | isa = XCBuildConfiguration; 191 | buildSettings = { 192 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 193 | GCC_C_LANGUAGE_STANDARD = c99; 194 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 195 | GCC_WARN_UNUSED_VARIABLE = YES; 196 | PREBINDING = NO; 197 | SDKROOT = macosx10.5; 198 | }; 199 | name = Release; 200 | }; 201 | /* End XCBuildConfiguration section */ 202 | 203 | /* Begin XCConfigurationList section */ 204 | 1DEB927408733DD40010E9CD /* Build configuration list for PBXNativeTarget "OSXSimpleAuth" */ = { 205 | isa = XCConfigurationList; 206 | buildConfigurations = ( 207 | 1DEB927508733DD40010E9CD /* Debug */, 208 | 1DEB927608733DD40010E9CD /* Release */, 209 | ); 210 | defaultConfigurationIsVisible = 0; 211 | defaultConfigurationName = Release; 212 | }; 213 | 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "OSXSimpleAuth" */ = { 214 | isa = XCConfigurationList; 215 | buildConfigurations = ( 216 | 1DEB927908733DD40010E9CD /* Debug */, 217 | 1DEB927A08733DD40010E9CD /* Release */, 218 | ); 219 | defaultConfigurationIsVisible = 0; 220 | defaultConfigurationName = Release; 221 | }; 222 | /* End XCConfigurationList section */ 223 | }; 224 | rootObject = 08FB7793FE84155DC02AAC07 /* Project object */; 225 | } 226 | --------------------------------------------------------------------------------