Commits

Anonymous committed d8d80e0

Ancient diary management for DOS -- not complete.

Comments (0)

Files changed (10)

+#ifndef __INC_DIARY_H
+#define __INC_DIARY_H
+//------------------------------------------------------------------------------
+#ifndef __cplusplus // Using C?!
+	extern "C++" { // Inform C to use name mangling in case of call
+#endif // __cplusplus
+
+void ShowTitle(void);
+void GetPassword(void);
+
+#ifndef __cplusplus // Using C?!
+	} // End explicit C++ identifiers for C
+#endif // __cplusplus
+//------------------------------------------------------------------------------
+#endif // __INC_DIARY_H

Binary file added.

+@Echo off
+rem First check parameters
+if '%1' == '' goto Syntax
+if not '%1' == '/Auth:5587' goto UnAuth
+if '%2' == '' goto NoPsw
+
+rem No decide exection mode depending on file status
+if not exist Diary.txt goto IsCr1
+goto IsCr2
+
+rem For normal operation skip these error routines
+rem End the program
+goto EndPrg
+
+:UnAuth
+REM Jump here for anuthorized execution
+
+echo Please run DIARY.EXE, this program is not supposed to be run
+echo by the user.
+
+rem End the program
+goto EndPrg
+
+:Syntax
+rem Jump here to display syntax
+
+echo Syntax is:
+echo.
+echo %0 AuthorizationCode Password
+echo.
+goto UnAuth
+
+:NoPsw
+rem Jump here if no password was passed on the command line
+
+echo ERROR: No password was passed - EDITIN cannot continue decryption
+
+goto EndPrg
+
+:IsCr1
+if exist Diary.zip goto SEPT
+goto NoDiary
+
+:SEPT
+rem Secure Erase PlainText
+SecDel Diary.txt /o:100 /gov
+goto DeCrPt
+
+:DeCrPt
+PkUnZip -s"%2" diary
+if exist Diary.txt goto EdtIt
+rem Error from PKUNZIP
+if errorlevel 14 echo Password incorrect
+if not errorlevel 14 echo Error decrypting
+if exist beep.bin type beep.bin
+goto EndPrg
+
+:IsCr2
+rem Does the crypto file exist 2
+if exist Diary.zip goto DeCrPt
+goto NoDiary
+
+:NoDiary
+echo No diary found!
+if exist beep.bin type beep.bin
+goto EndPrg
+
+:EdtIt
+echo Editing plaintext...
+edit diary.txt
+
+rem THIS NEXT LINE MUST APPEAR LAST!
+:EndPrg
+#ifndef __INC_GLOBALS_H
+#define __INC_GLOBALS_H
+
+#include "KeepPsw.H" // TKeepPassword class decl
+//------------------------------------------------------------------------------
+extern TKeepPassword KeepPassword; // Declaration of instance of class to keep the password, actual instance storage (definition) in Globals.CPP
+//------------------------------------------------------------------------------
+#define DIARYFILE_PLAINTEXT "Diary.txt"
+#define DIARYFILE_CRYTOTEXT "Diary.zip"
+#define DIARYPROG_EDIT_IN "EditIn.COM"
+#define DIARYPROG_EDIT_OUT "EditOut.COM"
+#define DIARYPROG_AUTH "/Auth:5587"
+//------------------------------------------------------------------------------
+#endif // __INC_GLOBALS
+#ifndef __INC_KEEP_PSW_H
+#define __INC_KEEP_PSW_H
+
+#include "PieCrust.H"
+//------------------------------------------------------------------------------
+class TKeepPassword : public PieCrust::TAbsBase // Keeps dynamic password for file encryption
+{
+private:
+		char* _PPsw; // Pointer to password string
+	void WipePsw(); // Wipes password securely from memory
+public:
+	TKeepPassword(); // Constructor
+   ~TKeepPassword(); // Destructor
+   const char* GetPsw(); // Returns pointer to password
+   const char* SetPsw(const char* NewPsw); // Sets to new password and gives new pointer (as GetPsw() would)
+   bool IsValidPsw(); // Determines if password there is a password stored here
+};
+//------------------------------------------------------------------------------
+#endif // __INC_KEEP_PSW_H
+#include <ConIO.H> // For the colors
+#include <StdIO.H>
+#include <String.H>
+#include <Process.H>
+#pragma hdrstop
+
+#include "Diary.H"
+#include "DOSWin.H" // TDOSWindow
+#include "PswDlg.H" // TPswDlg
+#include "TimeDLay.H"
+#include "Globals.H" // Access to global data
+#include "SmlFuncs.H"
+
+using namespace PieCrust; // Access to essential Daybo Logic routines
+using namespace Doswl; // Access all of the great Daybo Logic DOS winodwing library
+using namespace SmallFuncs; // Access to Nigel and I's small functions library
+//------------------------------------------------------------------------------
+int main()
+{
+	ShowTitle(); // Show the main title and copyright notice
+   GetPassword(); // Store password by asking user for it, password is stored in 'KeepPassword'
+   if (!KeepPassword.IsValidPsw()) // Password invalid (like not entered etc.)
+   {
+   	printf("User did not give a password\n"); // Print a simple message
+      return 0; // Terminate
+   }
+
+   // Now we execute a program to get into edit mode
+   size_t SizeLocalPsw = strlen(KeepPassword.GetPsw())+2;
+   char* LocalPsw = new char[SizeLocalPsw];
+   strcpy(LocalPsw, " ");
+   strcat(LocalPsw, KeepPassword.GetPsw()); // Make a password with a space preceding it
+   spawnl(P_WAIT, DIARYPROG_EDIT_IN, DIARYPROG_EDIT_IN, DIARYPROG_AUTH, LocalPsw, NULL); // Run it
+
+   if (CheckFileExistance(DIARYFILE_PLAINTEXT))
+   	spawnl(P_WAIT, DIARYPROG_EDIT_OUT, DIARYPROG_EDIT_OUT, DIARYPROG_AUTH, LocalPsw, NULL); // Run it
+   //We must wipe the password from local memory
+   for (size_t i=0;i<SizeLocalPsw-1;i++)
+   	LocalPsw[i] = 0x0; // Wipe char
+   delete[] LocalPsw; // Deallocate local password for program
+}
+//------------------------------------------------------------------------------
+void ShowTitle()
+{
+	TDOSWindow dw; // An instance of the DOS windowing library class 'TDOSWindow'
+   char line1[] = "Secured diary manager - by Professor\n";
+   char line2[] = "Overlord D.D.R. Palmer, (C)1998";
+   char line3[] = "Daybo Logic, all rights reserved\n";
+   const char* plines[] = {line1,line2,line3}; // Point to pointers of our two lines
+
+   dw.SetHeight(5); // Two lines and 3 for the borders at the top and bottom
+   dw.SetForegroundColor(YELLOW);
+   dw.SetBackgroundColor(BLUE);
+   dw.SetWidth(LongestStringLength(plines, 3/*lines*/)+4/*for borders and msg|border sep space*/);
+   dw.MoveToCentre();
+   dw.Show();
+   dw.PutText(1, line1);
+   dw.PutText(2, line2);
+   dw.PutText(3, line3);
+   DelaySecs(5); // Delay for five seconds
+}
+//------------------------------------------------------------------------------
+void GetPassword()
+{
+	TDOSWindow dw; // A DOS window
+   char line1[] = "Belinda, this is a restricted area,";
+   char line2[] = "please enter the password to enter.";
+
+   dw.SetHeight(4); // 2 for border and two for use#
+   dw.SetWidth(dw.GetExpectedWidth(line1)); // Set width for a line (both lines are the same length)
+   dw.MoveToCentre();
+   dw.SetTop(dw.GetTop() - 10); // Move the dialog up a bit
+   dw.Show();
+   dw.PutText(1, line1);
+   dw.PutText(2, line2); // Output text onto dialog
+
+   TPswDlg PswDlg; // Dialog to get password
+
+   PswDlg.SetWidth(60); // That will dp
+	PswDlg.MoveToCentre();
+   PswDlg.Show();
+   KeepPassword.SetPsw(PswDlg.GetPsw()); // Save password into global class for later use
+}
+//------------------------------------------------------------------------------
+@Echo off
+rem First check command line parameters
+if '%1' == '' goto Syntax
+if not '%1' == '/Auth:5587' goto UnAuth
+if '%2' == '' goto NoPsw
+
+rem Now to decide execution path depending on the existance of files
+rem The plaintext must exist because it's just been edited
+if exist Diary.zip goto SECT
+goto EncP
+
+rem For normal operation skip these error routines
+rem End the program
+goto EndPrg
+
+:UnAuth
+REM Jump here for anuthorized execution
+
+echo Please run DIARY.EXE, this program is not supposed to be run
+echo by the user.
+
+rem End the program
+goto EndPrg
+
+:SECT
+rem Secure Erase Cryptotext
+SecDel /o:100 /gov diary.zip
+goto EncP
+
+:EncP
+rem Encrypt plaintext with NO COMPRESSION
+pkzip -e0 -s%2 Diary diary.txt
+if exist Diary.zip goto SEPT
+if exist beep.bin type beep.bin
+echo WARNING!  An error occured during the encryption of the plaintext of
+echo Diary, the diary plaintext will not be destroyed and it is not
+echo encrypted so correct the error and re-edit to encrypt.
+echo.
+echo This error usually occurs if the disk has been write-protected or
+echo there is not enough space left on your disk.
+goto EndPrg
+
+:SEPT
+rem Secure erase plaintext
+SecDel /o:100 /gov diary.txt
+goto EndPrg
+
+:Syntax
+rem Jump here to display syntax
+
+echo Syntax is:
+echo.
+echo %0 AuthorizationCode Password
+echo.
+goto UnAuth
+
+:NoPsw
+rem Jump here if not password was passed on the command line
+
+echo ERROR: No password was passed - EDITOUT cannot continue encryption
+
+goto EndPrg
+
+
+rem THIS NEXT LINE MUST APPEAR LAST!
+:EndPrg
+#pragma hdrstop
+
+#include "Globals.H"
+//------------------------------------------------------------------------------
+TKeepPassword KeepPassword; // Instance of class to keep password
+#include <String.H>
+#pragma hdrstop
+
+#include "KeepPsw.H" // This module's header
+//------------------------------------------------------------------------------
+TKeepPassword::TKeepPassword()
+:	_PPsw(0)
+{
+}
+//------------------------------------------------------------------------------
+TKeepPassword::~TKeepPassword()
+{
+	if (_PPsw) // Allocated password?
+   	WipePsw(); // Make sure it's gone safely and securely!
+}
+//------------------------------------------------------------------------------
+const char* TKeepPassword::GetPsw()
+{
+	return _PPsw;
+}
+//------------------------------------------------------------------------------
+const char* TKeepPassword::SetPsw(const char* NewPsw)
+{
+	if (_PPsw) // Password already allocated?
+   	WipePsw(); // Get shot of current password
+
+   if (!NewPsw) return NULL; /* Be safe if no pointer sent, this makes a new
+									   feature really because it's a way to erase from
+                              the outside. */
+
+   _PPsw = new char[strlen(NewPsw)+1]; // Allocate space to copy sent password and keep address in our private pointer
+   strcpy(_PPsw, NewPsw); // Copy caller's sent password
+   return _PPsw; // Give a pointer to our new pointer !(won't be == NewPsw)!
+}
+//------------------------------------------------------------------------------
+void TKeepPassword::WipePsw() // Wipes password securely from mem
+{
+	if (_PPsw) // Password must be allocated
+   {
+   	size_t pswstrlen = strlen(_PPsw); // Calculate string length
+   	for (int i=0;i<pswstrlen;i++) // All elements of string
+      	_PPsw[i] = 0x0; // are zeroed
+
+      // Secure bit done, now deallocate space we just wiped
+      delete[] _PPsw;  _PPsw = NULL; // and remember deallocation by loading with no address
+   }
+   return;
+}
+//------------------------------------------------------------------------------
+bool TKeepPassword::IsValidPsw()
+{
+	if (!_PPsw) return false; // Not allocated, invalid
+   // Because at this point we know it's allocated we can safely dereference the pointer
+   if (strcmpi(_PPsw, "") == 0) return false; // Nothing here, invalid
+
+   return true; // Successfully passed tested, valid
+}
+//------------------------------------------------------------------------------
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.