Hi William
It's a simple testing code not finished yet but i think it could help beginners like me
Don't be cruel with me i'm not a C progorammer.
The goal here is to create 4 new attributes aCode, bCode, aCodeHas,bCodeHash everytime a new entry is added.
A step to add is how to filter by kind of entry or by DN .
Le lun. 18 févr. 2019 à 02:26, William Brown <wbrown@xxxxxxx> a écrit :
Yeah, I don’t think cos can do templating.
If you would be willing Oliver, would you submit your code to the project, and allow it to be made generic? That could help quite a few people out with similar queries.
> On 17 Feb 2019, at 00:20, Olivier JUDITH <gnulux@xxxxxxxxx> wrote:
>
> Hi ,
>
> There is a way to add attribute to user entry automatically called CoS . You can take a look on this link
> https://access.redhat.com/documwanentation/en-us/red_hat_directory_server/9.0/html/administration_guide/advanced_entry_management-assigning_class_of_service
>
> But afaik you cannot add an email based on the uid except if CoS support macros like ACI. To do that you have to create your own plugin see :https://access.redhat.com/documentation/en-us/red_hat_directory_server/9.0/html/plug-in_guide/
> I did the same for another kind of attribute.
> It works fine for me
>
>
> Le sam. 16 févr. 2019 à 14:29, Rosario Esposito <rosario.esposito@xxxxxxxxxx> a écrit :
>
> Hello,
> let's say whenever I create a new entry:
>
> uid=myuser,ou=people,dc=example,dc=com
>
> I would like this entry to have the attribute:
>
> mail: myuser@xxxxxxxxxxx
>
> (i.e. the value of 'mail' should be automatically set to the value of
> 'uid' + '@example.com')
>
> Is there a way for 389ds to do this task automatically ?
>
>
> Thanks,
> --
> Rosario Esposito
> System Administrator
> INFN - Napoli
> Phone: +39 081 676170
> Email: Rosario.Esposito@xxxxxxxxxx
> _______________________________________________
> 389-users mailing list -- 389-users@xxxxxxxxxxxxxxxxxxxxxxx
> To unsubscribe send an email to 389-users-leave@xxxxxxxxxxxxxxxxxxxxxxx
> Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
> List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
> List Archives: https://lists.fedoraproject.org/archives/list/389-users@xxxxxxxxxxxxxxxxxxxxxxx
> _______________________________________________
> 389-users mailing list -- 389-users@xxxxxxxxxxxxxxxxxxxxxxx
> To unsubscribe send an email to 389-users-leave@xxxxxxxxxxxxxxxxxxxxxxx
> Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
> List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
> List Archives: https://lists.fedoraproject.org/archives/list/389-users@xxxxxxxxxxxxxxxxxxxxxxx
—
Sincerely,
William Brown
Software Engineer, 389 Directory Server
SUSE Labs
_______________________________________________
389-users mailing list -- 389-users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to 389-users-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/389-users@xxxxxxxxxxxxxxxxxxxxxxx
#include <stdio.h> #include <string.h> #include "dirsrv/slapi-plugin.h" #include <openssl/sha.h> /* function prototypes */ int myCode_init( Slapi_PBlock *pb ); int myCode_setIdHash( Slapi_PBlock *pb ); int myCode_setHash( Slapi_PBlock *pb ); static const char *aCodeAttr = "aCode"; static const char *bCodeAttr = "bCode"; static const char *aCodeHashAttr = "aCodeHash"; static const char *bCodeHashAttr = "bCodeHash"; char *aCodeHashValue = "DuibLy8uRZ0I51bfOQA=="; char *bCodeHashValue = "DuibLy8uRZ0I51bfOQA=="; /* Description of the plug-in */ Slapi_PluginDesc plugindesc = { "Company-Code", "example.com", "0.1","pre-operation to add Code attributes" }; /* * Initialization function * * This function registers your plug-in function as a * pre-operation search function in the Directory Server. * You need to specify this initialization function in the * server configuration file so that the server calls * this initialization function on startup. */ #ifdef _WIN32 __declspec(dllexport) #endif int mySetCode_init( Slapi_PBlock *pb ) { /* Specify the version of the plug-in ( "03" in this release ) */ if (slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_03 ) != 0 || /* Specify the description of the plug-in */ slapi_pblock_set( pb,SLAPI_PLUGIN_DESCRIPTION, (void *) &plugindesc ) != 0 || /* * */ slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_ADD_FN, (void *) myCode_setHash ) !=0 ) { /* Log an error message and return -1 if a problem occurred*/ slapi_log_error( SLAPI_LOG_PLUGIN, "myCode_init" ,"Error registering the plug-in.\n" ); return( -1 ); } /* If successful, log a message and return 0 */ slapi_log_error( SLAPI_LOG_PLUGIN, "myCode_init" ,"Plug-in successfully registered.\n" ); return( 0 ); } /* * Generate the hash value of code */ void hashit(void *salt, char * code, char myhash[65]) { unsigned char hash[SHA256_DIGEST_LENGTH]; SHA256_CTX context; int i=0; SHA256_Init(&context); SHA256_Update(&context, code, strlen(code)); SHA256_Final(hash, &context); for( i=0; i<SHA256_DIGEST_LENGTH; i++){ sprintf(myhash + (i * 2), "%02x", hash[i]); } myhash[64]= 0; } const char * fetch_attr(Slapi_Entry *e, const char *attrname, const char *default_val) { Slapi_Attr *attr; Slapi_Value *val = NULL; if (slapi_entry_attr_find(e, attrname, &attr) != 0) return default_val; slapi_attr_first_value(attr, &val); return slapi_value_get_string(val); } int myCode_setIdHash( Slapi_PBlock *pb) { slapi_log_error( SLAPI_LOG_PLUGIN, "myCode_setEmpNumHash" ,"Plug-in Call set Emp num Hash.\n" ); return ( 0 ); } int myCode_setHash( Slapi_PBlock *pb ) { Slapi_Entry *entries; Slapi_DN *dn; char * mydn; Slapi_Attr *attr; slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &entries); slapi_pblock_get(pb, SLAPI_SEARCH_TARGET, &dn); if ( slapi_entry_attr_find( entries, bCodeAttr, &attr) == 0 ){ slapi_log_error( SLAPI_LOG_PLUGIN, "myCode_setHash" ,"attribute bCode found.\n" ); if ( slapi_entry_attr_find( entries, bCodeHashAttr, &attr) == 0 ){ slapi_log_error( SLAPI_LOG_PLUGIN, "myCode_Hash" ,"attribute bCodeHash found.\n" ); /* Check if value is equal to generated values */ } }else{ slapi_log_error( SLAPI_LOG_PLUGIN, "myCode_setHash" ,"attribute bCode not found.\n" ); slapi_entry_add_string( entries, bCodeHashAttr, bCodeHashValue); } if ( slapi_entry_attr_find( entries, aCodeAttr, &attr) == 0 ){ slapi_log_error( SLAPI_LOG_PLUGIN, "myCode_setHash" ,"attribute aCode found.\n" ); }else{ slapi_log_error( SLAPI_LOG_PLUGIN, "myCode_setHash" ,"attribute aCode not found.\n" ); slapi_entry_add_string( entries, aCodeHashAttr, aCodeHashValue); } return ( 0 ); } void setaCodeHash( Slapi_Entry *entry, int update) { } void setbCodeHash( Slapi_Entry *entry , int update){ }
_______________________________________________ 389-users mailing list -- 389-users@xxxxxxxxxxxxxxxxxxxxxxx To unsubscribe send an email to 389-users-leave@xxxxxxxxxxxxxxxxxxxxxxx Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/389-users@xxxxxxxxxxxxxxxxxxxxxxx