2003-08-13 05:53:07 +04:00
/*
Unix SMB / CIFS implementation .
Safe versions of getpw * calls
2011-03-02 18:06:32 +03:00
Copyright ( C ) Andrew Tridgell 1992 - 1998
Copyright ( C ) Jeremy Allison 1998 - 2005
2003-08-13 05:53:07 +04:00
Copyright ( C ) Andrew Bartlett 2002
2011-03-02 18:06:32 +03:00
Copyright ( C ) Timur Bakeyev 2005
Copyright ( C ) Bjoern Jacke 2006 - 2007
2003-08-13 05:53:07 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 05:53:07 +04:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 05:53:07 +04:00
*/
# include "includes.h"
2011-03-02 18:06:32 +03:00
# include "system/passwd.h"
# include "lib/util/util_pw.h"
2011-03-02 18:11:00 +03:00
struct passwd * tcopy_passwd ( TALLOC_CTX * mem_ctx ,
const struct passwd * from )
2003-08-13 05:53:07 +04:00
{
2007-09-09 23:34:30 +04:00
struct passwd * ret = talloc_zero ( mem_ctx , struct passwd ) ;
2003-08-13 05:53:07 +04:00
2007-09-09 23:34:30 +04:00
if ( ret = = NULL )
return NULL ;
2003-08-13 05:53:07 +04:00
2007-09-09 23:34:30 +04:00
ret - > pw_name = talloc_strdup ( ret , from - > pw_name ) ;
ret - > pw_passwd = talloc_strdup ( ret , from - > pw_passwd ) ;
ret - > pw_uid = from - > pw_uid ;
ret - > pw_gid = from - > pw_gid ;
ret - > pw_gecos = talloc_strdup ( ret , from - > pw_gecos ) ;
ret - > pw_dir = talloc_strdup ( ret , from - > pw_dir ) ;
ret - > pw_shell = talloc_strdup ( ret , from - > pw_shell ) ;
2003-08-13 05:53:07 +04:00
2007-09-09 23:34:30 +04:00
return ret ;
2003-08-13 05:53:07 +04:00
}
2011-03-02 18:11:00 +03:00
struct passwd * getpwnam_alloc ( TALLOC_CTX * mem_ctx , const char * name )
2003-08-13 05:53:07 +04:00
{
struct passwd * temp ;
2012-03-24 18:24:15 +04:00
temp = getpwnam ( name ) ;
2003-08-13 05:53:07 +04:00
if ( ! temp ) {
#if 0
if ( errno = = ENOMEM ) {
/* what now? */
}
# endif
return NULL ;
}
2011-03-02 18:11:00 +03:00
return tcopy_passwd ( mem_ctx , temp ) ;
2003-08-13 05:53:07 +04:00
}
2011-03-02 18:11:00 +03:00
/****************************************************************************
talloc ' ed version of getpwuid .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
struct passwd * getpwuid_alloc ( TALLOC_CTX * mem_ctx , uid_t uid )
2003-08-13 05:53:07 +04:00
{
struct passwd * temp ;
2012-03-24 18:25:05 +04:00
temp = getpwuid ( uid ) ;
2003-08-13 05:53:07 +04:00
if ( ! temp ) {
#if 0
if ( errno = = ENOMEM ) {
/* what now? */
}
# endif
return NULL ;
}
2011-03-02 18:11:00 +03:00
return tcopy_passwd ( mem_ctx , temp ) ;
2003-08-13 05:53:07 +04:00
}