Page 1 of 1 1
Topic Options
#128479 - 2004-10-27 06:34 PM MemberOf() - A better InGroup function
ebiard Offline
Fresh Scripter

Registered: 2003-03-13
Posts: 14
; Function : MemberOf()
;
; Author : Emmanuel Biard
; Contributor : Howard A. Bullock for some part of his TranslateName() function
;
; Action : MembreDe function tests if a user is member of a group (directly or not)
;
; Syntax : MemberOf(Group[, User])
;
; Version : 1.0
; Date : 27 december 2004
; Date revised : -
;
; Parameters :
; - Group, name of the group
; - User, name of the user (@USERID if not specified)
;
; Remarks : This function was created because the built-in InGroup kix function is not reliable at all, neither for direct membership tests nor for indirect ones.
;
; Returns :
; 0 if the user is not member of the group
; 1 if the user is member of the group
;
; Dependencies : LDAP directory
; KiXtart version : 4.20
;
; Example : if MemberOf("ThisGroup", "ThisUser")
;
Function NomComplet($NomCourt)
$NomComplet = ""
$oNomComplet = CreateObject("NameTranslate")
If Not(@ERROR)
$oNomComplet.Init(3, "")
If Not(@ERROR)
$oNomComplet.Set (3,$NomCourt)
If Not(@ERROR)
$NomComplet = $oNomComplet.Get(1)
EndIf
EndIf
EndIf
EndFunction

Function RecursifMembreDe($Groupe, $User)
$LDAPGroupe = NomComplet("@DOMAIN\"+$Groupe)
$oGroupe = GetObject("LDAP://" + $LDAPGroupe)
If Not(@ERROR)
For Each $Objet In $oGroupe.Members
Select
Case $Objet.Class = "group"
$Result = RecursifMembreDe($Objet.cn, $User)
If ($Result = 1)
$RecursifMembreDe = 1
Return
EndIf
Case $Objet.Class = "user"
If ($Objet.samAccountName == @USERID)
$RecursifMembreDe = 1
Return
EndIf
EndSelect
Next
EndIf
$RecursifMembreDe = 0
EndFunction

Function MemberOf($Groupe, OPTIONAL $User)
If ($User = "")
$User = @USERID
EndIf
$MemberOf = RecursifMembreDe($Groupe, $User)
EndFunction


Edited by ebiard (2004-10-27 06:53 PM)

Top
#128480 - 2004-10-27 06:48 PM Re: MembreDe() - Un meilleur / A better InGroup
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sorry boss....
but, your udf is not really an udf but library which uses UDFs.

could you strip it down to UDF.
and once done, at the proper header like said in the UDF library rules.

thanks.
_________________________
!

download KiXnet

Top
#128481 - 2004-10-27 07:00 PM Re:
ebiard Offline
Fresh Scripter

Registered: 2003-03-13
Posts: 14
I'm sorry not to understand what you mean buy "this is not an UDF", that i have to "strip it down to UDF" (I'm french !). Please explain me with more details.
And for the header, the link to use the correct header does not work. I've rebuilt the header to be more close of what is recommended.

Top
#128482 - 2004-10-27 07:31 PM Re:
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
what link?
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=82788&page=0&view=collapsed&sb=5&o=&fpart=1

is the first post seen on UDF library.
nothing not working in that.

what comes to trim to UDF means, you have multiple udfs in your udf sourcecode.
that's not udf anymore, that makes it library.
one udf is one udf.
loose the others from there.
if they are needed and not found in udf library, post them separately and mark them as dependencies.
_________________________
!

download KiXnet

Top
#128483 - 2004-10-27 09:01 PM Re:
Cybex Offline
Getting the hang of it
*****

Registered: 2004-07-21
Posts: 81
Loc: Brandon, FL.
ebiard, I think what he was trying to say about the header is that you need to "Make sure to post the
entire UDf within code-tags or post with PostPrep."

and also follow the standard format for the examples and the code. Which you seem to have gone back and done.
_________________________
Common sense isn't so common.

Top
#128484 - 2004-10-27 09:25 PM Re:
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
not really.
basically, the standard defines the header.

but it does not remove the fact that you have 3 UDFs in this post.
only 1 is allowed. thus the name UDF! not multiple but one.
_________________________
!

download KiXnet

Top
#128485 - 2004-10-28 04:03 AM Re:
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Also, I'm sure you didn' write it on this date
Quote:


; Date : 27 december 2004




_________________________
There are two types of vessels, submarines and targets.

