Novell is now a part of Micro Focus

Do you have any LDAP code to create...

Articles and Tips: qna

01 Dec 2002


Q.

Do you have any LDAP code to create eDirectory users? We are setting up our web page to create users and don't want to recreate the wheel. We are using PHP, but the LDAP calls should work.

A.

Here is a script to create users in eDirectory. Basically, we have a PHP web page running on a Linux server. My technicians authenticate to this webbed with LDAP to our NetWare 6 server. Then, they can enter a username and new password and it changes their eDirectory password and simple password.

The eDirectory password is set directly in the PHP with an LDAP call, however we found out that PHP could not directly change the simple password. So we created this script that creates an LDIF file which can call ICE on the Linux server. This utility is created to do Novell LDAP Simple Password Change for Humanities Information Systems, College of Humanities of The Ohio State University (2002).

Author: James Cheng

Compile with: gcc -o nldspc nldspc.c

#include <stdio.h>
#include <time.h>
	
static char usage[] = "Usage: nldspc <login dn> <password>\n"
	
"Example: nldspc cn=admin,o=cohums\n";
	
int main( int argc, char **argv )
	
{
	FILE *fp;
	char cmd[500];
	char dn[200];
	char pwd[20];
	char filepath[50];
	char filename[50];
	time_t ltime;
	
	if (argc != 3) 
	{
		printf("%s", usage);
		return (1);
	}
	
	strcpy(dn,argv[1]);
	strcpy(pwd, argv[2]);
	
//get current time as filename
	time( &ltime );
	
//Set the file path; ie. current directory as default
	sprintf(filepath,"");
	sprintf(filename,"%s%ld.ldif",filepath,ltime);
	
//write ldif to file
	if ((fp=fopen(filename,"w")) == NULL)
	{
		printf("Error on writing file.(%s)\n",filename);
		return (1);
	}
	
	fprintf(fp,"dn:%s\n",dn);
	fprintf(fp,"userpassword: %s\n",pwd);
	fclose(fp);
	
//run Novell ICE program to update simple password
//Please copy ice from ldap tool kits to the current directory
// "pwd" password
// "servername" LDAP server host name
	
	sprintf(cmd,"ice -e %s%ld.result -S LDIF -f %s -v -D LDAP -d
		\"cn=admin,ou=org1,ou=org2,o=cohums\" -w pwd -v -l -s servername
 		",filepath,ltime,filename);
	system(cmd);
	
//remove the ldif file
	sprintf(cmd,"rm %s",filename);
	system(cmd);
	
//You can comment out the lines below if you want to
//check the result of the operation
//remove result file
	sprintf(cmd,"rm 	%s%ld.result",filepath,ltime);
	system(cmd);
}

* Originally published in Novell AppNotes


Disclaimer

The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.

© Copyright Micro Focus or one of its affiliates