ed1700aeb09d3d86f0270d91792cae16f2784f8d
[samba.git] / source4 / libcli / util / 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 2 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, write to the Free Software
18  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 /* DOS error codes.  please read doserr.h */
22
23 #include "includes.h"
24 #include "pstring.h"
25
26 struct werror_code_struct {
27         const char *dos_errstr;
28         WERROR werror;
29 };
30
31 static const struct werror_code_struct dos_errs[] =
32 {
33         { "WERR_OK", WERR_OK },
34         { "WERR_BADFILE", WERR_BADFILE },
35         { "WERR_ACCESS_DENIED", WERR_ACCESS_DENIED },
36         { "WERR_BADFID", WERR_BADFID },
37         { "WERR_BADFUNC", WERR_BADFUNC },
38         { "WERR_BAD_NETPATH", WERR_BAD_NETPATH },
39         { "WERR_UNEXP_NET_ERR", WERR_UNEXP_NET_ERR },
40         { "WERR_INSUFFICIENT_BUFFER", WERR_INSUFFICIENT_BUFFER },
41         { "WERR_NO_SUCH_SHARE", WERR_NO_SUCH_SHARE },
42         { "WERR_FILE_EXISTS", WERR_FILE_EXISTS },
43         { "WERR_INVALID_PARAM", WERR_INVALID_PARAM },
44         { "WERR_NOT_SUPPORTED", WERR_NOT_SUPPORTED },
45         { "WERR_BAD_PASSWORD", WERR_BAD_PASSWORD },
46         { "WERR_NOMEM", WERR_NOMEM },
47         { "WERR_INVALID_NAME", WERR_INVALID_NAME },
48         { "WERR_UNKNOWN_LEVEL", WERR_UNKNOWN_LEVEL },
49         { "WERR_OBJECT_PATH_INVALID", WERR_OBJECT_PATH_INVALID },
50         { "WERR_ALREADY_EXISTS", WERR_ALREADY_EXISTS },
51         { "WERR_NO_MORE_ITEMS", WERR_NO_MORE_ITEMS },
52         { "WERR_MORE_DATA", WERR_MORE_DATA },
53         { "WERR_UNKNOWN_PRINTER_DRIVER", WERR_UNKNOWN_PRINTER_DRIVER },
54         { "WERR_INVALID_PRINTER_NAME", WERR_INVALID_PRINTER_NAME },
55         { "WERR_PRINTER_ALREADY_EXISTS", WERR_PRINTER_ALREADY_EXISTS },
56         { "WERR_INVALID_DATATYPE", WERR_INVALID_DATATYPE },
57         { "WERR_INVALID_ENVIRONMENT", WERR_INVALID_ENVIRONMENT },
58         { "WERR_INVALID_FORM_NAME", WERR_INVALID_FORM_NAME },
59         { "WERR_INVALID_FORM_SIZE", WERR_INVALID_FORM_SIZE },
60         { "WERR_ALREADY_SHARED", WERR_ALREADY_SHARED },
61         { "WERR_BUF_TOO_SMALL", WERR_BUF_TOO_SMALL },
62         { "WERR_JOB_NOT_FOUND", WERR_JOB_NOT_FOUND },
63         { "WERR_DEST_NOT_FOUND", WERR_DEST_NOT_FOUND },
64         { "WERR_NOT_LOCAL_DOMAIN", WERR_NOT_LOCAL_DOMAIN },
65         { "WERR_DEVICE_NOT_AVAILABLE", WERR_DEVICE_NOT_AVAILABLE },
66         { "WERR_PRINTER_DRIVER_IN_USE", WERR_PRINTER_DRIVER_IN_USE },
67         { "WERR_STATUS_MORE_ENTRIES", WERR_STATUS_MORE_ENTRIES },
68         { "WERR_NET_NAME_NOT_FOUND", WERR_NET_NAME_NOT_FOUND },
69         { "WERR_DEVICE_NOT_SHARED", WERR_DEVICE_NOT_SHARED },
70         { "WERR_DFS_NO_SUCH_VOL", WERR_DFS_NO_SUCH_VOL },
71         { "WERR_DFS_NO_SUCH_SHARE", WERR_DFS_NO_SUCH_SHARE },
72         { "WERR_DFS_NO_SUCH_SERVER", WERR_DFS_NO_SUCH_SERVER },
73         { "WERR_DFS_INTERNAL_ERROR", WERR_DFS_INTERNAL_ERROR },
74         { "WERR_DFS_CANT_CREATE_JUNCT", WERR_DFS_CANT_CREATE_JUNCT },
75         { "WERR_INVALID_SECURITY_DESCRIPTOR", WERR_INVALID_SECURITY_DESCRIPTOR },
76         { "WERR_UNKNOWN_REVISION", WERR_UNKNOWN_REVISION },
77         { "WERR_REVISION_MISMATCH", WERR_REVISION_MISMATCH },
78         { "WERR_INVALID_OWNER", WERR_INVALID_OWNER },
79         { "WERR_INVALID_COMPUTERNAME", WERR_INVALID_COMPUTERNAME },
80         { "WERR_INVALID_DOMAINNAME", WERR_INVALID_DOMAINNAME },
81         { "WERR_NO_SUCH_PRIVILEGE", WERR_NO_SUCH_PRIVILEGE },
82         { "WERR_PRIVILEGE_NOT_HELD", WERR_PRIVILEGE_NOT_HELD },
83         { "WERR_NO_SUCH_USER", WERR_NO_SUCH_USER },
84         { "WERR_NO_SUCH_DOMAIN", WERR_NO_SUCH_DOMAIN },
85         { "WERR_NO_SYSTEM_RESOURCES", WERR_NO_SYSTEM_RESOURCES },
86         { "WERR_DS_SERVICE_BUSY", WERR_DS_SERVICE_BUSY },
87         { "WERR_DS_SERVICE_UNAVAILABLE", WERR_DS_SERVICE_UNAVAILABLE },
88         { "WERR_DS_NO_SUCH_OBJECT", WERR_DS_NO_SUCH_OBJECT },
89         { "WERR_DS_OBJ_NOT_FOUND", WERR_DS_OBJ_NOT_FOUND },
90         { "WERR_DS_DRA_INVALID_PARAMETER", WERR_DS_DRA_INVALID_PARAMETER },
91         { "WERR_DS_DRA_BAD_DN", WERR_DS_DRA_BAD_DN },
92         { "WERR_DS_DRA_BAD_NC", WERR_DS_DRA_BAD_NC },
93         { "WERR_DS_DRA_INTERNAL_ERROR", WERR_DS_DRA_INTERNAL_ERROR },
94         { "WERR_DS_DRA_OUT_OF_MEM", WERR_DS_DRA_OUT_OF_MEM },
95         { "WERR_DS_SINGLE_VALUE_CONSTRAINT", WERR_DS_SINGLE_VALUE_CONSTRAINT },
96         { "WERR_DS_DRA_DB_ERROR", WERR_DS_DRA_DB_ERROR },
97         { "WERR_DS_DRA_NO_REPLICA", WERR_DS_DRA_NO_REPLICA },
98         { "WERR_DS_DRA_ACCESS_DENIED", WERR_DS_DRA_ACCESS_DENIED },
99         { "WERR_DS_DNS_LOOKUP_FAILURE", WERR_DS_DNS_LOOKUP_FAILURE },
100         { "WERR_DS_WRONG_LINKED_ATTRIBUTE_SYNTAX", WERR_DS_WRONG_LINKED_ATTRIBUTE_SYNTAX },
101         { "WERR_GENERAL_FAILURE", WERR_GENERAL_FAILURE },
102         { "WERR_PRINTQ_FULL", WERR_PRINTQ_FULL },
103         { "WERR_NO_SPOOL_SPACE", WERR_NO_SPOOL_SPACE },
104         { "WERR_CAN_NOT_COMPLETE", WERR_CAN_NOT_COMPLETE },
105         { "WERR_NOT_FOUND", WERR_NOT_FOUND },
106         { "WERR_SERVER_UNAVAILABLE", WERR_SERVER_UNAVAILABLE },
107         { "WERR_CLASS_NOT_REGISTERED", WERR_CLASS_NOT_REGISTERED },
108         { "WERR_NO_SHUTDOWN_IN_PROGRESS", WERR_NO_SHUTDOWN_IN_PROGRESS },
109         { "WERR_SHUTDOWN_ALREADY_IN_PROGRESS", WERR_SHUTDOWN_ALREADY_IN_PROGRESS },
110         { "WERR_SEC_E_ALGORITHM_MISMATCH", WERR_SEC_E_ALGORITHM_MISMATCH },
111         { NULL, W_ERROR(0) }
112 };
113
114
115
116
117 /* DFS errors */
118
119 /*****************************************************************************
120  returns a windows error message.  not amazingly helpful, but better than a number.
121  *****************************************************************************/
122 const char *win_errstr(WERROR werror)
123 {
124         static pstring msg;
125         int idx = 0;
126
127         while (dos_errs[idx].dos_errstr != NULL) {
128                 if (W_ERROR_V(dos_errs[idx].werror) == 
129                     W_ERROR_V(werror))
130                         return dos_errs[idx].dos_errstr;
131                 idx++;
132         }
133
134         slprintf(msg, sizeof(msg), "DOS code 0x%08x", W_ERROR_V(werror));
135
136         return msg;
137 }