"Fossies" - the Fresh Open Source Software Archive

Member "mod_auth_gssapi-1.6.3/src/util.c" (19 Jul 2018, 1662 Bytes) of package /linux/www/apache_httpd_modules/mod_auth_gssapi-1.6.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "util.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.6.0_vs_1.6.1.

    1 /* Copyright (C) 2017 mod_auth_gssapi contributors - See COPYING for (C) terms */
    2 
    3 #include "mod_auth_gssapi.h"
    4 
    5 #define NSS_BUF_MIN 1024
    6 #define NSS_BUF_MAX 1024*1024
    7 static char *get_buf(char *cur, size_t *len)
    8 {
    9     if (*len == 0) {
   10         *len = NSS_BUF_MIN;
   11     } else {
   12         *len *= 2;
   13     }
   14     if (*len > NSS_BUF_MAX) {
   15         *len = 0; /* will free the buf and return NULL */
   16     }
   17     return realloc(cur, *len);
   18 }
   19 
   20 int mag_get_user_uid(const char *name, uid_t *uid)
   21 {
   22     struct passwd pwd, *user;
   23     size_t buflen = 0;
   24     char *buf = NULL;
   25     int ret;
   26 
   27     do {
   28         buf = get_buf(buf, &buflen);
   29         if (buf == NULL || buflen == 0) {
   30             ret = ENOMEM;
   31             break;
   32         }
   33         ret = getpwnam_r(name, &pwd, buf, buflen, &user);
   34     } while (ret == ERANGE);
   35     if (ret != 0 || user != &pwd) {
   36         ret = (ret == 0) ? EINVAL : ret;
   37     } else {
   38         *uid = user->pw_uid;
   39     }
   40     free(buf);
   41     return ret;
   42 }
   43 
   44 int mag_get_group_gid(const char *name, gid_t *gid)
   45 {
   46     struct group grp, *group;
   47     size_t buflen = 0;
   48     char *buf = NULL;
   49     int ret;
   50 
   51     do {
   52         buf = get_buf(buf, &buflen);
   53         if (buf == NULL || buflen == 0) {
   54             ret = ENOMEM;
   55             break;
   56         }
   57         ret = getgrnam_r(name, &grp, buf, buflen, &group);
   58     } while (ret == ERANGE);
   59     if (ret != 0 || group != &grp) {
   60         ret = (ret == 0) ? EINVAL : ret;
   61     } else {
   62         *gid = group->gr_gid;
   63     }
   64     free(buf);
   65     return ret;
   66 }
   67 
   68 bool mag_strbuf_equal(const char *str, gss_buffer_t buf)
   69 {
   70     if (strncmp(str, buf->value, buf->length) != 0) return false;
   71     return buf->length == strlen(str);
   72 }