t_nt_security.cpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002 *                                                                             *
00003 *  Name   : test_nt_security                                                  *
00004 *  Author : Sue Richeson                                                      *
00005 *  Author : Chris Koeritz                                                     *
00006 *                                                                             *
00007 *******************************************************************************
00008 * Copyright (c) 2001-$now By Author.  This program is free software; you can  *
00009 * redistribute it and/or modify it under the terms of the GNU General Public  *
00010 * License as published by the Free Software Foundation; either version 2 of   *
00011 * the License or (at your option) any later version.  This is online at:      *
00012 *     http://www.fsf.org/copyleft/gpl.html                                    *
00013 * Please send any updates to: fred@gruntose.com                               *
00014 \*****************************************************************************/
00015 
00016 #include "resource.h"
00017 
00018 #include <basis/chaos.h>
00019 #include <basis/istring.h>
00020 #include <data_struct/static_memory_gremlin.h>
00021 #include <geometric/rectangle.cpp>
00022 #include <geometric/screen_rectangle.h>
00023 #include <geometric/warper.cpp>
00024 #include <security/nt_security.h>
00025 #include <textual/string_convert.h>
00026 
00027 BASIS_STARTUP_CODE;
00028 
00029 #ifndef __WIN32__
00030 // simple placeholder for non-winders platforms.
00031 int main(int formal(argc), char *formal(argv)[]) { return 0; }
00032 #else
00033 
00034 #include "t_nt_security.h"
00035 
00036 #include <mfc_ext/info_edit.h>
00037 #include <mfc_ext/tiny_app.cpp>
00038 
00039 #include <comdef.h>
00040 
00041 using namespace geometric;
00042 
00043 const screen_rectangle DEFAULT_WINDOW_SIZE(80, 200, 480, 480);
00044 
00045 const istring WINDOW_TITLE("Security Access Tester");
00046 
00048 
00049 #define LOG(to_print) print(istring(to_print) + istring("  ") + timestamp(false, true))
00050 #define PRINT(to_print) print(istring("     ") + istring(to_print))
00051 
00053 // required for COM usage.
00054 struct InitOle {
00055   InitOle()  { ::CoInitialize(NULL); }
00056   ~InitOle() { ::CoUninitialize();   }
00057 } _init_InitOle_;       // Global Instance to force load/unload of OLE
00058 
00060 
00061 BEGIN_MESSAGE_MAP(test_nt_security, tiny_shell)
00062   //{{AFX_MSG_MAP(test_nt_security)
00063   ON_WM_CREATE()
00064   ON_WM_CLOSE()
00065   //}}AFX_MSG_MAP
00066 
00067   ON_COMMAND(IDM_CLOSE, menu_exit_program)
00068 
00069   ON_COMMAND(IDM_NT_GETUSERANDDOMAINNAME, nt_get_user_and_domain_name)
00070   ON_COMMAND(IDM_NT_DOMAINBINDING, nt_domain_binding)
00071   ON_COMMAND(IDM_NT_DOMAINUSERBINDING, nt_domain_user_binding)
00072   ON_COMMAND(IDM_NT_SETPRIVILEGEONUSER, nt_set_privilege_on_user)
00073 
00074 END_MESSAGE_MAP()
00075 
00077 
00078 test_nt_security::test_nt_security()
00079 : tiny_shell(WINDOW_TITLE, "test_nt_security")
00080 { 
00081   menu(IDR_MENU_TEST_SECURITY);
00082   icon(ICON_TEST_SECURITY);
00083 }
00084 
00085 
00086 test_nt_security::~test_nt_security()
00087 {
00088     // Nothing to do.
00089 }
00090 
00091 
00092 afx_msg int test_nt_security::OnCreate(LPCREATESTRUCT lpCreateStruct)
00093 {
00094   tiny_shell::OnCreate(lpCreateStruct);
00095   return 0;
00096 }
00097 
00098 
00099 afx_msg void test_nt_security::OnClose()
00100 {
00101   #define func "OnClose"
00102   tiny_shell::OnClose();
00103   #undef func
00104 }
00105 
00106 
00107 int test_nt_security::execute()
00108 {
00109   #define func "execute"
00110   LOG("NT security tester is ready...");
00111   return 0;
00112   #undef func
00113 }
00114 
00115 
00116 istring test_nt_security::query_text(const istring &title)
00117 {
00118   istring to_return;
00119   info_edit querier(0, "", 150, "Enter String", title.s());
00120   // grab the string they entered and return it.
00121   if (querier.DoModal() == IDOK)
00122     to_return = querier.text();
00123 
00124   return to_return;
00125 }
00126 
00127 
00128 void test_nt_security::menu_exit_program()
00129 {
00130   PostMessage(WM_CLOSE);
00131 }
00132 
00133 
00134 void test_nt_security::nt_get_user_and_domain_name()
00135 {
00136     bool status;
00137     nt_security nt;
00138     istring userName;
00139     istring domainName;
00140 
00141     status = nt.GetUserAndDomainName(userName, domainName);
00142 
00143     LOG("nt_security::GetUserAndDomainName");
00144     if (status)
00145     {
00146         LOG("SUCCEEDED");
00147         PRINT(istring("Domain Name= ") + domainName + istring("   User Name= ") + userName);
00148     }
00149     else
00150         LOG("FAILED");
00151 }
00152 
00153 
00154 void test_nt_security::nt_domain_binding()
00155 {
00156     nt_security nt;
00157     istring binding;
00158     istring domain;
00159 
00160     domain = query_text("Enter the DOMAIN name");
00161     binding = nt.DomainBinding(domain);
00162 
00163     LOG(istring("nt_security::DomainBinding(") + domain + istring(")"));
00164     if (binding.empty())
00165         LOG("FAILED");
00166     else
00167     {
00168         LOG("SUCCEEDED");
00169         PRINT(istring("Domain binding= ") + binding);
00170     }
00171 }
00172 
00173 
00174 void test_nt_security::nt_domain_user_binding()
00175 {
00176     nt_security nt;
00177     istring binding;
00178     istring domain;
00179     istring user;
00180 
00181     domain = query_text("Enter the DOMAIN name");
00182     user = query_text("Enter the USER name");
00183     binding = nt.DomainUserBinding(domain, user);
00184 
00185     LOG(istring("nt_security::DomainUserBinding(") + domain 
00186                                           + istring(", ") + user + istring(")"));
00187     if (binding.empty())
00188         LOG("FAILED");
00189     else
00190     {
00191         LOG("SUCCEEDED");
00192         PRINT(istring("Domain and user binding= ") + binding);
00193     }
00194 }
00195 
00196 
00197 void test_nt_security::nt_set_privilege_on_user()
00198 {
00199 }
00200 
00202 
00203 tiny_application<test_nt_security> theApp;
00204 
00205 #endif
00206 

Generated on Fri Nov 28 04:29:39 2008 for HOOPLE Libraries by  doxygen 1.5.1