|
The aug command written in HBWL.
cmd sample_aug(string user,'user',string group, 'group');
int mode=1; // set the find object search mode 0=must be unique, 1=program dispalys options if not unique
if (unique) mode:=0; fi; // unique is a global system variable with the status of the unique flag.
user:=FindObj(mode,user,'User'); // make sure you have the whole name and it is a user-object
if (lasterror==0) // should be 0, otherwise an error
group=FindObj(mode,Group,'Group');
if (lasterror==0)
if (test) // check the test/norm mode setting
write('TEST: ');
else
addtogroup(user,group);
fi;
writeln(Format('Add user %s to group %s successfull',user,group));
else
writeln('Error: group does not exist, or not unique, or object is not a group');
fi;
else
writeln('Error: user does not exist, or not unique, or object is not a user');
fi;
endcmd;%0A%20%20%20cmd%20sample_aug%28string%20user%2C%27user%27%2Cstring%20group%2C%20%27group%27%29%3B%0A%20%20%20%0A%20%20%20int%20mode%3D1%3B%20%20%20%20%20%2F%2F%20set%20the%20find%20object%20search%20mode%200%3Dmust%20be%20unique%2C%201%3Dprogram%20dispalys%20options%20if%20not%20unique%0A%20%20%20if%20%28unique%29%20mode%3A%3D0%3B%20fi%3B%20%20%20%20%2F%2F%20unique%20is%20a%20global%20system%20variable%20with%20the%20status%20of%20the%20unique%20flag.%0A%20%20%20%0A%20%20%20user%3A%3DFindObj%28mode%2Cuser%2C%27User%27%29%3B%20%20%20%20%20%20%20%2F%2F%20make%20sure%20you%20have%20the%20whole%20name%20and%20it%20is%20a%20user-object%0A%20%20%20if%20%28lasterror%3D%3D0%29%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20should%20be%200%2C%20otherwise%20an%20error%20%0A%20%20%20%20%20%20%20group%3DFindObj%28mode%2CGroup%2C%27Group%27%29%3B%0A%20%20%20%20%20%20%20if%20%28lasterror%3D%3D0%29%0A%20%20%20%20%20%20%20%20%20%20%20if%20%28test%29%20%20%20%20%2F%2F%20check%20the%20test%2Fnorm%20mode%20setting%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20write%28%27TEST%3A%20%27%29%3B%0A%20%20%20%20%20%20%20%20%20%20%20else%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20addtogroup%28user%2Cgroup%29%3B%0A%20%20%20%20%20%20%20%20%20%20%20fi%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20writeln%28Format%28%27Add%20user%20%25s%20to%20group%20%25s%20successfull%27%2Cuser%2Cgroup%29%29%3B%0A%20%20%20%20%20%20%20else%20%0A%20%20%20%20%20%20%20%20%20%20%20writeln%28%27Error%3A%20group%20does%20not%20exist%2C%20or%20not%20unique%2C%20or%20object%20is%20not%20a%20group%27%29%3B%0A%20%20%20%20%20%20%20fi%3B%0A%20%20%20else%20%0A%20%20%20%20%20%20%20writeln%28%27Error%3A%20user%20does%20not%20exist%2C%20or%20not%20unique%2C%20or%20object%20is%20not%20a%20user%27%29%3B%0A%20%20%20fi%3B%0A%20%20%20%0A%20%20%20endcmd%3B%0A%20%20%20 The ahd command written in HBWL.
cmd shd(string User,"User",string P,"Path",string ?flags="RWECDMF","Flags",string ?force="Y","Force Create");
string obj1,answ;
bool flag = false;
string rights = 'RWECDMF';
int mode=1; if (unique) mode:=0; fi;
flags=uppercase(flags);
force=uppercase(force);
bool forceflag = (force=="Y");
if (flags<>"") rights=flags; fi;
obj1=FindObj(1,user,"User");
ifexit (lasterror<>0,"User object not found");
// optional you can add the username to the path
// p=p+'\\'+part(obj1,0);
// you can do any fancy thing you want here for the homedirectory.
p:=expandUNCFilename(P,false);
// check for the path to start with \\, because you have to esc a backslash with a \ you have to give 4 \ characters!
ifexit( substr(p,1,2)<>'\\\\', 'Homedirectory can not be local!');
// does the direcoty not exist and is the forceflag not set?
if (!directoryexists(p) & (!forceflag) )
repeat
write('Directory does not exists, create Y/N');
read(answ);
answ=uppercase(answ);
until ((answ<>'') & (answ=="Y") | (answ=='N') );
ifexit(answ=="N");
forceflag:=true;
fi;
// create directory if it doesn't exist if not in test mode
if (!directoryexists(p) & forceflag & !test)
ifexit(!forcedirectories(p),'Creation of directory failed');
fi;
// set the trustee, by using the command at if not in test mode
if (!test)
command(format("at %s %s %s",obj1,p,rights));
fi;
// we do have a unc path but we need a volume object and the path on the volume
// split the path into server,volume and path;
string server,volume,path;
parse(p,server,volume,path,true);
// look up the server
string serverDN:=FindObj(0,server,'NCP Server');
ifexit (serverdn=='', "Sorry, can't find server object in the eDirectory");
writeln(serverdn);
// now we can find lookup the volume object in the eDirectory
// search for a volume object with attribute Host Server set to the serverDN
// and the Host resource name set to the volume name
string volumedn:=search2('[root]','Volume','Host Server',serverdn,'Host Resource Name',volume);
ifexit(volumedn=='', "Sorry, can't find volume object in the eDirectory");
if (test)
writeln(Format('TEST: Would add homedirectory %s to %s',p,obj1));
else
savepathvalue(obj1,'Home Directory',volumedn,path,0,false);
writeln(Format('Homedirectory %s added to %s',p,obj1));
fi;
endcmd;%0A%20%20cmd%20shd%28string%20User%2C%22User%22%2Cstring%20P%2C%22Path%22%2Cstring%20%3Fflags%3D%22RWECDMF%22%2C%22Flags%22%2Cstring%20%3Fforce%3D%22Y%22%2C%22Force%20Create%22%29%3B%0A%20%20%20%20%20%0A%20%20%20%20%20string%20obj1%2Cansw%3B%0A%20%20%20%20%20bool%20flag%20%3D%20false%3B%0A%20%20%20%20%20string%20rights%20%3D%20%27RWECDMF%27%3B%0A%20%20%20%20%20int%20mode%3D1%3B%20%20%20if%20%28unique%29%20mode%3A%3D0%3B%20fi%3B%0A%20%20%20%0A%20%20%20%20%20flags%3Duppercase%28flags%29%3B%0A%20%20%20%20%20force%3Duppercase%28force%29%3B%0A%20%20%20%0A%20%20%20%20%20bool%20forceflag%20%3D%20%28force%3D%3D%22Y%22%29%3B%0A%20%20%20%20%20if%20%28flags%3C%3E%22%22%29%20%20rights%3Dflags%3B%20fi%3B%0A%20%20%20%0A%20%20%20%20%20obj1%3DFindObj%281%2Cuser%2C%22User%22%29%3B%0A%20%20%20%20%20ifexit%20%28lasterror%3C%3E0%2C%22User%20object%20not%20found%22%29%3B%0A%20%20%20%0A%20%20%20%20%20%2F%2F%20optional%20you%20can%20add%20the%20username%20to%20the%20path%0A%20%20%20%2F%2F%20%20p%3Dp%2B%27%5C%5C%27%2Bpart%28obj1%2C0%29%3B%0A%20%20%20%20%20%2F%2F%20you%20can%20do%20any%20fancy%20thing%20you%20want%20here%20for%20the%20homedirectory.%0A%20%20%20%0A%20%20%20%20%20p%3A%3DexpandUNCFilename%28P%2Cfalse%29%3B%0A%20%20%20%20%20%0A%20%20%20%20%20%2F%2F%20check%20for%20the%20path%20to%20start%20with%20%5C%5C%2C%20because%20you%20have%20to%20esc%20a%20backslash%20with%20a%20%5C%20you%20have%20to%20give%204%20%5C%20characters%21%0A%20%20%20%20%20ifexit%28%20substr%28p%2C1%2C2%29%3C%3E%27%5C%5C%5C%5C%27%2C%20%20%27Homedirectory%20can%20not%20be%20local%21%27%29%3B%0A%20%20%20%0A%20%20%20%20%20%2F%2F%20does%20the%20direcoty%20not%20exist%20and%20is%20the%20forceflag%20not%20set%3F%0A%20%20%20%20%20if%20%20%28%21directoryexists%28p%29%20%26amp%3B%20%28%21forceflag%29%20%29%0A%20%20%20%20%20%20%20%20%20%20repeat%0A%20%20%20%20%20%20%20%20%20%20%20%20write%28%27Directory%20does%20not%20exists%2C%20create%20Y%2FN%27%29%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20read%28answ%29%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20answ%3Duppercase%28answ%29%3B%0A%20%20%20%20%20%20%20%20%20%20until%20%28%28answ%3C%3E%27%27%29%20%26amp%3B%20%28answ%3D%3D%22Y%22%29%20%7C%20%28answ%3D%3D%27N%27%29%20%29%3B%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20ifexit%28answ%3D%3D%22N%22%29%3B%0A%20%20%20%20%20%20%20%20%20%20forceflag%3A%3Dtrue%3B%0A%20%20%20%20%20fi%3B%0A%20%20%20%20%20%0A%20%20%20%20%20%2F%2F%20create%20directory%20if%20it%20doesn%27t%20exist%20if%20not%20in%20test%20mode%0A%20%20%20%20%20if%20%28%21directoryexists%28p%29%20%26amp%3B%20forceflag%20%26amp%3B%20%21test%29%0A%20%20%20%20%20%20%20%20ifexit%28%21forcedirectories%28p%29%2C%27Creation%20of%20directory%20failed%27%29%3B%0A%20%20%20%20%20fi%3B%20%0A%20%20%20%0A%20%20%20%20%20%2F%2F%20set%20the%20trustee%2C%20by%20using%20the%20command%20at%20if%20not%20in%20test%20mode%0A%20%20%20%20%20if%20%28%21test%29%0A%20%20%20%20%20%20%20%20command%28format%28%22at%20%25s%20%25s%20%25s%22%2Cobj1%2Cp%2Crights%29%29%3B%20%0A%20%20%20%20%20fi%3B%0A%20%20%20%0A%20%20%20%20%20%2F%2F%20we%20do%20have%20a%20unc%20path%20but%20we%20need%20a%20volume%20object%20and%20the%20path%20on%20the%20volume%0A%20%20%20%20%20%0A%20%20%20%20%20%2F%2F%20split%20the%20path%20into%20server%2Cvolume%20and%20path%3B%0A%20%20%20%20%20%0A%20%20%20%20%20string%20server%2Cvolume%2Cpath%3B%0A%20%20%20%20%20parse%28p%2Cserver%2Cvolume%2Cpath%2Ctrue%29%3B%0A%20%20%20%0A%20%20%20%20%20%2F%2F%20look%20up%20the%20server%20%0A%20%20%20%20%20string%20serverDN%3A%3DFindObj%280%2Cserver%2C%27NCP%20Server%27%29%3B%0A%20%20%20%20%20ifexit%20%28serverdn%3D%3D%27%27%2C%20%22Sorry%2C%20can%27t%20find%20server%20object%20in%20the%20eDirectory%22%29%3B%0A%20%20%20%20%20%0A%20%20%20%20%20%0A%20%20%20%20%20writeln%28serverdn%29%3B%0A%20%20%20%20%20%0A%20%20%20%20%20%2F%2F%20now%20we%20can%20find%20lookup%20the%20volume%20object%20in%20the%20eDirectory%0A%20%20%20%20%20%2F%2F%20search%20for%20a%20volume%20object%20with%20attribute%20Host%20Server%20set%20to%20the%20serverDN%20%0A%20%20%20%20%20%2F%2F%20and%20the%20Host%20resource%20name%20%20set%20to%20the%20volume%20name%0A%20%20%20%20%20string%20volumedn%3A%3Dsearch2%28%27%5Broot%5D%27%2C%27Volume%27%2C%27Host%20Server%27%2Cserverdn%2C%27Host%20Resource%20Name%27%2Cvolume%29%3B%0A%20%20%20%20%20ifexit%28volumedn%3D%3D%27%27%2C%20%22Sorry%2C%20can%27t%20find%20volume%20object%20in%20the%20eDirectory%22%29%3B%0A%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20if%20%28test%29%0A%20%20%20%20%20%20%20%20writeln%28Format%28%27TEST%3A%20Would%20add%20homedirectory%20%25s%20to%20%25s%27%2Cp%2Cobj1%29%29%3B%0A%20%20%20%20%20else%0A%20%20%20%20%20%20%20%20savepathvalue%28obj1%2C%27Home%20Directory%27%2Cvolumedn%2Cpath%2C0%2Cfalse%29%3B%0A%20%20%20%20%20%20%20%20writeln%28Format%28%27Homedirectory%20%25s%20added%20to%20%25s%27%2Cp%2Cobj1%29%29%3B%0A%20%20%20%20%20fi%3B%0A%20%20%20endcmd%3B%0A%20%20%20 Copy trustee and Inheritance Mask in HBWL.
on hbwlver "1.03.00" do [ -echo "Minimal HBWL version 1.03.00 needed" -stop ]
cmd ct(String Source,"Source",String Dest,"Destination");
proc walk(String s1, String s2);
List dirs = getfiles(s1,true);
item it,trust;
List trustees;
int irm;
each (dirs,it)
write('.');
//writeln(s1,'\\',it.s);
trustees=listtrustee(s1+'\\'+it.s);
if (lasterror==0)
each(trustees,trust)
// writeln(' Trust=',trust.s,' ',trust.i);
addtrustee(s2+'\\'+it.s,trust.s,trust.i);
if (lasterror<>0)
writeln('Add err: ',s2,'\\',it.s,' ',lasterror);
endif;
next;
endif;
irm:=getfileinheritmask(s1+'\\'+it.s) and 0x1FF;
if (lasterror==0)
if (irm<>511)
// writeln('Mask: ',irm,' ',lasterror);
setfileinheritmask(s2+'\\'+it.s,irm);
if (lasterror<>0)
cwriteln(clred,"Err set IRM: ",s2,'\\',it.s,' ',lasterror);
endif;
endif;
else cwriteln(clred,"Err get IRM: ",s1,'\\',it.s,' ',lasterror);
endif;
walk(s1+'\\'+it.s,s2+'\\'+it.s);
next;
endproc;
walk(source,dest);
endcmd;%0Aon%20hbwlver%20%221.03.00%22%20do%20%5B%20-echo%20%22Minimal%20HBWL%20version%201.03.00%20needed%22%20-stop%20%5D%0A%0Acmd%20ct%28String%20Source%2C%22Source%22%2CString%20Dest%2C%22Destination%22%29%3B%0A%0Aproc%20walk%28String%20s1%2C%20String%20s2%29%3B%0A%0AList%20dirs%20%3D%20getfiles%28s1%2Ctrue%29%3B%0Aitem%20it%2Ctrust%3B%0AList%20trustees%3B%0Aint%20irm%3B%0A%0Aeach%20%28dirs%2Cit%29%0A%20%20write%28%27.%27%29%3B%0A%2F%2Fwriteln%28s1%2C%27%5C%5C%27%2Cit.s%29%3B%0A%20%20%20trustees%3Dlisttrustee%28s1%2B%27%5C%5C%27%2Bit.s%29%3B%0A%20%20%20if%20%28lasterror%3D%3D0%29%0A%20%20%20%20%20%20%20each%28trustees%2Ctrust%29%0A%2F%2F%20%20%20%20%20%20%20%20writeln%28%27%20%20Trust%3D%27%2Ctrust.s%2C%27%20%20%27%2Ctrust.i%29%3B%0A%20%20%20%20%20%20%20%20addtrustee%28s2%2B%27%5C%5C%27%2Bit.s%2Ctrust.s%2Ctrust.i%29%3B%0A%20%20%20%20%20%20%20%20if%20%28lasterror%3C%3E0%29%20%0A%20%20%20%20%20%20%20%20%20%20%20writeln%28%27Add%20err%3A%20%27%2Cs2%2C%27%5C%5C%27%2Cit.s%2C%27%20%27%2Clasterror%29%3B%0A%20%20%20%20%20%20%20%20endif%3B%0A%20%20%20%20%20%20next%3B%0A%20%20%20endif%3B%0A%20%20%20%0A%20%20%20irm%3A%3Dgetfileinheritmask%28s1%2B%27%5C%5C%27%2Bit.s%29%20and%200x1FF%3B%0A%20%20%20if%20%28lasterror%3D%3D0%29%20%0A%20%20%20%20%20%20if%20%28irm%3C%3E511%29%0A%2F%2F%20%20%20%20%20%20%20%20%20writeln%28%27Mask%3A%20%27%2Cirm%2C%27%20%20%27%2Clasterror%29%3B%0A%20%20%20%20%20%20%20%20%20setfileinheritmask%28s2%2B%27%5C%5C%27%2Bit.s%2Cirm%29%3B%0A%20%20%20%20%20%20%20%20%20if%20%28lasterror%3C%3E0%29%0A%20%20%20%20%20%20%20%20%20%20%20%20cwriteln%28clred%2C%22Err%20set%20IRM%3A%20%22%2Cs2%2C%27%5C%5C%27%2Cit.s%2C%27%20%27%2Clasterror%29%3B%0A%20%20%20%20%20%20%20%20%20endif%3B%20%20%20%0A%20%20%20%20%20%20endif%3B%0A%20%20%20else%20cwriteln%28clred%2C%22Err%20get%20IRM%3A%20%22%2Cs1%2C%27%5C%5C%27%2Cit.s%2C%27%20%27%2Clasterror%29%3B%0A%20%20%20endif%3B%0A%20%20%20%0A%20%20%20walk%28s1%2B%27%5C%5C%27%2Bit.s%2Cs2%2B%27%5C%5C%27%2Bit.s%29%3B%0A%20%20%0Anext%3B%0Aendproc%3B%0A%0Awalk%28source%2Cdest%29%3B%0A%0Aendcmd%3B%0A |