885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose Unix SMB/CIFS implementation.
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose Winbind client API
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose Copyright (C) Gerald (Jerry) Carter 2007
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose Copyright (C) Volker Lendecke 2010
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose This library is free software; you can redistribute it and/or
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose modify it under the terms of the GNU Lesser General Public
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose License as published by the Free Software Foundation; either
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose version 3 of the License, or (at your option) any later version.
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose This library is distributed in the hope that it will be useful,
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose Library General Public License for more details.
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose You should have received a copy of the GNU Lesser General Public License
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose/* Required Headers */
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose/* Convert a sid to a string into a buffer. Return the string
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose * length. If buflen is too small, return the string length that would
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose * result if it was long enough. */
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Boseint wbcSidToStringBuf(const struct wbcDomainSid *sid, char *buf, int buflen)
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose ofs = snprintf(buf, buflen, "S-%hhu-", (unsigned char)sid->sid_rev_num);
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "0x%llx",
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose (unsigned long long)id_auth);
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "%llu",
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose (unsigned long long)id_auth);
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "-%u",
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose/* Convert a binary SID to a character string */
885386b7e3f1c3e74b354576b98a092b0835d64eSumit BosewbcErr wbcSidToString(const struct wbcDomainSid *sid,
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose result = (char *)wbcAllocateMemory(len+1, 1, NULL);
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose/* Convert a character string to a binary SID */
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose const char *p;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose /* Sanity check for either "S-" or "s-" */
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose /* Get the SID revision number */
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose * Next the Identifier Authority. This is stored big-endian in a
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose * 6 byte array. If the authority value is >= UINT_MAX, then it should
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose * be expressed as a hex value, according to MS-DTYP.
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose x = strtoull(p, &q, 0);
f91029dd8d7dbc026a5c73e222926db957240cb4Yuri Chornoivan /* now read the subauthorities */
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose if (*q != '-') {
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose /* IF we ended early, then the SID could not be converted */
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose if (q && *q!='\0') {
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Boseconst char* wbcSidTypeString(enum wbcSidType type)
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose case WBC_SID_NAME_DOM_GRP: return "SID_DOM_GROUP";
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose case WBC_SID_NAME_WKN_GRP: return "SID_WKN_GROUP";
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose case WBC_SID_NAME_COMPUTER: return "SID_COMPUTER";
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose default: return "Unknown type";