Generate objectSID for LDIFDE import - active-directory

i'm writing an AD sync tool, which takes an LDIF file exported from an AD A, applies some replaceing and skip rules and creates another LDIF file that can then be applied to an AD B.
During the creation, i have read access on the AD B, so i can get the Schema to know what attribute-value pairs i can or can not set, and to see if there are allready objects that already exist in B that i only have to modify , but not to create. So far so good.
Right now, my rules do not copy the objectSid (and others), since they won't be right. As far as i checked, a SID is always composed of the domainSid and and an ID, like SOME-DOMAIN-SID-513 which is the SID of the Domain Users of that domain.
So IDs < then 1024 seem to be reserved for internal use while IDs > 1024 will be part of objects that where created on the way.
My question is now, can i create own objectSIDs for new entries that i want to create and set them in the LDIF file?
Any hints on that?

I don't think you can. I'm intrigued as to why you'd want to.

Related

DB2 row level access control: how to pass a user Id

In our web application we want to use DB2 row level access control to control who can view what. Each table would contain a column named userId which contain the user id. We want log-in users be able to see only row's usereId column with theirs id. I have seen db2 permission examples using DB2 session_id or user, for example taking DB2 given Banking example :
CREATE PERMISSION EXAMPLEBANKING.IN_TELLER_ROW_ACCESS
ON EXAMPLEBANKING.CUSTOMER FOR ROWS WHERE BRANCH in (
SELECT HOME_BRANCH FROM EXAMPLEBANKING.INTERNAL_INFO WHERE EMP_ID = SESSION_USER
)
ENFORCED FOR ALL ACCESS
ENABLE;
Our table gets updated dynamically hence we don't know what row get added or deleted hence we don't know what are all the user Id in the table.
At any given time, different user would log-on to the web to view information retrieve from the tables, the permission declaration above only take SESSION_USER as the input, can I change it to something like Java function parameter where one can pass arbitrary id to the permission? If not then how do I handle different log-in users at arbitrary time? Or do I just keep changing SESSION_USER dynamically as new user login (using "db2 set" ??)? If so then is this the best practice for this kind use case?
Thanks in advance.
Since the user ID in question is application-provided, not originating from the database, using SESSION_USER, which equals to the DB2 authorization ID, would not be appropriate. Instead you might use the CLIENT_USERID variable, as described here.
This might become a little tricky if you use connection pooling in your application, as the variable must be set each time after obtaining a connection from the pool and reset before returning it to the pool.
Check out Trusted Contexts, this is exactly why they exist. The linked article is fairly old (you can use trusted contexts with PHP, ruby, etc. now).

Splitting data from the same column in SQL

I am working on an SQL project and I am fairly new to SQL.
In the problem, there are accounts that are registered and accounts that aren't. What is the correct syntax to filter all of the registered ones onto one side and the non-registered one on the other side.
I am trying to make it look like two different columns.
Based on your edit, you're well on your way already. The missing part seems to be catching the banks that are registered in the first query, and the non-registered ones for the second query.
To do so, you can use a WHERE clause on the registered column to only grab those you want, like so (assuming registered will contain 1 for registered and 0 for unregistered:
...
WHERE
name LIKE '%bank1_201001%'
AND registered = 1
...
UNION ALL
...
WHERE
name LIKE '%bank2_201001%'
AND registered = 0
...
That would probably also remove the requirement for having to put in the actual bank name (I'm guessing you're doing that because you know the first one is registered and the second one is not?).
I'm not entirely certain if this is what you need. Particularly the "I'm trying to make a registered column with the banks that are registered underneath it" is kind of confusing. You initially select the name, which would be the bank name. The Registered column would then be a boolean column indicating Yes or No (or 1" and 0).
Let me know if this helps?

What does dsget use to query the directory?

