Back to index

lightning-sunbird  0.9+nobinonly
ntuserpin.c
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla Communicator client code, released
00015  * March 31, 1998.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /******************************************************
00039  *
00040  *  ntuserpin.c - Prompts for the key
00041  *  database passphrase.
00042  *
00043  ******************************************************/
00044 
00045 #if defined( _WIN32 ) && defined ( NET_SSL )
00046 
00047 #include <conio.h>
00048 #include "ntuserpin.h"
00049 
00050 #undef Debug
00051 #undef OFF
00052 #undef LITTLE_ENDIAN
00053 
00054 #include <stdio.h>
00055 #include <string.h>
00056 #include <sys/types.h>
00057 
00058 
00059 static int i=0;
00060 static int cbRemotePassword = 0;
00061 static const char nt_retryWarning[] =
00062 "Warning: You entered an incorrect PIN.\nIncorrect PIN may result in disabling the token";
00063 static const char prompt[] = "Enter PIN for";
00064 
00065 
00066 #define SZ_LOCAL_PWD 1024
00067 static char loclpwd[SZ_LOCAL_PWD] = "";
00068 struct SVRCORENTUserPinObj
00069 {
00070     SVRCOREPinObj base;
00071 };
00072 static const struct SVRCOREPinMethods vtable;
00073 /* ------------------------------------------------------------ */
00074 SVRCOREError
00075 SVRCORE_CreateNTUserPinObj(SVRCORENTUserPinObj **out)
00076 {
00077     SVRCOREError err = 0;
00078     SVRCORENTUserPinObj *obj = 0;
00079     do {
00080        obj = (SVRCORENTUserPinObj*)malloc(sizeof (SVRCORENTUserPinObj));
00081        if (!obj) { err = 1; break; }
00082        obj->base.methods = &vtable;
00083     } while(0);
00084     if (err)
00085     {
00086        SVRCORE_DestroyNTUserPinObj(obj);
00087        obj = 0;
00088     }
00089     *out = obj;
00090     return err;
00091 }
00092 void
00093 SVRCORE_DestroyNTUserPinObj(SVRCORENTUserPinObj *obj)
00094 {
00095   if (obj) free(obj);
00096 }
00097 static void destroyObject(SVRCOREPinObj *obj)
00098 {
00099   SVRCORE_DestroyNTUserPinObj((SVRCORENTUserPinObj*)obj);
00100 }
00101 static char *getPin(SVRCOREPinObj *obj, const char *tokenName, PRBool retry)
00102 {
00103     char *pwd;
00104     int ch;
00105     if (retry)
00106        printf("%s\n",nt_retryWarning);
00107     printf("%s %s:", prompt, tokenName);
00108     pwd = &loclpwd[0];
00109     do
00110     {
00111         ch = _getch();
00112        *pwd++ = (char )ch;
00113     } while( ch != '\r' && (pwd < &loclpwd[SZ_LOCAL_PWD - 1]));
00114     *(pwd-1)='\0';
00115     printf("\n");
00116 
00117     /* test for zero length password.  if zero length, return null */
00118     if ('\0' == loclpwd[0])
00119        return NULL;
00120 
00121     return &loclpwd[0];
00122 }
00123 
00124 /*
00125  * VTable
00126  */
00127 static const SVRCOREPinMethods vtable =
00128 { 0, 0, destroyObject, getPin };
00129 #endif /* defined( _WIN32 ) && defined ( NET_SSL ) */
00130