a9acb7335c3aa8e6b287cb9a625122d16a4323df
[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
25 struct werror_code_struct {
26         const char *dos_errstr;
27         WERROR werror;
28 };
29
30 static const struct werror_code_struct dos_errs[] =
31 {
32         { "WERR_OK", WERR_OK },
33         { "WERR_BADFILE", WERR_BADFILE },
34         { "WERR_ACCESS_DENIED", WERR_ACCESS_DENIED },
35         { "WERR_BADFID", WERR_BADFID },
36         { "WERR_BADFUNC", WERR_BADFUNC },
37         { "WERR_BAD_NETPATH", WERR_BAD_NETPATH },
38         { "WERR_INSUFFICIENT_BUFFER", WERR_INSUFFICIENT_BUFFER },
39         { "WERR_NO_SUCH_SHARE", WERR_NO_SUCH_SHARE },
40         { "WERR_ALREADY_EXISTS", WERR_ALREADY_EXISTS },
41         { "WERR_INVALID_PARAM", WERR_INVALID_PARAM },
42         { "WERR_NOT_SUPPORTED", WERR_NOT_SUPPORTED },
43         { "WERR_BAD_PASSWORD", WERR_BAD_PASSWORD },
44         { "WERR_NOMEM", WERR_NOMEM },
45         { "WERR_INVALID_NAME", WERR_INVALID_NAME },
46         { "WERR_UNKNOWN_LEVEL", WERR_UNKNOWN_LEVEL },
47         { "WERR_OBJECT_PATH_INVALID", WERR_OBJECT_PATH_INVALID },
48         { "WERR_NO_MORE_ITEMS", WERR_NO_MORE_ITEMS },
49         { "WERR_MORE_DATA", WERR_MORE_DATA },
50         { "WERR_UNKNOWN_PRINTER_DRIVER", WERR_UNKNOWN_PRINTER_DRIVER },
51         { "WERR_INVALID_PRINTER_NAME", WERR_INVALID_PRINTER_NAME },
52         { "WERR_PRINTER_ALREADY_EXISTS", WERR_PRINTER_ALREADY_EXISTS },
53         { "WERR_INVALID_DATATYPE", WERR_INVALID_DATATYPE },
54         { "WERR_INVALID_ENVIRONMENT", WERR_INVALID_ENVIRONMENT },
55         { "WERR_INVALID_FORM_NAME", WERR_INVALID_FORM_NAME },
56         { "WERR_INVALID_FORM_SIZE", WERR_INVALID_FORM_SIZE },
57         { "WERR_BUF_TOO_SMALL", WERR_BUF_TOO_SMALL },
58         { "WERR_JOB_NOT_FOUND", WERR_JOB_NOT_FOUND },
59         { "WERR_DEST_NOT_FOUND", WERR_DEST_NOT_FOUND },
60         { "WERR_NOT_LOCAL_DOMAIN", WERR_NOT_LOCAL_DOMAIN },
61         { "WERR_PRINTER_DRIVER_IN_USE", WERR_PRINTER_DRIVER_IN_USE },
62         { "WERR_STATUS_MORE_ENTRIES", WERR_STATUS_MORE_ENTRIES },
63         { "WERR_NET_NAME_NOT_FOUND", WERR_NET_NAME_NOT_FOUND },
64         { "WERR_DEVICE_NOT_SHARED", WERR_DEVICE_NOT_SHARED },
65         { "WERR_DFS_NO_SUCH_VOL", WERR_DFS_NO_SUCH_VOL },
66         { "WERR_DFS_NO_SUCH_SHARE", WERR_DFS_NO_SUCH_SHARE },
67         { "WERR_DFS_NO_SUCH_SERVER", WERR_DFS_NO_SUCH_SERVER },
68         { "WERR_DFS_INTERNAL_ERROR", WERR_DFS_INTERNAL_ERROR },
69         { "WERR_DFS_CANT_CREATE_JUNCT", WERR_DFS_CANT_CREATE_JUNCT },
70         { "WERR_INVALID_SECURITY_DESCRIPTOR", WERR_INVALID_SECURITY_DESCRIPTOR },
71         { "WERR_INVALID_OWNER", WERR_INVALID_OWNER },
72         { "WERR_INVALID_DOMAINNAME", WERR_INVALID_DOMAINNAME },
73         { "WERR_NO_SUCH_USER", WERR_NO_SUCH_USER },
74         { "WERR_NO_SUCH_DOMAIN", WERR_NO_SUCH_DOMAIN },
75         { "WERR_DS_SERVICE_BUSY", WERR_DS_SERVICE_BUSY },
76         { "WERR_DS_SERVICE_UNAVAILABLE", WERR_DS_SERVICE_UNAVAILABLE },
77         { "WERR_DS_NO_SUCH_OBJECT", WERR_DS_NO_SUCH_OBJECT },
78         { "WERR_DS_OBJ_NOT_FOUND", WERR_DS_OBJ_NOT_FOUND },
79         { "WERR_DS_DRA_BAD_DN", WERR_DS_DRA_BAD_DN },
80         { "WERR_DS_DRA_BAD_NC", WERR_DS_DRA_BAD_NC },
81         { "WERR_DS_DRA_DB_ERROR", WERR_DS_DRA_DB_ERROR },
82         { "WERR_DS_DRA_NO_REPLICA", WERR_DS_DRA_NO_REPLICA },
83         { "WERR_DS_WRONG_LINKED_ATTRIBUTE_SYNTAX", WERR_DS_WRONG_LINKED_ATTRIBUTE_SYNTAX },
84         { "WERR_GENERAL_FAILURE", WERR_GENERAL_FAILURE },
85         { "WERR_PRINTQ_FULL", WERR_PRINTQ_FULL },
86         { "WERR_NO_SPOOL_SPACE", WERR_NO_SPOOL_SPACE },
87         { "WERR_CAN_NOT_COMPLETE", WERR_CAN_NOT_COMPLETE },
88         { "WERR_SERVER_UNAVAILABLE", WERR_SERVER_UNAVAILABLE },
89         { NULL, W_ERROR(0) }
90 };
91
92
93
94
95 /* DFS errors */
96
97 /*****************************************************************************
98  returns a windows error message.  not amazingly helpful, but better than a number.
99  *****************************************************************************/
100 const char *win_errstr(WERROR werror)
101 {
102         static pstring msg;
103         int idx = 0;
104
105         while (dos_errs[idx].dos_errstr != NULL) {
106                 if (W_ERROR_V(dos_errs[idx].werror) == 
107                     W_ERROR_V(werror))
108                         return dos_errs[idx].dos_errstr;
109                 idx++;
110         }
111
112         slprintf(msg, sizeof(msg), "DOS code 0x%08x", W_ERROR_V(werror));
113
114         return msg;
115 }