Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (12 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified vendor/current/nsswitch/wbinfo.c

    r414 r740  
    2323
    2424#include "includes.h"
     25#include "popt_common.h"
    2526#include "winbind_client.h"
    2627#include "libwbclient/wbclient.h"
    2728#include "lib/popt/popt.h"
    2829#include "../libcli/auth/libcli_auth.h"
    29 #if !(_SAMBA_VERSION_) < 4
     30#if (_SAMBA_BUILD_) >= 4
    3031#include "lib/cmdline/popt_common.h"
    3132#endif
     
    4849        if (!WBC_ERROR_IS_OK(wbc_status)) {
    4950                d_fprintf(stderr, "could not obtain winbind interface "
    50                                   "details!\n");
     51                                  "details: %s\n", wbcErrorString(wbc_status));
    5152        }
    5253
     
    173174        wbc_status = wbcGetpwnam(user, &pwd);
    174175        if (!WBC_ERROR_IS_OK(wbc_status)) {
     176                d_fprintf(stderr, "failed to call wbcGetpwnam: %s\n",
     177                          wbcErrorString(wbc_status));
    175178                return false;
    176179        }
     
    185188                 pwd->pw_shell);
    186189
     190        wbcFreeMemory(pwd);
     191
    187192        return true;
    188193}
     
    196201        wbc_status = wbcGetpwuid(uid, &pwd);
    197202        if (!WBC_ERROR_IS_OK(wbc_status)) {
     203                d_fprintf(stderr, "failed to call wbcGetpwuid: %s\n",
     204                          wbcErrorString(wbc_status));
    198205                return false;
    199206        }
     
    208215                 pwd->pw_shell);
    209216
     217        wbcFreeMemory(pwd);
     218
    210219        return true;
    211220}
     
    220229        wbc_status = wbcGetpwsid(&sid, &pwd);
    221230        if (!WBC_ERROR_IS_OK(wbc_status)) {
     231                d_fprintf(stderr, "failed to call wbcGetpwsid: %s\n",
     232                          wbcErrorString(wbc_status));
    222233                return false;
    223234        }
     
    245256        wbc_status = wbcGetgrnam(group, &grp);
    246257        if (!WBC_ERROR_IS_OK(wbc_status)) {
     258                d_fprintf(stderr, "failed to call wbcGetgrnam: %s\n",
     259                          wbcErrorString(wbc_status));
    247260                return false;
    248261        }
     
    274287        wbc_status = wbcGetgrgid(gid, &grp);
    275288        if (!WBC_ERROR_IS_OK(wbc_status)) {
     289                d_fprintf(stderr, "failed to call wbcGetgrgid: %s\n",
     290                          wbcErrorString(wbc_status));
    276291                return false;
    277292        }
     
    307322        wbc_status = wbcGetGroups(user, &num_groups, &groups);
    308323        if (!WBC_ERROR_IS_OK(wbc_status)) {
     324                d_fprintf(stderr, "failed to call wbcGetGroups: %s\n",
     325                          wbcErrorString(wbc_status));
    309326                return false;
    310327        }
     
    332349        wbc_status = wbcStringToSid(user_sid_str, &user_sid);
    333350        if (!WBC_ERROR_IS_OK(wbc_status)) {
     351                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     352                          wbcErrorString(wbc_status));
    334353                return false;
    335354        }
     
    337356        wbc_status = wbcLookupUserSids(&user_sid, false, &num_sids, &sids);
    338357        if (!WBC_ERROR_IS_OK(wbc_status)) {
     358                d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n",
     359                          wbcErrorString(wbc_status));
    339360                return false;
    340361        }
    341362
    342363        for (i = 0; i < num_sids; i++) {
    343                 char *str = NULL;
    344                 wbc_status = wbcSidToString(&sids[i], &str);
    345                 if (!WBC_ERROR_IS_OK(wbc_status)) {
    346                         wbcFreeMemory(sids);
    347                         return false;
    348                 }
     364                char str[WBC_SID_STRING_BUFLEN];
     365                wbcSidToStringBuf(&sids[i], str, sizeof(str));
    349366                d_printf("%s\n", str);
    350                 wbcFreeMemory(str);
    351367        }
    352368
     
    367383        wbc_status = wbcStringToSid(user_sid_str, &user_sid);
    368384        if (!WBC_ERROR_IS_OK(wbc_status)) {
     385                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     386                          wbcErrorString(wbc_status));
    369387                return false;
    370388        }
     
    372390        wbc_status = wbcLookupUserSids(&user_sid, true, &num_sids, &sids);
    373391        if (!WBC_ERROR_IS_OK(wbc_status)) {
     392                d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n",
     393                          wbcErrorString(wbc_status));
    374394                return false;
    375395        }
    376396
    377397        for (i = 0; i < num_sids; i++) {
    378                 char *str = NULL;
    379                 wbc_status = wbcSidToString(&sids[i], &str);
    380                 if (!WBC_ERROR_IS_OK(wbc_status)) {
    381                         wbcFreeMemory(sids);
    382                         return false;
    383                 }
     398                char str[WBC_SID_STRING_BUFLEN];
     399                wbcSidToStringBuf(&sids[i], str, sizeof(str));
    384400                d_printf("%s\n", str);
    385                 wbcFreeMemory(str);
    386401        }
    387402
     
    400415        uint32_t *alias_rids = NULL;
    401416        uint32_t num_alias_rids;
    402         char *domain_sid_str = NULL;
     417        char domain_sid_str[WBC_SID_STRING_BUFLEN];
    403418
    404419        /* Send request */
     
    412427        wbc_status = wbcDomainInfo(domain, &dinfo);
    413428        if (!WBC_ERROR_IS_OK(wbc_status)) {
    414                 d_printf("wbcDomainInfo(%s) failed: %s\n", domain,
    415                          wbcErrorString(wbc_status));
     429                d_fprintf(stderr, "wbcDomainInfo(%s) failed: %s\n", domain,
     430                          wbcErrorString(wbc_status));
    416431                goto done;
    417432        }
     
    427442        }
    428443
    429         wbc_status = wbcSidToString(&dinfo->sid, &domain_sid_str);
    430         if (!WBC_ERROR_IS_OK(wbc_status)) {
    431                 goto done;
    432         }
     444        wbcSidToStringBuf(&dinfo->sid, domain_sid_str, sizeof(domain_sid_str));
    433445
    434446        for (i = 0; i < num_alias_rids; i++) {
     
    439451
    440452done:
    441         if (domain_sid_str) {
    442                 wbcFreeMemory(domain_sid_str);
    443         }
    444         if (dinfo) {
    445                 wbcFreeMemory(dinfo);
    446         }
     453        wbcFreeMemory(dinfo);
    447454        return (WBC_ERR_SUCCESS == wbc_status);
    448455}
     
    458465        wbc_status = wbcResolveWinsByName(name, &ip);
    459466        if (!WBC_ERROR_IS_OK(wbc_status)) {
     467                d_fprintf(stderr, "failed to call wbcResolveWinsByName: %s\n",
     468                          wbcErrorString(wbc_status));
    460469                return false;
    461470        }
     
    479488        wbc_status = wbcResolveWinsByIP(ip, &name);
    480489        if (!WBC_ERROR_IS_OK(wbc_status)) {
     490                d_fprintf(stderr, "failed to call wbcResolveWinsByIP: %s\n",
     491                          wbcErrorString(wbc_status));
    481492                return false;
    482493        }
     
    503514        wbc_status = wbcListTrusts(&domain_list, &num_domains);
    504515        if (!WBC_ERROR_IS_OK(wbc_status)) {
     516                d_fprintf(stderr, "failed to call wbcListTrusts: %s\n",
     517                          wbcErrorString(wbc_status));
    505518                return false;
    506519        }
     
    559572        }
    560573
     574        wbcFreeMemory(domain_list);
     575
    561576        return true;
    562577}
     
    589604        wbc_status = wbcListTrusts(&domain_list, &num_domains);
    590605        if (!WBC_ERROR_IS_OK(wbc_status)) {
     606                d_fprintf(stderr, "failed to call wbcListTrusts: %s\n",
     607                          wbcErrorString(wbc_status));
    591608                return false;
    592609        }
     
    609626        }
    610627
     628        wbcFreeMemory(domain_list);
     629
    611630        return true;
    612631}
     
    619638        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    620639        struct wbcDomainInfo *dinfo = NULL;
    621         char *sid_str = NULL;
     640        char sid_str[WBC_SID_STRING_BUFLEN];
    622641
    623642        if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
     
    629648        wbc_status = wbcDomainInfo(domain, &dinfo);
    630649        if (!WBC_ERROR_IS_OK(wbc_status)) {
    631                 return false;
    632         }
    633 
    634         wbc_status = wbcSidToString(&dinfo->sid, &sid_str);
    635         if (!WBC_ERROR_IS_OK(wbc_status)) {
    636                 wbcFreeMemory(dinfo);
    637                 return false;
    638         }
     650                d_fprintf(stderr, "failed to call wbcDomainInfo: %s\n",
     651                          wbcErrorString(wbc_status));
     652                return false;
     653        }
     654
     655        wbcSidToStringBuf(&dinfo->sid, sid_str, sizeof(sid_str));
    639656
    640657        /* Display response */
     
    655672                 "Yes" : "No");
    656673
    657         wbcFreeMemory(sid_str);
    658674        wbcFreeMemory(dinfo);
    659675
     
    743759        }
    744760        if (!WBC_ERROR_IS_OK(wbc_status)) {
    745                 return false;
    746         }
     761                d_fprintf(stderr, "failed to call wbcCheckTrustCredentials: "
     762                          "%s\n", wbcErrorString(wbc_status));
     763                return false;
     764        }
     765
     766        return true;
     767}
     768
     769/* Find the currently connected DCs */
     770
     771static bool wbinfo_dc_info(const char *domain_name)
     772{
     773        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     774        size_t i, num_dcs;
     775        const char **dc_names, **dc_ips;
     776
     777        wbc_status = wbcDcInfo(domain_name, &num_dcs,
     778                               &dc_names, &dc_ips);
     779        if (!WBC_ERROR_IS_OK(wbc_status)) {
     780                printf("Could not find dc info %s\n",
     781                       domain_name ? domain_name : "our domain");
     782                return false;
     783        }
     784
     785        for (i=0; i<num_dcs; i++) {
     786                printf("%s (%s)\n", dc_names[i], dc_ips[i]);
     787        }
     788        wbcFreeMemory(dc_names);
     789        wbcFreeMemory(dc_ips);
    747790
    748791        return true;
     
    775818        }
    776819        if (!WBC_ERROR_IS_OK(wbc_status)) {
     820                d_fprintf(stderr, "failed to call wbcChangeTrustCredentials: "
     821                          "%s\n", wbcErrorString(wbc_status));
    777822                return false;
    778823        }
     
    799844        }
    800845        if (!WBC_ERROR_IS_OK(wbc_status)) {
     846                d_fprintf(stderr, "failed to call wbcPingDc: %s\n",
     847                          wbcErrorString(wbc_status));
    801848                return false;
    802849        }
     
    811858        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    812859        struct wbcDomainSid sid;
    813         char *sid_str = NULL;
     860        char sid_str[WBC_SID_STRING_BUFLEN];
    814861
    815862        /* Send request */
     
    817864        wbc_status = wbcUidToSid(uid, &sid);
    818865        if (!WBC_ERROR_IS_OK(wbc_status)) {
    819                 return false;
    820         }
    821 
    822         wbc_status = wbcSidToString(&sid, &sid_str);
    823         if (!WBC_ERROR_IS_OK(wbc_status)) {
    824                 return false;
    825         }
     866                d_fprintf(stderr, "failed to call wbcUidToSid: %s\n",
     867                          wbcErrorString(wbc_status));
     868                return false;
     869        }
     870
     871        wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str));
    826872
    827873        /* Display response */
     
    829875        d_printf("%s\n", sid_str);
    830876
    831         wbcFreeMemory(sid_str);
    832 
    833877        return true;
    834878}
     
    840884        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    841885        struct wbcDomainSid sid;
    842         char *sid_str = NULL;
     886        char sid_str[WBC_SID_STRING_BUFLEN];
    843887
    844888        /* Send request */
     
    846890        wbc_status = wbcGidToSid(gid, &sid);
    847891        if (!WBC_ERROR_IS_OK(wbc_status)) {
    848                 return false;
    849         }
    850 
    851         wbc_status = wbcSidToString(&sid, &sid_str);
    852         if (!WBC_ERROR_IS_OK(wbc_status)) {
    853                 return false;
    854         }
     892                d_fprintf(stderr, "failed to call wbcGidToSid: %s\n",
     893                          wbcErrorString(wbc_status));
     894                return false;
     895        }
     896
     897        wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str));
    855898
    856899        /* Display response */
    857900
    858901        d_printf("%s\n", sid_str);
    859 
    860         wbcFreeMemory(sid_str);
    861902
    862903        return true;
     
    875916        wbc_status = wbcStringToSid(sid_str, &sid);
    876917        if (!WBC_ERROR_IS_OK(wbc_status)) {
     918                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     919                          wbcErrorString(wbc_status));
    877920                return false;
    878921        }
     
    880923        wbc_status = wbcSidToUid(&sid, &uid);
    881924        if (!WBC_ERROR_IS_OK(wbc_status)) {
     925                d_fprintf(stderr, "failed to call wbcSidToUid: %s\n",
     926                          wbcErrorString(wbc_status));
    882927                return false;
    883928        }
     
    900945        wbc_status = wbcStringToSid(sid_str, &sid);
    901946        if (!WBC_ERROR_IS_OK(wbc_status)) {
     947                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     948                          wbcErrorString(wbc_status));
    902949                return false;
    903950        }
     
    905952        wbc_status = wbcSidToGid(&sid, &gid);
    906953        if (!WBC_ERROR_IS_OK(wbc_status)) {
     954                d_fprintf(stderr, "failed to call wbcSidToGid: %s\n",
     955                          wbcErrorString(wbc_status));
    907956                return false;
    908957        }
     
    915964}
    916965
     966static bool wbinfo_sids_to_unix_ids(const char *arg)
     967{
     968        char sidstr[WBC_SID_STRING_BUFLEN];
     969        struct wbcDomainSid *sids;
     970        struct wbcUnixId *unix_ids;
     971        int i, num_sids;
     972        const char *p;
     973        wbcErr wbc_status;
     974
     975
     976        num_sids = 0;
     977        sids = NULL;
     978        p = arg;
     979
     980        while (next_token(&p, sidstr, LIST_SEP, sizeof(sidstr))) {
     981                sids = talloc_realloc(talloc_tos(), sids, struct wbcDomainSid,
     982                                      num_sids+1);
     983                if (sids == NULL) {
     984                        d_fprintf(stderr, "talloc failed\n");
     985                        return false;
     986                }
     987                wbc_status = wbcStringToSid(sidstr, &sids[num_sids]);
     988                if (!WBC_ERROR_IS_OK(wbc_status)) {
     989                        d_fprintf(stderr, "wbcSidToString(%s) failed: %s\n",
     990                                  sidstr, wbcErrorString(wbc_status));
     991                        TALLOC_FREE(sids);
     992                        return false;
     993                }
     994                num_sids += 1;
     995        }
     996
     997        unix_ids = talloc_array(talloc_tos(), struct wbcUnixId, num_sids);
     998        if (unix_ids == NULL) {
     999                TALLOC_FREE(sids);
     1000                return false;
     1001        }
     1002
     1003        wbc_status = wbcSidsToUnixIds(sids, num_sids, unix_ids);
     1004        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1005                d_fprintf(stderr, "wbcSidsToUnixIds failed: %s\n",
     1006                          wbcErrorString(wbc_status));
     1007                TALLOC_FREE(sids);
     1008                return false;
     1009        }
     1010
     1011        for (i=0; i<num_sids; i++) {
     1012
     1013                wbcSidToStringBuf(&sids[i], sidstr, sizeof(sidstr));
     1014
     1015                switch(unix_ids[i].type) {
     1016                case WBC_ID_TYPE_UID:
     1017                        d_printf("%s -> uid %d\n", sidstr, unix_ids[i].id.uid);
     1018                        break;
     1019                case WBC_ID_TYPE_GID:
     1020                        d_printf("%s -> gid %d\n", sidstr, unix_ids[i].id.gid);
     1021                        break;
     1022                default:
     1023                        d_printf("%s -> unmapped\n", sidstr);
     1024                        break;
     1025                }
     1026        }
     1027
     1028        TALLOC_FREE(sids);
     1029        TALLOC_FREE(unix_ids);
     1030
     1031        return true;
     1032}
     1033
    9171034static bool wbinfo_allocate_uid(void)
    9181035{
     
    9241041        wbc_status = wbcAllocateUid(&uid);
    9251042        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1043                d_fprintf(stderr, "failed to call wbcAllocateUid: %s\n",
     1044                          wbcErrorString(wbc_status));
    9261045                return false;
    9271046        }
     
    9431062        wbc_status = wbcAllocateGid(&gid);
    9441063        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1064                d_fprintf(stderr, "failed to call wbcAllocateGid: %s\n",
     1065                          wbcErrorString(wbc_status));
    9451066                return false;
    9461067        }
     
    9621083        wbc_status = wbcStringToSid(sid_str, &sid);
    9631084        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1085                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     1086                          wbcErrorString(wbc_status));
    9641087                return false;
    9651088        }
     
    9671090        wbc_status = wbcSetUidMapping(uid, &sid);
    9681091        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1092                d_fprintf(stderr, "failed to call wbcSetUidMapping: %s\n",
     1093                          wbcErrorString(wbc_status));
    9691094                return false;
    9701095        }
     
    9871112        wbc_status = wbcStringToSid(sid_str, &sid);
    9881113        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1114                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     1115                          wbcErrorString(wbc_status));
    9891116                return false;
    9901117        }
     
    9921119        wbc_status = wbcSetGidMapping(gid, &sid);
    9931120        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1121                d_fprintf(stderr, "failed to call wbcSetGidMapping: %s\n",
     1122                          wbcErrorString(wbc_status));
    9941123                return false;
    9951124        }
     
    10121141        wbc_status = wbcStringToSid(sid_str, &sid);
    10131142        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1143                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     1144                          wbcErrorString(wbc_status));
    10141145                return false;
    10151146        }
     
    10171148        wbc_status = wbcRemoveUidMapping(uid, &sid);
    10181149        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1150                d_fprintf(stderr, "failed to call wbcRemoveUidMapping: %s\n",
     1151                          wbcErrorString(wbc_status));
    10191152                return false;
    10201153        }
     
    10371170        wbc_status = wbcStringToSid(sid_str, &sid);
    10381171        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1172                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     1173                          wbcErrorString(wbc_status));
    10391174                return false;
    10401175        }
     
    10421177        wbc_status = wbcRemoveGidMapping(gid, &sid);
    10431178        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1179                d_fprintf(stderr, "failed to call wbcRemoveGidMapping: %s\n",
     1180                          wbcErrorString(wbc_status));
    10441181                return false;
    10451182        }
     
    10671204        wbc_status = wbcStringToSid(sid_str, &sid);
    10681205        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1206                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     1207                          wbcErrorString(wbc_status));
    10691208                return false;
    10701209        }
     
    10721211        wbc_status = wbcLookupSid(&sid, &domain, &name, &type);
    10731212        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1213                d_fprintf(stderr, "failed to call wbcLookupSid: %s\n",
     1214                          wbcErrorString(wbc_status));
    10741215                return false;
    10751216        }
     
    10971238        wbc_status = wbcStringToSid(sid_str, &sid);
    10981239        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1240                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     1241                          wbcErrorString(wbc_status));
    10991242                return false;
    11001243        }
     
    11021245        wbc_status = wbcGetDisplayName(&sid, &domain, &name, &type);
    11031246        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1247                d_fprintf(stderr, "failed to call wbcGetDisplayName: %s\n",
     1248                          wbcErrorString(wbc_status));
    11041249                return false;
    11051250        }
     
    11851330        ret = true;
    11861331done:
    1187         if (dinfo) {
    1188                 wbcFreeMemory(dinfo);
    1189         }
    1190         if (domain_name) {
    1191                 wbcFreeMemory(domain_name);
    1192         }
    1193         if (names) {
    1194                 wbcFreeMemory(names);
    1195         }
    1196         if (types) {
    1197                 wbcFreeMemory(types);
    1198         }
     1332        wbcFreeMemory(dinfo);
     1333        wbcFreeMemory(domain_name);
     1334        wbcFreeMemory(names);
     1335        wbcFreeMemory(types);
    11991336        TALLOC_FREE(mem_ctx);
    12001337        return ret;
    12011338}
    12021339
     1340static bool wbinfo_lookup_sids(const char *arg)
     1341{
     1342        char sidstr[WBC_SID_STRING_BUFLEN];
     1343        struct wbcDomainSid *sids;
     1344        struct wbcDomainInfo *domains;
     1345        struct wbcTranslatedName *names;
     1346        int num_domains;
     1347        int i, num_sids;
     1348        const char *p;
     1349        wbcErr wbc_status;
     1350
     1351
     1352        num_sids = 0;
     1353        sids = NULL;
     1354        p = arg;
     1355
     1356        while (next_token(&p, sidstr, LIST_SEP, sizeof(sidstr))) {
     1357                sids = talloc_realloc(talloc_tos(), sids, struct wbcDomainSid,
     1358                                      num_sids+1);
     1359                if (sids == NULL) {
     1360                        d_fprintf(stderr, "talloc failed\n");
     1361                        return false;
     1362                }
     1363                wbc_status = wbcStringToSid(sidstr, &sids[num_sids]);
     1364                if (!WBC_ERROR_IS_OK(wbc_status)) {
     1365                        d_fprintf(stderr, "wbcSidToString(%s) failed: %s\n",
     1366                                  sidstr, wbcErrorString(wbc_status));
     1367                        TALLOC_FREE(sids);
     1368                        return false;
     1369                }
     1370                num_sids += 1;
     1371        }
     1372
     1373        wbc_status = wbcLookupSids(sids, num_sids, &domains, &num_domains,
     1374                                   &names);
     1375        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1376                d_fprintf(stderr, "wbcLookupSids failed: %s\n",
     1377                          wbcErrorString(wbc_status));
     1378                TALLOC_FREE(sids);
     1379                return false;
     1380        }
     1381
     1382        for (i=0; i<num_sids; i++) {
     1383                wbcSidToStringBuf(&sids[i], sidstr, sizeof(sidstr));
     1384
     1385                d_printf("%s -> %s\\%s %d\n", sidstr,
     1386                         domains[names[i].domain_index].short_name,
     1387                         names[i].name, names[i].type);
     1388        }
     1389        return true;
     1390}
     1391
    12031392/* Convert string to sid */
    12041393
     
    12071396        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    12081397        struct wbcDomainSid sid;
    1209         char *sid_str;
     1398        char sid_str[WBC_SID_STRING_BUFLEN];
    12101399        enum wbcSidType type;
    12111400        fstring domain_name;
     
    12201409                                   &sid, &type);
    12211410        if (!WBC_ERROR_IS_OK(wbc_status)) {
    1222                 return false;
    1223         }
    1224 
    1225         wbc_status = wbcSidToString(&sid, &sid_str);
    1226         if (!WBC_ERROR_IS_OK(wbc_status)) {
    1227                 return false;
    1228         }
     1411                d_fprintf(stderr, "failed to call wbcLookupName: %s\n",
     1412                          wbcErrorString(wbc_status));
     1413                return false;
     1414        }
     1415
     1416        wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str));
    12291417
    12301418        /* Display response */
    12311419
    12321420        d_printf("%s %s (%d)\n", sid_str, wbcSidTypeString(type), type);
    1233 
    1234         wbcFreeMemory(sid_str);
    12351421
    12361422        return true;
     
    13121498                                     sizeof(flags));
    13131499        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1500                d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
     1501                          wbcErrorString(wbc_status));
    13141502                goto done;
    13151503        }
     
    13221510                                     sizeof(uid));
    13231511        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1512                d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
     1513                          wbcErrorString(wbc_status));
    13241514                goto done;
    13251515        }
     
    13321522                                     strlen(cctype)+1);
    13331523        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1524                d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
     1525                          wbcErrorString(wbc_status));
    13341526                goto done;
    13351527        }
     
    13441536        if (error) {
    13451537                d_fprintf(stderr,
    1346                          "error code was %s (0x%x)\nerror messsage was: %s\n",
     1538                         "error code was %s (0x%x)\nerror message was: %s\n",
    13471539                         error->nt_string,
    13481540                         error->nt_status,
     
    14151607        if (response.data.auth.nt_status)
    14161608                d_fprintf(stderr,
    1417                          "error code was %s (0x%x)\nerror messsage was: %s\n",
     1609                         "error code was %s (0x%x)\nerror message was: %s\n",
    14181610                         response.data.auth.nt_status_string,
    14191611                         response.data.auth.nt_status,
     
    15161708        if (wbc_status == WBC_ERR_AUTH_ERROR) {
    15171709                d_fprintf(stderr,
    1518                          "error code was %s (0x%x)\nerror messsage was: %s\n",
     1710                         "error code was %s (0x%x)\nerror message was: %s\n",
    15191711                         err->nt_string,
    15201712                         err->nt_status,
     
    15291721
    15301722        return WBC_ERROR_IS_OK(wbc_status);
     1723}
     1724
     1725/* Authenticate a user with a plaintext password */
     1726
     1727static bool wbinfo_pam_logon(char *username)
     1728{
     1729        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     1730        struct wbcLogonUserParams params;
     1731        struct wbcAuthErrorInfo *error;
     1732        char *s = NULL;
     1733        char *p = NULL;
     1734        TALLOC_CTX *frame = talloc_tos();
     1735        uint32_t flags;
     1736        uint32_t uid;
     1737
     1738        ZERO_STRUCT(params);
     1739
     1740        if ((s = talloc_strdup(frame, username)) == NULL) {
     1741                return false;
     1742        }
     1743
     1744        if ((p = strchr(s, '%')) != NULL) {
     1745                *p = 0;
     1746                p++;
     1747                params.password = talloc_strdup(frame, p);
     1748        } else {
     1749                params.password = wbinfo_prompt_pass(frame, NULL, username);
     1750        }
     1751        params.username = s;
     1752
     1753        flags = WBFLAG_PAM_CACHED_LOGIN;
     1754
     1755        wbc_status = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
     1756                                     "flags", 0,
     1757                                     (uint8_t *)&flags, sizeof(flags));
     1758        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1759                d_printf("wbcAddNamedBlob failed: %s\n",
     1760                         wbcErrorString(wbc_status));
     1761                return false;
     1762        }
     1763
     1764        uid = getuid();
     1765
     1766        wbc_status = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
     1767                                     "user_uid", 0,
     1768                                     (uint8_t *)&uid, sizeof(uid));
     1769        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1770                d_printf("wbcAddNamedBlob failed: %s\n",
     1771                         wbcErrorString(wbc_status));
     1772                return false;
     1773        }
     1774
     1775        wbc_status = wbcLogonUser(&params, NULL, &error, NULL);
     1776
     1777        wbcFreeMemory(params.blobs);
     1778
     1779        d_printf("plaintext password authentication %s\n",
     1780                 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
     1781
     1782        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1783                d_fprintf(stderr,
     1784                          "error code was %s (0x%x)\nerror message was: %s\n",
     1785                          error->nt_string,
     1786                          (int)error->nt_status,
     1787                          error->display_string);
     1788                wbcFreeMemory(error);
     1789                return false;
     1790        }
     1791        return true;
    15311792}
    15321793
     
    16071868        if (response.data.auth.nt_status)
    16081869                d_fprintf(stderr,
    1609                          "error code was %s (0x%x)\nerror messsage was: %s\n",
     1870                         "error code was %s (0x%x)\nerror message was: %s\n",
    16101871                         response.data.auth.nt_status_string,
    16111872                         response.data.auth.nt_status,
     
    16841945        wbc_status = wbcListGroups(domain, &num_groups, &groups);
    16851946        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1947                d_fprintf(stderr, "failed to call wbcListGroups: %s\n",
     1948                          wbcErrorString(wbc_status));
    16861949                return false;
    16871950        }
     
    17542017        OPT_GETDCNAME,
    17552018        OPT_DSGETDCNAME,
     2019        OPT_DC_INFO,
    17562020        OPT_USERDOMGROUPS,
    17572021        OPT_SIDALIASES,
    17582022        OPT_USERSIDS,
     2023        OPT_LOOKUP_SIDS,
    17592024        OPT_ALLOCATE_UID,
    17602025        OPT_ALLOCATE_GID,
     
    17632028        OPT_REMOVE_UID_MAPPING,
    17642029        OPT_REMOVE_GID_MAPPING,
     2030        OPT_SIDS_TO_XIDS,
    17652031        OPT_SEPARATOR,
    17662032        OPT_LIST_ALL_DOMAINS,
     
    17732039        OPT_ONLINESTATUS,
    17742040        OPT_CHANGE_USER_PASSWORD,
    1775         OPT_PING_DC,
    17762041        OPT_CCACHE_SAVE,
    17772042        OPT_SID_TO_FULLNAME,
    17782043        OPT_NTLMV2,
     2044        OPT_PAM_LOGON,
     2045        OPT_LOGOFF,
     2046        OPT_LOGOFF_USER,
     2047        OPT_LOGOFF_UID,
    17792048        OPT_LANMAN
    17802049};
     
    17942063        bool use_ntlmv2 = false;
    17952064        bool use_lanman = false;
     2065        char *logoff_user = getenv("USER");
     2066        int logoff_uid = geteuid();
    17962067
    17972068        struct poptOption long_options[] = {
     
    18102081                  OPT_SID_TO_FULLNAME, "Converts sid to fullname", "SID" },
    18112082                { "lookup-rids", 'R', POPT_ARG_STRING, &string_arg, 'R', "Converts RIDs to names", "RIDs" },
     2083                { "lookup-sids", 0, POPT_ARG_STRING, &string_arg,
     2084                  OPT_LOOKUP_SIDS, "Converts SIDs to types and names",
     2085                  "Sid-List"},
    18122086                { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" },
    18132087                { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" },
     
    18222096                { "remove-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_UID_MAPPING, "Remove uid to sid mapping in idmap", "UID,SID" },
    18232097                { "remove-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_GID_MAPPING, "Remove gid to sid mapping in idmap", "GID,SID" },
     2098                { "sids-to-unix-ids", 0, POPT_ARG_STRING, &string_arg,
     2099                  OPT_SIDS_TO_XIDS, "Translate SIDs to Unix IDs", "Sid-List" },
    18242100                { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
    18252101                { "change-secret", 'c', POPT_ARG_NONE, 0, 'c', "Change shared secret" },
    1826                 { "ping-dc", 0, POPT_ARG_NONE, 0, OPT_PING_DC,
     2102                { "ping-dc", 'P', POPT_ARG_NONE, 0, 'P',
    18272103                  "Check the NETLOGON connection" },
    18282104                { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
    18292105                { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
    18302106                { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" },
    1831                 { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Show sequence numbers of all domains" },
     2107                { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Deprecated command, see --online-status" },
    18322108                { "online-status", 0, POPT_ARG_NONE, 0, OPT_ONLINESTATUS, "Show whether domains are marked as online or offline"},
    18332109                { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" },
     
    18432119                { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" },
    18442120                { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" },
     2121                { "pam-logon", 0, POPT_ARG_STRING, &string_arg, OPT_PAM_LOGON,
     2122                  "do a pam logon equivalent", "user%password" },
     2123                { "logoff", 0, POPT_ARG_NONE, NULL, OPT_LOGOFF,
     2124                  "log off user", "uid" },
     2125                { "logoff-user", 0, POPT_ARG_STRING, &logoff_user,
     2126                  OPT_LOGOFF_USER, "username to log off" },
     2127                { "logoff-uid", 0, POPT_ARG_INT, &logoff_uid,
     2128                  OPT_LOGOFF_UID, "uid to log off" },
    18452129                { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
    18462130                { "ccache-save", 0, POPT_ARG_STRING, &string_arg,
     
    18502134                  "Get a DC name for a foreign domain", "domainname" },
    18512135                { "dsgetdcname", 0, POPT_ARG_STRING, &string_arg, OPT_DSGETDCNAME, "Find a DC for a domain", "domainname" },
     2136                { "dc-info", 0, POPT_ARG_STRING, &string_arg, OPT_DC_INFO,
     2137                  "Find the currently known DCs", "domainname" },
    18522138                { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
    18532139                { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
     
    19442230                        }
    19452231                        break;
     2232                case OPT_LOOKUP_SIDS:
     2233                        if (!wbinfo_lookup_sids(string_arg)) {
     2234                                d_fprintf(stderr, "Could not lookup SIDs %s\n",
     2235                                          string_arg);
     2236                                goto done;
     2237                        }
     2238                        break;
    19462239                case 'n':
    19472240                        if (!wbinfo_lookupname(string_arg)) {
     
    20532346                        }
    20542347                        break;
     2348                case OPT_SIDS_TO_XIDS:
     2349                        if (!wbinfo_sids_to_unix_ids(string_arg)) {
     2350                                d_fprintf(stderr, "wbinfo_sids_to_unix_ids "
     2351                                          "failed\n");
     2352                                goto done;
     2353                        }
     2354                        break;
    20552355                case 't':
    20562356                        if (!wbinfo_check_secret(opt_domain_name)) {
     
    20652365                        }
    20662366                        break;
    2067                 case OPT_PING_DC:
     2367                case 'P':
    20682368                        if (!wbinfo_ping_dc()) {
    20692369                                d_fprintf(stderr, "Could not ping our DC\n");
     
    21922492                                break;
    21932493                        }
     2494                case OPT_PAM_LOGON:
     2495                        if (!wbinfo_pam_logon(string_arg)) {
     2496                                d_fprintf(stderr, "pam_logon failed for %s\n",
     2497                                          string_arg);
     2498                                goto done;
     2499                        }
     2500                        break;
     2501                case OPT_LOGOFF:
     2502                {
     2503                        wbcErr wbc_status;
     2504
     2505                        wbc_status = wbcLogoffUser(logoff_user, logoff_uid,
     2506                                                   "");
     2507                        d_printf("Logoff %s (%d): %s\n", logoff_user,
     2508                                 logoff_uid, wbcErrorString(wbc_status));
     2509                        break;
     2510                }
    21942511                case 'K': {
    21952512                                uint32_t flags = WBFLAG_PAM_KRB5 |
     
    22462563                        }
    22472564                        break;
     2565                case OPT_DC_INFO:
     2566                        if (!wbinfo_dc_info(string_arg)) {
     2567                                goto done;
     2568                        }
     2569                        break;
    22482570                case OPT_SEPARATOR: {
    22492571                        const char sep = winbind_separator();
     
    22752597                /* generic configuration options */
    22762598                case OPT_DOMAIN_NAME:
    2277                         break;
    22782599                case OPT_VERBOSE:
    2279                         break;
    22802600                case OPT_NTLMV2:
    2281                         break;
    22822601                case OPT_LANMAN:
     2602                case OPT_LOGOFF_USER:
     2603                case OPT_LOGOFF_UID:
    22832604                        break;
    22842605                default:
Note: See TracChangeset for help on using the changeset viewer.