source: trunk/Cocoa/Pester/Source/wakein.m@ 118

Last change on this file since 118 was 118, checked in by Nicholas Riley, 21 years ago

Broken, to-be-removed authorization implementation

File size: 2.3 KB
RevLine 
[117]1//
2// wakein.m
3// Pester
4//
5// Created by Nicholas Riley on Tue Mar 11 2003.
6// Copyright (c) 2003 Nicholas Riley. All rights reserved.
7//
8
9#import <Cocoa/Cocoa.h>
[118]10#import "PSPowerManager.h"
[117]11#import "wakein.h"
12
[118]13// System interfaces
14#include <stdio.h>
15#include <unistd.h>
16// MoreIsBetter interfaces
17#include "MoreUNIX.h"
18#include "MoreSecurity.h"
19#include "MoreCFQ.h"
[117]20
[118]21static OSStatus SetAutoWake(AuthorizationRef auth, CFDictionaryRef request, CFDictionaryRef *result) {
22 OSStatus err;
23 assert(auth != NULL);
24 assert(request != NULL);
25 assert( result != NULL);
26 assert(*result == NULL);
27 assert(geteuid() == getuid());
28 static const char *kRightName = "net.sabi.Pester.wakein.SetAutoWake";
29 static const AuthorizationFlags kAuthFlags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights;
30 AuthorizationItem right = { kRightName, 0, NULL, 0 };
31 AuthorizationRights rights = { 1, &right };
32 err = AuthorizationCopyRights(auth, &rights, kAuthorizationEmptyEnvironment, kAuthFlags, NULL);
33 // sometimes we don't get here via authexec, so ignore this
34
35 err = MoreSecSetPrivilegedEUID();
36 if (err != noErr) return err;
37
[117]38 [[NSAutoreleasePool alloc] init];
39
[118]40 NSNumber *wakeTime = [(NSDictionary *)request objectForKey: kPesterWakeTime];
41 NSLog(@"setting wake time: %@", wakeTime);
42 if (wakeTime == nil) return noErr;
[117]43
[118]44 long long secs = [wakeTime unsignedLongLongValue];
45 if (secs < 0 || secs > ULONG_MAX) return paramErr;
[117]46
47 NS_DURING
[118]48 [PSPowerManager setWakeInterval: (unsigned long)secs];
[117]49 NS_HANDLER
[118]50 *result = (CFDictionaryRef)[NSDictionary dictionaryWithObject: [localException description] forKey: kPesterWakeException];
51 return ioErr;
[117]52 NS_ENDHANDLER
53
[118]54 *result = (CFDictionaryRef)[NSDictionary dictionary];
55
56 return noErr;
[117]57}
[118]58
59int main(int argc, const char *argv[]) {
60 OSStatus err;
61 int result;
62 AuthorizationRef auth;
63
64 auth = MoreSecHelperToolCopyAuthRef();
65 err = MoreSecDestroyInheritedEnvironment(kMoreSecKeepStandardFilesMask, argv);
66 if (err == 0) {
67 err = MoreUNIXIgnoreSIGPIPE();
68 }
69 if (err == 0) {
70 err = MoreSecHelperToolMain(STDIN_FILENO, STDOUT_FILENO, auth, SetAutoWake, argc, argv);
71 }
72 result = MoreSecErrorToHelperToolResult(err);
73
74 return result;
75}
Note: See TracBrowser for help on using the repository browser.