Xsanity Sanity for Apple's Xsan and Final Cut Server.
  
Tuesday, May 21 2013 @ 11:40 PM EDT
Topics
Storage (39)
People (1)
Xsan (103)
How To (26)
User Functions
Username:

Password:

Don't have an account yet? Sign up as a New User
Who's Online
Guest Users: 13
Sponsorship

Xsanity is proudly sponsored by:

Tekserve
The Old Reliable Mac Shop

Syntax to push LDAP JPEGPhoto entry via dscl

 
Post new topic   Reply to topic    Xsanity Forums Forum Index -> Networking
View previous topic :: View next topic  
Author Message
TheMacTech
JBOD
JBOD


Joined: 03 Feb 2009
Posts: 1

PostPosted: Tue Feb 03, 2009 4:44 pm    Post subject: Syntax to push LDAP JPEGPhoto entry via dscl Reply with quote

I want to push a jpeg picture of a user in his LDAP entry using DSCL.

The jpeg is saved in the LDAP entry in a hex dump format. I am able to retrieve a picture using:

dscl . read /LDAPv3/127.0.0.1/Users/username JPEGPhoto | xxd -r -p > filename.jpg

but if I try to push a jpg using:

dscl -u 'diradmin' -P 'password' /LDAPv3/127.0.0.1/ -create /Users/username JPEGPhoto `xxd -p ~/Desktop/Photo.jpg`

I do get a hex dump in the JPEGPhoto entry, but it must improperly formatted as it doesn't show the picture in workgroup manager or the directory utility.

Anyone know the proper way to get a user's picture in his LDAP entry via terminal?

Thanks

Manuel
Back to top
View user's profile Send private message
jtownsend
Xsan Master
Xsan Master


Joined: 24 Feb 2008
Posts: 74

PostPosted: Thu Feb 05, 2009 6:28 pm    Post subject: Reply with quote

dscl cannot edit binary attributes, even though it does display their values as hex.

There are two ways you could do this. One is using ldapmodify, which uses LDIF format and you can pass binary data through LDIF. There may also be a way to refer to an external file, but to get the base64 you can use the openssl command line tool.

The other is using dsimport... you can put a prefix of base64: on an attribute type and it will treat the data in the file as base64, or you can use externalbinary: and put a filename to a JPEG file in the import file, then the actual data comes from the JPEG file.

Here's an example import file, using this technique:

Code:
0x0A 0x5C 0x3A 0x2C dsRecTypeStandard:Users 2 dsAttrTypeStandard:RecordName externalbinary:dsAttrTypeStandard:JPEGPhoto
testuser:test.jpg


You could import this into an existing record which does not have the JPEGPhoto attribute yet like so:

Code:
dsimport -g test.txt /LDAPv3/127.0.0.1 M -u diradmin


In this example I am assuming that there is a test.jpg file alongside test.txt, which contains the data we want to attach to the record.

dsimport writes a log file to ~/Library/Logs/ImportExport/ which you can check if there are any problems.
Back to top
View user's profile Send private message
aaron
Site Admin
Site Admin


Joined: 19 Mar 2005
Posts: 405

PostPosted: Mon Feb 14, 2011 11:07 pm    Post subject: Reply with quote

Humorously enough, I needed this command just this week. I also discovered some unintended consequences when using the example above. It seems dsimport is too smart and does more than we want it to. Specifically, when used with my 10.5.8 Open Directory server, the above command will assign a new User ID (UniqueID) and GUID (GeneratedUID) to the user. It also erases alternate short names (RecordName).

The solution is to import more information. The minimum necessary fields for me were something like this:

Code:
0x0A 0x5C 0x3A 0x2C dsRecTypeStandard:Users 4 dsAttrTypeStandard:RecordName dsAttrTypeStandard:UniqueID dsAttrTypeStandard:GeneratedUID externalbinary:dsAttrTypeStandard:JPEGPhoto
aaron,AF,abf:1025:0842B052-0B0E-11D8-A5BF-000A95785C7A:AF.jpg


Note the first line is quite long, from "0x0A" until "JPEGPhoto" should be on one line.

I was importing photos for 170 users, and used a PHP script to extract the existing data from LDAP. You could also try to use dsexport to extract the necessary data, append the photo, and then import.
_________________
Aaron Freimark
http://www.tekserve.com/vcard/af.vcf
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Xsanity Forums Forum Index -> Networking All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Best Viewed on a Mac | Suggested Browser: Whatever floats yer boat.