BOOL string_to_sid(DOM_SID *sidout, const char *sidstr)
{
pstring tok;
- const char *p = sidstr;
+ char *p;
/* BIG NOTE: this function only does SIDS where the identauth is not >= 2^32 */
uint32 ia;
+
+ if (StrnCaseCmp( sidstr, "S-", 2)) {
+ DEBUG(0,("string_to_sid: Sid %s does not start with 'S-'.\n", sidstr));
+ return False;
+ }
memset((char *)sidout, '\0', sizeof(DOM_SID));
- if (StrnCaseCmp( sidstr, "S-", 2)) {
- DEBUG(0,("string_to_sid: Sid %s does not start with 'S-'.\n", sidstr));
+ p = strdup(sidstr + 2);
+ if (p == NULL) {
+ DEBUG(0, ("string_to_sid: out of memory!\n"));
return False;
}
- p += 2;
if (!next_token(&p, tok, "-", sizeof(tok))) {
DEBUG(0,("string_to_sid: Sid %s is not in a valid format.\n", sidstr));
+ SAFE_FREE(p);
return False;
}
if (!next_token(&p, tok, "-", sizeof(tok))) {
DEBUG(0,("string_to_sid: Sid %s is not in a valid format.\n", sidstr));
+ SAFE_FREE(p);
return False;
}
sid_append_rid(sidout, (uint32)strtoul(tok, NULL, 10));
}
+ SAFE_FREE(p);
return True;
}
uint32 len = 0;
uint32 lmpwlen, ntpwlen, hourslen;
BOOL ret = True;
+
+ if(sampass == NULL || buf == NULL) {
+ DEBUG(0, ("init_sam_from_buffer: NULL parameters found!\n"));
+ return False;
+ }
/* unpack the buffer into variables */
len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING,
uint32 nt_pw_len = 16;
/* do we have a valid SAM_ACCOUNT pointer? */
- if (sampass == NULL)
+ if (sampass == NULL) {
+ DEBUG(0, ("init_buffer_from_sam: SAM_ACCOUNT is NULL!\n"));
return -1;
-
+ }
+
*buf = NULL;
buflen = 0;
global_tdb_ent.passwd_tdb = NULL;
}
- DEBUG(7, ("endtdbpwent: closed password file.\n"));
+ DEBUG(7, ("endtdbpwent: closed sam database.\n"));
}
/*****************************************************************
return False;
}
- /* skip all RID entries */
- while ((global_tdb_ent.key.dsize != 0) && (strncmp (global_tdb_ent.key.dptr, prefix, prefixlen)))
+ /* skip all non-USER entries (eg. RIDs) */
+ while ((global_tdb_ent.key.dsize != 0) && (strncmp(global_tdb_ent.key.dptr, prefix, prefixlen)))
/* increment to next in line */
- global_tdb_ent.key = tdb_nextkey (global_tdb_ent.passwd_tdb, global_tdb_ent.key);
+ global_tdb_ent.key = tdb_nextkey(global_tdb_ent.passwd_tdb, global_tdb_ent.key);
/* do we have an valid interation pointer? */
if(global_tdb_ent.passwd_tdb == NULL) {
return False;
}
- data = tdb_fetch (global_tdb_ent.passwd_tdb, global_tdb_ent.key);
+ data = tdb_fetch(global_tdb_ent.passwd_tdb, global_tdb_ent.key);
if (!data.dptr) {
DEBUG(5,("pdb_getsampwent: database entry not found.\n"));
return False;
}
/* unpack the buffer */
- if (!init_sam_from_buffer (user, data.dptr, data.dsize)) {
+ if (!init_sam_from_buffer(user, data.dptr, data.dsize)) {
DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n"));
SAFE_FREE(data.dptr);
return False;
uid = pw->pw_uid;
gid = pw->pw_gid;
- pdb_set_uid (user, uid);
- pdb_set_gid (user, gid);
+ pdb_set_uid(user, uid);
+ pdb_set_gid(user, gid);
/* increment to next in line */
- global_tdb_ent.key = tdb_nextkey (global_tdb_ent.passwd_tdb, global_tdb_ent.key);
+ global_tdb_ent.key = tdb_nextkey(global_tdb_ent.passwd_tdb, global_tdb_ent.key);
return True;
}
unix_strlower(sname, -1, name, sizeof(name));
get_private_directory(tdbfile);
- pstrcat (tdbfile, PASSDB_FILE_NAME);
+ pstrcat(tdbfile, PASSDB_FILE_NAME);
/* set search key */
slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name);
key.dptr = keystr;
- key.dsize = strlen (keystr) + 1;
+ key.dsize = strlen(keystr) + 1;
/* open the accounts TDB */
if (!(pwd_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDONLY, 0600))) {
}
/* get the record */
- data = tdb_fetch (pwd_tdb, key);
+ data = tdb_fetch(pwd_tdb, key);
if (!data.dptr) {
DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n"));
DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
- tdb_close (pwd_tdb);
+ tdb_close(pwd_tdb);
return False;
}
/* unpack the buffer */
- if (!init_sam_from_buffer (user, data.dptr, data.dsize)) {
+ if (!init_sam_from_buffer(user, data.dptr, data.dsize)) {
DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n"));
SAFE_FREE(data.dptr);
+ tdb_close(pwd_tdb);
return False;
}
SAFE_FREE(data.dptr);
+
+ /* cleanup */
+ tdb_close(pwd_tdb);
/* validate the account and fill in UNIX uid and gid. sys_getpwnam()
- is used instaed of Get_Pwnam() as we do not need to try case
+ is used instead of Get_Pwnam() as we do not need to try case
permutations */
if ((pw=sys_getpwnam(pdb_get_username(user)))) {
uid = pw->pw_uid;
gid = pw->pw_gid;
- pdb_set_uid (user, uid);
- pdb_set_gid (user, gid);
+ pdb_set_uid(user, uid);
+ pdb_set_gid(user, gid);
+ }
+ else {
+ DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n",
+ pdb_get_username(user)));
+ return False;
}
-
- /* cleanup */
- tdb_close (pwd_tdb);
return True;
}