File: cdkBroker.m

package info (click to toggle)
vmware-view-open-client 4.5.0-271013%2Bdfsg-1
  • links: PTS, VCS
  • area: contrib
  • in suites: squeeze
  • size: 11,380 kB
  • ctags: 9,913
  • sloc: ansic: 63,319; cpp: 13,550; sh: 3,919; objc: 3,366; pascal: 1,573; perl: 729; makefile: 104
file content (610 lines) | stat: -rw-r--r-- 13,424 bytes parent folder | download | duplicates (2)
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
/*********************************************************
 * Copyright (C) 2009 VMware, Inc. All rights reserved.
 *
 * This file is part of VMware View Open Client.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation version 2.1 and no later version.
 *
 * This program is released with an additional exemption that
 * compiling, linking, and/or using the OpenSSL libraries with this
 * program is allowed.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 *
 *********************************************************/

/*
 * cdkBroker.m --
 *
 *      Implementation of CdkBroker object.
 */

extern "C" {
#include "vm_basic_types.h"
#define _UINT64
}


#import "brokerAdapter.hh"
#import "cdkBroker.h"
#import "cdkBrokerAddress.h"
#import "cdkDesktop.h"
#import "cdkKeychain.h"
#import "cdkString.h"


@interface CdkDesktop (Friend)
-(cdk::Desktop *)adaptedDesktop;
@end // @interface CdkDesktop (Friend)


@implementation CdkBroker


@synthesize delegate;


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker brokerWithAddress:defaultUser:defaultDomain:delegate:] --
 *
 *      Create and return an autoreleased CdkBroker object.
 *
 * Results:
 *      A new CdkBroker, or nil on error.
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

+(CdkBroker *)broker
{
   return [[[CdkBroker alloc] init] autorelease];
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker init] --
 *
 *      Initialize an object by creating an adapter delegate and the
 *      broker object we will be wrapping.
 *
 * Results:
 *      self or nil on error.
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

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

   mAdapter = new cdk::BrokerAdapter();
   mAdapter->SetBroker(self);

   mBroker = new cdk::Broker();
   mBroker->SetDelegate(mAdapter);

   return self;
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker dealloc] --
 *
 *      Free our resources.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)dealloc
{
   delete mBroker;
   delete mAdapter;

   [super dealloc];
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker address] --
 *
 *      Return the address our broker is connected to.
 *
 * Results:
 *      A CdkBrokerAddress.
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(CdkBrokerAddress *)address
{
   return [CdkBrokerAddress
             addressWithHostname:[NSString stringWithUtilString:mBroker->GetHostname()]
                            port:mBroker->GetPort()
                          secure:mBroker->GetSecure()];
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker desktops] --
 *
 *      Get the list of desktops available to the user.
 *
 * Results:
 *      An NSArray of CdkDesktops.
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(NSArray *)desktops
{
   NSMutableArray *a = [NSMutableArray arrayWithCapacity:mBroker->mDesktops.size()];
   for (std::vector<cdk::Desktop *>::iterator i = mBroker->mDesktops.begin();
	i != mBroker->mDesktops.end(); i++) {
      CdkDesktop *desktop = [[CdkDesktop alloc] initWithDesktop:*i];
      [a addObject:desktop];
      [desktop release];
   }
   return a;
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker connectToAddress:defaultUser:defaultDomain:] --
 *
 *      Initiates the authentication process to a given address.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      The broker connects and attempts to log in to the passed-in broker.
 *
 *-----------------------------------------------------------------------------
 */

-(void)connectToAddress:(CdkBrokerAddress *)address
            defaultUser:(NSString *)defaultUser
          defaultDomain:(NSString *)defaultDomain
{
   mBroker->Initialize([NSString utilStringWithString:[address hostname]],
                       [address port],
                       [address secure],
                       [NSString utilStringWithString:defaultUser],
                       [NSString utilStringWithString:defaultDomain]);
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker cancelRequests] --
 *
 *      Cancel all current requests.
 *
 * Results:
 *      THe number of requests that were canceled.
 *
 * Side effects:
 *      Outstanding RPCs are canceled.
 *
 *-----------------------------------------------------------------------------
 */

