Prefix global defines
[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 #include <afs/afs_consts.h>
14
15 #include <windows.h>
16 #include <stdlib.h>
17 #include <malloc.h>
18 #include <string.h>
19 #include <stdio.h>
20 #include <time.h>
21 #include <winsock2.h>
22 #include <errno.h>
23 #include <assert.h>
24
25 #include <osi.h>
26 #include <afsint.h>
27 #include <WINNT\afsreg.h>
28
29 #include "fs_utils.h"
30 #include "cmd.h"
31
32 #define MAXNAME 100
33 #define MAXINSIZE 1300    /* pioctl complains if data is larger than this */
34
35 static char space[AFS_PIOCTL_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     char *a;
51     char *b; {
52     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(char *apath)
66 {
67     struct ViceIoctl blob;
68     afs_int32 code;
69
70     blob.in_size = 0;
71     blob.out_size = AFS_PIOCTL_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 = AFS_PIOCTL_MAXSIZE;
90     blob.out = space;
91
92     code = pioctl_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
93     if (code == 0)
94         return !strnicmp("Freelance.Local.Root",space,blob.out_size);
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     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(struct cmd_syndesc *as, void *arock)
276 {
277     afs_int32 code;
278     struct ViceIoctl blob;
279     int error;
280     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     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 = AFS_PIOCTL_MAXSIZE;
402         blob.out = space;
403         memset(space, 0, AFS_PIOCTL_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                    blob.out_size,
412                    space);
413
414         else {
415             error = 1;
416             if (errno == EINVAL)
417                 fprintf(stderr,"'%s' is not a symlink.\n",
418                        ti->data);
419             else {
420                 Die(errno, (ti->data ? ti->data : parent_dir));
421             }
422         }
423     }
424     return error;
425 }
426
427 static MakeLinkCmd(struct cmd_syndesc *as, void *arock)
428 {
429     afs_int32 code;
430     struct ViceIoctl blob;
431     char * parent;
432     char path[1024] = "";
433
434     strcpy(path, as->parms[0].items->data);
435     parent = Parent(path);
436
437     if (!InAFS(parent)) {
438 #ifdef WIN32
439         const char * nbname = NetbiosName();
440         int len = (int)strlen(nbname);
441
442         if (parent[0] == '\\' && parent[1] == '\\' &&
443             parent[len+2] == '\\' &&
444             parent[len+3] == '\0' &&
445             !strnicmp(nbname,&parent[2],len))
446         {
447             sprintf(path,"%sall\\%s", parent, &as->parms[0].items->data[strlen(parent)]);
448             parent = Parent(path);
449             if (!InAFS(parent)) {
450                 fprintf(stderr,"%s: symlinks must be created within the AFS file system\n", pn);
451                 return 1;
452             }
453         } else 
454 #endif
455         {
456             fprintf(stderr,"%s: symlinks must be created within the AFS file system\n", pn);
457             return 1;
458         }
459     }
460
461 #ifdef WIN32
462     if ( IsFreelanceRoot(parent) && !IsAdmin() ) {
463         fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
464         return 1;
465     }
466
467     fprintf(stderr, "Creating symlink [%s] to [%s]\n", path, as->parms[1].items->data);
468
469     /* create symlink with a special pioctl for Windows NT, since it doesn't
470      * have a symlink system call.
471      */
472     blob.out_size = 0;
473     blob.in_size = 1 + (long)strlen(as->parms[1].items->data);
474     blob.in = as->parms[1].items->data;
475     blob.out = NULL;
476     code = pioctl_utf8(path, VIOC_SYMLINK, &blob, 0);
477 #else /* not WIN32 */
478     code = symlink(as->parms[1].items->data, path);
479 #endif /* not WIN32 */
480     if (code) {
481         Die(errno, as->parms[0].items->data);
482         return 1;
483     }
484     return 0;
485 }
486
487 /*
488  * Delete AFS symlinks.  Variables are used as follows:
489  *       tbuffer: Set to point to the null-terminated directory name of the
490  *          symlink (or ``.'' if none is provided)
491  *      tp: Set to point to the actual name of the symlink to nuke.
492  */
493 static RemoveLinkCmd(struct cmd_syndesc *as, void *arock)
494 {
495     afs_int32 code=0;
496     struct ViceIoctl blob;
497     struct cmd_item *ti;
498     char tbuffer[1024];
499     char lsbuffer[1024];
500     char *tp;
501     
502     for(ti=as->parms[0].items; ti; ti=ti->next) {
503         /* once per file */
504         tp = (char *) strrchr(ti->data, '\\');
505         if (!tp)
506             tp = (char *) strrchr(ti->data, '/');
507         if (tp) {
508             strncpy(tbuffer, ti->data, code=(afs_int32)(tp-ti->data+1));  /* the dir name */
509             tbuffer[code] = 0;
510             tp++;   /* skip the slash */
511
512 #ifdef WIN32
513             if (!InAFS(tbuffer)) {
514                 const char * nbname = NetbiosName();
515                 int len = (int)strlen(nbname);
516
517                 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
518                      tbuffer[len+2] == '\\' &&
519                      tbuffer[len+3] == '\0' &&
520                      !strnicmp(nbname,&tbuffer[2],len))
521                 {
522                     sprintf(tbuffer,"\\\\%s\\all\\", nbname);
523                 }
524             }
525 #endif
526         }
527         else {
528             fs_ExtractDriveLetter(ti->data, tbuffer);
529             strcat(tbuffer, ".");
530             tp = ti->data;
531             fs_StripDriveLetter(tp, tp, 0);
532         }
533         blob.in = tp;
534         blob.in_size = (int)strlen(tp)+1;
535         blob.out = lsbuffer;
536         blob.out_size = sizeof(lsbuffer);
537         code = pioctl_utf8(tbuffer, VIOC_LISTSYMLINK, &blob, 0);
538         if (code) {
539             if (errno == EINVAL)
540                 fprintf(stderr,"symlink: '%s' is not a symlink.\n", ti->data);
541             else {
542                 Die(errno, ti->data);
543             }
544             continue;   /* don't bother trying */
545         }
546
547         if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
548             fprintf(stderr,"symlink: Only AFS Client Administrators may alter the root.afs volume\n");
549             code = 1;
550             continue;   /* skip */
551         }
552
553         blob.out_size = 0;
554         blob.in = tp;
555         blob.in_size = (long)strlen(tp)+1;
556         code = pioctl_utf8(tbuffer, VIOC_DELSYMLINK, &blob, 0);
557         if (code) {
558             Die(errno, ti->data);
559         }
560     }
561     return code;
562 }
563
564 static void
565 FreeUtf8CmdLine(int argc, char ** argv)
566 {
567     int i;
568     for (i=0; i < argc; i++) {
569         if (argv[i])
570             free(argv[i]);
571     }
572     free(argv);
573 }
574
575 static char **
576 MakeUtf8Cmdline(int argc, const wchar_t **wargv)
577 {
578     char ** argv;
579     int i;
580
581     argv = calloc(argc, sizeof(argv[0]));
582     if (argv == NULL)
583         return NULL;
584
585     for (i=0; i < argc; i++) {
586         int s;
587
588         s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, FALSE);
589         if (s == 0 ||
590             (argv[i] = calloc(s+1, sizeof(char))) == NULL) {
591             break;
592         }
593
594         s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], s+1, NULL, FALSE);
595         if (s == 0) {
596             break;
597         }
598     }
599
600     if (i < argc) {
601         FreeUtf8CmdLine(argc, argv);
602         return NULL;
603     }
604
605     return argv;
606 }
607
608 static    struct ViceIoctl gblob;
609 static int debug = 0;
610
611 int wmain(int argc, wchar_t **wargv)
612 {
613     afs_int32 code;
614     struct cmd_syndesc *ts;
615     char ** argv;
616     
617 #ifdef  AFS_AIX32_ENV
618     /*
619      * The following signal action for AIX is necessary so that in case of a 
620      * crash (i.e. core is generated) we can include the user's data section 
621      * in the core dump. Unfortunately, by default, only a partial core is
622      * generated which, in many cases, isn't too useful.
623      */
624     struct sigaction nsa;
625     
626     sigemptyset(&nsa.sa_mask);
627     nsa.sa_handler = SIG_DFL;
628     nsa.sa_flags = SA_FULLDUMP;
629     sigaction(SIGSEGV, &nsa, NULL);
630 #endif
631
632 #ifdef WIN32
633     WSADATA WSAjunk;
634     WSAStartup(0x0101, &WSAjunk);
635 #endif /* WIN32 */
636
637     /* try to find volume location information */
638     
639     argv = MakeUtf8Cmdline(argc, wargv);
640
641     osi_Init();
642
643     ts = cmd_CreateSyntax("list", ListLinkCmd, NULL, "list symlink");    
644     cmd_AddParm(ts, "-name", CMD_LIST, 0, "name");
645     
646     ts = cmd_CreateSyntax("make", MakeLinkCmd, NULL, "make symlink");
647     cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name");
648     cmd_AddParm(ts, "-to", CMD_SINGLE, 0, "target");
649
650     ts = cmd_CreateSyntax("remove", RemoveLinkCmd, NULL, "remove symlink");
651     cmd_AddParm(ts, "-name", CMD_LIST, 0, "name");
652     cmd_CreateAlias(ts, "rm");
653
654     code = cmd_Dispatch(argc, argv);
655
656 #ifndef WIN32
657     if (rxInitDone) rx_Finalize();
658 #endif /* not WIN32 */
659     
660     FreeUtf8CmdLine(argc, argv);
661     
662     return code;
663 }
664
665 void Die(code, filename)
666     int   code;
667     char *filename;
668 { /*Die*/
669
670     if (code == EINVAL) {
671         if (filename)
672             fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
673         else fprintf(stderr,"%s: Invalid argument.\n", pn);
674     }
675     else if (code == ENOENT) {
676         if (filename) fprintf(stderr,"%s: File '%s' doesn't exist.\n", pn, filename);
677         else fprintf(stderr,"%s: no such file returned.\n", pn);
678     }
679     else if (code == EEXIST) {
680         if (filename) fprintf(stderr,"%s: File '%s' already exists.\n", pn, filename);
681         else fprintf(stderr,"%s: the specified file already exists.\n", pn);
682     }
683     else if (code == EROFS)  fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
684     else if (code == EACCES || code == EPERM) {
685         if (filename) fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
686         else fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
687     }
688     else if (code == ENODEV) {
689         fprintf(stderr,"%s: AFS service may not have started.\n", pn);
690     }
691     else if (code == ESRCH) {
692         fprintf(stderr,"%s: Cell name not recognized.\n", pn);
693     }
694     else if (code == EPIPE) {
695         fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
696     }
697     else if (code == EFBIG) {
698         fprintf(stderr,"%s: Cache size too large.\n", pn);
699     }
700     else if (code == ETIMEDOUT) {
701         if (filename)
702             fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
703         else
704             fprintf(stderr,"%s: Connection timed out", pn);
705     }
706     else {
707         if (filename) fprintf(stderr,"%s:'%s'", pn, filename);
708         else fprintf(stderr,"%s", pn);
709 #ifdef WIN32
710         fprintf(stderr, ": code 0x%x\n", code);
711 #else /* not WIN32 */
712         fprintf(stderr,": %s\n", afs_error_message(code));
713 #endif /* not WIN32 */
714     }
715 } /*Die*/