Back to index

openldap  2.4.31
Defines | Functions | Variables
group.c File Reference
#include "nssov.h"
#include <grp.h>

Go to the source code of this file.

Defines

#define CN_KEY   0
#define PWD_KEY   1
#define GID_KEY   2
#define UID_KEY   3
#define MEM_KEY   4

Functions

 NSSOV_CBPRIV (group, nssov_info *ni;char buf[256];struct berval name;struct berval gidnum;struct berval user;int wantmembers;)
static int mkfilter_group_bymember (nssov_group_cbp *cbp, struct berval *buf)
static int isvalidgroupname (struct berval *name)
static int write_group (nssov_group_cbp *cbp, Entry *entry)
 NSSOV_HANDLE (NSSOV_HANDLE(group, byname)
 READ_TYPE (fp, gid, gid_t)
 Debug (LDAP_DEBUG_TRACE,"nssov_group_bygid(%s)\n", cbp.gidnum.bv_val, 0, 0)
 nssov_filter_byid (cbp.mi, GID_KEY,&cbp.gidnum,&filter)) NSSOV_HANDLE(group
 READ_STRING (fp, cbp.buf)
 if (!isvalidusername(&cbp.user))
 Debug (LDAP_DEBUG_TRACE,"nssov_group_bymember(%s)\n", cbp.user.bv_val, 0, 0)

Variables

static struct berval = BER_BVC("(objectClass=posixGroup)")
filter bv_val = fbuf
cbp gidnum bv_len = snprintf(cbp.buf,sizeof(cbp.buf),"%d",gid)
cbp wantmembers = 1
cbp ni = ni
BER_BVZEROcbp
 NSLCD_ACTION_GROUP_BYGID
 bymember
char fbuf [1024]
 NSLCD_ACTION_GROUP_BYMEMBER

Define Documentation

#define CN_KEY   0

Definition at line 54 of file group.c.

#define GID_KEY   2

Definition at line 56 of file group.c.

#define MEM_KEY   4

Definition at line 58 of file group.c.

#define PWD_KEY   1

Definition at line 55 of file group.c.

#define UID_KEY   3

Definition at line 57 of file group.c.


Function Documentation

Debug ( LDAP_DEBUG_TRACE  ,
"nssov_group_bygid(%s)\n ,
cbp.gidnum.  bv_val,
,
 
)
Debug ( LDAP_DEBUG_TRACE  ,
"nssov_group_bymember(%s)\n ,
cbp.user.  bv_val,
,
 
)
if ( !isvalidusername &.  user)

Definition at line 322 of file group.c.

                                        {
              Debug(LDAP_DEBUG_ANY,"nssov_group_bymember(%s): invalid user name\n",cbp.user.bv_val,0,0);
              return -1;
       }
static int isvalidgroupname ( struct berval name) [static]

Definition at line 111 of file group.c.

{
       int i;

       if ( !name->bv_val || !name->bv_len )
              return 0;
       /* check first character */
       if ( ! ( (name->bv_val[0]>='A' && name->bv_val[0] <= 'Z') ||
                                    (name->bv_val[0]>='a' && name->bv_val[0] <= 'z') ||
                                    (name->bv_val[0]>='0' && name->bv_val[0] <= '9') ||
                                    name->bv_val[0]=='.' || name->bv_val[0]=='_' ) )
              return 0;
       /* check other characters */
       for (i=1;i<name->bv_len;i++)
       {
#ifndef STRICT_GROUPS
              /* allow spaces too */
              if (name->bv_val[i] == ' ') continue;
#endif
              if ( ! ( (name->bv_val[i]>='A' && name->bv_val[i] <= 'Z') ||
                                           (name->bv_val[i]>='a' && name->bv_val[i] <= 'z') ||
                                           (name->bv_val[i]>='0' && name->bv_val[i] <= '9') ||
                                           name->bv_val[i]=='.' || name->bv_val[i]=='_' || name->bv_val[i]=='-') )
                     return 0;
       }
       /* no test failed so it must be good */
       return -1;
}

Here is the caller graph for this function:

static int mkfilter_group_bymember ( nssov_group_cbp *  cbp,
struct berval buf 
) [static]

Definition at line 73 of file group.c.

{
       struct berval dn;
       /* try to translate uid to DN */
       nssov_uid2dn(cbp->op,cbp->ni,&cbp->user,&dn);
       if (BER_BVISNULL(&dn)) {
              if (cbp->user.bv_len + cbp->mi->mi_filter.bv_len + cbp->mi->mi_attrs[UID_KEY].an_desc->ad_cname.bv_len + 6 >
                     buf->bv_len )
                     return -1;
              buf->bv_len = snprintf(buf->bv_val, buf->bv_len, "(&%s(%s=%s))",
                     cbp->mi->mi_filter.bv_val, cbp->mi->mi_attrs[UID_KEY].an_desc->ad_cname.bv_val,
                     cbp->user.bv_val );
       } else { /* also lookup using user DN */
              if (cbp->user.bv_len + cbp->mi->mi_filter.bv_len + cbp->mi->mi_attrs[UID_KEY].an_desc->ad_cname.bv_len +
                     dn.bv_len + cbp->mi->mi_attrs[MEM_KEY].an_desc->ad_cname.bv_len + 12 > buf->bv_len )
                     return -1;
              buf->bv_len = snprintf(buf->bv_val, buf->bv_len, "(&%s(|(%s=%s)(%s=%s)))",
                     cbp->mi->mi_filter.bv_val,
                     cbp->mi->mi_attrs[UID_KEY].an_desc->ad_cname.bv_val, cbp->user.bv_val,
                     cbp->mi->mi_attrs[MEM_KEY].an_desc->ad_cname.bv_val, dn.bv_val );
       }
       return 0;
}

Here is the call graph for this function:

NSSOV_CBPRIV ( group  ,
nssov_info *ni;char buf;struct berval name;struct berval gidnum;struct berval user;int wantmembers [256] 
)
nssov_filter_byid ( cbp.  mi,
GID_KEY  ,
&cbp.  gidnum,
filter 
)
NSSOV_HANDLE ( NSSOV_HANDLE group,
byname   
)

Definition at line 275 of file group.c.

                              {sizeof(fbuf)};
       filter.bv_val = fbuf;
       READ_STRING(fp,cbp.buf);
       cbp.name.bv_len = tmpint32;
       cbp.name.bv_val = cbp.buf;
       if (!isvalidgroupname(&cbp.name)) {
              Debug(LDAP_DEBUG_ANY,"nssov_group_byname(%s): invalid group name\n",cbp.name.bv_val,0,0);
              return -1;
       }
       cbp.wantmembers = 1;
       cbp.ni = ni;
       BER_BVZERO(&cbp.gidnum);
       BER_BVZERO(&cbp.user);,
       Debug(LDAP_DEBUG_TRACE,"nslcd_group_byname(%s)\n",cbp.name.bv_val,0,0);,
       NSLCD_ACTION_GROUP_BYNAME,
       nssov_filter_byname(cbp.mi,CN_KEY,&cbp.name,&filter)
)

