All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stewart Smith <stewart@linux.vnet.ibm.com>
To: OpenBMC Patches <openbmc-patches@stwcx.xyz>, openbmc@lists.ozlabs.org
Subject: Re: [PATCH phosphor-networkd] Validating user & group names prior to system call and wait() on proc spawned with pexpect.
Date: Fri, 12 Feb 2016 09:18:58 +1100	[thread overview]
Message-ID: <87egcioppp.fsf@linux.vnet.ibm.com> (raw)
In-Reply-To: <1455224447-11108-2-git-send-email-openbmc-patches@stwcx.xyz>

OpenBMC Patches <openbmc-patches@stwcx.xyz> writes:
> From: Hariharasubramanian R <hramasub@in.ibm.com>
>
> ---
>  userman.py | 106 ++++++++++++++++++++++++++++++++++++++++++++-----------------
>  1 file changed, 76 insertions(+), 30 deletions(-)
>
> diff --git a/userman.py b/userman.py
> index 6109582..033d3d1 100755
> --- a/userman.py
> +++ b/userman.py
> @@ -25,7 +25,8 @@ OBJ_NAME_USER = '/org/openbmc/UserManager/User'
>      Object Path > /org/openbmc/UserManager/Groups
>          Interface:Method > org.openbmc.Enrol.GroupAddSys string:"groupname"
>          Interface:Method > org.openbmc.Enrol.GroupAddUsr string:"groupname"
> -        Interface:Method > org.openbmc.Enrol.GroupList
> +        Interface:Method > org.openbmc.Enrol.GroupListUsr
> +        Interface:Method > org.openbmc.Enrol.GroupListSys
>      Object Path > /org/openbmc/UserManager/Group
>          Interface:Method > org.openbmc.Enrol.GroupDel string:"groupname"
>      Object Path > /org/openbmc/UserManager/Users
> @@ -60,16 +61,26 @@ class UserManGroups (dbus.service.Object):
>  
>      @dbus.service.method(INTF_NAME, "s", "x")
>      def GroupAddUsr (self, groupname):
> +        if not groupname : return 1
> +
> +        groups = self.GroupListAll ()
> +        if groupname in groups: return 1
> +
>          r = call (["addgroup", groupname])
>          return r
>  
>      @dbus.service.method(INTF_NAME, "s", "x")
>      def GroupAddSys (self, groupname):
> +        if not groupname : return 1
> +
> +        groups = self.GroupListAll ()
> +        if groupname in groups: return 1
> +
>          r = call (["addgroup", "-S", groupname])
>          return 0
>  
>      @dbus.service.method(INTF_NAME, "", "as")
> -    def GroupList (self):
> +    def GroupListUsr (self):
>          groupList = []
>          with open("/etc/group", "r") as f:
>              for grent in f:
> @@ -78,6 +89,23 @@ class UserManGroups (dbus.service.Object):
>                      groupList.append(groupParams[0])
>          return groupList
>  
> +    @dbus.service.method(INTF_NAME, "", "as")
> +    def GroupListSys (self):
> +        groupList = []
> +        with open("/etc/group", "r") as f:
> +            for grent in f:
> +                groupParams = grent.split (":")
> +                if (int(groupParams[2]) > 100 and int(groupParams[2]) < 1000): groupList.append(groupParams[0])
> +        return groupList

Why aren't you using an existing python module such as grp rather than
writing your own (likely buggy) parser?

It seems to have existed since at least python 2.6...
https://docs.python.org/2.6/library/grp.html

> @@ -111,39 +144,31 @@ class UserManUsers (dbus.service.Object):
>  
>      @dbus.service.method(INTF_NAME, "ssss", "x")
>      def UserAdd (self, gecos, username, groupname, passwd):
> +        if not username: return 1
> +
> +        users = self.UserList ()
> +        if username in users : return 1
> +
>          if groupname:
> -            cmd = "adduser "  + " -g "  + gecos + " -G ", groupname + " " + username
> +            groups = Groupsobj.GroupListAll ()
> +            if groupname not in groups: return 1
> +
> +        opts = ""
> +        if gecos: opts = " -g " + '"' + gecos + '"'
> +
> +        if groupname:
> +            cmd = "adduser "  + opts + " " + " -G " + groupname + " " + username
>          else:
> -            cmd = "adduser "  + " -g "  + gecos + username
> +            cmd = "adduser "  + opts + " " + username

I note there's a python-libuser package on ubuntu, is that a library
that could be used instead?

-- 
Stewart Smith
OPAL Architect, IBM.

  reply	other threads:[~2016-02-11 22:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-11 21:00 [PATCH phosphor-networkd] Validating user & group names prior to system call and wait() on proc… OpenBMC Patches
2016-02-11 21:00 ` [PATCH phosphor-networkd] Validating user & group names prior to system call and wait() on proc spawned with pexpect OpenBMC Patches
2016-02-11 22:18   ` Stewart Smith [this message]
2016-02-11 22:39     ` Brad Bishop
2016-02-11 23:11       ` Stewart Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87egcioppp.fsf@linux.vnet.ibm.com \
    --to=stewart@linux.vnet.ibm.com \
    --cc=openbmc-patches@stwcx.xyz \
    --cc=openbmc@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.