Changeset 740 for vendor/current/nsswitch/wbinfo.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified vendor/current/nsswitch/wbinfo.c ¶
r414 r740 23 23 24 24 #include "includes.h" 25 #include "popt_common.h" 25 26 #include "winbind_client.h" 26 27 #include "libwbclient/wbclient.h" 27 28 #include "lib/popt/popt.h" 28 29 #include "../libcli/auth/libcli_auth.h" 29 #if !(_SAMBA_VERSION_) <430 #if (_SAMBA_BUILD_) >= 4 30 31 #include "lib/cmdline/popt_common.h" 31 32 #endif … … 48 49 if (!WBC_ERROR_IS_OK(wbc_status)) { 49 50 d_fprintf(stderr, "could not obtain winbind interface " 50 "details !\n");51 "details: %s\n", wbcErrorString(wbc_status)); 51 52 } 52 53 … … 173 174 wbc_status = wbcGetpwnam(user, &pwd); 174 175 if (!WBC_ERROR_IS_OK(wbc_status)) { 176 d_fprintf(stderr, "failed to call wbcGetpwnam: %s\n", 177 wbcErrorString(wbc_status)); 175 178 return false; 176 179 } … … 185 188 pwd->pw_shell); 186 189 190 wbcFreeMemory(pwd); 191 187 192 return true; 188 193 } … … 196 201 wbc_status = wbcGetpwuid(uid, &pwd); 197 202 if (!WBC_ERROR_IS_OK(wbc_status)) { 203 d_fprintf(stderr, "failed to call wbcGetpwuid: %s\n", 204 wbcErrorString(wbc_status)); 198 205 return false; 199 206 } … … 208 215 pwd->pw_shell); 209 216 217 wbcFreeMemory(pwd); 218 210 219 return true; 211 220 } … … 220 229 wbc_status = wbcGetpwsid(&sid, &pwd); 221 230 if (!WBC_ERROR_IS_OK(wbc_status)) { 231 d_fprintf(stderr, "failed to call wbcGetpwsid: %s\n", 232 wbcErrorString(wbc_status)); 222 233 return false; 223 234 } … … 245 256 wbc_status = wbcGetgrnam(group, &grp); 246 257 if (!WBC_ERROR_IS_OK(wbc_status)) { 258 d_fprintf(stderr, "failed to call wbcGetgrnam: %s\n", 259 wbcErrorString(wbc_status)); 247 260 return false; 248 261 } … … 274 287 wbc_status = wbcGetgrgid(gid, &grp); 275 288 if (!WBC_ERROR_IS_OK(wbc_status)) { 289 d_fprintf(stderr, "failed to call wbcGetgrgid: %s\n", 290 wbcErrorString(wbc_status)); 276 291 return false; 277 292 } … … 307 322 wbc_status = wbcGetGroups(user, &num_groups, &groups); 308 323 if (!WBC_ERROR_IS_OK(wbc_status)) { 324 d_fprintf(stderr, "failed to call wbcGetGroups: %s\n", 325 wbcErrorString(wbc_status)); 309 326 return false; 310 327 } … … 332 349 wbc_status = wbcStringToSid(user_sid_str, &user_sid); 333 350 if (!WBC_ERROR_IS_OK(wbc_status)) { 351 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 352 wbcErrorString(wbc_status)); 334 353 return false; 335 354 } … … 337 356 wbc_status = wbcLookupUserSids(&user_sid, false, &num_sids, &sids); 338 357 if (!WBC_ERROR_IS_OK(wbc_status)) { 358 d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n", 359 wbcErrorString(wbc_status)); 339 360 return false; 340 361 } 341 362 342 363 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)); 349 366 d_printf("%s\n", str); 350 wbcFreeMemory(str);351 367 } 352 368 … … 367 383 wbc_status = wbcStringToSid(user_sid_str, &user_sid); 368 384 if (!WBC_ERROR_IS_OK(wbc_status)) { 385 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 386 wbcErrorString(wbc_status)); 369 387 return false; 370 388 } … … 372 390 wbc_status = wbcLookupUserSids(&user_sid, true, &num_sids, &sids); 373 391 if (!WBC_ERROR_IS_OK(wbc_status)) { 392 d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n", 393 wbcErrorString(wbc_status)); 374 394 return false; 375 395 } 376 396 377 397 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)); 384 400 d_printf("%s\n", str); 385 wbcFreeMemory(str);386 401 } 387 402 … … 400 415 uint32_t *alias_rids = NULL; 401 416 uint32_t num_alias_rids; 402 char *domain_sid_str = NULL;417 char domain_sid_str[WBC_SID_STRING_BUFLEN]; 403 418 404 419 /* Send request */ … … 412 427 wbc_status = wbcDomainInfo(domain, &dinfo); 413 428 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)); 416 431 goto done; 417 432 } … … 427 442 } 428 443 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)); 433 445 434 446 for (i = 0; i < num_alias_rids; i++) { … … 439 451 440 452 done: 441 if (domain_sid_str) { 442 wbcFreeMemory(domain_sid_str); 443 } 444 if (dinfo) { 445 wbcFreeMemory(dinfo); 446 } 453 wbcFreeMemory(dinfo); 447 454 return (WBC_ERR_SUCCESS == wbc_status); 448 455 } … … 458 465 wbc_status = wbcResolveWinsByName(name, &ip); 459 466 if (!WBC_ERROR_IS_OK(wbc_status)) { 467 d_fprintf(stderr, "failed to call wbcResolveWinsByName: %s\n", 468 wbcErrorString(wbc_status)); 460 469 return false; 461 470 } … … 479 488 wbc_status = wbcResolveWinsByIP(ip, &name); 480 489 if (!WBC_ERROR_IS_OK(wbc_status)) { 490 d_fprintf(stderr, "failed to call wbcResolveWinsByIP: %s\n", 491 wbcErrorString(wbc_status)); 481 492 return false; 482 493 } … … 503 514 wbc_status = wbcListTrusts(&domain_list, &num_domains); 504 515 if (!WBC_ERROR_IS_OK(wbc_status)) { 516 d_fprintf(stderr, "failed to call wbcListTrusts: %s\n", 517 wbcErrorString(wbc_status)); 505 518 return false; 506 519 } … … 559 572 } 560 573 574 wbcFreeMemory(domain_list); 575 561 576 return true; 562 577 } … … 589 604 wbc_status = wbcListTrusts(&domain_list, &num_domains); 590 605 if (!WBC_ERROR_IS_OK(wbc_status)) { 606 d_fprintf(stderr, "failed to call wbcListTrusts: %s\n", 607 wbcErrorString(wbc_status)); 591 608 return false; 592 609 } … … 609 626 } 610 627 628 wbcFreeMemory(domain_list); 629 611 630 return true; 612 631 } … … 619 638 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 620 639 struct wbcDomainInfo *dinfo = NULL; 621 char *sid_str = NULL;640 char sid_str[WBC_SID_STRING_BUFLEN]; 622 641 623 642 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){ … … 629 648 wbc_status = wbcDomainInfo(domain, &dinfo); 630 649 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)); 639 656 640 657 /* Display response */ … … 655 672 "Yes" : "No"); 656 673 657 wbcFreeMemory(sid_str);658 674 wbcFreeMemory(dinfo); 659 675 … … 743 759 } 744 760 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 771 static 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); 747 790 748 791 return true; … … 775 818 } 776 819 if (!WBC_ERROR_IS_OK(wbc_status)) { 820 d_fprintf(stderr, "failed to call wbcChangeTrustCredentials: " 821 "%s\n", wbcErrorString(wbc_status)); 777 822 return false; 778 823 } … … 799 844 } 800 845 if (!WBC_ERROR_IS_OK(wbc_status)) { 846 d_fprintf(stderr, "failed to call wbcPingDc: %s\n", 847 wbcErrorString(wbc_status)); 801 848 return false; 802 849 } … … 811 858 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 812 859 struct wbcDomainSid sid; 813 char *sid_str = NULL;860 char sid_str[WBC_SID_STRING_BUFLEN]; 814 861 815 862 /* Send request */ … … 817 864 wbc_status = wbcUidToSid(uid, &sid); 818 865 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)); 826 872 827 873 /* Display response */ … … 829 875 d_printf("%s\n", sid_str); 830 876 831 wbcFreeMemory(sid_str);832 833 877 return true; 834 878 } … … 840 884 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 841 885 struct wbcDomainSid sid; 842 char *sid_str = NULL;886 char sid_str[WBC_SID_STRING_BUFLEN]; 843 887 844 888 /* Send request */ … … 846 890 wbc_status = wbcGidToSid(gid, &sid); 847 891 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)); 855 898 856 899 /* Display response */ 857 900 858 901 d_printf("%s\n", sid_str); 859 860 wbcFreeMemory(sid_str);861 902 862 903 return true; … … 875 916 wbc_status = wbcStringToSid(sid_str, &sid); 876 917 if (!WBC_ERROR_IS_OK(wbc_status)) { 918 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 919 wbcErrorString(wbc_status)); 877 920 return false; 878 921 } … … 880 923 wbc_status = wbcSidToUid(&sid, &uid); 881 924 if (!WBC_ERROR_IS_OK(wbc_status)) { 925 d_fprintf(stderr, "failed to call wbcSidToUid: %s\n", 926 wbcErrorString(wbc_status)); 882 927 return false; 883 928 } … … 900 945 wbc_status = wbcStringToSid(sid_str, &sid); 901 946 if (!WBC_ERROR_IS_OK(wbc_status)) { 947 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 948 wbcErrorString(wbc_status)); 902 949 return false; 903 950 } … … 905 952 wbc_status = wbcSidToGid(&sid, &gid); 906 953 if (!WBC_ERROR_IS_OK(wbc_status)) { 954 d_fprintf(stderr, "failed to call wbcSidToGid: %s\n", 955 wbcErrorString(wbc_status)); 907 956 return false; 908 957 } … … 915 964 } 916 965 966 static 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 917 1034 static bool wbinfo_allocate_uid(void) 918 1035 { … … 924 1041 wbc_status = wbcAllocateUid(&uid); 925 1042 if (!WBC_ERROR_IS_OK(wbc_status)) { 1043 d_fprintf(stderr, "failed to call wbcAllocateUid: %s\n", 1044 wbcErrorString(wbc_status)); 926 1045 return false; 927 1046 } … … 943 1062 wbc_status = wbcAllocateGid(&gid); 944 1063 if (!WBC_ERROR_IS_OK(wbc_status)) { 1064 d_fprintf(stderr, "failed to call wbcAllocateGid: %s\n", 1065 wbcErrorString(wbc_status)); 945 1066 return false; 946 1067 } … … 962 1083 wbc_status = wbcStringToSid(sid_str, &sid); 963 1084 if (!WBC_ERROR_IS_OK(wbc_status)) { 1085 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 1086 wbcErrorString(wbc_status)); 964 1087 return false; 965 1088 } … … 967 1090 wbc_status = wbcSetUidMapping(uid, &sid); 968 1091 if (!WBC_ERROR_IS_OK(wbc_status)) { 1092 d_fprintf(stderr, "failed to call wbcSetUidMapping: %s\n", 1093 wbcErrorString(wbc_status)); 969 1094 return false; 970 1095 } … … 987 1112 wbc_status = wbcStringToSid(sid_str, &sid); 988 1113 if (!WBC_ERROR_IS_OK(wbc_status)) { 1114 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 1115 wbcErrorString(wbc_status)); 989 1116 return false; 990 1117 } … … 992 1119 wbc_status = wbcSetGidMapping(gid, &sid); 993 1120 if (!WBC_ERROR_IS_OK(wbc_status)) { 1121 d_fprintf(stderr, "failed to call wbcSetGidMapping: %s\n", 1122 wbcErrorString(wbc_status)); 994 1123 return false; 995 1124 } … … 1012 1141 wbc_status = wbcStringToSid(sid_str, &sid); 1013 1142 if (!WBC_ERROR_IS_OK(wbc_status)) { 1143 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 1144 wbcErrorString(wbc_status)); 1014 1145 return false; 1015 1146 } … … 1017 1148 wbc_status = wbcRemoveUidMapping(uid, &sid); 1018 1149 if (!WBC_ERROR_IS_OK(wbc_status)) { 1150 d_fprintf(stderr, "failed to call wbcRemoveUidMapping: %s\n", 1151 wbcErrorString(wbc_status)); 1019 1152 return false; 1020 1153 } … … 1037 1170 wbc_status = wbcStringToSid(sid_str, &sid); 1038 1171 if (!WBC_ERROR_IS_OK(wbc_status)) { 1172 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 1173 wbcErrorString(wbc_status)); 1039 1174 return false; 1040 1175 } … … 1042 1177 wbc_status = wbcRemoveGidMapping(gid, &sid); 1043 1178 if (!WBC_ERROR_IS_OK(wbc_status)) { 1179 d_fprintf(stderr, "failed to call wbcRemoveGidMapping: %s\n", 1180 wbcErrorString(wbc_status)); 1044 1181 return false; 1045 1182 } … … 1067 1204 wbc_status = wbcStringToSid(sid_str, &sid); 1068 1205 if (!WBC_ERROR_IS_OK(wbc_status)) { 1206 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 1207 wbcErrorString(wbc_status)); 1069 1208 return false; 1070 1209 } … … 1072 1211 wbc_status = wbcLookupSid(&sid, &domain, &name, &type); 1073 1212 if (!WBC_ERROR_IS_OK(wbc_status)) { 1213 d_fprintf(stderr, "failed to call wbcLookupSid: %s\n", 1214 wbcErrorString(wbc_status)); 1074 1215 return false; 1075 1216 } … … 1097 1238 wbc_status = wbcStringToSid(sid_str, &sid); 1098 1239 if (!WBC_ERROR_IS_OK(wbc_status)) { 1240 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 1241 wbcErrorString(wbc_status)); 1099 1242 return false; 1100 1243 } … … 1102 1245 wbc_status = wbcGetDisplayName(&sid, &domain, &name, &type); 1103 1246 if (!WBC_ERROR_IS_OK(wbc_status)) { 1247 d_fprintf(stderr, "failed to call wbcGetDisplayName: %s\n", 1248 wbcErrorString(wbc_status)); 1104 1249 return false; 1105 1250 } … … 1185 1330 ret = true; 1186 1331 done: 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); 1199 1336 TALLOC_FREE(mem_ctx); 1200 1337 return ret; 1201 1338 } 1202 1339 1340 static 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 1203 1392 /* Convert string to sid */ 1204 1393 … … 1207 1396 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 1208 1397 struct wbcDomainSid sid; 1209 char *sid_str;1398 char sid_str[WBC_SID_STRING_BUFLEN]; 1210 1399 enum wbcSidType type; 1211 1400 fstring domain_name; … … 1220 1409 &sid, &type); 1221 1410 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)); 1229 1417 1230 1418 /* Display response */ 1231 1419 1232 1420 d_printf("%s %s (%d)\n", sid_str, wbcSidTypeString(type), type); 1233 1234 wbcFreeMemory(sid_str);1235 1421 1236 1422 return true; … … 1312 1498 sizeof(flags)); 1313 1499 if (!WBC_ERROR_IS_OK(wbc_status)) { 1500 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n", 1501 wbcErrorString(wbc_status)); 1314 1502 goto done; 1315 1503 } … … 1322 1510 sizeof(uid)); 1323 1511 if (!WBC_ERROR_IS_OK(wbc_status)) { 1512 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n", 1513 wbcErrorString(wbc_status)); 1324 1514 goto done; 1325 1515 } … … 1332 1522 strlen(cctype)+1); 1333 1523 if (!WBC_ERROR_IS_OK(wbc_status)) { 1524 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n", 1525 wbcErrorString(wbc_status)); 1334 1526 goto done; 1335 1527 } … … 1344 1536 if (error) { 1345 1537 d_fprintf(stderr, 1346 "error code was %s (0x%x)\nerror mess sage was: %s\n",1538 "error code was %s (0x%x)\nerror message was: %s\n", 1347 1539 error->nt_string, 1348 1540 error->nt_status, … … 1415 1607 if (response.data.auth.nt_status) 1416 1608 d_fprintf(stderr, 1417 "error code was %s (0x%x)\nerror mess sage was: %s\n",1609 "error code was %s (0x%x)\nerror message was: %s\n", 1418 1610 response.data.auth.nt_status_string, 1419 1611 response.data.auth.nt_status, … … 1516 1708 if (wbc_status == WBC_ERR_AUTH_ERROR) { 1517 1709 d_fprintf(stderr, 1518 "error code was %s (0x%x)\nerror mess sage was: %s\n",1710 "error code was %s (0x%x)\nerror message was: %s\n", 1519 1711 err->nt_string, 1520 1712 err->nt_status, … … 1529 1721 1530 1722 return WBC_ERROR_IS_OK(wbc_status); 1723 } 1724 1725 /* Authenticate a user with a plaintext password */ 1726 1727 static 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(¶ms.num_blobs, ¶ms.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(¶ms.num_blobs, ¶ms.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(¶ms, 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; 1531 1792 } 1532 1793 … … 1607 1868 if (response.data.auth.nt_status) 1608 1869 d_fprintf(stderr, 1609 "error code was %s (0x%x)\nerror mess sage was: %s\n",1870 "error code was %s (0x%x)\nerror message was: %s\n", 1610 1871 response.data.auth.nt_status_string, 1611 1872 response.data.auth.nt_status, … … 1684 1945 wbc_status = wbcListGroups(domain, &num_groups, &groups); 1685 1946 if (!WBC_ERROR_IS_OK(wbc_status)) { 1947 d_fprintf(stderr, "failed to call wbcListGroups: %s\n", 1948 wbcErrorString(wbc_status)); 1686 1949 return false; 1687 1950 } … … 1754 2017 OPT_GETDCNAME, 1755 2018 OPT_DSGETDCNAME, 2019 OPT_DC_INFO, 1756 2020 OPT_USERDOMGROUPS, 1757 2021 OPT_SIDALIASES, 1758 2022 OPT_USERSIDS, 2023 OPT_LOOKUP_SIDS, 1759 2024 OPT_ALLOCATE_UID, 1760 2025 OPT_ALLOCATE_GID, … … 1763 2028 OPT_REMOVE_UID_MAPPING, 1764 2029 OPT_REMOVE_GID_MAPPING, 2030 OPT_SIDS_TO_XIDS, 1765 2031 OPT_SEPARATOR, 1766 2032 OPT_LIST_ALL_DOMAINS, … … 1773 2039 OPT_ONLINESTATUS, 1774 2040 OPT_CHANGE_USER_PASSWORD, 1775 OPT_PING_DC,1776 2041 OPT_CCACHE_SAVE, 1777 2042 OPT_SID_TO_FULLNAME, 1778 2043 OPT_NTLMV2, 2044 OPT_PAM_LOGON, 2045 OPT_LOGOFF, 2046 OPT_LOGOFF_USER, 2047 OPT_LOGOFF_UID, 1779 2048 OPT_LANMAN 1780 2049 }; … … 1794 2063 bool use_ntlmv2 = false; 1795 2064 bool use_lanman = false; 2065 char *logoff_user = getenv("USER"); 2066 int logoff_uid = geteuid(); 1796 2067 1797 2068 struct poptOption long_options[] = { … … 1810 2081 OPT_SID_TO_FULLNAME, "Converts sid to fullname", "SID" }, 1811 2082 { "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"}, 1812 2086 { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" }, 1813 2087 { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" }, … … 1822 2096 { "remove-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_UID_MAPPING, "Remove uid to sid mapping in idmap", "UID,SID" }, 1823 2097 { "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" }, 1824 2100 { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" }, 1825 2101 { "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', 1827 2103 "Check the NETLOGON connection" }, 1828 2104 { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" }, 1829 2105 { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" }, 1830 2106 { "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" }, 1832 2108 { "online-status", 0, POPT_ARG_NONE, 0, OPT_ONLINESTATUS, "Show whether domains are marked as online or offline"}, 1833 2109 { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" }, … … 1843 2119 { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" }, 1844 2120 { "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" }, 1845 2129 { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" }, 1846 2130 { "ccache-save", 0, POPT_ARG_STRING, &string_arg, … … 1850 2134 "Get a DC name for a foreign domain", "domainname" }, 1851 2135 { "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" }, 1852 2138 { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL }, 1853 2139 { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" }, … … 1944 2230 } 1945 2231 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; 1946 2239 case 'n': 1947 2240 if (!wbinfo_lookupname(string_arg)) { … … 2053 2346 } 2054 2347 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; 2055 2355 case 't': 2056 2356 if (!wbinfo_check_secret(opt_domain_name)) { … … 2065 2365 } 2066 2366 break; 2067 case OPT_PING_DC:2367 case 'P': 2068 2368 if (!wbinfo_ping_dc()) { 2069 2369 d_fprintf(stderr, "Could not ping our DC\n"); … … 2192 2492 break; 2193 2493 } 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 } 2194 2511 case 'K': { 2195 2512 uint32_t flags = WBFLAG_PAM_KRB5 | … … 2246 2563 } 2247 2564 break; 2565 case OPT_DC_INFO: 2566 if (!wbinfo_dc_info(string_arg)) { 2567 goto done; 2568 } 2569 break; 2248 2570 case OPT_SEPARATOR: { 2249 2571 const char sep = winbind_separator(); … … 2275 2597 /* generic configuration options */ 2276 2598 case OPT_DOMAIN_NAME: 2277 break;2278 2599 case OPT_VERBOSE: 2279 break;2280 2600 case OPT_NTLMV2: 2281 break;2282 2601 case OPT_LANMAN: 2602 case OPT_LOGOFF_USER: 2603 case OPT_LOGOFF_UID: 2283 2604 break; 2284 2605 default:
Note:
See TracChangeset
for help on using the changeset viewer.