Top
#128486 - 2004-10-28 04:14 AM Re:
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I propose this thread be moved to scripts. It can then be further discussed and if the original author has a desire to meat the UDF posting guidlines, can be reposted here as separate UDFs.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#128487 - 2004-10-28 08:16 AM Re: MemberOf() - A better InGroup function
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Hello ebiard

I have moved this post to the SCRIPTS forum where it is more appropriate.

In essence, a UDF is a single User Defined Function that performs some task. Your post has 3 UDFs in it, which would make it more like a LIBRARY of functions.

What you could do if you wanted to would be to post all 3 of them as individual UDFs and list each of them as a dependancy for each other. However that may be too much work and thus is better to just have it here in the SCRIPTS forum where this type of post normally would belong.

I take it that you're wanting to do more then just TRUE/FALSE on membership in a group by saying that InGroup does not work. I have not found that to be the case. I use InGroup quite a bit and including Universal groups, and so far it has been working for me. How far the nesting goes for InGroup I'm not sure, but deep nesting is also frowned upon by Microsoft and most Admins even if AD does support it.

I see that you say dependancy is KiXtart v4.20 I don't know for sure, but perhaps your issues or complaint about InGroup is from the version level. Have you tried v4.22 to determine if that is able to correct the issue?

Top
#128488 - 2004-10-28 12:24 PM Re: MemberOf() - A better InGroup function
ebiard Offline
Fresh Scripter

Registered: 2003-03-13
Posts: 14
Ok i've understood the problem that a UDF must be one function.
For the link that does not work, it is the link for postprep zip that brings to a 404 censored page, but maybe i don't need it.
NTDOC, I can assure u the InGroup function is not reliable, and 4.20 is not a dependancy but the kix32 version used. 4.22 does not change anything on this point.
I modified the code to obtain a unique function.
Do what you want of it.
Bye.
Code:

Function MemberOf($Groupe, OPTIONAL $User)
;
; IF THE USER IS NOT SPECIFIED, CURRENT USER IS USED
If ($User = "")
$User = @USERID
EndIf
;
; RETRIEVES THE FULL QUALIFIED NAME OF THE GROUP
$LDAPGroupe = ""
$oLDAPGroupe = CreateObject("NameTranslate")
If Not(@ERROR)
$oLDAPGroupe.Init(3, "")
If Not(@ERROR)
$oLDAPGroupe.Set(3,"@DOMAIN\"+$Groupe)
If Not(@ERROR)
$LDAPGroupe = $oLDAPGroupe.Get(1)
EndIf
EndIf
EndIf
;
; CONNECTION TO THE GROUP
$oGroupe = GetObject("LDAP://" + $LDAPGroupe)
;
; BROWSE GROUP MEMBERS
If Not(@ERROR)
For Each $Objet In $oGroupe.Members
Select
;
; IF THE MEMBER IS A GROUP, RECURSIVELY GOES ON
Case $Objet.Class = "group"
$Result = MemberOf($Objet.cn, $User)
If ($Result = 1)
$MemberOf= 1
Return
EndIf
; IF THE MEMBER IS A USER, IS IT THE ONE ?
Case $Objet.Class = "user"
If ($Objet.samAccountName == @USERID)
$MemberOf= 1
Return
EndIf
EndSelect
Next
EndIf
$MemberOf = 0
EndFunction



Edited by ebiard (2004-10-28 01:26 PM)

Top
#128489 - 2004-10-28 03:00 PM Re: MemberOf() - A better InGroup function
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
alrighty, now as that not working part is back in the discussion, I would also like to know where kixtart fails with ingroup.
what type of environment how it's ran and what type of failure in specific.
met by everyone or just somebody?
problem happens for new or for old groups too?

I would wait yet still some time before saying that kixtart ingroup would not always work...

although, have seen some problems with it, specifically, iirc, we had a name resolution problem back then.
_________________________
!

download KiXnet

Top
#193607 - 2009-04-27 04:17 PM Re: MemberOf() - A better InGroup function [Re: Lonkero]
bekickst Offline
Fresh Scripter

Registered: 2009-02-17
Posts: 6
Loc: Berlin Germany
I had the same problem Lonkero. When I tested the skript on my own computer, the group membership was corrected when I logged on again and ran the skript (including /f). It didn`t work on some other Computers though. In the end I used the function memberof, that I found here. Now its working perfectly.

It`s not a bug. Itīs a feature.


Edited by bekickst (2009-04-27 04:20 PM)

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 381 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.065 seconds in which 0.026 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org