Merge WERR_NO_SUCH_LOGON_SESSION from Samba4.
[ira/wip.git] / source3 / libsmb / doserr.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  DOS error routines
4  *  Copyright (C) Tim Potter 2002.
5  *  
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 3 of the License, or
9  *  (at your option) any later version.
10  *  
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *  
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 /* DOS error codes.  please read doserr.h */
21
22 #include "includes.h"
23
24 typedef const struct
25 {
26         const char *dos_errstr;
27         WERROR werror;
28 } werror_code_struct;
29
30 werror_code_struct dos_errs[] =
31 {
32         { "WERR_OK", WERR_OK },
33         { "WERR_GENERAL_FAILURE", WERR_GENERAL_FAILURE },
34         { "WERR_BADFILE", WERR_BADFILE },
35         { "WERR_ACCESS_DENIED", WERR_ACCESS_DENIED },
36         { "WERR_BADFID", WERR_BADFID },
37         { "WERR_BADFUNC", WERR_BADFUNC },
38         { "WERR_INSUFFICIENT_BUFFER", WERR_INSUFFICIENT_BUFFER },
39         { "WERR_SEM_TIMEOUT", WERR_SEM_TIMEOUT },
40         { "WERR_NO_SUCH_SHARE", WERR_NO_SUCH_SHARE },
41         { "WERR_ALREADY_EXISTS", WERR_ALREADY_EXISTS },
42         { "WERR_INVALID_PARAM", WERR_INVALID_PARAM },
43         { "WERR_NOT_SUPPORTED", WERR_NOT_SUPPORTED },
44         { "WERR_BAD_PASSWORD", WERR_BAD_PASSWORD },
45         { "WERR_NOMEM", WERR_NOMEM },
46         { "WERR_INVALID_NAME", WERR_INVALID_NAME },
47         { "WERR_UNKNOWN_LEVEL", WERR_UNKNOWN_LEVEL },
48         { "WERR_OBJECT_PATH_INVALID", WERR_OBJECT_PATH_INVALID },
49         { "WERR_NO_MORE_ITEMS", WERR_NO_MORE_ITEMS },
50         { "WERR_MORE_DATA", WERR_MORE_DATA },
51         { "WERR_UNKNOWN_PRINTER_DRIVER", WERR_UNKNOWN_PRINTER_DRIVER },
52         { "WERR_INVALID_PRINTER_NAME", WERR_INVALID_PRINTER_NAME },
53         { "WERR_PRINTER_ALREADY_EXISTS", WERR_PRINTER_ALREADY_EXISTS },
54         { "WERR_INVALID_DATATYPE", WERR_INVALID_DATATYPE },
55         { "WERR_INVALID_ENVIRONMENT", WERR_INVALID_ENVIRONMENT },
56         { "WERR_INVALID_FORM_NAME", WERR_INVALID_FORM_NAME },
57         { "WERR_INVALID_FORM_SIZE", WERR_INVALID_FORM_SIZE },
58         { "WERR_BUF_TOO_SMALL", WERR_BUF_TOO_SMALL },
59         { "WERR_JOB_NOT_FOUND", WERR_JOB_NOT_FOUND },
60         { "WERR_DEST_NOT_FOUND", WERR_DEST_NOT_FOUND },
61         { "WERR_NOT_LOCAL_DOMAIN", WERR_NOT_LOCAL_DOMAIN },
62         { "WERR_NO_LOGON_SERVERS", WERR_NO_LOGON_SERVERS },
63         { "WERR_NO_SUCH_LOGON_SESSION", WERR_NO_SUCH_LOGON_SESSION },
64         { "WERR_PRINTER_DRIVER_IN_USE", WERR_PRINTER_DRIVER_IN_USE },
65         { "WERR_STATUS_MORE_ENTRIES  ", WERR_STATUS_MORE_ENTRIES },
66         { "WERR_DFS_NO_SUCH_VOL", WERR_DFS_NO_SUCH_VOL },
67         { "WERR_DFS_NO_SUCH_SHARE", WERR_DFS_NO_SUCH_SHARE },
68         { "WERR_DFS_NO_SUCH_SERVER", WERR_DFS_NO_SUCH_SERVER },
69         { "WERR_DFS_INTERNAL_ERROR", WERR_DFS_INTERNAL_ERROR },
70         { "WERR_DFS_CANT_CREATE_JUNCT", WERR_DFS_CANT_CREATE_JUNCT },
71         { "WERR_MACHINE_LOCKED", WERR_MACHINE_LOCKED },
72         { "WERR_DOMAIN_CONTROLLER_NOT_FOUND", WERR_DOMAIN_CONTROLLER_NOT_FOUND },
73         { "WERR_SETUP_NOT_JOINED", WERR_SETUP_NOT_JOINED },
74         { "WERR_SETUP_ALREADY_JOINED", WERR_SETUP_ALREADY_JOINED },
75         { "WERR_SETUP_DOMAIN_CONTROLLER", WERR_SETUP_DOMAIN_CONTROLLER },
76         { "WERR_DEVICE_NOT_AVAILABLE", WERR_DEVICE_NOT_AVAILABLE },
77         { "WERR_LOGON_FAILURE", WERR_LOGON_FAILURE },
78         { "WERR_NO_SUCH_DOMAIN", WERR_NO_SUCH_DOMAIN },
79         { "WERR_INVALID_SECURITY_DESCRIPTOR", WERR_INVALID_SECURITY_DESCRIPTOR },
80         { "WERR_INVALID_OWNER", WERR_INVALID_OWNER },
81         { "WERR_SERVER_UNAVAILABLE", WERR_SERVER_UNAVAILABLE },
82         { "WERR_IO_PENDING", WERR_IO_PENDING },
83         { "WERR_INVALID_SERVICE_CONTROL", WERR_INVALID_SERVICE_CONTROL },
84         { "WERR_SERVICE_ALREADY_RUNNING", WERR_SERVICE_ALREADY_RUNNING },
85         { "WERR_NET_NAME_NOT_FOUND", WERR_NET_NAME_NOT_FOUND },
86         { "WERR_REG_CORRUPT", WERR_REG_CORRUPT },
87         { "WERR_REG_IO_FAILURE", WERR_REG_IO_FAILURE },
88         { "WERR_REG_FILE_INVALID", WERR_REG_FILE_INVALID },
89         { "WERR_SERVICE_DISABLED", WERR_SERVICE_DISABLED },
90         { "WERR_CAN_NOT_COMPLETE", WERR_CAN_NOT_COMPLETE},
91         { "WERR_INVALID_FLAGS", WERR_INVALID_FLAGS},
92         { NULL, W_ERROR(0) }
93 };
94
95 /*****************************************************************************
96  Returns a DOS error message.  not amazingly helpful, but better than a number.
97  *****************************************************************************/
98
99 const char *dos_errstr(WERROR werror)
100 {
101         char *result;
102         int idx = 0;
103
104         while (dos_errs[idx].dos_errstr != NULL) {
105                 if (W_ERROR_V(dos_errs[idx].werror) == 
106                     W_ERROR_V(werror))
107                         return dos_errs[idx].dos_errstr;
108                 idx++;
109         }
110
111         result = talloc_asprintf(talloc_tos(), "DOS code 0x%08x",
112                                  W_ERROR_V(werror));
113         SMB_ASSERT(result != NULL);
114         return result;
115 }
116
117 /* compat function for samba4 */
118 const char *win_errstr(WERROR werror)
119 {
120         return dos_errstr(werror);
121 }