NSSOV_HANDLE(
       group,bygid,
       gid_t gid;
       char fbuf[1024];
       struct berval filter = {sizeof(fbuf)};

Here is the call graph for this function:

READ_STRING ( fp  ,
cbp.  buf 
)
READ_TYPE ( fp  ,
gid  ,
gid_t   
)
static int write_group ( nssov_group_cbp *  cbp,
Entry entry 
) [static]

Definition at line 140 of file group.c.

{
       struct berval tmparr[2], tmpgid[2];
       struct berval *names,*gids,*members;
       struct berval passwd = {0};
       Attribute *a;
       int i,j,nummembers,rc;

       /* get group name (cn) */
       if (BER_BVISNULL(&cbp->name))
       {
              a = attr_find(entry->e_attrs, cbp->mi->mi_attrs[CN_KEY].an_desc);
              if ( !a )
              {
                     Debug(LDAP_DEBUG_ANY,"group entry %s does not contain %s value\n",
                                   entry->e_name.bv_val, cbp->mi->mi_attrs[CN_KEY].an_desc->ad_cname.bv_val,0);
                     return 0;
              }
              names = a->a_vals;
       }
       else
       {
              names=tmparr;
              names[0]=cbp->name;
              BER_BVZERO(&names[1]);
       }
       /* get the group id(s) */
       if (BER_BVISNULL(&cbp->gidnum))
       {
              a = attr_find(entry->e_attrs, cbp->mi->mi_attrs[GID_KEY].an_desc);
              if ( !a )
              {
                     Debug(LDAP_DEBUG_ANY,"group entry %s does not contain %s value\n",
                                   entry->e_name.bv_val, cbp->mi->mi_attrs[GID_KEY].an_desc->ad_cname.bv_val,0);
                     return 0;
              }
              gids = a->a_vals;
       }
       else
       {
              gids=tmpgid;
              gids[0]=cbp->gidnum;
              BER_BVZERO(&gids[1]);
       }
       /* get group passwd (userPassword) (use only first entry) */
       a = attr_find(entry->e_attrs, cbp->mi->mi_attrs[PWD_KEY].an_desc);
       if (a)
              get_userpassword(&a->a_vals[0], &passwd);
       if (BER_BVISNULL(&passwd))
              passwd=default_group_userPassword;
       /* get group members (memberUid&uniqueMember) */
       if (cbp->wantmembers) {
              Attribute *b;
              i = 0; j = 0;
              a = attr_find(entry->e_attrs, cbp->mi->mi_attrs[UID_KEY].an_desc);
              b = attr_find(entry->e_attrs, cbp->mi->mi_attrs[MEM_KEY].an_desc);
              if ( a )
                     i += a->a_numvals;
              if ( b )
                     i += b->a_numvals;
              if ( i ) {
                     members = cbp->op->o_tmpalloc( (i+1) * sizeof(struct berval), cbp->op->o_tmpmemctx );
                     
                     if ( a ) {
                            for (i=0; i<a->a_numvals; i++) {
                                   if (isvalidusername(&a->a_vals[i])) {
                                          ber_dupbv_x(&members[j],&a->a_vals[i],cbp->op->o_tmpmemctx);
                                          j++;
                                   }
                            }
                     }
                     a = b;
                     if ( a ) {
                            for (i=0; i<a->a_numvals; i++) {
                                   if (nssov_dn2uid(cbp->op,cbp->ni,&a->a_nvals[i],&members[j]))
                                          j++;
                            }
                     }
                     nummembers = j;
                     BER_BVZERO(&members[j]);
              } else {
                     members=NULL;
                     nummembers = 0;
              }

       } else {
              members=NULL;
              nummembers = 0;
       }
       /* write entries for all names and gids */
       for (i=0;!BER_BVISNULL(&names[i]);i++)
       {
              if (!isvalidgroupname(&names[i]))
              {
                     Debug(LDAP_DEBUG_ANY,"nssov: group entry %s contains invalid group name: \"%s\"\n",
                                                                                           entry->e_name.bv_val,names[i].bv_val,0);
              }
              else
              {
                     for (j=0;!BER_BVISNULL(&gids[j]);j++)
                     {
                            char *tmp;
                            int tmpint32;
                            gid_t gid;
                            gid = strtol(gids[j].bv_val, &tmp, 0);
                            if ( *tmp ) {
                                   Debug(LDAP_DEBUG_ANY,"nssov: group entry %s contains non-numeric %s value: \"%s\"\n",
                                          entry->e_name.bv_val, cbp->mi->mi_attrs[GID_KEY].an_desc->ad_cname.bv_val,
                                          names[i].bv_val);
                                   continue;
                            }
                            WRITE_INT32(cbp->fp,NSLCD_RESULT_BEGIN);
                            WRITE_BERVAL(cbp->fp,&names[i]);
                            WRITE_BERVAL(cbp->fp,&passwd);
                            WRITE_TYPE(cbp->fp,gid,gid_t);
                            /* write a list of values */
                            WRITE_INT32(cbp->fp,nummembers);
                            if (nummembers)
                            {
                                   int k;
                                   for (k=0;k<nummembers;k++) {
                                          WRITE_BERVAL(cbp->fp,&members[k]);
                                   }
                            }
                     }
              }
       }
       /* free and return */
       if (members!=NULL)
              ber_bvarray_free_x( members, cbp->op->o_tmpmemctx );
       return rc;
}

Here is the call graph for this function:


Variable Documentation

static struct berval = BER_BVC("(objectClass=posixGroup)") [static]

Definition at line 42 of file group.c.

cbp user bv_len = snprintf(cbp.buf,sizeof(cbp.buf),"%d",gid)

Definition at line 304 of file group.c.

Definition at line 301 of file group.c.

Definition at line 315 of file group.c.

Definition at line 307 of file group.c.

char fbuf[1024]

Definition at line 315 of file group.c.

cbp ni = ni

Definition at line 306 of file group.c.

Definition at line 309 of file group.c.

Definition at line 330 of file group.c.

Definition at line 305 of file group.c.