<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: C API for removing a user in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/c-api-for-removing-a-user/m-p/2673836#M917097</link>
    <description>Hi:&lt;BR /&gt;&lt;BR /&gt;All is is saying is that my baby example was not very robust.&lt;BR /&gt;&lt;BR /&gt;char *the_user; &lt;BR /&gt;int status; &lt;BR /&gt;char s_cmd[256]; &lt;BR /&gt;&lt;BR /&gt;(void) sprintf(s_cmd,"userdel -r s",the_user); &lt;BR /&gt;cc = system(userdel); &lt;BR /&gt;&lt;BR /&gt;The problem is that is is conceivable (though very unlikely) that the length of the command might exceed the size of s_cmd [256] characters - a buffer overflow.&lt;BR /&gt;&lt;BR /&gt;# ----------------------------------------&lt;BR /&gt;The nit-picky though really not need method:&lt;BR /&gt;&lt;BR /&gt;#define CMD "/sbin/userdel -r "&lt;BR /&gt;&lt;BR /&gt;extern int errno;&lt;BR /&gt;&lt;BR /&gt;int remove_user(char *the_user)&lt;BR /&gt;{&lt;BR /&gt;  int cc = 0;&lt;BR /&gt;&lt;BR /&gt;  if (the_user != NULL)&lt;BR /&gt;    {&lt;BR /&gt;      int len = 4; /* cushion */&lt;BR /&gt;      char *s_cmd = NULL;&lt;BR /&gt;&lt;BR /&gt;      len += (int) strlen(the_user);&lt;BR /&gt;      len += (int) strlen(CMD);&lt;BR /&gt;      s_cmd = (char *) malloc(size_t) len);&lt;BR /&gt;      if (s_cmd != NULL)&lt;BR /&gt;        {&lt;BR /&gt;          (void) sprintf(s_cmd,&lt;BR /&gt;                         "%s %s",CMD,the_user);&lt;BR /&gt;          cc = system(s_cmd);&lt;BR /&gt;          free ((void *) s_cmd));&lt;BR /&gt;        }&lt;BR /&gt;       else cc = (errno != 0) ? errno : -2;&lt;BR /&gt;     }&lt;BR /&gt;   else cc = -1;&lt;BR /&gt;   return(cc);&lt;BR /&gt;} /* remove_user */  &lt;BR /&gt; &lt;BR /&gt;-----------------------------------------&lt;BR /&gt;&lt;BR /&gt;cc = remove_user("clay");&lt;BR /&gt;        &lt;BR /&gt;Barring any typo's that should be a fully robust version. In real life, as long as you make sure that the length of the user name is no more than ~220 the baby example will be perfectly robust.&lt;BR /&gt;&lt;BR /&gt;                &lt;BR /&gt;Regards, Clay&lt;BR /&gt;</description>
    <pubDate>Fri, 01 Mar 2002 16:03:31 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2002-03-01T16:03:31Z</dc:date>
    <item>
      <title>C API for removing a user</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-api-for-removing-a-user/m-p/2673832#M917093</link>
      <description>Dear all,&lt;BR /&gt;&lt;BR /&gt;Is there a C API for removing a user?&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Thu, 28 Feb 2002 20:58:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-api-for-removing-a-user/m-p/2673832#M917093</guid>
      <dc:creator>Helen Gao</dc:creator>
      <dc:date>2002-02-28T20:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: C API for removing a user</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-api-for-removing-a-user/m-p/2673833#M917094</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;By far the easiest method is to call the userdel command via system. e.g.&lt;BR /&gt;&lt;BR /&gt;char *the_user;&lt;BR /&gt;int status;&lt;BR /&gt;char s_cmd[256];&lt;BR /&gt;&lt;BR /&gt;(void) sprintf(s_cmd,"userdel -r %s",the_user);&lt;BR /&gt;cc = system(userdel);&lt;BR /&gt;&lt;BR /&gt;Clay&lt;BR /&gt;</description>
      <pubDate>Thu, 28 Feb 2002 21:16:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-api-for-removing-a-user/m-p/2673833#M917094</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-02-28T21:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: C API for removing a user</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-api-for-removing-a-user/m-p/2673834#M917095</link>
      <description>I would put an absolute path on that userdel for security purposes.&lt;BR /&gt;&lt;BR /&gt;You might want to consider protecting that from buffer overflows too.</description>
      <pubDate>Thu, 28 Feb 2002 22:21:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-api-for-removing-a-user/m-p/2673834#M917095</guid>
      <dc:creator>Eric Ladner</dc:creator>
      <dc:date>2002-02-28T22:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: C API for removing a user</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-api-for-removing-a-user/m-p/2673835#M917096</link>
      <description>Thanks, guys.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt;You might want to consider protecting that &amp;gt;&amp;gt;from buffer overflows too.  &lt;BR /&gt;&lt;BR /&gt;Eric, could you give me more detail on this?&lt;BR /&gt; &lt;BR /&gt;   &lt;BR /&gt;  &lt;BR /&gt;   &lt;BR /&gt;</description>
      <pubDate>Fri, 01 Mar 2002 15:45:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-api-for-removing-a-user/m-p/2673835#M917096</guid>
      <dc:creator>Helen Gao</dc:creator>
      <dc:date>2002-03-01T15:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: C API for removing a user</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-api-for-removing-a-user/m-p/2673836#M917097</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;All is is saying is that my baby example was not very robust.&lt;BR /&gt;&lt;BR /&gt;char *the_user; &lt;BR /&gt;int status; &lt;BR /&gt;char s_cmd[256]; &lt;BR /&gt;&lt;BR /&gt;(void) sprintf(s_cmd,"userdel -r s",the_user); &lt;BR /&gt;cc = system(userdel); &lt;BR /&gt;&lt;BR /&gt;The problem is that is is conceivable (though very unlikely) that the length of the command might exceed the size of s_cmd [256] characters - a buffer overflow.&lt;BR /&gt;&lt;BR /&gt;# ----------------------------------------&lt;BR /&gt;The nit-picky though really not need method:&lt;BR /&gt;&lt;BR /&gt;#define CMD "/sbin/userdel -r "&lt;BR /&gt;&lt;BR /&gt;extern int errno;&lt;BR /&gt;&lt;BR /&gt;int remove_user(char *the_user)&lt;BR /&gt;{&lt;BR /&gt;  int cc = 0;&lt;BR /&gt;&lt;BR /&gt;  if (the_user != NULL)&lt;BR /&gt;    {&lt;BR /&gt;      int len = 4; /* cushion */&lt;BR /&gt;      char *s_cmd = NULL;&lt;BR /&gt;&lt;BR /&gt;      len += (int) strlen(the_user);&lt;BR /&gt;      len += (int) strlen(CMD);&lt;BR /&gt;      s_cmd = (char *) malloc(size_t) len);&lt;BR /&gt;      if (s_cmd != NULL)&lt;BR /&gt;        {&lt;BR /&gt;          (void) sprintf(s_cmd,&lt;BR /&gt;                         "%s %s",CMD,the_user);&lt;BR /&gt;          cc = system(s_cmd);&lt;BR /&gt;          free ((void *) s_cmd));&lt;BR /&gt;        }&lt;BR /&gt;       else cc = (errno != 0) ? errno : -2;&lt;BR /&gt;     }&lt;BR /&gt;   else cc = -1;&lt;BR /&gt;   return(cc);&lt;BR /&gt;} /* remove_user */  &lt;BR /&gt; &lt;BR /&gt;-----------------------------------------&lt;BR /&gt;&lt;BR /&gt;cc = remove_user("clay");&lt;BR /&gt;        &lt;BR /&gt;Barring any typo's that should be a fully robust version. In real life, as long as you make sure that the length of the user name is no more than ~220 the baby example will be perfectly robust.&lt;BR /&gt;&lt;BR /&gt;                &lt;BR /&gt;Regards, Clay&lt;BR /&gt;</description>
      <pubDate>Fri, 01 Mar 2002 16:03:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-api-for-removing-a-user/m-p/2673836#M917097</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-03-01T16:03:31Z</dc:date>
    </item>
  </channel>
</rss>

