summaryrefslogtreecommitdiffstats
path: root/src/kim/agent/mac/ServerThread.m
blob: 6d5ba5ed5cdb5f5c6ae339e0cdba707e22b04846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
 * Copyright 2008 Massachusetts Institute of Technology.
 * All Rights Reserved.
 *
 * Export of this software from the United States of America may
 * require a specific license from the United States Government.
 * It is the responsibility of any person or organization contemplating
 * export to obtain such a license before exporting.
 * 
 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
 * distribute this software and its documentation for any purpose and
 * without fee is hereby granted, provided that the above copyright
 * notice appear in all copies and that both that copyright notice and
 * this permission notice appear in supporting documentation, and that
 * the name of M.I.T. not be used in advertising or publicity pertaining
 * to distribution of the software without specific, written prior
 * permission.  Furthermore if you modify this software you must label
 * your software as modified software and not distribute it in such a
 * fashion that it might be confused with the original M.I.T. software.
 * M.I.T. makes no representations about the suitability of
 * this software for any purpose.  It is provided "as is" without express
 * or implied warranty.
 */
#import "ServerThread.h"
#import <Kerberos/kim.h>
#import <Kerberos/kipc_server.h>
#import "kim_migServer.h"


@implementation ClientConnection

@synthesize port;

/* ------------------------------------------------------------------------ */

- (id) initWithPort: (mach_port_t) connectionPort
               name: (NSString *) name
               path: (NSString *) path
      front_process: (bool) frontProcess
{
    if ((self = [super init])) {
        port = connectionPort;
        callerIsFrontProcess = frontProcess;
        applicationName = [name retain];
        applicationPath = [path retain];
    }
    
    return self;
}

/* ------------------------------------------------------------------------ */

- (kim_identity) enterIdentityWithError: (kim_error *) outError
{
    kim_error err = KIM_NO_ERROR;
    kim_identity identity = NULL;
    
    *outError = err;
    return identity;
}

/* ------------------------------------------------------------------------ */

- (kim_identity) selectIdentityWithHints: (kim_selection_hints) hints
                                 error: (kim_error *) outError
{
    kim_error err = KIM_NO_ERROR;
    kim_identity identity = NULL;
    
    *outError = err;
    return identity;
}

/* ------------------------------------------------------------------------ */

- (NSString *) authPromptWithIdentity: (kim_identity) identity
                                 type: (kim_prompt_type) type
                            hideReply: (bool) hideReply
                                title: (NSString *) title
                              message: (NSString *) message
                          description: (NSString *) description
                                error: (kim_error *) outError
{
    kim_error err = KIM_NO_ERROR;
    NSString *reply = @"A reply";
    
    *outError = err;
    return reply;
}

/* ------------------------------------------------------------------------ */

- (NSArray *) changePasswordWithIdentity: (kim_identity) identity
                    oldPasswordIsExpired: (bool) oldPasswordIsExpired
                                   error: (kim_error *) outError
{
    kim_error err = KIM_NO_ERROR;
    NSString *oldPassword = @"an old password";
    NSString *newPassword = @"a new password";
    NSString *verifyPassword = @"a verify password";
    
    *outError = err;
    return !err ? [NSArray arrayWithObjects: oldPassword, newPassword, verifyPassword, NULL] : NULL;    
}

/* ------------------------------------------------------------------------ */

- (kim_error) handleError: (kim_error) error
                 identity: (kim_identity) identity
                  message: (NSString *) message
              description: (NSString *) description
{
    kim_error err = KIM_NO_ERROR;
    
    return err;
}

/* ------------------------------------------------------------------------ */

- (void) dealloc
{
    [applicationName release];
    [applicationPath release];
    [super dealloc];
}

@end

@implementation ServerThread

/* ------------------------------------------------------------------------ */

+ (ServerThread *) sharedServerThread
{
    static ServerThread *gServerThread = NULL;
    
    if (!gServerThread) {
        gServerThread = [[ServerThread alloc] init];
    }
    
    return gServerThread;
}

/* ------------------------------------------------------------------------ */

- (id) init
{
    if ((self = [super init])) {
        connections = [[NSMutableArray alloc] init];
        if (!connections) {
            [self release];
            self = nil;
        }
    }
    
    return self;
}

/* ------------------------------------------------------------------------ */

- (void) dealloc
{
    [connections release];
    [super dealloc];
}

/* ------------------------------------------------------------------------ */

- (kern_return_t) listen
{
    return kipc_server_run_server (kim_server);
}

/* ------------------------------------------------------------------------ */

- (void) addConnectionWithPort: (mach_port_t) port
                          name: (NSString *) name
                          path: (NSString *) path
                  frontProcess: (bool) frontProcess
{
    ClientConnection *client = [[ClientConnection alloc] initWithPort: port
                                                                 name: name
                                                                 path: path
                                                        front_process: frontProcess];
    if (client) {
        [connections addObject: client];
    }
    
    [client release];
}

/* ------------------------------------------------------------------------ */

- (void) removeConnectionWithPort: (mach_port_t) port
{
    for (ClientConnection *client in connections) {
        if (client.port == port) {
            [connections removeObject: client];
        }
    }
    
    if (![connections count]) {
        kipc_server_quit ();
    }
}


/* ------------------------------------------------------------------------ */

- (ClientConnection *) connectionForPort: (mach_port_t) port
{
    for (ClientConnection *client in connections) {
        if (client.port == port) {
            return client;
        }
    }    
    return NULL;
}

@end