bd40b643c7b620df6c09c9551b349d602ca736a4
[openafs.git] / src / WINNT / afsd / symlink.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afs/param.h>
11 #include <afs/stds.h>
12 #include <afs/com_err.h>
13
14 #include <windows.h>
15 #include <stdlib.h>
16 #include <malloc.h>
17 #include <string.h>
18 #include <stdio.h>
19 #include <time.h>
20 #include <winsock2.h>
21 #include <errno.h>
22 #include <assert.h>
23
24 #include <osi.h>
25 #include <afsint.h>
26 #include <WINNT\afsreg.h>
27
28 #include "fs_utils.h"
29 #include "cmd.h"
30
31 #define MAXNAME 100
32 #define MAXSIZE 2048
33 #define MAXINSIZE 1300    /* pioctl complains if data is larger than this */
34
35 static char space[MAXSIZE];
36 static char tspace[1024];
37
38 #ifndef WIN32
39 static struct ubik_client *uclient;
40 #endif /* not WIN32 */
41
42
43 static char pn[] = "symlink";
44 static int rxInitDone = 0;
45
46 void Die();
47
48 #if 0
49 foldcmp (a, b)
50     register char *a;
51     register char *b; {
52     register char t, u;
53     while (1) {
54         t = *a++;
55         u = *b++;
56         if (t >= 'A' && t <= 'Z') t += 0x20;
57         if (u >= 'A' && u <= 'Z') u += 0x20;
58         if (t != u) return 1;
59         if (t == 0) return 0;
60     }
61 }
62 #endif
63
64 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
65 static int InAFS(register char *apath)
66 {
67     struct ViceIoctl blob;
68     register afs_int32 code;
69
70     blob.in_size = 0;
71     blob.out_size = MAXSIZE;
72     blob.out = space;
73
74     code = pioctl_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
75     if (code) {
76         if ((errno == EINVAL) || (errno == ENOENT)) 
77             return 0;
78     }
79     return 1;
80 }
81
82 static int 
83 IsFreelanceRoot(char *apath)
84 {
85     struct ViceIoctl blob;
86     afs_int32 code;
87
88     blob.in_size = 0;
89     blob.out_size = MAXSIZE;
90     blob.out = space;
91
92     code = pioctl_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
93     if (code == 0)
94         return !stricmp("Freelance.Local.Root",space);
95     return 1;   /* assume it is because it is more restrictive that way */
96 }
97
98 static const char * NetbiosName(void)
99 {
100     static char buffer[1024] = "AFS";
101     HKEY  parmKey;
102     DWORD code;
103     DWORD dummyLen;
104     DWORD enabled = 0;
105
106     code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
107                          0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
108     if (code == ERROR_SUCCESS) {
109         dummyLen = sizeof(buffer);
110         code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
111                                buffer, &dummyLen);
112         RegCloseKey (parmKey);
113     } else {
114         strcpy(buffer, "AFS");
115     }
116     return buffer;
117 }
118
119 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
120
121 static BOOL IsAdmin (void)
122 {
123     static BOOL fAdmin = FALSE;
124     static BOOL fTested = FALSE;
125
126     if (!fTested)
127     {
128         /* Obtain the SID for the AFS client admin group.  If the group does
129          * not exist, then assume we have AFS client admin privileges.
130          */
131         PSID psidAdmin = NULL;
132         DWORD dwSize, dwSize2;
133         char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
134         char *pszRefDomain = NULL;
135         SID_NAME_USE snu = SidTypeGroup;
136
137         dwSize = sizeof(pszAdminGroup);
138
139         if (!GetComputerName(pszAdminGroup, &dwSize)) {
140             /* Can't get computer name.  We return false in this case.
141                Retain fAdmin and fTested. This shouldn't happen.*/
142             return FALSE;
143         }
144
145         dwSize = 0;
146         dwSize2 = 0;
147
148         strcat(pszAdminGroup,"\\");
149         strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME);
150
151         LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
152         /* that should always fail. */
153
154         if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
155             /* if we can't find the group, then we allow the operation */
156             fAdmin = TRUE;
157             return TRUE;
158         }
159
160         if (dwSize == 0 || dwSize2 == 0) {
161             /* Paranoia */
162             fAdmin = TRUE;
163             return TRUE;
164         }
165
166         psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
167         assert(psidAdmin);
168         pszRefDomain = (char *)malloc(dwSize2);
169         assert(pszRefDomain);
170
171         if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
172             /* We can't lookup the group now even though we looked it up earlier.  
173                Could this happen? */
174             fAdmin = TRUE;
175         } else {
176             /* Then open our current ProcessToken */
177             HANDLE hToken;
178
179             if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
180             {
181
182                 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
183                     /* We'll have to allocate a chunk of memory to store the list of
184                      * groups to which this user belongs; find out how much memory
185                      * we'll need.
186                      */
187                     DWORD dwSize = 0;
188                     PTOKEN_GROUPS pGroups;
189
190                     GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
191
192                     pGroups = (PTOKEN_GROUPS)malloc(dwSize);
193                     assert(pGroups);
194
195                     /* Allocate that buffer, and read in the list of groups. */
196                     if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
197                     {
198                         /* Look through the list of group SIDs and see if any of them
199                          * matches the AFS Client Admin group SID.
200                          */
201                         size_t iGroup = 0;
202                         for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
203                         {
204                             if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
205                                 fAdmin = TRUE;
206                             }
207                         }
208                     }
209
210                     if (pGroups)
211                         free(pGroups);
212                 }
213
214                 /* if do not have permission because we were not explicitly listed
215                  * in the Admin Client Group let's see if we are the SYSTEM account
216                  */
217                 if (!fAdmin) {
218                     PTOKEN_USER pTokenUser;
219                     SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
220                     PSID pSidLocalSystem = 0;
221                     DWORD gle;
222
223                     GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
224
225                     pTokenUser = (PTOKEN_USER)malloc(dwSize);
226                     assert(pTokenUser);
227
228                     if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
229                         gle = GetLastError();
230
231                     if (AllocateAndInitializeSid( &SIDAuth, 1,
232                                                   SECURITY_LOCAL_SYSTEM_RID,
233                                                   0, 0, 0, 0, 0, 0, 0,
234                                                   &pSidLocalSystem))
235                     {
236                         if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
237                             fAdmin = TRUE;
238                         }
239
240                         FreeSid(pSidLocalSystem);
241                     }
242
243                     if ( pTokenUser )
244                         free(pTokenUser);
245                 }
246             }
247         }
248
249         free(psidAdmin);
250         free(pszRefDomain);
251
252         fTested = TRUE;
253     }
254
255     return fAdmin;
256 }
257
258 /* return a static pointer to a buffer */
259 static char *Parent(apath)
260 char *apath; {
261     register char *tp;
262     strcpy(tspace, apath);
263     tp = strrchr(tspace, '\\');
264     if (tp) {
265         *(tp+1) = 0;    /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
266     }
267     else {
268         fs_ExtractDriveLetter(apath, tspace);
269         strcat(tspace, ".");
270     }
271     return tspace;
272 }
273
274
275 static ListLinkCmd(register struct cmd_syndesc *as, void *arock)
276 {
277     register afs_int32 code;
278     struct ViceIoctl blob;
279     int error;
280     register struct cmd_item *ti;
281     char orig_name[1024];               /*Original name, may be modified*/
282     char true_name[1024];               /*``True'' dirname (e.g., symlink target)*/
283     char parent_dir[1024];              /*Parent directory of true name*/
284     register char *last_component;      /*Last component of true name*/
285 #ifndef WIN32
286     struct stat statbuff;               /*Buffer for status info*/
287 #endif /* not WIN32 */
288 #ifndef WIN32
289     int link_chars_read;                /*Num chars read in readlink()*/
290 #endif /* not WIN32 */
291     int thru_symlink;                   /*Did we get to a mount point via a symlink?*/
292     
293     error = 0;
294     for(ti=as->parms[0].items; ti; ti=ti->next) {
295         /* once per file */
296         thru_symlink = 0;
297 #ifdef WIN32
298         strcpy(orig_name, ti->data);
299 #else /* not WIN32 */
300         sprintf(orig_name, "%s%s",
301                 (ti->data[0] == '/') ? "" : "./",
302                 ti->data);
303 #endif /* not WIN32 */
304
305 #ifndef WIN32
306         if (lstat(orig_name, &statbuff) < 0) {
307             /* if lstat fails, we should still try the pioctl, since it
308                 may work (for example, lstat will fail, but pioctl will
309                     work if the volume of offline (returning ENODEV). */
310             statbuff.st_mode = S_IFDIR; /* lie like pros */
311         }
312
313         /*
314          * The lstat succeeded.  If the given file is a symlink, substitute
315          * the file name with the link name.
316          */
317         if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
318             thru_symlink = 1;
319             /*
320              * Read name of resolved file.
321              */
322             link_chars_read = readlink(orig_name, true_name, 1024);
323             if (link_chars_read <= 0) {
324                 fprintf(stderr,"%s: Can't read target name for '%s' symbolic link!\n",
325                        pn, orig_name);
326                 exit(1);
327             }
328
329             /*
330              * Add a trailing null to what was read, bump the length.
331              */
332             true_name[link_chars_read++] = 0;
333
334             /*
335              * If the symlink is an absolute pathname, we're fine.  Otherwise, we
336              * have to create a full pathname using the original name and the
337              * relative symlink name.  Find the rightmost slash in the original
338              * name (we know there is one) and splice in the symlink value.
339              */
340             if (true_name[0] != '\\') {
341                 last_component = (char *) strrchr(orig_name, '\\');
342                 strcpy(++last_component, true_name);
343                 strcpy(true_name, orig_name);
344             }
345         }
346         else
347             strcpy(true_name, orig_name);
348 #else   /* WIN32 */
349         strcpy(true_name, orig_name);
350 #endif /* WIN32 */
351
352         /*
353          * Find rightmost slash, if any.
354          */
355         last_component = (char *) strrchr(true_name, '\\');
356         if (!last_component)
357             last_component = (char *) strrchr(true_name, '/');
358         if (last_component) {
359             /*
360              * Found it.  Designate everything before it as the parent directory,
361              * everything after it as the final component.
362              */
363             strncpy(parent_dir, true_name, last_component - true_name + 1);
364             parent_dir[last_component - true_name + 1] = 0;
365             last_component++;   /*Skip the slash*/
366
367 #ifdef WIN32
368             if (!InAFS(parent_dir)) {
369                 const char * nbname = NetbiosName();
370                 int len = (int)strlen(nbname);
371
372                 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
373                     parent_dir[len+2] == '\\' &&
374                     parent_dir[len+3] == '\0' &&
375                     !strnicmp(nbname,&parent_dir[2],len))
376                 {
377                     sprintf(parent_dir,"\\\\%s\\all\\", nbname);
378                 }
379             }
380 #endif
381         }
382         else {
383             /*
384              * No slash appears in the given file name.  Set parent_dir to the current
385              * directory, and the last component as the given name.
386              */
387             fs_ExtractDriveLetter(true_name, parent_dir);
388             strcat(parent_dir, ".");
389             last_component = true_name;
390             fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
391         }
392
393         if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
394             fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n", pn);
395             fprintf(stderr,"%s: of a name in the 'symlink list' command.\n", pn);
396             error = 1;
397             continue;
398         }
399         blob.in = last_component;
400         blob.in_size = (long)strlen(last_component)+1;
401         blob.out_size = MAXSIZE;
402         blob.out = space;
403         memset(space, 0, MAXSIZE);
404
405         code = pioctl_utf8(parent_dir, VIOC_LISTSYMLINK, &blob, 1);
406
407         if (code == 0)
408             printf("'%s' is a %ssymlink to '%s'\n",
409                    ti->data,
410                    (thru_symlink ? "symbolic link, leading to a " : ""),
411                    space);
412
413         else {
414             error = 1;
415             if (errno == EINVAL)
416                 fprintf(stderr,"'%s' is not a symlink.\n",
417                        ti->data);
418             else {
419                 Die(errno, (ti->data ? ti->data : parent_dir));
420             }
421         }
422     }
423     return error;
424 }
425
426 static MakeLinkCmd(register struct cmd_syndesc *as, void *arock)
427 {
428     register afs_int32 code;
429     struct ViceIoctl blob;
430     char * parent;
431     char path[1024] = "";
432
433     strcpy(path, as->parms[0].items->data);
434     parent = Parent(path);
435
436     if (!InAFS(parent)) {
437 #ifdef WIN32
438         const char * nbname = NetbiosName();
439         int len = (int)strlen(nbname);
440
441         if (parent[0] == '\\' && parent[1] == '\\' &&
442             parent[len+2] == '\\' &&
443             parent[len+3] == '\0' &&
444             !strnicmp(nbname,&parent[2],len))
445         {
446             sprintf(path,"%sall\\%s", parent, &as->parms[0].items->data[strlen(parent)]);
447             parent = Parent(path);
448             if (!InAFS(parent)) {
449                 fprintf(stderr,"%s: symlinks must be created within the AFS file system\n", pn);
450                 return 1;
451             }
452         } else 
453 #endif
454         {
455             fprintf(stderr,"%s: symlinks must be created within the AFS file system\n", pn);
456             return 1;
457         }
458     }
459
460 #ifdef WIN32
461     if ( IsFreelanceRoot(parent) && !IsAdmin() ) {
462         fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
463         return 1;
464     }
465
466     fprintf(stderr, "Creating symlink [%s] to [%s]\n", path, as->parms[1].items->data);
467
468     /* create symlink with a special pioctl for Windows NT, since it doesn't
469      * have a symlink system call.
470      */
471     blob.out_size = 0;
472     blob.in_size = 1 + (long)strlen(as->parms[1].items->data);
473     blob.in = as->parms[1].items->data;
474     blob.out = NULL;
475     code = pioctl_utf8(path, VIOC_SYMLINK, &blob, 0);
476 #else /* not WIN32 */
477     code = symlink(as->parms[1].items->data, path);
478 #endif /* not WIN32 */
479     if (code) {
480         Die(errno, as->parms[0].items->data);
481         return 1;
482     }
483     return 0;
484 }
485
486 /*
487  * Delete AFS symlinks.  Variables are used as follows:
488  *       tbuffer: Set to point to the null-terminated directory name of the
489  *          symlink (or ``.'' if none is provided)
490  *      tp: Set to point to the actual name of the symlink to nuke.
491  */
492 static RemoveLinkCmd(register struct cmd_syndesc *as, void *arock)
493 {
494     register afs_int32 code=0;
495     struct ViceIoctl blob;
496     register struct cmd_item *ti;
497     char tbuffer[1024];
498     char lsbuffer[1024];
499     register char *tp;
500     
501     for(ti=as->parms[0].items; ti; ti=ti->next) {
502         /* once per file */
503         tp = (char *) strrchr(ti->data, '\\');
504         if (!tp)
505             tp = (char *) strrchr(ti->data, '/');
506         if (tp) {
507             strncpy(tbuffer, ti->data, code=(afs_int32)(tp-ti->data+1));  /* the dir name */
508             tbuffer[code] = 0;
509             tp++;   /* skip the slash */
510
511 #ifdef WIN32
512             if (!InAFS(tbuffer)) {
513                 const char * nbname = NetbiosName();
514                 int len = (int)strlen(nbname);
515
516                 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
517                      tbuffer[len+2] == '\\' &&
518                      tbuffer[len+3] == '\0' &&
519                      !strnicmp(nbname,&tbuffer[2],len))
520                 {
521                     sprintf(tbuffer,"\\\\%s\\all\\", nbname);
522                 }
523             }
524 #endif
525         }
526         else {
527             fs_ExtractDriveLetter(ti->data, tbuffer);
528             strcat(tbuffer, ".");
529             tp = ti->data;
530             fs_StripDriveLetter(tp, tp, 0);
531         }
532         blob.in = tp;
533         blob.in_size = (int)strlen(tp)+1;
534         blob.out = lsbuffer;
535         blob.out_size = sizeof(lsbuffer);
536         code = pioctl_utf8(tbuffer, VIOC_LISTSYMLINK, &blob, 0);
537         if (code) {
538             if (errno == EINVAL)
539                 fprintf(stderr,"symlink: '%s' is not a symlink.\n", ti->data);
540             else {
541                 Die(errno, ti->data);
542             }
543             continue;   /* don't bother trying */
544         }
545
546         if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
547             fprintf(stderr,"symlink: Only AFS Client Administrators may alter the root.afs volume\n");
548             code = 1;
549             continue;   /* skip */
550         }
551
552         blob.out_size = 0;
553         blob.in = tp;
554         blob.in_size = (long)strlen(tp)+1;
555         code = pioctl_utf8(tbuffer, VIOC_DELSYMLINK, &blob, 0);
556         if (code) {
557             Die(errno, ti->data);
558         }
559     }
560     return code;
561 }
562
563 static void
564 FreeUtf8CmdLine(int argc, char ** argv)
565 {
566     int i;
567     for (i=0; i < argc; i++) {
568         if (argv[i])
569             free(argv[i]);
570     }
571     free(argv);
572 }
573
574 static char **
575 MakeUtf8Cmdline(int argc, const wchar_t **wargv)
576 {
577     char ** argv;
578     int i;
579
580     argv = calloc(argc, sizeof(argv[0]));
581     if (argv == NULL)
582         return NULL;
583
584     for (i=0; i < argc; i++) {
585         int s;
586
587         s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, FALSE);
588         if (s == 0 ||
589             (argv[i] = calloc(s+1, sizeof(char))) == NULL) {
590             break;
591         }
592
593         s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], s+1, NULL, FALSE);
594         if (s == 0) {
595             break;
596         }
597     }
598
599     if (i < argc) {
600         FreeUtf8CmdLine(argc, argv);
601         return NULL;
602     }
603
604     return argv;
605 }
606
607 static    struct ViceIoctl gblob;
608 static int debug = 0;
609
610 int wmain(int argc, wchar_t **wargv)
611 {
612     register afs_int32 code;
613     register struct cmd_syndesc *ts;
614     char ** argv;
615     
616 #ifdef  AFS_AIX32_ENV
617     /*
618      * The following signal action for AIX is necessary so that in case of a 
619      * crash (i.e. core is generated) we can include the user's data section 
620      * in the core dump. Unfortunately, by default, only a partial core is
621      * generated which, in many cases, isn't too useful.
622      */
623     struct sigaction nsa;
624     
625     sigemptyset(&nsa.sa_mask);
626     nsa.sa_handler = SIG_DFL;
627     nsa.sa_flags = SA_FULLDUMP;
628     sigaction(SIGSEGV, &nsa, NULL);
629 #endif
630
631 #ifdef WIN32
632     WSADATA WSAjunk;
633     WSAStartup(0x0101, &WSAjunk);
634 #endif /* WIN32 */
635
636     /* try to find volume location information */
637     
638     argv = MakeUtf8Cmdline(argc, wargv);
639
640     osi_Init();
641
642     ts = cmd_CreateSyntax("list", ListLinkCmd, NULL, "list symlink");    
643     cmd_AddParm(ts, "-name", CMD_LIST, 0, "name");
644     
645     ts = cmd_CreateSyntax("make", MakeLinkCmd, NULL, "make symlink");
646     cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name");
647     cmd_AddParm(ts, "-to", CMD_SINGLE, 0, "target");
648
649     ts = cmd_CreateSyntax("remove", RemoveLinkCmd, NULL, "remove symlink");
650     cmd_AddParm(ts, "-name", CMD_LIST, 0, "name");
651     cmd_CreateAlias(ts, "rm");
652
653     code = cmd_Dispatch(argc, argv);
654
655 #ifndef WIN32
656     if (rxInitDone) rx_Finalize();
657 #endif /* not WIN32 */
658     
659     FreeUtf8CmdLine(argc, argv);
660     
661     return code;
662 }
663
664 void Die(code, filename)
665     int   code;
666     char *filename;
667 { /*Die*/
668
669     if (code == EINVAL) {
670         if (filename)
671             fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
672         else fprintf(stderr,"%s: Invalid argument.\n", pn);
673     }
674     else if (code == ENOENT) {
675         if (filename) fprintf(stderr,"%s: File '%s' doesn't exist.\n", pn, filename);
676         else fprintf(stderr,"%s: no such file returned.\n", pn);
677     }
678     else if (code == EEXIST) {
679         if (filename) fprintf(stderr,"%s: File '%s' already exists.\n", pn, filename);
680         else fprintf(stderr,"%s: the specified file already exists.\n", pn);
681     }
682     else if (code == EROFS)  fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
683     else if (code == EACCES || code == EPERM) {
684         if (filename) fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
685         else fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
686     }
687     else if (code == ENODEV) {
688         fprintf(stderr,"%s: AFS service may not have started.\n", pn);
689     }
690     else if (code == ESRCH) {
691         fprintf(stderr,"%s: Cell name not recognized.\n", pn);
692     }
693     else if (code == EPIPE) {
694         fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
695     }
696     else if (code == EFBIG) {
697         fprintf(stderr,"%s: Cache size too large.\n", pn);
698     }
699     else if (code == ETIMEDOUT) {
700         if (filename)
701             fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
702         else
703             fprintf(stderr,"%s: Connection timed out", pn);
704     }
705     else {
706         if (filename) fprintf(stderr,"%s:'%s'", pn, filename);
707         else fprintf(stderr,"%s", pn);
708 #ifdef WIN32
709         fprintf(stderr, ": code 0x%x\n", code);
710 #else /* not WIN32 */
711         fprintf(stderr,": %s\n", afs_error_message(code));
712 #endif /* not WIN32 */
713     }
714 } /*Die*/