Converts NT user RID to a UNIX uid.
********************************************************************/
-uid_t pdb_user_rid_to_uid(uint32 user_rid)
+uid_t fallback_pdb_user_rid_to_uid(uint32 user_rid)
{
return (uid_t)(((user_rid & (~USER_RID_TYPE))- 1000)/RID_MULTIPLIER);
}
/*******************************************************************
- Converts NT group RID to a UNIX gid.
+ converts UNIX uid to an NT User RID.
********************************************************************/
-gid_t pdb_group_rid_to_gid(uint32 group_rid)
+uint32 fallback_pdb_uid_to_user_rid(uid_t uid)
{
- return (gid_t)(((group_rid & (~GROUP_RID_TYPE))- 1000)/RID_MULTIPLIER);
+ return (((((uint32)uid)*RID_MULTIPLIER) + 1000) | USER_RID_TYPE);
}
/*******************************************************************
- converts UNIX uid to an NT User RID.
+ Converts NT group RID to a UNIX gid.
********************************************************************/
-uint32 pdb_uid_to_user_rid(uid_t uid)
+gid_t pdb_group_rid_to_gid(uint32 group_rid)
{
- return (((((uint32)uid)*RID_MULTIPLIER) + 1000) | USER_RID_TYPE);
+ return (gid_t)(((group_rid & (~GROUP_RID_TYPE))- 1000)/RID_MULTIPLIER);
}
/*******************************************************************
return context->pdb_selected->delete_sam_account(context, sam_acct);
}
+static uint32 context_uid_to_user_rid(struct pdb_context *context, uid_t uid)
+{
+ if ((!context) || (!context->pdb_selected)) {
+ DEBUG(0, ("invalid pdb_context specified!\n"));
+ return False;
+ }
+
+ return context->pdb_selected->uid_to_user_rid(context, uid);
+}
+
+static uid_t context_user_rid_to_uid(struct pdb_context *context, uint32 rid)
+{
+ if ((!context) || (!context->pdb_selected)) {
+ DEBUG(0, ("invalid pdb_context specified!\n"));
+ return False;
+ }
+
+ return context->pdb_selected->user_rid_to_uid(context, rid);
+}
+
static void free_pdb_context(struct pdb_context **context)
{
if (((*context)->pdb_selected) && ((*context)->pdb_selected->free_private_data)) {
(*context)->pdb_add_sam_account = context_add_sam_account;
(*context)->pdb_update_sam_account = context_update_sam_account;
(*context)->pdb_delete_sam_account = context_delete_sam_account;
+ (*context)->pdb_uid_to_user_rid = context_uid_to_user_rid;
+ (*context)->pdb_user_rid_to_uid = context_user_rid_to_uid;
(*context)->free_fn = free_pdb_context;
return pdb_context->pdb_delete_sam_account(pdb_context, sam_acct);
}
+uid_t pdb_user_rid_to_uid(uint32 rid)
+{
+ struct pdb_context *pdb_context = pdb_get_static_context(False);
+
+ if (!pdb_context) {
+ return False;
+ }
+
+ return pdb_context->pdb_user_rid_to_uid(pdb_context, rid);
+}
+
+uint32 pdb_uid_to_user_rid(uid_t uid)
+{
+ struct pdb_context *pdb_context = pdb_get_static_context(False);
+
+ if (!pdb_context) {
+ return False;
+ }
+
+ return pdb_context->pdb_uid_to_user_rid(pdb_context, uid);
+}
+
#endif /* !defined(WITH_NISPLUS_SAM) */
/***************************************************************
}
}
+/**********************************************************************
+ get rid by uid
+*********************************************************************/
+
+static uint32 ldapsam_uid_to_user_rid(struct pdb_context *context, uid_t uid)
+{
+ return fallback_pdb_uid_to_user_rid(uid);
+}
+
+/**********************************************************************
+ get uid by rid
+*********************************************************************/
+
+static uid_t ldapsam_user_rid_to_uid(struct pdb_context *context, uint32 rid)
+{
+ return fallback_pdb_user_rid_to_uid(rid);
+}
+
/**********************************************************************
Delete entry from LDAP for username
*********************************************************************/
(*pdb_method)->add_sam_account = ldapsam_add_sam_account;
(*pdb_method)->update_sam_account = ldapsam_update_sam_account;
(*pdb_method)->delete_sam_account = ldapsam_delete_sam_account;
+ (*pdb_method)->uid_to_user_rid = ldapsam_uid_to_user_rid;
+ (*pdb_method)->user_rid_to_uid = ldapsam_user_rid_to_uid;
/* TODO: Setup private data and free */
return True;
}
+/**********************************************************************
+ get rid by uid
+*********************************************************************/
+
+static uint32 smbpasswd_uid_to_rid(struct pdb_context *context, uid_t uid)
+{
+ return fallback_pdb_uid_to_user_rid(uid);
+}
+
+/**********************************************************************
+ get uid by rid
+*********************************************************************/
+
+static uid_t smbpasswd_rid_to_uid(struct pdb_context *context, uint32 rid)
+{
+ return fallback_pdb_user_rid_to_uid(rid);
+}
+
+
static BOOL smbpasswd_add_sam_account(struct pdb_context *context, const SAM_ACCOUNT *sampass)
{
struct smbpasswd_privates *smbpasswd_state = (struct smbpasswd_privates*)context->pdb_selected->private_data;
(*pdb_method)->add_sam_account = smbpasswd_add_sam_account;
(*pdb_method)->update_sam_account = smbpasswd_update_sam_account;
(*pdb_method)->delete_sam_account = smbpasswd_delete_sam_account;
+ (*pdb_method)->uid_to_user_rid = smbpasswd_uid_to_rid;
+ (*pdb_method)->user_rid_to_uid = smbpasswd_rid_to_uid;
/* Setup private data and free function */
#define USERPREFIX "USER_"
#define RIDPREFIX "RID_"
+#define BASE_RID 0x200
+
struct tdbsam_privates {
TDB_CONTEXT *passwd_tdb;
TDB_DATA key;
/**********************************************************************
Intialize a BYTE buffer from a SAM_ACCOUNT struct
*********************************************************************/
-static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, uint8 **buf,
- const SAM_ACCOUNT *sampass, uint32 user_rid, uint32 group_rid)
+static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state,
+ uint8 **buf, const SAM_ACCOUNT *sampass)
{
size_t len, buflen;
pass_last_set_time,
pass_can_change_time,
pass_must_change_time;
+
+ uint32 user_rid, group_rid;
+
const char *username;
const char *domain;
const char *nt_username;
pass_must_change_time = (uint32)pdb_get_pass_must_change_time(sampass);
pass_last_set_time = (uint32)pdb_get_pass_last_set_time(sampass);
+ user_rid = pdb_get_user_rid(sampass);
+ group_rid = pdb_get_group_rid(sampass);
username = pdb_get_username(sampass);
if (username) username_len = strlen(username) +1;
return tdbsam_getsampwnam (context, user, name);
}
+/***************************************************************************
+ Search by rid and give back the uid!
+ **************************************************************************/
+
+uid_t tdbsam_rid_to_uid (struct pdb_context *context, uint32 rid)
+{
+ uid_t ret;
+ SAM_ACCOUNT *sa;
+
+ if (!NT_STATUS_IS_OK(pdb_init_sam(&sa))) return -1;
+ if (!tdbsam_getsampwrid (context, sa, rid)) {
+ ret = -1;
+ goto done;
+ }
+ else {
+ ret = pdb_get_uid(sa);
+ }
+done:
+ pdb_free_sam(&sa);
+ return ret;
+}
+
+/***************************************************************************
+ Search by uid and give back the rid!
+ **************************************************************************/
+
+uint32 tdbsam_uid_to_rid (struct pdb_context *context, uid_t uid)
+{
+ uint32 ret;
+ char *name;
+ struct passwd *pw;
+ SAM_ACCOUNT *sa;
+
+ if (!NT_STATUS_IS_OK(pdb_init_sam(&sa))) return 0;
+ pw = getpwuid(uid);
+ if (!pw) return 0;
+ name = strdup(pw->pw_name);
+ if (!tdbsam_getsampwnam (context, sa, name)) {
+ ret = 0;
+ goto done;
+ }
+ else {
+ ret = pdb_get_user_rid(sa);
+ }
+done:
+ SAFE_FREE(name);
+ pdb_free_sam(&sa);
+ return ret;
+}
+
/***************************************************************************
Delete a SAM_ACCOUNT
****************************************************************************/
fstring keystr;
fstring name;
BOOL ret = True;
- uint32 user_rid;
- uint32 group_rid;
- int32 tdb_ret;
+ uint32 user_rid;
+ int32 tdb_ret;
/* invalidate the existing TDB iterator if it is open */
if (tdb_state->passwd_tdb) {
return False;
}
- /* if we don't have a RID, then make them up. */
- if (!(user_rid = pdb_get_user_rid(newpwd))) {
- if (!tdb_state->permit_non_unix_accounts) {
- DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a RID\n",pdb_get_username(newpwd)));
- ret = False;
- goto done;
- } else {
- user_rid = tdb_state->low_nua_rid;
- tdb_ret = tdb_change_int32_atomic(pwd_tdb, "NUA_NEXT_RID", &user_rid, RID_MULTIPLIER);
+ /* if flag == TDB_INSERT then make up a new RID else throw an error. */
+ if (!pdb_get_user_rid(newpwd)) {
+ if (flag & TDB_INSERT) {
+ user_rid = BASE_RID;
+ tdb_ret = tdb_change_int32_atomic(pwd_tdb, "RID_COUNTER", &user_rid, RID_MULTIPLIER);
if (tdb_ret == -1) {
ret = False;
goto done;
}
+ pdb_set_user_rid(newpwd, user_rid);
+ } else {
+ DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a RID\n",pdb_get_username(newpwd)));
+ ret = False;
+ goto done;
}
}
- if (!(group_rid = pdb_get_group_rid(newpwd))) {
- if (!tdb_state->permit_non_unix_accounts) {
+ if (!pdb_get_group_rid(newpwd)) {
+ if (flag & TDB_INSERT) {
+ if (!tdb_state->permit_non_unix_accounts) {
+ DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n",pdb_get_username(newpwd)));
+ ret = False;
+ goto done;
+ } else {
+ /* This seems like a good default choice for non-unix users */
+ pdb_set_group_rid(newpwd, DOMAIN_GROUP_RID_USERS);
+ }
+ } else {
DEBUG (0,("tdb_update_sam: Failing to store a SAM_ACCOUNT for [%s] without a primary group RID\n",pdb_get_username(newpwd)));
ret = False;
goto done;
- } else {
- /* This seems like a good default choice for non-unix users */
- group_rid = DOMAIN_GROUP_RID_USERS;
}
}
/* copy the SAM_ACCOUNT struct into a BYTE buffer for storage */
- if ((data.dsize=init_buffer_from_sam (tdb_state, &buf, newpwd, user_rid, group_rid)) == -1) {
+ if ((data.dsize=init_buffer_from_sam (tdb_state, &buf, newpwd)) == -1) {
DEBUG(0,("tdb_update_sam: ERROR - Unable to copy SAM_ACCOUNT info BYTE buffer!\n"));
ret = False;
goto done;
(*pdb_method)->add_sam_account = tdbsam_add_sam_account;
(*pdb_method)->update_sam_account = tdbsam_update_sam_account;
(*pdb_method)->delete_sam_account = tdbsam_delete_sam_account;
+ (*pdb_method)->uid_to_user_rid = tdbsam_uid_to_rid;
+ (*pdb_method)->user_rid_to_uid = tdbsam_rid_to_uid;
tdb_state = talloc_zero(pdb_context->mem_ctx, sizeof(struct tdbsam_privates));
return NT_STATUS_UNSUCCESSFUL;
}
- tdb_state->low_nua_rid=pdb_uid_to_user_rid(low_nua_uid);
+ tdb_state->low_nua_rid=fallback_pdb_uid_to_user_rid(low_nua_uid);
- tdb_state->high_nua_rid=pdb_uid_to_user_rid(high_nua_uid);
+ tdb_state->high_nua_rid=fallback_pdb_uid_to_user_rid(high_nua_uid);
return NT_STATUS_OK;
}