home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / ShellPanel / NILogin.m < prev    next >
Encoding:
Text File  |  1992-11-10  |  2.0 KB  |  67 lines

  1. /* File: NILogin.m - (Interactive) Unix shell version of NILoginPanel
  2.  *
  3.  * By: Christopher Lane (lane@sumex-aim.stanford.edu)
  4.  *
  5.  * Date: 10 November 1992
  6.  *
  7.  * Copyright: 1991 & 1992 by The Leland Stanford Junior University.
  8.  * This program may be distributed without restriction for non-commercial use.
  9.  *
  10.  * Warning: This code doesn't work, NILoginPanel doesn't perform as advertised.
  11.  */
  12.  
  13. #import <stdlib.h>
  14. #import <getopt.h>
  15. #import <nikit/NIDomain.h>
  16. #import <nikit/NILoginPanel.h>
  17. #import <appkit/Application.h>
  18.  
  19. #define USAGE "usage: %s [-d domain] [-u user] [-p prompt] [-b]\n"
  20. #define INSTRUCTION "This change to the NetInfo database requires privilege, please log in as an authorized user."
  21. #define EXIT_USAGE (2)
  22.  
  23. #define LOCAL "."
  24.  
  25. void main(int argc, char *argv[])
  26. {
  27.     ni_status nstatus;
  28.     id panel, domain;
  29.     BOOL enableUser = YES;
  30.     ni_name domainName = LOCAL;
  31.     int context, option, status = EXIT_SUCCESS;
  32.     const char *userName = "root", *instruction = INSTRUCTION;
  33.     
  34.     context = [(NXApp = [Application new]) activateSelf:YES];
  35.     
  36.     panel = [NILoginPanel new];
  37.     
  38.     domain = [[NIDomain alloc] init];
  39.     
  40.     while ((option = getopt(argc, argv, "d:u:p:b")) != EOF)
  41.         switch (option) {
  42.         case 'd': domainName = (ni_name) optarg; break;
  43.         case 'u': userName = optarg; break;
  44.         case 'p': instruction = optarg; break;
  45.         case 'b': enableUser = NO; break;
  46.         default : status = EXIT_USAGE;
  47.         }
  48.     if (optind < argc) status = EXIT_USAGE;
  49.     
  50.     if (status == EXIT_USAGE) (void) fprintf(stderr, USAGE, [NXApp appName]);
  51.     else if ((nstatus = [domain setConnection:domainName]) != NI_OK)
  52.         (void) fprintf(stderr, "%s\n", ni_error(nstatus));
  53. //    else if ([panel runModal:NXApp inDomain:[domain getDomainHandle]])
  54.     else if ([panel runModal:NXApp inDomain:[domain getDomainHandle] withUser:userName withInstruction:instruction allowChange:enableUser])
  55.         status = ([panel isValidLogin:NXApp]) ? EXIT_SUCCESS : EXIT_FAILURE;
  56.     else status = EXIT_FAILURE;
  57.     
  58.     [panel free];
  59.     [[domain disconnectFromCurrent] free];
  60.     
  61.     if (context) (void) [NXApp activate:context];
  62.     
  63.     [NXApp free];
  64.     
  65.     exit(status);
  66. }
  67.