Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include "includes.h"
#include "winbindd.h"
#undef DBGC_CLASS
if ( account_tdb )
return True;
-
- /* Nope. Try to open it */
- if (!(account_tdb = tdb_open_log(lock_path("winbindd_idmap.tdb"), 0,
- TDB_DEFAULT, O_RDWR | O_CREAT, 0600)))
- {
- /* last chance -- maybe idmap has already opened it */
- if ( !(account_tdb = idmap_tdb_handle()) ) {
+ /* winbindd_idmap.tdb should always be opened by the idmap_init()
+ code first */
- DEBUG(0, ("winbindd_idmap_init: Unable to open idmap database\n"));
- return False;
- }
+ if ( !(account_tdb = idmap_tdb_handle()) ) {
+ DEBUG(0, ("winbindd_accountdb_init: Unable to retreive handle for database\n"));
+ return False;
}
/* yeah! */
DEBUG(10,("passwd2string: converting passwd struct for %s\n",
pw->pw_name));
- ret = snprintf( string, sizeof(string), "%s:%s:%lu:%lu:%s:%s:%s",
+ ret = pstr_sprintf( string, "%s:%s:%lu:%lu:%s:%s:%s",
pw->pw_name,
pw->pw_passwd ? pw->pw_passwd : "x",
(unsigned long)pw->pw_uid,
pw->pw_shell );
if ( ret < 0 ) {
- DEBUG(0,("passwd2string: snprintf() failed!\n"));
+ DEBUG(0,("passwd2string: pstr_sprintf() failed!\n"));
return NULL;
}
if ( num_gr_members ) {
fstring buffer;
- gr_members = (char**)smb_xmalloc(sizeof(char*)*num_gr_members+1);
+ gr_members = (char**)smb_xmalloc(sizeof(char*)*(num_gr_members+1));
i = 0;
while ( next_token(&str, buffer, ",", sizeof(buffer)) && i<num_gr_members ) {
fstrcpy( gr_mem_str, "" );
}
- ret = snprintf( string, sizeof(string)-1, "%s:%s:%lu:%s",
+ ret = pstr_sprintf( string, "%s:%s:%lu:%s",
grp->gr_name,
grp->gr_passwd ? grp->gr_passwd : "*",
(unsigned long)grp->gr_gid,
SAFE_FREE( gr_mem_str );
if ( ret < 0 ) {
- DEBUG(0,("group2string: snprintf() failed!\n"));
+ DEBUG(0,("group2string: pstr_sprintf() failed!\n"));
return NULL;
}
{
static fstring key;
- snprintf( key, sizeof(key), "%s/NAME/%s", WBKEY_PASSWD, name );
+ fstr_sprintf( key, "%s/NAME/%s", WBKEY_PASSWD, name );
return key;
}
{
static fstring key;
- snprintf( key, sizeof(key), "%s/UID/%lu", WBKEY_PASSWD, (unsigned long)uid );
+ fstr_sprintf( key, "%s/UID/%lu", WBKEY_PASSWD, (unsigned long)uid );
return key;
}
{
static fstring key;
- snprintf( key, sizeof(key), "%s/NAME/%s", WBKEY_GROUP, name );
+ fstr_sprintf( key, "%s/NAME/%s", WBKEY_GROUP, name );
return key;
}
{
static fstring key;
- snprintf( key, sizeof(key), "%s/GID/%lu", WBKEY_GROUP, (unsigned long)gid );
+ fstr_sprintf( key, "%s/GID/%lu", WBKEY_GROUP, (unsigned long)gid );
return key;
}
/**********************************************************************
**********************************************************************/
-BOOL wb_storepwnam( const WINBINDD_PW *pw )
+static BOOL wb_storepwnam( const WINBINDD_PW *pw )
{
char *namekey, *uidkey;
TDB_DATA data;
/**********************************************************************
**********************************************************************/
-BOOL wb_storegrnam( const WINBINDD_GR *grp )
+static BOOL wb_storegrnam( const WINBINDD_GR *grp )
{
char *namekey, *gidkey;
TDB_DATA data;
if ( !grp || !user )
return False;
- for ( i=0; i<grp->num_gr_mem && !found; i++ ) {
- if ( StrCaseCmp( grp->gr_mem[i], user ) == 0 )
+ for ( i=0; i<grp->num_gr_mem; i++ ) {
+ if ( StrCaseCmp( grp->gr_mem[i], user ) == 0 ) {
found = True;
+ break;
+ }
}
if ( !found )
/* still some remaining members */
if ( grp->num_gr_mem > 1 ) {
- memmove( grp->gr_mem[i], grp->gr_mem[i+1], sizeof(char*)*(grp->num_gr_mem-(i+1)) );
+ SAFE_FREE(grp->gr_mem[i]);
grp->num_gr_mem--;
+ grp->gr_mem[i] = grp->gr_mem[grp->num_gr_mem];
+ grp->gr_mem[grp->num_gr_mem] = NULL;
}
else { /* last one */
free_winbindd_gr( grp );
fstring key;
char *name = (char*)state;
- snprintf( key, sizeof(key), "%s/NAME", WBKEY_GROUP );
+ fstr_sprintf( key, "%s/NAME", WBKEY_GROUP );
len = strlen(key);
/* if this is a group entry then, check the members */
fstring key;
struct _check_primary_grp *check = (struct _check_primary_grp*)params;
- snprintf( key, sizeof(key), "%s/NAME", WBKEY_PASSWD );
+ fstr_sprintf( key, "%s/NAME", WBKEY_PASSWD );
len = strlen(key);
/* if this is a group entry then, check the members */
{
char *user, *group;
unid_t id;
- WINBINDD_PW pw;
+ WINBINDD_PW pw, *pw_check;
WINBINDD_GR *wb_grp;
struct group *unix_grp;
gid_t primary_gid;
DEBUG(3, ("[%5lu]: create_user: user=>(%s), group=>(%s)\n",
(unsigned long)state->pid, user, group));
+
+ if ( (pw_check=wb_getpwnam(user)) != NULL ) {
+ DEBUG(0,("winbindd_create_user: Refusing to create user that already exists (%s)\n",
+ user));
+ return WINBINDD_ERROR;
+ }
+
if ( !*group )
group = lp_template_primary_group();
{
char *group;
unid_t id;
- WINBINDD_GR grp;
+ WINBINDD_GR grp, *grp_check;
uint32 flags = state->request.flags;
uint32 rid;
DEBUG(3, ("[%5lu]: create_group: (%s)\n", (unsigned long)state->pid, group));
- /* get a new uid */
+ if ( (grp_check=wb_getgrnam(group)) != NULL ) {
+ DEBUG(0,("winbindd_create_group: Refusing to create group that already exists (%s)\n",
+ group));
+ return WINBINDD_ERROR;
+ }
+
+ /* get a new gid */
if ( !NT_STATUS_IS_OK(idmap_allocate_id( &id, ID_GROUPID)) ) {
DEBUG(0,("winbindd_create_group: idmap_allocate_id() failed!\n"));
group = state->request.data.acct_mgt.groupname;
user = state->request.data.acct_mgt.username;
- DEBUG(3, ("[%5lu]: remove_user_to_group: delete %s from %s\n", (unsigned long)state->pid,
+ DEBUG(3, ("[%5lu]: remove_user_from_group: delete %s from %s\n", (unsigned long)state->pid,
user, group));
/* don't worry about checking the username since we're removing it anyways */
/* make sure it is a valid group */
if ( !(grp = wb_getgrnam( group )) ) {
- DEBUG(4,("winbindd_remove_user_to_group: Cannot remove a user to a non-extistent group\n"));
+ DEBUG(4,("winbindd_remove_user_from_group: Cannot remove a user from a non-extistent group\n"));
return WINBINDD_ERROR;
}
group = state->request.data.acct_mgt.groupname;
user = state->request.data.acct_mgt.username;
- DEBUG(3, ("[%5d]: set_user_primary_grou:p group %s for user %s\n", state->pid,
- group, user));
+ DEBUG(3, ("[%5lu]: set_user_primary_group: group %s for user %s\n",
+ (unsigned long)state->pid, group, user));
/* make sure it is a valid user */