File: gss_err.c

package info (click to toggle)
gss-ntlmssp 0.7.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid
  • size: 2,168 kB
  • ctags: 884
  • sloc: ansic: 9,283; sh: 4,373; makefile: 241; xml: 150
file content (140 lines) | stat: -rw-r--r-- 4,738 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* Copyright (C) 2014 GSS-NTLMSSP contributors, see COPYING for license */

#include "config.h"

#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <gssapi/gssapi.h>
#include <gssapi/gssapi_ext.h>

#include "gss_ntlmssp.h"

#ifdef HAVE_NLS
#include <libintl.h>
#define _(s) dgettext(PACKAGE, (s))
#else
#define _(s) (s)
#endif
#define N_(s) s

/* the order is determined by ntlm_err_code order */
static const char *err_strs[] = {
                           N_("Unknown Error"),
    /* ERR_DECODE */       N_("Failed to decode data"),
    /* ERR_ENCODE */       N_("Failed to encode data"),
    /* ERR_CRYPTO */       N_("Crypto routine failure"),
    /* ERR_NOARG */        N_("A required argument is missing"),
    /* ERR_BADARG */       N_("Invalid value in argument"),
    /* ERR_NONAME */       N_("Name is empty"),
    /* ERR_NOSRVNAME */    N_("Not a server name"),
    /* ERR_NOUSRNAME */    N_("Not a user name"),
    /* ERR_BADLMLEVEL */   N_("Bad LM compatibility Level"),
    /* ERR_IMPOSSIBLE */   N_("An impossible error occurred"),
    /* ERR_BADCTX */       N_("Invalid or incomplete context"),
    /* ERR_WRONGCTX */     N_("Wrong context type"),
    /* ERR_WRONGMSG */     N_("Wrong message type"),
    /* ERR_REQNEGFLAG */   N_("A required Negotiate flag was not provided"),
    /* ERR_FAILNEGFLAGS */ N_("Failed to negotiate a common set of flags"),
    /* ERR_BADNEGFLAGS */  N_("Invalid combinations of negotiate flags"),
    /* ERR_NOSRVCRED */    N_("Not a server credential type"),
    /* ERR_NOUSRCRED */    N_("Not a user credential type"),
    /* ERR_BADCRED */      N_("Invalid or unknown credential"),
    /* ERR_NOTOKEN */      N_("Empty or missing token"),
    /* ERR_NOTSUPPORTED */ N_("Feature not supported"),
    /* ERR_NOTAVAIL */     N_("Feature not available"),
    /* ERR_NAMETOOLONG */  N_("Name is too long"),
    /* ERR_NOBINDINGS */   N_("Required channel bingings are not available"),
    /* ERR_TIMESKEW */     N_("Server and client clocks are too far apart"),
    /* ERR_EXPIRED */      N_("Expired"),
    /* ERR_KEYLEN */       N_("Invalid key length"),
    /* ERR_NONTLMV1 */     N_("NTLM version 1 not allowed"),
    /* ERR_NOUSRFOUND */   N_("User not found"),
};

#define UNKNOWN_ERROR err_strs[0]

uint32_t gssntlm_display_status(uint32_t *minor_status,
                                uint32_t status_value,
                                int status_type,
                                gss_OID mech_type,
                                uint32_t *message_context,
                                gss_buffer_t status_string)
{
    uint32_t retmaj;
    uint32_t retmin;
    /* if you can't say it in ~6 lines of text we don't bother */
    char buf[512];
    int err;

    if (!status_string) {
        return GSSERRS(ERR_NOARG, GSS_S_CALL_INACCESSIBLE_READ);
    }

    if (status_type != GSS_C_MECH_CODE) {
        return GSSERRS(ERR_BADARG, GSS_S_BAD_STATUS);
    }

    *minor_status = 0;
    *message_context = 0;
    status_string->length = 0;
    status_string->value = NULL;

    if (!status_value) {
        /* There must have been *some* error. No point saying 'Success' */
        goto done;
    }

    if (status_value > ERR_BASE && status_value < ERR_LAST) {
        status_string->value = strdup(_(err_strs[status_value - ERR_BASE]));
        if (!status_string->value) {
            return GSSERRS(ENOMEM, GSS_S_FAILURE);
        }
        goto done;
    }

    /* handle both XSI and GNU specific varints of strerror_r */
    errno = 0;
#if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE)
    /* XSI version */
    err = strerror_r(status_value, buf, 400);
    /* The XSI-compliant strerror_r() function returns 0 on success.
     * On error, a (positive) error number is returned (since glibc
     * 2.13), or -1 is returned and errno is set to indicate the
     * error (glibc versions before 2.13). */
#else
    {
        char *ret;
        ret = strerror_r(status_value, buf, 400);
        if (ret == NULL) {
            err = errno;
        } else {
            if (ret != buf) {
                memmove(buf, ret, strlen(ret) + 1);
            }
            err = 0;
        }
    }
#endif
    if (err == -1) err = errno;
    switch (err) {
    case ERANGE:
        /* Screw it, they can have a truncated version */
    case 0:
        status_string->value = strdup(buf);
        break;
    default:
        break;
    }

done:
    if (!status_string->value) {
        status_string->value = strdup(_(UNKNOWN_ERROR));
        if (!status_string->value) {
            return GSSERRS(ENOMEM, GSS_S_FAILURE);
        }
    }
    status_string->length = strlen(status_string->value);
    return GSSERRS(0, GSS_S_COMPLETE);
}