Visitor Stats


Visits today:20
Visits yesterday:72
Visits in this month:1043
Visits total:103850
Bots today:16


DosNDS usercommand sample

This is an example of the Static Group Implementation in DosNDS with userdefined commands. This sample will only work with DN version 1.05.05 and HBWL 1.01.02 (or higher)!

This script/command sample is created for the purpose of explaining what can be done with the usercommands in DosNDS and WineDir.

On this website there is a free utility StaticGroup, see also the documentation of Static group. Here the utility is build in HBWL for DosNDS or WineDir.

Before you can understand the script you need to know how StaticGroup works and which extra attributes the program needs.

There are three important attributes.

  • The query and config attribute.
  • The Include list attribute.
  • The Exclude list attribute.

The include attribute is default "Owner", this is a multivalued DN-attribute.
The exclude attribute is default "See Also", this is also a multivalued DN-attribute.

The third and most important attribute is a multivalued String attribute. In a group this can be "L", "Full Name", "OU", "O" or "Description".
Every value that start with q: is a query value. The query is build like a ldap query.
ldap:///ou=xxx.o=hbw??sub?(objectclass=user)

The value that start with a s: is the config value. At the moment the configvalue is just a number.


The following config information is put into this number:

  • Bit 0 = add/sync (if 1 then add) (1)
  • Bit 1 = apply exclude list (2)
  • Bit 2 = apply include list (4)
  • Bit 3 = X-chain not used at the moment. (8)

E.g.
You want to "sync" the group and use exclude and include the value is 2+4 = 6.
You want to "add" and only include 1+4 = 5 so the value in eDir is "s:5"

Important: The context part (ou=xxx.o=wb) has to contain a "." and not a ","
The attributes in the filter part are "ldap names"

In this sample there are a few commands, 6 for "reading" and "setting" the attribute names. The attribute names are stored in "global" variable (variables that are not within a cmd). To access these variable you need to use getglobal("name",variable) and setglobal("name",value).

Of course it is possible to hardcode the attributes in the other commands, but for the example it is better to do it this way. The getglobal and setglobal are the way to use common information between commands.

There are 3 commands (lq, qd and aq) that access the queries in the query attribute. There are no commands for accessing the config value! These commands will be added later.

 

