[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Help (Was: [Cdd-commits] cdd/common/cdd/share/cdd/unixgroups cdd-actions,1.11,1.12)



On Fri, 18 Jun 2004, Andreas Tille wrote:

> Modified Files:
> 	cdd-actions
> Log Message:
> Try to implement functionality of get-group-users - but failed for the moment.
Because get-group-users is one of the last remainings of my badly designed first
try in med-common I wanted to replace this.  The sense was to provide lists of
users for the usage in a debconf question.  As a result we need the following:

  1) List of all users (in the used role system - whatever it is) including
     real name.
  2) List of all users in the role #CDD#/role

Both lists have to have to following form:

  login1 (Real Name1), login2 (Real Name2), login 3 ...

The lists should be in alphabethical order (I sorted according to login names
but that's cosmetic).  In get-group-users I used temporary files for sorting
but I think this sucks.  What we need IMHO is the following

  1. Helper function which provides a (not necessarily sorted) list of
     all users / all users in role for each role system (currently only
     unixgroups)
  2. Common function which parses this list and brings this into the right
     form (sorting, komma separated, etc.)

I would like to hear your opinons because I'm a little bit unsure which is the
right way for implementation.  The diff below was my first attempt which was
only implemented in unixgroups as a single function but I had my doubt if it is
flexible enough regarding sorting and formating which has to be done for all
other (future) role systems as well.  Moreover sorting is not yet implented
(because I do not see an elegant way) and I wonder if there is an elegant method
to find out the real names of registered CDD users.

This is my "riddle of the weekend" for you. ;-)

Kind regards

          Andreas.

>
> Index: cdd-actions
> ===================================================================
> RCS file: /cvsroot/cdd/cdd/common/cdd/share/cdd/unixgroups/cdd-actions,v
> retrieving revision 1.11
> retrieving revision 1.12
> diff -u -d -r1.11 -r1.12
> --- cdd-actions	14 Jun 2004 20:57:47 -0000	1.11
> +++ cdd-actions	18 Jun 2004 12:43:55 -0000	1.12
> @@ -8,6 +8,11 @@
>
>  #checkCDD() is backend indep, and is defined in ${SHAREDIR}/cdd-action
>
> +# Read adduser config to find out from which ID normal users start
> +# Default = 1000
> +FIRST_UID=1000
> +[ -s /etc/adduser.conf ] && . /etc/adduser.conf
> +
>  # checks if User $1 exists as a system user
>  checkUser() {
>  	RET=0
> @@ -82,7 +87,6 @@
>  	return ${RET}
>  }
>
> -
>  # echoes list of users having role $2 in CDD $1
>  # if $3 exists use ',' as separator between user names
>  getUsersInRole() {
> @@ -102,6 +106,41 @@
>  	fi
>  	return ${RET}
>  }
> +
> +# echoes list of all users of the system
> +# $1 = 1 - simply login names, $1 = 0 (or anything else) - login names and real name
> +# if $1 exists use ',' as separator between user names
> +getAllUsers() {
> +	RET=0
> +	if [ "$#" -ne 1 -a "$#" -ne 2 ]; then
> +		RET=64 # EX_USAGE
> +	else
> +		SIMPLE=$1
> +		KOMMA=" "
> +		# Append ',' if second argument is given
> +		if [ "$#" -eq 2 ]; then
> +			KOMMA=", "
> +		fi
> +		USERS=""
> +		(IFS=":"
> +			while read user pass uid gid name rest ; do
> +				if [ $uid -ge $FIRST_UID -a "$user" != "nobody" ] ; then
> +        				name=`echo $name | sed "s/,.*//"`
> +					if [ "$USERS" != "" ] ; then
> +						USERS="$USERS$KOMMA"
> +					fi
> +				        if [ $SIMPLE -eq 1 ] ; then
> +				                USERS="$USERS$user"
> +				        else
> +				                USERS="$USERS$user ($name)"
> +					fi
> +				fi
> +			done < /etc/passwd
> +			echo $USERS
> +		)
> +	fi
> +	return ${RET}
> +}
>  # echo all Role covered by user $2 in CDD $1
>  getUserRoles() {
>  	RET=0
> @@ -156,7 +195,7 @@
>  	if [ "$#" -ne 2 ]; then
>  		RET=64 # EX_USAGE
>  	else
> -		${DRYRUN} addgroup --system "${ROLE}"
> +		${DRYRUN} addgroup --system "${ROLE}" || true
>  		RET=$?
>  	fi
>  	return ${RET}
>
>
> _______________________________________________
> Cdd-commits mailing list
> Cdd-commits@lists.alioth.debian.org
> http://lists.alioth.debian.org/mailman/listinfo/cdd-commits
>



Reply to: