private void ShowPendingPermissionRequests() { string outputMessage = ""; List <string[]> outputList = PermissionAPI.RetrieveRequestResponses(Convert.ToInt32(this.userID), out outputMessage); GUIHandler.PrintTableOrMessage(outputList, outputMessage); }
private void ShowAllPermissions() { string outputMessage = ""; List <string[]> outputList = PermissionAPI.RetrieveAllPermissions(out outputMessage); GUIHandler.PrintTableOrMessage(outputList, outputMessage); }
private void NewPermissionRequest() { ShowAllPermissions(); Console.WriteLine("Choose permission Id"); string permissionChoice = Console.ReadLine(); Console.WriteLine("Define duration of permission"); string duration = Console.ReadLine(); string outputMessage = ""; bool isConsentGiven = ConsentAPI.CheckForConsent(Convert.ToInt32(this.userID), Convert.ToInt32(permissionChoice), out outputMessage); if (outputMessage != "" && !isConsentGiven) { Console.WriteLine(PermissionAPI.CreatePermissionRequest(this.userID, permissionChoice, duration)); DateTime dateDuration = new DateTime(); dateDuration = DateTime.Now; dateDuration = dateDuration.AddHours(Convert.ToDouble(duration)); Console.WriteLine(ConsentAPI.SaveConsent(Convert.ToInt32(this.userID), Convert.ToInt32(permissionChoice), dateDuration)); } else { Console.WriteLine(outputMessage); } }
private void RetrieveAllPermissions() { string outputMessage = ""; List <string[]> tableContent = PermissionAPI.RetrieveAllPermissions(out outputMessage); foreach (string[] columns in tableContent) { string permissionID = columns[0]; string legalText = columns[1]; _viewModel.AddPermissionToList(Convert.ToInt32(permissionID), legalText); } }
/// <summary> /// 当前登录用户是否为管理员 /// 百万次执行时间:8063、9097、9755 ms /// </summary> /// <returns></returns> public static bool IsAdmin() { const int SECURITY_BUILTIN_DOMAIN_RID = 0x20; const int DOMAIN_ALIAS_RID_ADMINS = 0x220; byte[] NtAuthority = new byte[6]; NtAuthority[5] = 5; // SECURITY_NT_AUTHORITY IntPtr AdministratorsGroup; int ret = PermissionAPI.AllocateAndInitializeSid(NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, out AdministratorsGroup); if (ret != 0) { if (PermissionAPI.CheckTokenMembership(IntPtr.Zero, AdministratorsGroup, ref ret) == 0) { ret = 0; } PermissionAPI.FreeSid(AdministratorsGroup); } return(ret != 0); }