2000-07-10 09:40:43 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2000-07-10 09:40:43 +04:00
winbind client code
Copyright ( C ) Tim Potter 2000
Copyright ( C ) Andrew Tridgell 2000
This library is free software ; you can redistribute it and / or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation ; either
version 2 of the License , or ( at your option ) any later version .
This library 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
Library General Public License for more details .
You should have received a copy of the GNU Library General Public
License along with this library ; if not , write to the
Free Software Foundation , Inc . , 59 Temple Place - Suite 330 ,
Boston , MA 02111 - 1307 , USA .
*/
# include "includes.h"
2001-12-13 14:58:38 +03:00
# include "nsswitch/nss.h"
2000-07-10 09:40:43 +04:00
2001-08-25 00:32:01 +04:00
NSS_STATUS winbindd_request ( int req_type ,
struct winbindd_request * request ,
struct winbindd_response * response ) ;
2001-06-04 08:12:38 +04:00
2000-07-10 09:40:43 +04:00
/* Call winbindd to convert a name to a sid */
2002-01-26 12:55:38 +03:00
BOOL winbind_lookup_name ( const char * dom_name , const char * name , DOM_SID * sid ,
2001-08-13 06:33:24 +04:00
enum SID_NAME_USE * name_type )
2000-07-10 09:40:43 +04:00
{
struct winbindd_request request ;
2000-07-11 05:04:09 +04:00
struct winbindd_response response ;
2001-06-04 08:12:38 +04:00
NSS_STATUS result ;
2000-07-10 09:40:43 +04:00
2000-07-11 05:04:09 +04:00
if ( ! sid | | ! name_type )
return False ;
2000-07-10 09:40:43 +04:00
2000-07-11 05:04:09 +04:00
/* Send off request */
2000-07-10 09:40:43 +04:00
2000-07-11 05:04:09 +04:00
ZERO_STRUCT ( request ) ;
ZERO_STRUCT ( response ) ;
2000-07-10 09:40:43 +04:00
2002-01-26 12:55:38 +03:00
fstrcpy ( request . data . name . dom_name , dom_name ) ;
fstrcpy ( request . data . name . name , name ) ;
2001-06-04 08:12:38 +04:00
2000-07-11 05:04:09 +04:00
if ( ( result = winbindd_request ( WINBINDD_LOOKUPNAME , & request ,
2000-07-10 09:40:43 +04:00
& response ) ) = = NSS_STATUS_SUCCESS ) {
string_to_sid ( sid , response . data . sid . sid ) ;
2000-08-23 04:45:40 +04:00
* name_type = ( enum SID_NAME_USE ) response . data . sid . type ;
2000-07-10 09:40:43 +04:00
}
2000-07-11 05:04:09 +04:00
return result = = NSS_STATUS_SUCCESS ;
2000-07-10 09:40:43 +04:00
}
/* Call winbindd to convert sid to name */
2002-01-26 12:55:38 +03:00
BOOL winbind_lookup_sid ( DOM_SID * sid ,
fstring dom_name , fstring name ,
2001-08-13 06:33:24 +04:00
enum SID_NAME_USE * name_type )
2000-07-10 09:40:43 +04:00
{
struct winbindd_request request ;
struct winbindd_response response ;
2001-06-04 08:12:38 +04:00
NSS_STATUS result ;
2000-07-10 09:40:43 +04:00
fstring sid_str ;
/* Initialise request */
ZERO_STRUCT ( request ) ;
ZERO_STRUCT ( response ) ;
sid_to_string ( sid_str , sid ) ;
fstrcpy ( request . data . sid , sid_str ) ;
/* Make request */
result = winbindd_request ( WINBINDD_LOOKUPSID , & request , & response ) ;
/* Copy out result */
if ( result = = NSS_STATUS_SUCCESS ) {
2002-01-26 12:55:38 +03:00
fstrcpy ( dom_name , response . data . name . dom_name ) ;
fstrcpy ( name , response . data . name . name ) ;
2000-08-23 04:45:40 +04:00
* name_type = ( enum SID_NAME_USE ) response . data . name . type ;
2001-08-13 06:33:24 +04:00
DEBUG ( 10 , ( " winbind_lookup_sid: SUCCESS: SID %s -> %s %s \n " ,
sid_str , dom_name , name ) ) ;
2000-08-23 04:45:40 +04:00
}
return ( result = = NSS_STATUS_SUCCESS ) ;
}
/* Call winbindd to convert SID to uid */
2000-10-13 05:59:14 +04:00
BOOL winbind_sid_to_uid ( uid_t * puid , DOM_SID * sid )
2000-08-23 04:45:40 +04:00
{
struct winbindd_request request ;
struct winbindd_response response ;
int result ;
fstring sid_str ;
if ( ! puid )
return False ;
/* Initialise request */
ZERO_STRUCT ( request ) ;
ZERO_STRUCT ( response ) ;
sid_to_string ( sid_str , sid ) ;
fstrcpy ( request . data . sid , sid_str ) ;
/* Make request */
result = winbindd_request ( WINBINDD_SID_TO_UID , & request , & response ) ;
/* Copy out result */
if ( result = = NSS_STATUS_SUCCESS ) {
* puid = response . data . uid ;
2000-07-10 09:40:43 +04:00
}
return ( result = = NSS_STATUS_SUCCESS ) ;
}
/* Call winbindd to convert uid to sid */
2000-10-13 05:59:14 +04:00
BOOL winbind_uid_to_sid ( DOM_SID * sid , uid_t uid )
2000-07-10 09:40:43 +04:00
{
struct winbindd_request request ;
struct winbindd_response response ;
int result ;
2000-08-02 06:11:55 +04:00
if ( ! sid )
return False ;
2000-07-10 09:40:43 +04:00
/* Initialise request */
ZERO_STRUCT ( request ) ;
ZERO_STRUCT ( response ) ;
request . data . uid = uid ;
/* Make request */
result = winbindd_request ( WINBINDD_UID_TO_SID , & request , & response ) ;
/* Copy out result */
if ( result = = NSS_STATUS_SUCCESS ) {
string_to_sid ( sid , response . data . sid . sid ) ;
} else {
sid_copy ( sid , & global_sid_NULL ) ;
}
return ( result = = NSS_STATUS_SUCCESS ) ;
}
2000-08-23 04:45:40 +04:00
/* Call winbindd to convert SID to gid */
2000-07-10 09:40:43 +04:00
2000-10-13 05:59:14 +04:00
BOOL winbind_sid_to_gid ( gid_t * pgid , DOM_SID * sid )
2000-08-23 04:45:40 +04:00
{
struct winbindd_request request ;
struct winbindd_response response ;
int result ;
fstring sid_str ;
if ( ! pgid )
return False ;
/* Initialise request */
ZERO_STRUCT ( request ) ;
ZERO_STRUCT ( response ) ;
sid_to_string ( sid_str , sid ) ;
fstrcpy ( request . data . sid , sid_str ) ;
/* Make request */
2001-06-07 04:38:16 +04:00
result = winbindd_request ( WINBINDD_SID_TO_GID , & request , & response ) ;
2000-08-23 04:45:40 +04:00
/* Copy out result */
if ( result = = NSS_STATUS_SUCCESS ) {
* pgid = response . data . gid ;
}
return ( result = = NSS_STATUS_SUCCESS ) ;
}
/* Call winbindd to convert gid to sid */
2000-10-13 05:59:14 +04:00
BOOL winbind_gid_to_sid ( DOM_SID * sid , gid_t gid )
2000-07-10 09:40:43 +04:00
{
struct winbindd_request request ;
struct winbindd_response response ;
int result ;
2000-08-02 06:11:55 +04:00
if ( ! sid )
return False ;
2000-07-10 09:40:43 +04:00
/* Initialise request */
ZERO_STRUCT ( request ) ;
ZERO_STRUCT ( response ) ;
request . data . gid = gid ;
/* Make request */
result = winbindd_request ( WINBINDD_GID_TO_SID , & request , & response ) ;
/* Copy out result */
if ( result = = NSS_STATUS_SUCCESS ) {
string_to_sid ( sid , response . data . sid . sid ) ;
} else {
sid_copy ( sid , & global_sid_NULL ) ;
}
return ( result = = NSS_STATUS_SUCCESS ) ;
}
2000-08-02 06:11:55 +04:00
2000-10-11 09:25:32 +04:00
/* Fetch the list of groups a user is a member of from winbindd. This is
2002-01-27 15:12:22 +03:00
used by winbind_getgroups . */
2000-08-02 06:11:55 +04:00
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
static int wb_getgroups ( const char * user , gid_t * * groups )
2000-10-11 09:25:32 +04:00
{
struct winbindd_request request ;
struct winbindd_response response ;
int result ;
/* Call winbindd */
fstrcpy ( request . data . username , user ) ;
ZERO_STRUCT ( response ) ;
2000-10-11 09:45:06 +04:00
result = winbindd_request ( WINBINDD_GETGROUPS , & request , & response ) ;
2000-10-11 09:25:32 +04:00
if ( result = = NSS_STATUS_SUCCESS ) {
/* Return group list. Don't forget to free the group list
when finished . */
* groups = ( gid_t * ) response . extra_data ;
return response . data . num_entries ;
}
return - 1 ;
}
/* Return a list of groups the user is a member of. This function is
useful for large systems where inverting the group database would be too
time consuming . If size is zero , list is not modified and the total
number of groups for the user is returned . */
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
int winbind_getgroups ( const char * user , int size , gid_t * list )
2000-10-11 09:25:32 +04:00
{
gid_t * groups = NULL ;
int result , i ;
2001-11-14 00:28:31 +03:00
/*
2002-01-18 05:37:55 +03:00
* Don ' t do the lookup if the name has no separator _and_ we are not in
* ' winbind use default domain ' mode .
2001-11-14 00:28:31 +03:00
*/
2002-01-18 05:37:55 +03:00
if ( ! ( strchr ( user , * lp_winbind_separator ( ) ) | | lp_winbind_use_default_domain ( ) ) )
2001-11-14 00:28:31 +03:00
return - 1 ;
2000-10-11 09:25:32 +04:00
/* Fetch list of groups */
result = wb_getgroups ( user , & groups ) ;
2001-11-14 00:28:31 +03:00
if ( size = = 0 )
goto done ;
2000-10-11 09:25:32 +04:00
if ( result > size ) {
result = - 1 ;
errno = EINVAL ; /* This is what getgroups() does */
goto done ;
}
/* Copy list of groups across */
for ( i = 0 ; i < result ; i + + ) {
list [ i ] = groups [ i ] ;
}
done :
2001-09-17 08:52:45 +04:00
SAFE_FREE ( groups ) ;
2000-10-11 09:25:32 +04:00
return result ;
}