+static NTSTATUS check_info3_in_group(TALLOC_CTX *mem_ctx,
+ NET_USER_INFO_3 *info3,
+ const char *group_sid)
+{
+ DOM_SID require_membership_of_sid;
+ DOM_SID *all_sids;
+ size_t num_all_sids = (2 + info3->num_groups2 + info3->num_other_sids);
+ size_t i, j = 0;
+
+ /* Parse the 'required group' SID */
+
+ if (!group_sid || !group_sid[0]) {
+ /* NO sid supplied, all users may access */
+ return NT_STATUS_OK;
+ }
+
+ if (!string_to_sid(&require_membership_of_sid, group_sid)) {
+ DEBUG(0, ("check_info3_in_group: could not parse %s as a SID!",
+ group_sid));
+
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ all_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_all_sids);
+ if (!all_sids)
+ return NT_STATUS_NO_MEMORY;
+
+ /* and create (by appending rids) the 'domain' sids */
+
+ sid_copy(&all_sids[0], &(info3->dom_sid.sid));
+
+ if (!sid_append_rid(&all_sids[0], info3->user_rid)) {
+ DEBUG(3,("could not append user's primary RID 0x%x\n",
+ info3->user_rid));
+
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ j++;
+
+ sid_copy(&all_sids[1], &(info3->dom_sid.sid));
+
+ if (!sid_append_rid(&all_sids[1], info3->group_rid)) {
+ DEBUG(3,("could not append additional group rid 0x%x\n",
+ info3->group_rid));
+
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ j++;
+
+ for (i = 0; i < info3->num_groups2; i++) {
+
+ sid_copy(&all_sids[j], &(info3->dom_sid.sid));
+
+ if (!sid_append_rid(&all_sids[j], info3->gids[i].g_rid)) {
+ DEBUG(3,("could not append additional group rid 0x%x\n",
+ info3->gids[i].g_rid));
+
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ j++;
+ }
+
+ /* Copy 'other' sids. We need to do sid filtering here to
+ prevent possible elevation of privileges. See:
+
+ http://www.microsoft.com/windows2000/techinfo/administration/security/sidfilter.asp
+ */
+
+ for (i = 0; i < info3->num_other_sids; i++) {
+ sid_copy(&all_sids[info3->num_groups2 + i + 2],
+ &info3->other_sids[i].sid);
+ j++;
+ }
+
+ for (i = 0; i < j; i++) {
+ fstring sid1, sid2;
+ DEBUG(10, ("User has SID: %s\n",
+ sid_to_string(sid1, &all_sids[i])));
+ if (sid_equal(&require_membership_of_sid, &all_sids[i])) {
+ DEBUG(10, ("SID %s matches %s - user permitted to authenticate!\n",
+ sid_to_string(sid1, &require_membership_of_sid), sid_to_string(sid2, &all_sids[i])));
+ return NT_STATUS_OK;
+ }
+ }
+
+ /* Do not distinguish this error from a wrong username/pw */
+
+ return NT_STATUS_LOGON_FAILURE;
+}
+
+/**********************************************************************
+ Authenticate a user with a clear text password
+**********************************************************************/