on hbwlver "1.01.02" goto cannot1
 
 // Some global variable we need.
 String sg_query   = "L";   
 String sg_exclude = "See Also";
 String sg_include = "Owner";
 
 register sg_query      // not mandatory but it's better, these attributes can't be deleted
 register sg_exclude    // register is a DN/WineDir command, so no ; at the end!
 register sg_include
 
 // we will add the following commands.
 // lqa, lqae, lqai, sqa, sqae, aqai   these manipulates the attribute names for the staticgroup
 // lq, dq, aq                         list/delete/add queries in the staticgroup object.
 
 // The list commands for the attributes above
 cmd lqa;
 string h;
 getglobal("sg_query",h);
 writeln(h);
 endcmd;
 
 cmd lqae;
 string h;
 getglobal("sg_exclude",h);
 writeln(h);
 endcmd;
 
 cmd lqai;
 string h;
 getglobal("sg_include",h);
 writeln(h);
 endcmd;
 
 // The set commands for the gloabal attribute.
 cmd sqa(String attribute,"query attribute");
 setglobal("sg_query",attribute);
 endcmd;
 
 cmd sqae(String attribute,"query attribute");
 setglobal("sg_exclude",attribute);
 endcmd;
 
 cmd sqai(String attribute,"query attribute");
 setglobal("sg_include",attribute);
 endcmd;
 
 //Read and show the queries from the group object.
 cmd lq(String obj,"Group");
 list h;
 item it;
 int i;
 string attribute;
 
 getglobal("sg_query",attribute);
 
 obj:=solve(obj,"group,zenworkstationgroup");   // on error stop!
 ifhalt(obj=="");       // during select user selected 0.
 
 h=getvalues(obj,attribute);
 sort(h);
 
 i=0;
 each(h,it)
 if (lowercase(substr(it.s,1,2))=="q:")
 printf("%c%3d %c%s\n",clred,i,clWhite,substr(it.s,3,strlen(it.s)-2));
 i++;
 fi;
 next;
 endcmd;
 
 //Read the queries from the group object.
 cmd dq(String obj,"Group",Int ?nr=-1,"Query Number");
 list h;
 item it;
 int i;
 string attribute;
 string sel;
 
 getglobal("sg_query",attribute);
 
 obj:=solve(obj,"group,zenworkstationgroup");   // on error stop!
 ifhalt (obj=="");       // during select user selected 0.
 
 // read all queries and the status line
 h=getvalues(obj,attribute);
 sort(h);   // make sure the status line is at the bottom
 
 // check to see if last value is s:.....
 if (nr<0)
 i=0;
 each(h,it)
 if (lowercase(substr(it.s,1,2))=="q:")
 printf("%c%3d %c%s\n",clRed,i,clWhite,substr(it.s,3,strlen(it.s)-2));
 i++;
 fi;
 next;
 
 repeat
 Write('Delete nr: '); read(sel);
 ifexit(sel=='');
 nr:=stoi(sel);
 until (nr>=0) &amp; (nr<i);
 fi;
 
 if (nr<count(h))
 getelement(h,nr,it);
 if (!test)
 nr:=-2;    
 if (nr!=0)
 cWriteln(clred,format('Delete failed, error: %d',nr));
 fi;
 else
 cWriteln(clYellow,"Would delete: ",it.s);
 fi;
 fi;    
 endcmd;    
 
 
 //Add query to the group object.
 cmd aq(String obj,"Group", String query,"Query");
 string attribute;
 item it;
 
 getglobal("sg_query",attribute);
 
 obj:=solve(obj,"group,zenworkstationgroup");   // on error stop!
 ifhalt(obj=="");       // during select user selected 0.
 
 // should do a "structure check for the query......
 it.s:='q:'+query;
 if (!test)
 savevalue(obj,attribute,it,false);
 else
 cWriteln(clYellow,"Would add: ",it.s);
 fi;
 endcmd;    
 
 // Need to add an command for Incl/Excl en add/syn options!
 
 // The real work
 //Read the queries from the group object.
 cmd sg(String obj,"Group",String ?flags,"Flags");
 
 lfunc do_filter(String obj, String s);
 list l=split(s,'?');      // s= q:ldap:///context??scope?filter
 // so element 0 contains  q:ldap:///context
 //    element 1 empty
 //    element 2 scope
 //    element 3 filter
 item it;
 
 getelement(l,0,it); string ctxt:=substr(it.s,11,strlen(it.s)-10);
 
 int scope;
 getelement(l,2,it);
 
 case (it.s)
 of ('base') scope = 0; endof;
 of ('one')  scope = 1; endof;
 of ('sub')  scope = 2; endof;
 default halt("Stoppen......"); endof;
 endcase;
 
 getelement(l,3,it);  string filt = it.s;
 
 qlist q=filter(ctxt,scope,filt,'');
 result:=getQlistDN(q);
 
 endfunc;
 
 
 list tq,hq,h;
 item it;
 int i,mode;
 String s;
 
 string attribute;
 string exclude;
 string include;
 
 bool inclfl = false;
 bool exclfl = false;
 bool addfl   =false;
 
 
 getglobal("sg_query",attribute);
 getglobal("sg_include",include);
 getglobal("sg_exclude",exclude);
 
 obj=solve(obj,"group,zenworkstationgroup");
 ifhalt(obj=="");
 
 // read all queries and the status line
 h=getvalues(obj,attribute);
 sort(h);   // make sure the status line is at the bottom
 
 setltype(tq,1);
 each(h,it)
 s=it.s;
 if (substr(s,1,2)=='q:')
 hq=do_filter(obj,s);
 tq=hq or tq; // combine all queries
 else if (substr(s,1,2)=='s:')
 s=substr(s,3,strlen(s)-2);
 mode=stoi(s);
 addfl = (mode and 1==1);
 exclfl= (mode and 2==2);
 inclfl= (mode and 4==4);
 // bit 3 (=value 8) is the x-chain option, not used here..
 fi;
 fi;
 next;
 
 // include
 if (inclfl)
 hq=getvalues(obj,include);
 tq=tq or hq;     // add all objects in hq to tq
 fi;
 
 //exclude
 if (exclfl)
 hq=getvalues(obj,exclude);
 tq=tq xor hq;    // remove all objectnames in hq from tq;
 fi;
 
 hq = getvalues(obj,'member');  // get the current member(s);
 if (addfl)
 tq = tq xor hq;   // remove all the existing members, only the new values are added
 else  // sync
 h = hq xor tq;    // all elements in h are "to much", so delete these
 tq = tq xor hq;  // olny the extra
 
 if (!test)
 each(h,it)
 remfromgroup(it.s,obj);
 next;
 else
 each(h,it)
 writeln("Would remove extra: ",it.s);
 next;
 fi;
 fi;
 
 // add the values....
 each(tq,it)
 if (!test)
 addtogroup(it.s,obj); 
 else                                  
 printf("Would add: %s",it.s);
 fi;
 next;
 endcmd;    
 
 Echo Added commands: lqa, lqae, lqai, sqa, sqae, aqai, lq, dq, aq, sg
 
 goto the_end
 :cannot1
 Echo Sorry these commands need al least HBWL version 1.01.02
 
 :the_end