-(int)cancelRequests
{
   return mBroker->CancelRequests();
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker setCookieFile:] --
 *
 *      Sets the cookie file for this broker to use.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)setCookieFile:(NSString *)cookieFile // IN
{
   mBroker->SetCookieFile([NSString utilStringWithString:cookieFile]);
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker reset] --
 *
 *      Reset the broker.  Erases all state and allows the user to
 *      connect again.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)reset
{
   mBroker->Reset();
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker acceptDisclaimer] --
 *
 *      Notify the broker that the user has accepted the disclaimer.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)acceptDisclaimer
{
   mBroker->AcceptDisclaimer();
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker submitCertificateFromIdentity:] --
 *
 *      Authenticate to the broker using a given identity.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)submitCertificateFromIdentity:(SecIdentityRef)ident // IN
{
   CdkKeychain *keychain = [CdkKeychain sharedKeychain];
   mBroker->SubmitCertificate(
      ident ? [keychain certificateWithIdentity:ident] : NULL,
      ident ? [keychain privateKeyWithIdentity:ident] : NULL);
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker submitUsername:passcode:] --
 *
 *      Authenticate to the broker using a given username and RSA
 *      passcode.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)submitUsername:(NSString *)username // IN
             passcode:(NSString *)passcode // IN
{
   mBroker->SubmitPasscode([NSString utilStringWithString:username],
                           [NSString utilStringWithString:passcode]);
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker nextTokencode:] --
 *
 *      Authenticate to the broker using a given RSA tokencode.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)submitNextTokencode:(NSString *)tokencode // IN
{
   mBroker->SubmitNextTokencode([NSString utilStringWithString:tokencode]);
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker submitPin:pin:] --
 *
 *      Authenticate to the broker using given RSA pins.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)submitPin:(NSString *)pin1
             pin:(NSString *)pin2
{
   mBroker->SubmitPins([NSString utilStringWithString:pin1],
                       [NSString utilStringWithString:pin2]);
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker submitUsername:password:domain:] --
 *
 *      Authenticate to the broker using windows credentials.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)submitUsername:(NSString *)username // IN
             password:(NSString *)password // IN
               domain:(NSString *)domain   // IN
{
   mBroker->SubmitPassword([NSString utilStringWithString:username],
                           [NSString utilStringWithString:password],
                           [NSString utilStringWithString:domain]);
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker submitOldPassword:newPassword:confirm:] --
 *
 *      Provide a new password for the user.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)submitOldPassword:(NSString *)oldPassword // IN
             newPassword:(NSString *)newPassword // IN
                 confirm:(NSString *)confirm     // IN
{
   mBroker->ChangePassword([NSString utilStringWithString:oldPassword],
                           [NSString utilStringWithString:newPassword],
                           [NSString utilStringWithString:confirm]);
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker loadDesktops] --
 *
 *      Request a desktop from the user.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)loadDesktops
{
   mBroker->LoadDesktops();
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker connectDesktop:] --
 *
 *      Connect the user to the desktop.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)connectDesktop:(CdkDesktop *)desktop // IN
{
   mBroker->ConnectDesktop([desktop adaptedDesktop]);
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker reconnectDesktop] --
 *
 *      Reconnect the user to the desktop.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)reconnectDesktop
{
   mBroker->ReconnectDesktop();
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker resetDesktop:quit:] --
 *
 *      Reset (reboot) a desktop and then maybe exit when finished.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)resetDesktop:(CdkDesktop *)desktop
               quit:(BOOL)quit
{
   mBroker->ResetDesktop([desktop adaptedDesktop], quit);
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker killSession:] --
 *
 *      Forcefully log out the user from a desktop.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)killSession:(CdkDesktop *)desktop // IN
{
   mBroker->KillSession([desktop adaptedDesktop]);
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker rollbackDesktop:] --
 *
 *      Initiate a desktop roll back.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)rollbackDesktop:(CdkDesktop *)desktop // IN
{
   mBroker->RollbackDesktop([desktop adaptedDesktop]);
}


/*
 *-----------------------------------------------------------------------------
 *
 * -[CdkBroker logout] --
 *
 *      Log the user out from this broker.
 *
 * Results:
 *      None
 *
 * Side effects:
 *      None
 *
 *-----------------------------------------------------------------------------
 */

-(void)logout
{
   mBroker->Logout();
}


@end // @implementation CdkBroker