summaryrefslogtreecommitdiffstats
path: root/private/nw/nwscript/unc.c
blob: 8f99320b9f42c32d507568323a1819952a8988c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*************************************************************************
*
*  UNC.C
*
*  NetWare format to UNC format
*
*  Copyright (c) 1995 Microsoft Corporation
*
*  $Log:   N:\NT\PRIVATE\NW4\NWSCRIPT\VCS\UNC.C  $
*  
*     Rev 1.4   10 Apr 1996 14:24:00   terryt
*  Hotfix for 21181hq
*  
*     Rev 1.4   12 Mar 1996 19:56:18   terryt
*  Relative NDS names and merge
*  
*     Rev 1.3   04 Jan 1996 18:57:26   terryt
*  Bug fixes reported by MS
*  
*     Rev 1.2   22 Dec 1995 14:27:04   terryt
*  Add Microsoft headers
*  
*     Rev 1.1   22 Dec 1995 11:09:18   terryt
*  Fixes
*  
*     Rev 1.0   15 Nov 1995 18:08:14   terryt
*  Initial revision.
*  
*     Rev 1.1   23 May 1995 19:37:24   terryt
*  Spruce up source
*  
*     Rev 1.0   15 May 1995 19:11:10   terryt
*  Initial revision.
*  
*************************************************************************/
#include <stdio.h>
#include <direct.h>
#include <time.h>
#include <stdlib.h>

#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <windows.h>

#include "inc/common.h"

/********************************************************************

        NTNWtoUNCFormat

Routine Description:

        Given a connection handle and a path, change it to UNC format
        if it's in NetWare format.  I.E.

        SYS:\usr\terryt   ==>   \\HELIUM\SYS\usr\terryt

        Don't do the conversion if it's not in NetWare format.

Arguments:

        ConnectionHandle   -  Connection Handle
        NetWarePath        -  Input original path

Return Value:
        UNC string

 *******************************************************************/
char *
NTNWtoUNCFormat( char * NetWarePath )
{
    static char UNCPath[1024];
    unsigned int Result;
    char ServerName[48];
    char * p;
    char * q;

    /*
     *  If it's UNC already, leave it alone
     */
    if ( ( NetWarePath[0] == '\\' ) && ( NetWarePath[1] == '\\' ) )
        return NetWarePath;
    if ( ( NetWarePath[0] == '/' ) && ( NetWarePath[1] == '/' ) )
        return NetWarePath;

    /*
     *  if it's drive:dir, leave it alone
     */
    if ( NetWarePath[0] && ( NetWarePath[1] == ':' ) )
        return NetWarePath;

    /*
     *  if it's not volume:dir, leave it alone
     */
    p = strchr( NetWarePath, ':' );
    if ( !p )
        return NetWarePath;

    /*
     * if slashes before :, it must be a file server
     */
    q = strchr( NetWarePath, '\\' );
    if ( q && ( q < p ) )
    {
        strcpy( UNCPath, "\\\\" );
        *p = '\0';
        strcat( UNCPath, NetWarePath );
        if (( *(p + 1) != '\\' ) && ( *(p + 1) != '/' ) )
           strcat( UNCPath, "\\" );
        strcat( UNCPath, p + 1 );
        *p = ':';
        return UNCPath;
    }

    q = strchr( NetWarePath, '/' );
    if ( q && ( q < p ) )
    {
        strcpy( UNCPath, "\\\\" );
        *q = '\\';
        *p = '\0';
        strcat( UNCPath, NetWarePath );
        if (( *(p + 1) != '\\' ) && ( *(p + 1) != '/' ) )
           strcat( UNCPath, "\\" );
        strcat( UNCPath, p + 1 );
        *q = '/';
        *p = ':';
        return UNCPath;
    }

    strcpy( UNCPath, "\\\\" );
    strcat( UNCPath, PREFERRED_SERVER );
    strcat( UNCPath, "\\" );
    *p = '\0';
    strcat( UNCPath, NetWarePath );
    if (( *(p + 1) != '\\' ) && ( *(p + 1) != '/' ) )
        strcat( UNCPath, "\\" );
    strcat( UNCPath, p + 1 );
    *p = ':';

    return UNCPath;
}