How to read msExchMailboxSecurityDescriptor attribute in C# - active-directory

I am trying to read all the user attributes in AD.
How to read msExchMailboxSecurityDescriptor attribute in C# ?
I used the following code but I got a cast error. Any suggestions would be welcome.
DirectoryObjectSecurity oSec = new ActiveDirectorySecurity();
oSec.SetSecurityDescriptorBinaryForm((byte[])val);
String m_Value = oSec.GetSecurityDescriptorSddlForm(AccessControlSections.All);
return m_Value;

Ok. I was able to figure it out. The code is given below for anyone interested. I wish Microsoft had put out some code samples so that people do not have to break their heads.
SecurityDescriptor sd = (SecurityDescriptor) p_InputValue;
AccessControlList acl = (AccessControlList)sd.DiscretionaryAcl;
String m_Trustee = "";
String m_AccessMask = "";
String m_AceType = "";
String m_ReturnValue="";
foreach (AccessControlEntry ace in (IEnumerable)acl)
{
m_Trustee = m_Trustee + "," + ace.Trustee;
m_AccessMask = m_AccessMask + "," + ace.AccessMask.ToString();
m_AceType = m_AceType + "," +ace.AceType.ToString();
}
m_ReturnValue="Trustee: " + m_Trustee + " " + "AccessMask: " + m_AccessMask + "AceType: " + m_AceType;
return m_ReturnValue

Related

How to put some variables in the script into the configuration file, read and parse it from the configuration file?

For example , the connection string required by the ODBC connection is placed in the configuration file for easy maintenance.
connDict = dict(`ip`port`db`uid`pwd`driver, [`192.168.xxx.xxx, `xxxxx, `xxxx, `user, "passwd", `MySQL])
odbcconn = odbc::connect("Driver={" + connDict.driver + "};Server=" + connDict.ip + ";Port=" + connDict.port + ";Database=" + connDict.db + "; Uid=" + connDict.uid + ";Pwd=" + connDict.pwd + ";")
Execute the following script to convert the dictionary into JSON format data conforming to the DolphinDB specification and put it in a JSON file.
connDict = dict(`ip`port`db`uid`pwd`driver, [`192.168.xxx.xxx, `xxxxx, `xxxx, `user, "passwd", `MySQL])
toJson(connDict)
Custom functions, read JSON files and convert them into dictionaries.
def getMysqlConnDictFrom Json(filePath) {
              f = file(filePath)
              arr = f.readLines()
              json = reduce(concat, trim(arr[arr != string(NULL)]))
              return fromJson(json)
}
 
connDict = getMysqlConnDictFromJson("/data/software/dolphin/server/mysqlconn.json")

How to create azure file storage SAS url(without azure libraries)?

My main target is to create a SAS url (without azure libraries)for file.
I tried to create azure storage SAS with blob and everything worked correctly. When I try to do the same in File i got an error. This is my code:
string azAccName = "AccountName";
string resource = "/upgfile/prt.png";
string endPoint = "https://" + azAccName + ".file.core.windows.net";
string uri = endPoint + resource;
string _now = DateTime.UtcNow.ToString("s") + "Z";
string _noww = DateTime.UtcNow.AddHours(3).AddMinutes(5).ToString("s") + "Z";
string StorageKey = "xxx";
string signedpermissions = "r";
string signedstart = _now;//"2017-02-14"; //yyyy-mm--dd
string signedexpiry = _noww;// "2017-02-14";
string canonicalizedresource = "/file/" + azAccName + resource; //"/blob/myaccount/music/intro.mp3"
string signedidentifier = ""; //YWJjZGVmZw==
string signedIP = "";
string signedProtocol = "https";
string signedversion = "2015-02-21";
string rscc = ""; //Cache-Control
string rscd = "file; attachment"; //Content-Disposition
string rsce = ""; //Content-Encoding
string rscl = ""; //Content-Language
string rsct = "binary"; //Content-Type binary
string StringToSign = signedpermissions + "\n" +
signedstart + "\n" +
signedexpiry + "\n" +
canonicalizedresource + "\n" +
signedidentifier + "\n" +
signedversion + "\n" +
rscc + "\n" +
rscd + "\n" +
rsce + "\n" +
rscl + "\n" +
rsct;
HMACSHA256 hmac = new HMACSHA256(Convert.FromBase64String(StorageKey));
string signature = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(StringToSign)));
string link = String.Format("{0}?sv={1}&st={2}&se={3}&sr={4}&sp={5}&rscd={8}&rsct={9}&spr={6}&sig={7}",
uri,
signedversion,
signedstart,
signedexpiry,
"c", //b for blob
signedpermissions,
"https",
signature.Replace("/", "%2"),
rscd,///////////////
rsct);
I am getting this error.
<Error>
<Code>AuthenticationFailed</Code>
<Message>
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:92eda75a-001a-0072-501d-1bb6fd000000 Time:2017-08-22T08:03:58.6115733Z
</Message>
<AuthenticationErrorDetail>Signature fields not well formed.</AuthenticationErrorDetail>
</Error>
I have almost the same code for blob(small differences) and it works correctly.
Any suggestions?
I believe the issue is missing parameters in your stringToSign. You must include all parameters as specified here:
StringToSign = signedpermissions + "\n" +
signedstart + "\n" +
signedexpiry + "\n" +
canonicalizedresource + "\n" +
signedidentifier + "\n" +
signedIP + "\n" +
signedProtocol + "\n" +
signedversion + "\n" +
rscc + "\n" +
rscd + "\n" +
rsce + "\n" +
rscl + "\n" +
rsct
If you're not using a parameter (for example signedIP in your case), you must specify an empty line.
Based on this, your StringToSign should be:
string StringToSign = signedpermissions + "\n" +
signedstart + "\n" +
signedexpiry + "\n" +
canonicalizedresource + "\n" +
signedidentifier + "\n" +
"\n" + //For signed IP
"\n" + //For signed Protocol
signedversion + "\n" +
rscc + "\n" +
rscd + "\n" +
rsce + "\n" +
rscl + "\n" +
rsct;
Furthermore sr (signed resource type) in the link should be f (for file) instead of c that you're using.

