Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1298607
  • 博文数量: 287
  • 博客积分: 11000
  • 博客等级: 上将
  • 技术积分: 3833
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-16 08:43
文章分类
文章存档

2013年(15)

2012年(17)

2011年(17)

2010年(135)

2009年(85)

2008年(18)

分类: 系统运维

2010-06-11 10:04:16

QSYRUSRI - Retrieve User Information
 
Q: Is there an API for determining if a user profile is a member of a group?

A: There isn't anything THIS simple, but you could certainly write a
service program, and IT could be this simple to use. :)

In fact, here's one that I wrote, along with an example of using it:

Example of calling GROUP service program:
     D/COPY QRPGLESRC,GROUP_H
     D Msg             S             50A

     c     *entry        plist
     c                   parm                    UserID           10
     c                   parm                    Group            10

     c                   if        IsInGroup(UserID: Group) = 1
     c                   eval      Msg = 'User is in that group!'
     C                   else
     c                   eval      Msg = 'User is not in that group!'
     c                   endif

     c                   dsply                   Msg

     c                   eval      *inlr = *on

Start of header file for GROUP service program (GROUP_H):
     D IsInGroup       PR            10I 0
     D   UsrPrf                      10A   const
     D   GrpPrf                      10A   const
    
Start of source for GROUP service program:
     D/COPY QRPGLESRC,GROUP_H
     P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P*  IsInGroup( UserProfile : GroupProfile)
     P*       Checks if a user is in a given group profile.
     P*
     P*  Returns:  -1 = Error, 0 = Not In Group, 1 = Is In Group
     P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P IsInGroup       B                   export
     D IsInGroup       PI            10I 0
     D   UsrPrf                      10A   const
     D   GrpPrf                      10A   const

     D RtvUsrPrf       PR                  ExtPgm('QSYRUSRI')
     D   RcvVar                   32766A   OPTIONS(*VARSIZE)
     D   RcvVarLen                   10I 0 const
     D   Format                       8A   const
     D   UsrPrf                      10A   const
     D   Error                    32766A   OPTIONS(*VARSIZE)

     D dsEC            DS
     D*                                    Bytes Provided (size of struct)
     D  dsECBytesP             1      4B 0 INZ(256)
     D*                                    Bytes Available (returned by API)
     D  dsECBytesA             5      8B 0 INZ(0)
     D*                                    Msg ID of Error Msg Returned
     D  dsECMsgID              9     15
     D*                                    Reserved
     D  dsECReserv            16     16
     D*                                    Msg Data of Error Msg Returned
     D  dsECMsgDta            17    256

     D dsRU            DS
     D*                                    Bytes Returned
     D   dsRUBytRtn                  10I 0
     D*                                    Bytes Available
     D   dsRUBytAvl                  10I 0
     D*                                    User Profile Name
     D   dsRUUsrPrf                  10A
     D*                                    User Class
     D   dsRUClass                   10A
     D*                                    Special Authorities
     D   dsRUSpcAut                  15A
     D*                                    Group Profile Name
     D   dsRUGrpPrf                  10A
     D*                                    Owner
     D   dsRUOwner                   10A
     D*                                    Group Authority
     D   dsRUGrpAut                  10A
     D*                                    Limit Capabilities
     D   dsRULmtCap                  10A
     D*                                    Group Authority Type
     D   dsRUAutTyp                  10A
     D*                                    (reserved)
     D   dsRUResrv1                   3A
     D*                                    Offset to Supplemental Groups
     D   dsRUoffSG                   10I 0
     D*                                    Number of Supplemental Groups
     D   dsRUnumSG                   10I 0
     D*                                    Supplemental Groups
     D   dsRUSupGrp                  10A   DIM(15)

     D X               S              5I 0

     C* Get User Profile
     c                   callp     RtvUsrPrf( dsRU: %Size(dsRU): 'USRI0200':
     c                                           UsrPrf: dsEC)

     C* Check for errors
     c                   if        dsECBytesA > 0
     c                   return    -1
     c                   endif
     c                   if        dsRUnumSG<0 or dsRUnumSG>15
     c                   return    -1
     c                   endif

     C* In primary group?
     c                   if        dsRUGrpPrf = GrpPrf
     c                   return    1
     c                   endif

     C* In supplemental group?
     c                   do        dsRUnumSG     X
     c                   if        dsRUSupGrp(X) = GrpPrf
     c                   return    1
     c                   endif
     c                   enddo

     C* Not in group.
     c                   return    0
     P                 E


Thanks to Scott Klement
阅读(1048) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~