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/source4/heimdal/lib/krb5/principal.c

    r414 r740  
    7777 */
    7878
    79 void KRB5_LIB_FUNCTION
     79KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    8080krb5_free_principal(krb5_context context,
    8181                    krb5_principal p)
     
    9999 */
    100100
    101 void KRB5_LIB_FUNCTION
     101KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    102102krb5_principal_set_type(krb5_context context,
    103103                        krb5_principal principal,
     
    107107}
    108108
    109 int KRB5_LIB_FUNCTION
     109/**
     110 * Get the type of the principal
     111 *
     112 * @param context A Kerberos context.
     113 * @param principal principal to get the type for
     114 *
     115 * @return the type of principal
     116 *
     117 * @ingroup krb5_principal
     118 */
     119
     120KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    110121krb5_principal_get_type(krb5_context context,
    111122                        krb5_const_principal principal)
     
    114125}
    115126
    116 const char* KRB5_LIB_FUNCTION
     127/**
     128 * Get the realm of the principal
     129 *
     130 * @param context A Kerberos context.
     131 * @param principal principal to get the realm for
     132 *
     133 * @return realm of the principal, don't free or use after krb5_principal is freed
     134 *
     135 * @ingroup krb5_principal
     136 */
     137
     138KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    117139krb5_principal_get_realm(krb5_context context,
    118140                         krb5_const_principal principal)
     
    121143}                       
    122144
    123 const char* KRB5_LIB_FUNCTION
     145KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    124146krb5_principal_get_comp_string(krb5_context context,
    125147                               krb5_const_principal principal,
     
    142164 */
    143165
    144 unsigned int KRB5_LIB_FUNCTION
     166KRB5_LIB_FUNCTION unsigned int KRB5_LIB_CALL
    145167krb5_principal_get_num_comp(krb5_context context,
    146168                            krb5_const_principal principal)
     
    149171}
    150172
    151 krb5_error_code KRB5_LIB_FUNCTION
     173/**
     174 * Parse a name into a krb5_principal structure, flags controls the behavior.
     175 *
     176 * @param context Kerberos 5 context
     177 * @param name name to parse into a Kerberos principal
     178 * @param flags flags to control the behavior
     179 * @param principal returned principal, free with krb5_free_principal().
     180 *
     181 * @return An krb5 error code, see krb5_get_error_message().
     182 *
     183 * @ingroup krb5_principal
     184 */
     185
     186KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    152187krb5_parse_name_flags(krb5_context context,
    153188                      const char *name,
     
    338373}
    339374
    340 krb5_error_code KRB5_LIB_FUNCTION
     375/**
     376 * Parse a name into a krb5_principal structure
     377 *
     378 * @param context Kerberos 5 context
     379 * @param name name to parse into a Kerberos principal
     380 * @param principal returned principal, free with krb5_free_principal().
     381 *
     382 * @return An krb5 error code, see krb5_get_error_message().
     383 *
     384 * @ingroup krb5_principal
     385 */
     386
     387KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    341388krb5_parse_name(krb5_context context,
    342389                const char *name,
     
    426473}
    427474
    428 krb5_error_code KRB5_LIB_FUNCTION
     475/**
     476 * Unparse the principal name to a fixed buffer
     477 *
     478 * @param context A Kerberos context.
     479 * @param principal principal to unparse
     480 * @param name buffer to write name to
     481 * @param len length of buffer
     482 *
     483 * @return An krb5 error code, see krb5_get_error_message().
     484 *
     485 * @ingroup krb5_principal
     486 */
     487
     488KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    429489krb5_unparse_name_fixed(krb5_context context,
    430490                        krb5_const_principal principal,
     
    435495}
    436496
    437 krb5_error_code KRB5_LIB_FUNCTION
     497/**
     498 * Unparse the principal name to a fixed buffer. The realm is skipped
     499 * if its a default realm.
     500 *
     501 * @param context A Kerberos context.
     502 * @param principal principal to unparse
     503 * @param name buffer to write name to
     504 * @param len length of buffer
     505 *
     506 * @return An krb5 error code, see krb5_get_error_message().
     507 *
     508 * @ingroup krb5_principal
     509 */
     510
     511KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    438512krb5_unparse_name_fixed_short(krb5_context context,
    439513                              krb5_const_principal principal,
     
    445519}
    446520
    447 krb5_error_code KRB5_LIB_FUNCTION
     521/**
     522 * Unparse the principal name with unparse flags to a fixed buffer.
     523 *
     524 * @param context A Kerberos context.
     525 * @param principal principal to unparse
     526 * @param flags unparse flags
     527 * @param name buffer to write name to
     528 * @param len length of buffer
     529 *
     530 * @return An krb5 error code, see krb5_get_error_message().
     531 *
     532 * @ingroup krb5_principal
     533 */
     534
     535KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    448536krb5_unparse_name_fixed_flags(krb5_context context,
    449537                              krb5_const_principal principal,
     
    509597 */
    510598
    511 krb5_error_code KRB5_LIB_FUNCTION
     599KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    512600krb5_unparse_name(krb5_context context,
    513601                  krb5_const_principal principal,
     
    530618 */
    531619
    532 krb5_error_code KRB5_LIB_FUNCTION
     620KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    533621krb5_unparse_name_flags(krb5_context context,
    534622                        krb5_const_principal principal,
     
    539627}
    540628
    541 krb5_error_code KRB5_LIB_FUNCTION
     629/**
     630 * Unparse the principal name to a allocated buffer. The realm is
     631 * skipped if its a default realm.
     632 *
     633 * @param context A Kerberos context.
     634 * @param principal principal to unparse
     635 * @param name returned buffer, free with krb5_xfree()
     636 *
     637 * @return An krb5 error code, see krb5_get_error_message().
     638 *
     639 * @ingroup krb5_principal
     640 */
     641
     642KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    542643krb5_unparse_name_short(krb5_context context,
    543644                        krb5_const_principal principal,
     
    547648}
    548649
    549 #if 0 /* not implemented */
    550 
    551 krb5_error_code KRB5_LIB_FUNCTION
    552 krb5_unparse_name_ext(krb5_context context,
    553                       krb5_const_principal principal,
    554                       char **name,
    555                       size_t *size)
    556 {
    557     krb5_abortx(context, "unimplemented krb5_unparse_name_ext called");
    558 }
    559 
    560 #endif
    561 
    562 krb5_error_code KRB5_LIB_FUNCTION
     650/**
     651 * Set a new realm for a principal, and as a side-effect free the
     652 * previous realm.
     653 *
     654 * @param context A Kerberos context.
     655 * @param principal principal set the realm for
     656 * @param realm the new realm to set
     657 *
     658 * @return An krb5 error code, see krb5_get_error_message().
     659 *
     660 * @ingroup krb5_principal
     661 */
     662
     663KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    563664krb5_principal_set_realm(krb5_context context,
    564665                         krb5_principal principal,
     
    577678}
    578679
    579 
    580 krb5_error_code KRB5_LIB_FUNCTION
     680#ifndef HEIMDAL_SMALLER
     681/**
     682 * Build a principal using vararg style building
     683 *
     684 * @param context A Kerberos context.
     685 * @param principal returned principal
     686 * @param rlen length of realm
     687 * @param realm realm name
     688 * @param ... a list of components ended with NULL.
     689 *
     690 * @return An krb5 error code, see krb5_get_error_message().
     691 *
     692 * @ingroup krb5_principal
     693 */
     694
     695KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    581696krb5_build_principal(krb5_context context,
    582697                     krb5_principal *principal,
     
    590705    ret = krb5_build_principal_va(context, principal, rlen, realm, ap);
    591706    va_end(ap);
     707    return ret;
     708}
     709#endif
     710
     711/**
     712 * Build a principal using vararg style building
     713 *
     714 * @param context A Kerberos context.
     715 * @param principal returned principal
     716 * @param realm realm name
     717 * @param ... a list of components ended with NULL.
     718 *
     719 * @return An krb5 error code, see krb5_get_error_message().
     720 *
     721 * @ingroup krb5_principal
     722 */
     723
     724KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     725krb5_make_principal(krb5_context context,
     726                    krb5_principal *principal,
     727                    krb5_const_realm realm,
     728                    ...)
     729{
     730    krb5_error_code ret;
     731    krb5_realm r = NULL;
     732    va_list ap;
     733    if(realm == NULL) {
     734        ret = krb5_get_default_realm(context, &r);
     735        if(ret)
     736            return ret;
     737        realm = r;
     738    }
     739    va_start(ap, realm);
     740    ret = krb5_build_principal_va(context, principal, strlen(realm), realm, ap);
     741    va_end(ap);
     742    if(r)
     743        free(r);
    592744    return ret;
    593745}
     
    677829}
    678830
    679 krb5_error_code KRB5_LIB_FUNCTION
    680 krb5_make_principal(krb5_context context,
    681                     krb5_principal *principal,
    682                     krb5_const_realm realm,
    683                     ...)
    684 {
    685     krb5_error_code ret;
    686     krb5_realm r = NULL;
    687     va_list ap;
    688     if(realm == NULL) {
    689         ret = krb5_get_default_realm(context, &r);
    690         if(ret)
    691             return ret;
    692         realm = r;
    693     }
    694     va_start(ap, realm);
    695     ret = krb5_build_principal_va(context, principal, strlen(realm), realm, ap);
    696     va_end(ap);
    697     if(r)
    698         free(r);
    699     return ret;
    700 }
    701 
    702 krb5_error_code KRB5_LIB_FUNCTION
     831KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    703832krb5_build_principal_va(krb5_context context,
    704833                        krb5_principal *principal,
     
    710839}
    711840
    712 krb5_error_code KRB5_LIB_FUNCTION
     841KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    713842krb5_build_principal_va_ext(krb5_context context,
    714843                            krb5_principal *principal,
     
    721850
    722851
    723 krb5_error_code KRB5_LIB_FUNCTION
     852KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    724853krb5_build_principal_ext(krb5_context context,
    725854                         krb5_principal *principal,
     
    736865}
    737866
    738 
    739 krb5_error_code KRB5_LIB_FUNCTION
     867/**
     868 * Copy a principal
     869 *
     870 * @param context A Kerberos context.
     871 * @param inprinc principal to copy
     872 * @param outprinc copied principal, free with krb5_free_principal()
     873 *
     874 * @return An krb5 error code, see krb5_get_error_message().
     875 *
     876 * @ingroup krb5_principal
     877 */
     878
     879
     880KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    740881krb5_copy_principal(krb5_context context,
    741882                    krb5_const_principal inprinc,
     
    768909 *
    769910 * @ingroup krb5_principal
    770  */
    771 
    772 krb5_boolean KRB5_LIB_FUNCTION
     911 * @see krb5_principal_compare()
     912 * @see krb5_realm_compare()
     913 */
     914
     915KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    773916krb5_principal_compare_any_realm(krb5_context context,
    774917                                 krb5_const_principal princ1,
     
    785928}
    786929
    787 krb5_boolean KRB5_LIB_FUNCTION
     930KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    788931_krb5_principal_compare_PrincipalName(krb5_context context,
    789932                                      krb5_const_principal princ1,
     
    801944
    802945
     946/**
     947 * Compares the two principals, including realm of the principals and returns
     948 * TRUE if they are the same and FALSE if not.
     949 *
     950 * @param context Kerberos 5 context
     951 * @param princ1 first principal to compare
     952 * @param princ2 second principal to compare
     953 *
     954 * @ingroup krb5_principal
     955 * @see krb5_principal_compare_any_realm()
     956 * @see krb5_realm_compare()
     957 */
     958
    803959/*
    804960 * return TRUE iff princ1 == princ2
    805961 */
    806962
    807 krb5_boolean KRB5_LIB_FUNCTION
     963KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    808964krb5_principal_compare(krb5_context context,
    809965                       krb5_const_principal princ1,
     
    815971}
    816972
    817 /*
     973/**
    818974 * return TRUE iff realm(princ1) == realm(princ2)
    819  */
    820 
    821 krb5_boolean KRB5_LIB_FUNCTION
     975 *
     976 * @param context Kerberos 5 context
     977 * @param princ1 first principal to compare
     978 * @param princ2 second principal to compare
     979 *
     980 * @ingroup krb5_principal
     981 * @see krb5_principal_compare_any_realm()
     982 * @see krb5_principal_compare()
     983 */
     984
     985KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    822986krb5_realm_compare(krb5_context context,
    823987                   krb5_const_principal princ1,
     
    827991}
    828992
    829 /*
     993/**
    830994 * return TRUE iff princ matches pattern
    831  */
    832 
    833 krb5_boolean KRB5_LIB_FUNCTION
     995 *
     996 * @ingroup krb5_principal
     997 */
     998
     999KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    8341000krb5_principal_match(krb5_context context,
    8351001                     krb5_const_principal princ,
     
    8481014}
    8491015
    850 #if defined(KRB4) || !defined(HEIMDAL_SMALLER)
    851 
    852 static struct v4_name_convert {
    853     const char *from;
    854     const char *to;
    855 } default_v4_name_convert[] = {
    856     { "ftp",    "ftp" },
    857     { "hprop",  "hprop" },
    858     { "pop",    "pop" },
    859     { "imap",   "imap" },
    860     { "rcmd",   "host" },
    861     { "smtp",   "smtp" },
    862     { NULL, NULL }
    863 };
    864 
    865 #endif
    866 
    867 #ifdef KRB4
    868 
    869 /*
    870  * return the converted instance name of `name' in `realm'.
    871  * look in the configuration file and then in the default set above.
    872  * return NULL if no conversion is appropriate.
    873  */
    874 
    875 static const char*
    876 get_name_conversion(krb5_context context, const char *realm, const char *name)
    877 {
    878     struct v4_name_convert *q;
    879     const char *p;
    880 
    881     p = krb5_config_get_string(context, NULL, "realms", realm,
    882                                "v4_name_convert", "host", name, NULL);
    883     if(p == NULL)
    884         p = krb5_config_get_string(context, NULL, "libdefaults",
    885                                    "v4_name_convert", "host", name, NULL);
    886     if(p)
    887         return p;
    888 
    889     /* XXX should be possible to override default list */
    890     p = krb5_config_get_string(context, NULL,
    891                                "realms",
    892                                realm,
    893                                "v4_name_convert",
    894                                "plain",
    895                                name,
    896                                NULL);
    897     if(p)
    898         return NULL;
    899     p = krb5_config_get_string(context, NULL,
    900                                "libdefaults",
    901                                "v4_name_convert",
    902                                "plain",
    903                                name,
    904                                NULL);
    905     if(p)
    906         return NULL;
    907     for(q = default_v4_name_convert; q->from; q++)
    908         if(strcmp(q->from, name) == 0)
    909             return q->to;
    910     return NULL;
    911 }
    912 
    913 /*
    914  * convert the v4 principal `name.instance@realm' to a v5 principal in `princ'.
    915  * if `resolve', use DNS.
    916  * if `func', use that function for validating the conversion
    917  */
    918 
    919 krb5_error_code KRB5_LIB_FUNCTION
    920 krb5_425_conv_principal_ext2(krb5_context context,
    921                              const char *name,
    922                              const char *instance,
    923                              const char *realm,
    924                              krb5_boolean (*func)(krb5_context,
    925                                                   void *, krb5_principal),
    926                              void *funcctx,
    927                              krb5_boolean resolve,
    928                              krb5_principal *princ)
    929 {
    930     const char *p;
    931     krb5_error_code ret;
    932     krb5_principal pr;
    933     char host[MAXHOSTNAMELEN];
    934     char local_hostname[MAXHOSTNAMELEN];
    935 
    936     /* do the following: if the name is found in the
    937        `v4_name_convert:host' part, is assumed to be a `host' type
    938        principal, and the instance is looked up in the
    939        `v4_instance_convert' part. if not found there the name is
    940        (optionally) looked up as a hostname, and if that doesn't yield
    941        anything, the `default_domain' is appended to the instance
    942        */
    943 
    944     if(instance == NULL)
    945         goto no_host;
    946     if(instance[0] == 0){
    947         instance = NULL;
    948         goto no_host;
    949     }
    950     p = get_name_conversion(context, realm, name);
    951     if(p == NULL)
    952         goto no_host;
    953     name = p;
    954     p = krb5_config_get_string(context, NULL, "realms", realm,
    955                                "v4_instance_convert", instance, NULL);
    956     if(p){
    957         instance = p;
    958         ret = krb5_make_principal(context, &pr, realm, name, instance, NULL);
    959         if (ret)
    960             return ret;
    961         if(func == NULL || (*func)(context, funcctx, pr)){
    962             *princ = pr;
    963             return 0;
    964         }
    965         krb5_free_principal(context, pr);
    966         *princ = NULL;
    967         krb5_clear_error_message (context);
    968         return HEIM_ERR_V4_PRINC_NO_CONV;
    969     }
    970     if(resolve){
    971         krb5_boolean passed = FALSE;
    972         char *inst = NULL;
    973 #ifdef USE_RESOLVER
    974         struct rk_dns_reply *r;
    975 
    976         r = rk_dns_lookup(instance, "aaaa");
    977         if (r) {
    978             if (r->head && r->head->type == rk_ns_t_aaaa) {
    979                 inst = strdup(r->head->domain);
    980                 passed = TRUE;
    981             }
    982             rk_dns_free_data(r);
    983         } else {
    984             r = rk_dns_lookup(instance, "a");
    985             if (r) {
    986                 if(r->head && r->head->type == rk_ns_t_a) {
    987                     inst = strdup(r->head->domain);
    988                     passed = TRUE;
    989                 }
    990                 rk_dns_free_data(r);
    991             }
    992         }
    993 #else
    994         struct addrinfo hints, *ai;
    995        
    996         memset (&hints, 0, sizeof(hints));
    997         hints.ai_flags = AI_CANONNAME;
    998         ret = getaddrinfo(instance, NULL, &hints, &ai);
    999         if (ret == 0) {
    1000             const struct addrinfo *a;
    1001             for (a = ai; a != NULL; a = a->ai_next) {
    1002                 if (a->ai_canonname != NULL) {
    1003                     inst = strdup (a->ai_canonname);
    1004                     passed = TRUE;
    1005                     break;
    1006                 }
    1007             }
    1008             freeaddrinfo (ai);
    1009         }
    1010 #endif
    1011         if (passed) {
    1012             if (inst == NULL) {
    1013                 krb5_set_error_message(context, ENOMEM,
    1014                                        N_("malloc: out of memory", ""));
    1015                 return ENOMEM;
    1016             }
    1017             strlwr(inst);
    1018             ret = krb5_make_principal(context, &pr, realm, name, inst,
    1019                                       NULL);
    1020             free (inst);
    1021             if(ret == 0) {
    1022                 if(func == NULL || (*func)(context, funcctx, pr)){
    1023                     *princ = pr;
    1024                     return 0;
    1025                 }
    1026                 krb5_free_principal(context, pr);
    1027             }
    1028         }
    1029     }
    1030     if(func != NULL) {
    1031         snprintf(host, sizeof(host), "%s.%s", instance, realm);
    1032         strlwr(host);
    1033         ret = krb5_make_principal(context, &pr, realm, name, host, NULL);
    1034         if (ret)
    1035             return ret;
    1036         if((*func)(context, funcctx, pr)){
    1037             *princ = pr;
    1038             return 0;
    1039         }
    1040         krb5_free_principal(context, pr);
    1041     }
    1042 
    1043     /*
    1044      * if the instance is the first component of the local hostname,
    1045      * the converted host should be the long hostname.
    1046      */
    1047 
    1048     if (func == NULL &&
    1049         gethostname (local_hostname, sizeof(local_hostname)) == 0 &&
    1050         strncmp(instance, local_hostname, strlen(instance)) == 0 &&
    1051         local_hostname[strlen(instance)] == '.') {
    1052         strlcpy(host, local_hostname, sizeof(host));
    1053         goto local_host;
    1054     }
    1055 
    1056     {
    1057         char **domains, **d;
    1058         domains = krb5_config_get_strings(context, NULL, "realms", realm,
    1059                                           "v4_domains", NULL);
    1060         for(d = domains; d && *d; d++){
    1061             snprintf(host, sizeof(host), "%s.%s", instance, *d);
    1062             ret = krb5_make_principal(context, &pr, realm, name, host, NULL);
    1063             if (ret) {
    1064                 krb5_config_free_strings(domains);
    1065                 return ret;
    1066             }
    1067             if(func == NULL || (*func)(context, funcctx, pr)){
    1068                 *princ = pr;
    1069                 krb5_config_free_strings(domains);
    1070                 return 0;
    1071             }
    1072             krb5_free_principal(context, pr);
    1073         }
    1074         krb5_config_free_strings(domains);
    1075     }
    1076 
    1077 
    1078     p = krb5_config_get_string(context, NULL, "realms", realm,
    1079                                "default_domain", NULL);
    1080     if(p == NULL){
    1081         /* this should be an error, just faking a name is not good */
    1082         krb5_clear_error_message (context);
    1083         return HEIM_ERR_V4_PRINC_NO_CONV;
    1084     }
    1085        
    1086     if (*p == '.')
    1087         ++p;
    1088     snprintf(host, sizeof(host), "%s.%s", instance, p);
    1089 local_host:
    1090     ret = krb5_make_principal(context, &pr, realm, name, host, NULL);
    1091     if (ret)
    1092         return ret;
    1093     if(func == NULL || (*func)(context, funcctx, pr)){
    1094         *princ = pr;
    1095         return 0;
    1096     }
    1097     krb5_free_principal(context, pr);
    1098     krb5_clear_error_message (context);
    1099     return HEIM_ERR_V4_PRINC_NO_CONV;
    1100 no_host:
    1101     p = krb5_config_get_string(context, NULL,
    1102                                "realms",
    1103                                realm,
    1104                                "v4_name_convert",
    1105                                "plain",
    1106                                name,
    1107                                NULL);
    1108     if(p == NULL)
    1109         p = krb5_config_get_string(context, NULL,
    1110                                    "libdefaults",
    1111                                    "v4_name_convert",
    1112                                    "plain",
    1113                                    name,
    1114                                    NULL);
    1115     if(p)
    1116         name = p;
    1117 
    1118     ret = krb5_make_principal(context, &pr, realm, name, instance, NULL);
    1119     if (ret)
    1120         return ret;
    1121     if(func == NULL || (*func)(context, funcctx, pr)){
    1122         *princ = pr;
    1123         return 0;
    1124     }
    1125     krb5_free_principal(context, pr);
    1126     krb5_clear_error_message (context);
    1127     return HEIM_ERR_V4_PRINC_NO_CONV;
    1128 }
    1129 
    1130 #endif /* KRB4 */
    1131 
    1132 #ifndef HEIMDAL_SMALLER
    1133 
    1134 static int
    1135 check_list(const krb5_config_binding *l, const char *name, const char **out)
    1136 {
    1137     while(l){
    1138         if (l->type != krb5_config_string)
    1139             continue;
    1140         if(strcmp(name, l->u.string) == 0) {
    1141             *out = l->name;
    1142             return 1;
    1143         }
    1144         l = l->next;
    1145     }
    1146     return 0;
    1147 }
    1148 
    1149 static int
    1150 name_convert(krb5_context context, const char *name, const char *realm,
    1151              const char **out)
    1152 {
    1153     const krb5_config_binding *l;
    1154     l = krb5_config_get_list (context,
    1155                               NULL,
    1156                               "realms",
    1157                               realm,
    1158                               "v4_name_convert",
    1159                               "host",
    1160                               NULL);
    1161     if(l && check_list(l, name, out))
    1162         return KRB5_NT_SRV_HST;
    1163     l = krb5_config_get_list (context,
    1164                               NULL,
    1165                               "libdefaults",
    1166                               "v4_name_convert",
    1167                               "host",
    1168                               NULL);
    1169     if(l && check_list(l, name, out))
    1170         return KRB5_NT_SRV_HST;
    1171     l = krb5_config_get_list (context,
    1172                               NULL,
    1173                               "realms",
    1174                               realm,
    1175                               "v4_name_convert",
    1176                               "plain",
    1177                               NULL);
    1178     if(l && check_list(l, name, out))
    1179         return KRB5_NT_UNKNOWN;
    1180     l = krb5_config_get_list (context,
    1181                               NULL,
    1182                               "libdefaults",
    1183                               "v4_name_convert",
    1184                               "host",
    1185                               NULL);
    1186     if(l && check_list(l, name, out))
    1187         return KRB5_NT_UNKNOWN;
    1188 
    1189     /* didn't find it in config file, try built-in list */
    1190 #ifdef KRB4
    1191     {
    1192         struct v4_name_convert *q;
    1193         for(q = default_v4_name_convert; q->from; q++) {
    1194             if(strcmp(name, q->to) == 0) {
    1195                 *out = q->from;
    1196                 return KRB5_NT_SRV_HST;
    1197             }
    1198         }
    1199     }
    1200 #endif
    1201     return -1;
    1202 }
    1203 
    1204 /*
    1205  * convert the v5 principal in `principal' into a v4 corresponding one
    1206  * in `name, instance, realm'
    1207  * this is limited interface since there's no length given for these
    1208  * three parameters.  They have to be 40 bytes each (ANAME_SZ).
    1209  */
    1210 
    1211 krb5_error_code KRB5_LIB_FUNCTION
    1212 krb5_524_conv_principal(krb5_context context,
    1213                         const krb5_principal principal,
    1214                         char *name,
    1215                         char *instance,
    1216                         char *realm)
    1217 {
    1218     const char *n, *i, *r;
    1219     char tmpinst[40];
    1220     int type = princ_type(principal);
    1221     const int aname_sz = 40;
    1222 
    1223     r = principal->realm;
    1224 
    1225     switch(principal->name.name_string.len){
    1226     case 1:
    1227         n = principal->name.name_string.val[0];
    1228         i = "";
    1229         break;
    1230     case 2:
    1231         n = principal->name.name_string.val[0];
    1232         i = principal->name.name_string.val[1];
    1233         break;
    1234     default:
    1235         krb5_set_error_message(context, KRB5_PARSE_MALFORMED,
    1236                                N_("cannot convert a %d "
    1237                                   "component principal", ""),
    1238                                principal->name.name_string.len);
    1239         return KRB5_PARSE_MALFORMED;
    1240     }
    1241 
    1242     {
    1243         const char *tmp;
    1244         int t = name_convert(context, n, r, &tmp);
    1245         if(t >= 0) {
    1246             type = t;
    1247             n = tmp;
    1248         }
    1249     }
    1250 
    1251     if(type == KRB5_NT_SRV_HST){
    1252         char *p;
    1253 
    1254         strlcpy (tmpinst, i, sizeof(tmpinst));
    1255         p = strchr(tmpinst, '.');
    1256         if(p)
    1257             *p = 0;
    1258         i = tmpinst;
    1259     }
    1260 
    1261     if (strlcpy (name, n, aname_sz) >= aname_sz) {
    1262         krb5_set_error_message(context, KRB5_PARSE_MALFORMED,
    1263                                N_("too long name component to convert", ""));
    1264         return KRB5_PARSE_MALFORMED;
    1265     }
    1266     if (strlcpy (instance, i, aname_sz) >= aname_sz) {
    1267         krb5_set_error_message(context, KRB5_PARSE_MALFORMED,
    1268                                N_("too long instance component to convert", ""));
    1269         return KRB5_PARSE_MALFORMED;
    1270     }
    1271     if (strlcpy (realm, r, aname_sz) >= aname_sz) {
    1272         krb5_set_error_message(context, KRB5_PARSE_MALFORMED,
    1273                                N_("too long realm component to convert", ""));
    1274         return KRB5_PARSE_MALFORMED;
    1275     }
    1276     return 0;
    1277 }
    1278 
    1279 #endif /* !HEIMDAL_SMALLER */
    1280 
    12811016/**
    12821017 * Create a principal for the service running on hostname. If
     
    12951030 */
    12961031                       
    1297 krb5_error_code KRB5_LIB_FUNCTION
     1032KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    12981033krb5_sname_to_principal (krb5_context context,
    12991034                         const char *hostname,
     
    13651100};
    13661101
    1367 krb5_error_code
     1102/**
     1103 * Parse nametype string and return a nametype integer
     1104 *
     1105 * @ingroup krb5_principal
     1106 */
     1107
     1108KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    13681109krb5_parse_nametype(krb5_context context, const char *str, int32_t *nametype)
    13691110{
     
    13801121    return KRB5_PARSE_MALFORMED;
    13811122}
     1123
     1124/**
     1125 * Check if the cname part of the principal is a krbtgt principal
     1126 *
     1127 * @ingroup krb5_principal
     1128 */
     1129
     1130KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
     1131krb5_principal_is_krbtgt(krb5_context context, krb5_const_principal p)
     1132{
     1133    return p->name.name_string.len == 2 &&
     1134        strcmp(p->name.name_string.val[0], KRB5_TGS_NAME) == 0;
     1135
     1136}
Note: See TracChangeset for help on using the changeset viewer.