I am in an organization with an Active Directory with a very deep nested group structure. I would like to query the directory to recursively find user members of a group from a Linux machine. On a Windows machine,
dsget group "dn_of_group" -members -expand
does exactly what I want and does it very quickly. When I tried to get the same results via LDAP with
(memberOf:1.2.840.113556.1.4.1941:=dn_of_group)
the query takes almost a minute to run. Does dsget use LDAP under the hood or does it use some other means to query the directory? And if so, is there any way for me to also use that?
Edit:
Clarified that I need the members which are users.
The framework 3.5 with System.DirectoryServices.AccountManagement Namespace provides a method that searches all groups recursively and returns the groups in which the user is a member. The returned set may also include additional groups that system would consider the user a member of for authorization purposes.
UserPrincipal.GetAuthorizationGroups()
The groups that are returned by this method may include groups from a different scope and store than the principal. For example, if the principal is an AD DS object that has a DN of "CN=SpecialGroups,DC=Fabrikam,DC=com, the returned set can contain groups that belong to the "CN=NormalGroups,DC=Fabrikam,DC=com
In the other direction you've got :
GroupPrincipal.GetMembers(bool recursive)
See Remarks

Active Directory query for username, first name, last name and email

Pardon my ignorance, I do not know much about AD (let lone querying with AD or googling for that). I would like to get a list of all the users in a particular domain, their first name, last name and email ids. Would a network admin (or help desk in my case) be able to do that ? My other option: I have the usernames in an excel sheet, Full name in another text file (amongst other data - say XXXyy , FirstName LastName- I would have to split,parse it to extract the name) and email in another file and none of them are in order. There might be some missing data too :(
What would be the best way to go about it with Querying AD ?
Edit:May be I should be more specific. If I was seeing what my network admin would be doing to get me this info, what would he be doing ?
Active Directory exposes query interface via OLE DB and ADO. The provider is "ADsDSOObject", the query syntax goes like this:
<LDAP://mydomain.com>;(objectType=user);givenname,sn
Perversely, the URL schema name LDAP must be capitalized.
Excel does not have a built-in ADO client, unless you code in VBA.
UPDATE: wrote a simple JavaScript query script for you:
var conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=ADsDSOObject");
var rs = conn.Execute("<LDAP://your-domain.com>;(objectClass=user);sn,givenname");
var i;
if(!rs.EOF)
{
rs.MoveFirst();
while(!rs.EOF)
{
WScript.Echo(rs.Fields.Item("givenname")+","+rs.Fields.Item("sn")+"\n");
rs.MoveNext();
}
}
It queries the fiest and last name of all users in your domain. Place your domain name in the third line. Then save it as a .js file, and execute thusly:
cscript adquery.js >a.txt
And you'll end up with a text file called a.txt, with the names of your users, comma-separated. Import it into Excel or something.
In Excel, if you are willing to mess with macros, you can write a VBA function against ADO that performs the same query. Or use .NET's DirectorySearcher, recent versions of Excel let you consume .NET objects.
If you're using the .NET platform, I would suggest looking into the System.DirectoryServices namespace, which "provides easy access to Active Directory Domain Services from managed code."
MSDN also provides code samples for performing common tasks using System.DirectoryServices, available in both VB and C#. If you're familiar with one of these languages, you should hopefully be able to glean what you need (at least to get started, and then perhaps be able to ask other, more specific questions here on SO) from these examples.
Hope this helps!

Matching DB records to Active Directory entries?

I have been tasked with coming up with a solution where I am not sure if there is a solid answer:
How can I match username records from an application's database to users in our Active Directory?
I have two applications this needs to be done for - 1st application I only have firstname and lastname information. Second application i have the application's username, which is similar to activeD's but not a definate match. I also have firstname lastname info.
Now, simply put I can just write a script that matches all the records in ActiveD that match the firstname lastname in the application DB, but that is fraught with errors.
Having no unique identifier to begin with might make this an impossible task, but before I start to task someone else with manually comparing the data after running the script, I thought I would ask the delightful StackOverflow crew to chew on it. There are always methods I don't think of, after all.
So any brilliant ideas out there to accomplish this task?
Thanks guys
Once you get them matched up automatically and the exceptions by hand, make a custom attribute in Active directory where you can store the information to keep them matched up in the future.
You could store the Active Directory object GUID against the database record.
Well, the one thing that will be indeed unique in AD is the sAMAccountName for each user. If you find a way to associate your users in your two databases with a SAM Account Name, you should have no big trouble anymore to do an automatic sync check with AD.
That property is already available in AD, you don't need to add any additional artificial IDs, and it's much easier to read than a GUID.
Marc

Resources