/********************************************************* * Main Function Entry * *********************************************************/ int _cdecl main(int argc, char **argv) { HANDLE hFile; DWORD dwReturn; wchar_t szTemp[256] = {0}; swprintf_s(szTemp,256, L"\\\\.\\Example\\%s", argv[1]); hFile = CreateFile(szTemp, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if(hFile != INVALID_HANDLE_VALUE) { while(szTemp[0] != 'q' && szTemp[0] != 'Q') { printf("Press enter to get a string from the driver or 'Q' to quit\n"); _getws_s(szTemp,256); if(szTemp[0] != 'q' && szTemp[0] != 'Q') { memset(szTemp, 0, sizeof(szTemp)); dwReturn = 0; ReadFile(hFile, szTemp, sizeof(szTemp), &dwReturn, NULL); printf("%d bytes read\n", dwReturn); printf("'%s'\n", szTemp); } } CloseHandle(hFile); } return 0; }
void modify(struct node *temp, wchar_t *find) { struct node *modi, *fresh; wchar_t *key; wchar_t *mod; modi = temp; printf("## Here is modify function!\n"); if(overlapflag>1) { int select; printf("who want to modify?(input overlapflag) : "); scanf_s("%d",&select); fflush(stdin); modi = findobject(NULL,select); destroySLL(); } if(wcscmp(modi->Name,L"none") != 0) { wprintf(L"Name : %s\n",modi->Name); } if(wcscmp(modi->Tel,L"none") != 0) { wprintf(L"Tel : %s\n",modi->Tel); } if(wcscmp(modi->Email,L"none") != 0) { wprintf(L"Email : %s\n",modi->Email); } if(wcscmp(modi->Note,L"none") != 0) { wprintf(L"Note : %s\n",modi->Note); } printf("What do you want to modify? (name(1), tel(2), email(3), note(4) :)"); if(overlapflag < 2) { getchar(); } key = (wchar_t *)malloc(60); _getws_s(key,30); if(wcscmp(key,L"quit") == 0) { return ; } else { key = wcstol(key, NULL, 10); switch((int)key) { case 1: fresh = (struct node*)malloc(sizeof(struct node)); fresh->Tel = (wchar_t *)malloc(200); fresh->Email = (wchar_t *)malloc(300); fresh->Note = (wchar_t *)malloc(1000); wcscpy_s(fresh->Tel,100,modi->Tel); wcscpy_s(fresh->Email,150,modi->Email); wcscpy_s(fresh->Note,500,modi->Note); printf("input new name : "); mod = (wchar_t *)malloc(200); _getws_s(mod,100); root = removeNode(root, modi->Name, modi->overlapflag); shakeflag--; addToBST(mod, fresh->Tel, fresh->Email, fresh->Note); CoverWrite(); break; case 2: printf("input new phone number : "); mod = (wchar_t *)malloc(200); _getws_s(mod,100); wcscpy_s(modi->Tel,100,mod); CoverWrite(); break; case 3: printf("input new email : "); mod = (wchar_t *)malloc(300); _getws_s(mod,150); wcscpy_s(modi->Email,150,mod); CoverWrite(); break; case 4: printf("input new note : "); mod = (wchar_t *)malloc(1000); _getws_s(mod,500); wcscpy_s(modi->Note,500,mod); CoverWrite(); break; } } }
// // Based on the input switches, pick the specified device to use. // bool PickDevice(IMMDevice **DeviceToUse, bool *IsDefaultDevice, ERole *DefaultDeviceRole) { HRESULT hr; bool retValue = true; IMMDeviceEnumerator *deviceEnumerator = NULL; IMMDeviceCollection *deviceCollection = NULL; *IsDefaultDevice = false; // Assume we're not using the default device. hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&deviceEnumerator)); if (FAILED(hr)) { printf("Unable to instantiate device enumerator: %x\n", hr); retValue = false; goto Exit; } IMMDevice *device = NULL; // // First off, if none of the console switches was specified, use the console device. // if (!UseConsoleDevice && !UseCommunicationsDevice && !UseMultimediaDevice && OutputEndpoint == NULL) { // // The user didn't specify an output device, prompt the user for a device and use that. // hr = deviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &deviceCollection); if (FAILED(hr)) { printf("Unable to retrieve device collection: %x\n", hr); retValue = false; goto Exit; } printf("Select an output device:\n"); printf(" 0: Default Console Device\n"); printf(" 1: Default Communications Device\n"); printf(" 2: Default Multimedia Device\n"); UINT deviceCount; hr = deviceCollection->GetCount(&deviceCount); if (FAILED(hr)) { printf("Unable to get device collection length: %x\n", hr); retValue = false; goto Exit; } for (UINT i = 0 ; i < deviceCount ; i += 1) { LPWSTR deviceName; deviceName = GetDeviceName(deviceCollection, i); if (deviceName == NULL) { retValue = false; goto Exit; } printf(" %d: %S\n", i + 3, deviceName); free(deviceName); } wchar_t choice[10]; _getws_s(choice); // Note: Using the safe CRT version of _getws. long deviceIndex; wchar_t *endPointer; deviceIndex = wcstoul(choice, &endPointer, 0); if (deviceIndex == 0 && endPointer == choice) { printf("unrecognized device index: %S\n", choice); retValue = false; goto Exit; } switch (deviceIndex) { case 0: UseConsoleDevice = 1; break; case 1: UseCommunicationsDevice = 1; break; case 2: UseMultimediaDevice = 1; break; default: hr = deviceCollection->Item(deviceIndex - 3, &device); if (FAILED(hr)) { printf("Unable to retrieve device %d: %x\n", deviceIndex - 3, hr); retValue = false; goto Exit; } break; } } else if (OutputEndpoint != NULL) { hr = deviceEnumerator->GetDevice(OutputEndpoint, &device); if (FAILED(hr)) { printf("Unable to get endpoint for endpoint %S: %x\n", OutputEndpoint, hr); retValue = false; goto Exit; } } if (device == NULL) { ERole deviceRole = eConsole; // Assume we're using the console role. if (UseConsoleDevice) { deviceRole = eConsole; } else if (UseCommunicationsDevice) { deviceRole = eCommunications; } else if (UseMultimediaDevice) { deviceRole = eMultimedia; } hr = deviceEnumerator->GetDefaultAudioEndpoint(eRender, deviceRole, &device); if (FAILED(hr)) { printf("Unable to get default device for role %d: %x\n", deviceRole, hr); retValue = false; goto Exit; } *IsDefaultDevice = true; *DefaultDeviceRole = deviceRole; } *DeviceToUse = device; retValue = true; Exit: SafeRelease(&deviceCollection); SafeRelease(&deviceEnumerator); return retValue; }
void wmain( int argc, wchar_t *argv[ ]) { //Handle the command line arguments. LPOLESTR pszBuffer = NULL; pszBuffer = new OLECHAR[MAX_PATH*2]; if(pszBuffer == NULL) goto ret; if (argv[1] == NULL) { wprintf(L"This program finds a user in the current Window 2000 domain\n"); wprintf(L"and displays its objectSid property in string form.\n"); wprintf(L"This program demonstrates reading a property of type octet string.\n\n"); wprintf(L"Enter Common Name of the user to find:"); if ( !_getws_s(pszBuffer, MAX_PATH*2)) { delete [] pszBuffer; wprintf(L"String exceeded buffer size.\n\n"); return; } } else if ( !wcscpy_s(pszBuffer, MAX_PATH*2, argv[1])) { delete [] pszBuffer; wprintf(L"String exceeded buffer size.\n\n"); return; } //if empty string, exit. if (0==wcscmp(L"", pszBuffer)) goto ret; wprintf(L"\nFinding user: %s...\n",pszBuffer); //Intialize COM CoInitialize(NULL); HRESULT hr = S_OK; //Get rootDSE and the domain container's DN. IADs *pObject = NULL; IDirectorySearch *pDS = NULL; LPOLESTR szPath = NULL; szPath = new OLECHAR[MAX_PATH]; if(szPath == NULL) goto ret; VARIANT var; hr = ADsOpenObject(L"LDAP://rootDSE", NULL, NULL, ADS_SECURE_AUTHENTICATION, //Use Secure Authentication IID_IADs, (void**)&pObject); if (FAILED(hr)) { wprintf(L"Not Found. Could not bind to the domain.\n"); if (pObject) pObject->Release(); goto ret; } VariantInit(&var); hr = pObject->Get(L"defaultNamingContext",&var); if (SUCCEEDED(hr)) { wcscpy_s(szPath,MAX_PATH,L"LDAP://"); wcscat_s(szPath,MAX_PATH,var.bstrVal); VariantClear(&var); if (pObject) { pObject->Release(); pObject = NULL; } //Bind to the root of the current domain. hr = ADsOpenObject(szPath, NULL, NULL, ADS_SECURE_AUTHENTICATION, //Use Secure Authentication IID_IDirectorySearch, (void**)&pDS); if (SUCCEEDED(hr)) { hr = FindUserByName(pDS, //Container to search pszBuffer, //Name of user to find. &pObject); //Return a pointer to the user if (SUCCEEDED(hr)) { //Get the objectSid property hr = pObject->Get(L"objectSid", &var); if (SUCCEEDED(hr)) { LPBYTE pByte = NULL; wprintf (L"----------------------------------------------\n"); wprintf (L"----------Call GetLPBYTEtoOctetString---------\n"); wprintf (L"----------------------------------------------\n"); hr = GetLPBYTEtoOctetString(&var, //IN. Pointer to variant containing the octetstring. &pByte //OUT. Return LPBYTE to the data represented in octetstring. ); PSID pObjectSID = (PSID)pByte; //Convert SID to string. LPOLESTR szSID = NULL; ConvertSidToStringSid(pObjectSID, &szSID); wprintf(L"objectSid:%s\n",szSID); LocalFree(szSID); //Free the buffer. CoTaskMemFree(pByte); } else wprintf(L"Get method failed with hr: %x\n",hr); VariantClear(&var); } else { wprintf(L"User \"%s\" not Found.\n",pszBuffer); wprintf (L"FindUserByName failed with the following HR: %x\n", hr); } if (pObject) pObject->Release(); } if (pDS) pDS->Release(); } ret: if(pszBuffer) delete pszBuffer; if(szPath) delete szPath; //Uninitalize COM CoUninitialize(); return; }
int _tmain(int argc, _TCHAR* argv[]) { int result = -1; HANDLE lsa = 0; //wchar_t unlock[MAX_GROUPNAME] = L""; TRACE(L"-------------------------\n"); //EnablePrivilege(L"SeTcbPrivilege"); if(!RegisterLogonProcess(LOGON_PROCESS_NAME, &lsa)) TRACEMSG(GetLastError()); if(IsWindowsServer()) { TRACE(L"Windows Server\n"); } else { TRACE(L"Windows pas Server\n"); } /* if(GetGroupName(gUnlockGroupName, unlock, sizeof unlock / sizeof *unlock) == S_OK) { wchar_t caption[512]; wchar_t text[2048]; OutputDebugString(L"Group name "); OutputDebugString(unlock); OutputDebugString(L"\n"); if((GetNoticeText(L"Caption", caption, sizeof caption / sizeof *caption) == S_OK) && (GetNoticeText(L"Text", text, sizeof text / sizeof *text) == S_OK)) { wchar_t message[MAX_USERNAME + sizeof text / sizeof *text]; wchar_t *read = text; wchar_t *write = text; while(*read) { if((*read == '\\') && (*(read+1) == 'n')) { *write++ = '\n'; read += 2; } else { *write++ = *read++; } } *write = 0; wsprintf(message, text, unlock); //Will insert group name if there is a %s in the message MessageBox(0, message, caption, MB_YESNOCANCEL|MB_ICONEXCLAMATION); } } */ if(argc > 1) for(int i=1; i<argc; ++i) { // wchar_t user[MAX_USERNAME]; // wchar_t domain[MAX_DOMAIN]; wchar_t passwd[MAX_PASSWORD]; wchar_t username[512]; wchar_t domain[512]; HANDLE current_user = 0; OpenProcessToken(GetCurrentProcess(), TOKEN_READ, ¤t_user); GetUsernameAndDomainFromToken(current_user, username, sizeof username / sizeof *username, domain, sizeof domain / sizeof *domain); if(ShouldHookUnlockPasswordDialog(current_user)) { TRACE(L"Should hook.\n"); } if (_getws_s(passwd, MAX_PASSWORD) == passwd) { result = ShouldUnlockForUser(lsa, current_user, L".", argv[i], passwd); switch(result) { case eLetMSGINAHandleIt: TRACE(L"TEST result is eLetMSGINAHandleIt\n"); wprintf(L"Actual result : eLetMSGINAHandleIt\n"); break; case eUnlock: TRACE(L"TEST result is eUnlock\n"); wprintf(L"Actual result : eUnlock\n"); break; case eForceLogoff: TRACE(L"TEST result is eForceLogoff\n"); wprintf(L"Actual result : eForceLogoff\n"); break; } } else { TRACE(L"Unable to read password\n"); break; } CloseHandle(current_user); } LsaDeregisterLogonProcess(lsa); //DisablePrivilege(L"SeTcbPrivilege"); return result; }