Return-Path: Delivered-To: apmail-apr-dev-archive@www.apache.org Received: (qmail 50876 invoked from network); 2 Jan 2011 05:09:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 2 Jan 2011 05:09:30 -0000 Received: (qmail 88024 invoked by uid 500); 2 Jan 2011 05:09:30 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 87691 invoked by uid 500); 2 Jan 2011 05:09:28 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Id: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 87683 invoked by uid 99); 2 Jan 2011 05:09:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 02 Jan 2011 05:09:27 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of bill.speirs@gmail.com designates 209.85.212.50 as permitted sender) Received: from [209.85.212.50] (HELO mail-vw0-f50.google.com) (209.85.212.50) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 02 Jan 2011 05:09:18 +0000 Received: by vws14 with SMTP id 14so5152471vws.37 for ; Sat, 01 Jan 2011 21:08:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=mTOtGKivh9dYNqYmN3beXLYgzAuySlbcZsWytixpXyE=; b=ggOaXhT6v79sbI4u+mYNdTv9Jdq8CF+sSwqrypZzo8Xs4VDDR5SlgA+TI8E264SNHx C7SVonrXQRFdLRospw7jhRKUQ0qKCtf8oxBVeShqlmAD93Os1kIuCpE63FZhPeeDloK2 VmweLn9Xk7LkTHF+MR44+H95cISmJnXQx6O/o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=HPjqikuBsFEfRQ6VU6DJT+QFO7afkjDLLymU8ZJkozhkpW8M3V9MkafG2hxw+g8w6G 8YOiCi8+kYjPtbbeuGeTceScLm1pWYVuB6HRDIpsLNX4FTLrFZtclniJqX7Jo6YHLhB/ FJJAdqSo7elIEEC074Ldsvc5/RTsHUman3uPE= Received: by 10.220.96.204 with SMTP id i12mr1728402vcn.158.1293944937749; Sat, 01 Jan 2011 21:08:57 -0800 (PST) Received: from [192.168.1.100] (c-71-235-103-23.hsd1.ct.comcast.net [71.235.103.23]) by mx.google.com with ESMTPS id c15sm3904468vcs.31.2011.01.01.21.08.56 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 01 Jan 2011 21:08:56 -0800 (PST) Message-ID: <4D200867.3040400@gmail.com> Date: Sun, 02 Jan 2011 00:08:55 -0500 From: William R Speirs User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 MIME-Version: 1.0 To: dev@apr.apache.org Subject: Re: Getting the groups a user belongs to References: <1292004744.78761.ezmlm@apr.apache.org> <4D13BA56.4030603@gmail.com> In-Reply-To: <4D13BA56.4030603@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Bump... Haven't heard anything, but it was over the holidays so I figured most people had checked-out. Thanks... Bill- On 12/23/2010 04:08 PM, William R Speirs wrote: > I took a first stab at the Windows code for this... it's ugly. There is a lot of > apr_wchar_t* <-> char* conversion code. Is there an easier way to do this? > > If not, then maybe it would be helpful to create two functions with the > following signatures that do all of the string length and allocation work for you: > > apr_wchar_t* apr_conv_utf8_to_ucs2(char *str, apr_pool_t *p); > char* apr_conv_ucs2_to_utf8(apr_wchar_t *str, apr_pool_t *p); > > > Here is my code, not sure if this name is 100% consistent with the rest of the > codebase: > > APR_DECLARE(apr_status_t) apr_uid_groups_get(apr_gid_t **groups, int *ngroup, > const char *username, apr_pool_t *p) > { > #ifdef _WIN32_WCE > return APR_ENOTIMPL; > #else > GROUP_USERS_INFO_0 *pGroups = NULL; > DWORD entriesRead = 0; > DWORD totalEntries = 0; > NET_API_STATUS status; > FIXED_INFO *pFixedInfo = NULL; > ULONG infoSize = 0; > DWORD i; > > apr_wchar_t *wUsername; > apr_size_t wUsernameLen; > > apr_wchar_t *fullDomain; > apr_size_t fullDomainLen; > apr_size_t domainLen; > > char *groupName; > > // first call is to get the size > status = GetNetworkParams(pFixedInfo, &infoSize); > > pFixedInfo = (FIXED_INFO*)apr_palloc(p, infoSize); > > // now make the actual call > status = GetNetworkParams(pFixedInfo, &infoSize); > > // printf("DOMAIN: %s\n", pFixedInfo->DomainName); > > if(NERR_Success != status) > return APR_EINVAL; > > // convert the username to an apr_wchar_t > domainLen = lstrlen(username); // re-use of var here > wUsernameLen = lstrlen(username) * sizeof(apr_wchar_t); > wUsername = (apr_wchar_t*)apr_palloc(p, wUsernameLen); > apr_conv_utf8_to_ucs2(username, &domainLen, wUsername, &wUsernameLen); > > // get the length of the domain string > domainLen = lstrlenA(pFixedInfo->DomainName); > > // if there is no domain name, then get local groups > if(0 == domainLen) { > // printf("NO DOMAIN\n"); > > status = NetUserGetLocalGroups(NULL, wUsername, 0, > LG_INCLUDE_INDIRECT, > (LPBYTE*) &pGroups, > MAX_PREFERRED_LENGTH, > &entriesRead, &totalEntries); > > if(NERR_Success != status) { > NetApiBufferFree(pGroups); > return APR_EINVAL; > } > > } else { // we have a domain, get those groups > domainLen = lstrlen(pFixedInfo->DomainName); > fullDomainLen = (2 + domainLen) * sizeof(apr_wchar_t); > fullDomain = (apr_wchar_t*)apr_palloc(p, fullDomainLen); > > // add the \\ to the start of the domain > fullDomain[0] = '\\'; > fullDomain[1] = '\\'; > fullDomainLen -= 2; > > // convert over to an apr_wchar_t > apr_conv_utf8_to_ucs2(pFixedInfo->DomainName, &domainLen, > fullDomain+2, &fullDomainLen); > > status = NetUserGetGroups(fullDomain, wUsername, 0, > (LPBYTE*) &pGroups, > MAX_PREFERRED_LENGTH, > &entriesRead, &totalEntries); > > if(NERR_Success != status) { > NetApiBufferFree(pGroups); > return APR_EINVAL; > } > } > > // allocate space for all of the apr_gid_t > *groups = (apr_gid_t*)apr_palloc(p, entriesRead); > *ngroup = entriesRead; > > // we have all of the groups, but as strings > for(i=0; i < entriesRead; ++i) { > printf("GROUP: %S\n", pGroups[i].grui0_name); > > // convert the wchar_t group name to a char* group name > domainLen = lstrlenW(pGroups[i].grui0_name); > wUsernameLen = domainLen * sizeof(char); > groupName = (char*)apr_palloc(p, wUsernameLen); > apr_conv_ucs2_to_utf8(pGroups[i].grui0_name, &domainLen, > groupName, &wUsernameLen); > > apr_gid_get(*groups[i], groupName, p); > } > > // free the memory associated with the groups > NetApiBufferFree(pGroups); > > return APR_SUCCESS; > > #endif > } > > > > Thoughts? > > Bill- > > On 12/13/2010 09:33 AM, Bill Speirs wrote: >>>> The other issue is that on Windows I get back a char* for the groups; >>>> whereas, on >>>> Unix/Linux I get back a gid list. Is there a preference? Would people rather >>>> a function >>>> that returns a gid list or a char* list? >>> >>> Well, we should treat them as apr_gid_t, which on win32 would devolve to a >>> pointer >>> to a full UUID of the appropriate group (and we then unwind the identifier >>> into a >>> human-readable string with the appropriate apr_group_name_get function). >> >> In Linux this is a non-issue as the function naturally returns >> apr_gid_t; whereas, with Windows I only get back a char* for the >> group. I can call LookupAccountName on each name to get the >> SID/apr_gid_t. If there is a function to get apr_gid_ts for the groups >> a user is a member of, I am unaware of such a function. >> >> Bill-