AS2 Extract top 5 from array

Good evening everyone!
Anyone knows how to extract the top 5 numbers (the highest) from an array?
I have an XML with names, surnames and score and want to extract the top 5 to create a chart.
As for now, I am getting all the info in this way:
num = xmlData.childNodes.length;
for (var i = 0; i <= num - 1; i++)
{
names[i] = this.childNodes[i].childNodes[6].firstChild.nodeValue;
surnames[i] = this.childNodes[i].childNodes[5].firstChild.nodeValue;
points[i] = this.childNodes[i].childNodes[0].firstChild.nodeValue;
pointsint[i] = parseInt(speeds[i]);
trace(i + "." + pointsint[i] + " (" + names[i] + " " + surnames[i] + ")");
}
Thank you for any help!
Organize data as generic object entries and Array.sortOn(...) (http://help.adobe.com/en_US/as2/reference/flashlite/WS5b3ccc516d4fbf351e63e3d118ccf9c47f-7ea5.html). I didn't test it but I think the idea is clear:
var num = xmlData.childNodes.length;
var entries = [];
for (var i = 0; i <= num - 1; i++)
{
var anEntry = {};
var aNode = xmlData.childNodes[i];
anEntry['name'] = aNode.childNodes[6].firstChild.nodeValue;
anEntry['surname'] = aNode.childNodes[5].firstChild.nodeValue;
var aSpeed = aNode.childNodes[0].firstChild.nodeValue;
anEntry['speed'] = parseInt(aSpeed);
entries.push(anEntry);
trace(i + "." + anEntry['speed'] + " (" + anEntry['name'] + " " + anEntry['surname'] + ")");
}
entries.sortOn("speed", Array.DESCENDING | Array.NUMERIC);
// Now first five elements of entries Array is what you want.

creating a 2D array from String arrays

I have built a program which takes 13 comma separated values of user input and appends them into a text file, each to a new line. Not too difficult, but I am new.
Now I am trying to bring these single line arrays back from the file into a 2D array where I hope to work with the values. I think I am close, but there is an obvious mistake that my inexperience does not allow me to see. I also know that there are much better class strategies written to handle this task, but again . . . newbie.
What I think is happening is that the entire file is being written into one location in the 2D array(I can sysout the finalArray , and it looks right, but only in position [0][0]). So how do I get each "z" to fill in the next open slot as it processes through ?. Hope you can help, here is my code:
String[][] finalArray = new String[100][13];
int i=-1;
try
{
x = new BufferedReader(new FileReader(readFile));
} catch (FileNotFoundException e1)
{
e1.printStackTrace();
}
try
{
while ((line = x.readLine()) != null)
{
String[] y = line.split(separator);
try
{
z ="["+ y[0] + "," + y[1] + "," + y[2] + "," + y[3]
+ "," + y[4] + "," + y[5] + "," + y[6] + "," + y[7]
+ "," + y[8] + "," + y[9] + "," + y[10] + y[11]
+ "," + y[12] + "," + y[13]+"]";
finalArray[i+1][0] = z;
z is not array it is a String but You have array of string array
therefore your loop must look like this
i=0; // array starts with 0 Item
while ((line = x.readLine()) != null)
{
finalArray[i++] = line.split(separator);
}

XMPP implementation in silverlight authentication returns failure

I am trying to implement Xmpp protocol in silverlight and trying to connect to Facebook, here I am getting everything correct until <challenge .. > obtained from server.
I am using X Facebook platform authentication.
I have done this with following code:
byte[] ch = Convert.FromBase64String(message.challenge);
string challenge = System.Text.Encoding.UTF8.GetString(ch, 0, ch.Length);
string response = "";
long callId = DateTime.UtcNow.Ticks;
MD5 md = new MD5();
String signature1 = "api_key=203366556348506"
+ "call_id=" + callId
+ "method=auth.xmpp_login"
+ param[2]
+ "session_key=" + messageClient.SessionKey
+ "v=1.0"
+ messageClient.AppSecret;
md.Value = signature1;
response = "method=auth.xmpp_login&api_key=203366556348506&session_key=bc6d6e00462cc2bb73a824bd.4-100001565408667&call_id=" + callId + "&sig=c47d741cb8f18c4e78b990f48e2f63aa&v=1.0&" + param[2];
message.Request = "<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(response)) + "</response>";
this.messageClient.SendMessageAsync(message);
But I am getting following message from server:
<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
Please let me know where I am going wrong.
Try following code:
String signature1 = "api_key=" + messageClient.ApiKey
+ "call_id=" + callId
+ "method=auth.xmpp_login"
+ param[2]
+ "session_key=" + messageClient.SessionKey
+ "v=1.0"
+ messageClient.AppSecret;
md.Value = signature1;
response = "method=auth.xmpp_login&api_key=" + messageClient.ApiKey + "&session_key=" + messageClient.SessionKey + "&call_id=" + callId + "&sig=" + md.FingerPrint.ToLower() + "&v=1.0&" + param[2];
I have changed response string to the one above.
This has returned success for me. Hope this will help you.

Resources