summaryrefslogtreecommitdiffstats
path: root/private/net/svcdlls/repl/server/expget.c
blob: 62ad37bda74f4aaf0d39e324f03167a0a6645f06 (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*++

Copyright (c) 1992-1993  Microsoft Corporation

Module Name:

    ExpGet.c

Abstract:

    This file contains NetrReplExportDirGetInfo.

Author:

    John Rogers (JohnRo) 08-Jan-1992

Environment:

    Runs under Windows NT.
    Requires ANSI C extensions: slash-slash comments, long external names.

Revision History:

    08-Jan-1992 JohnRo
        Created.
    15-Jan-1992 JohnRo
        Corrected name of this routine.
    20-Jan-1992 JohnRo
        Netr prototypes are now generated by MIDL and put in repl.h.
    20-Jan-1992 JohnRo
        Changed prototype to match MIDL requirements.
    28-Jan-1992 JohnRo
        Changed ExportDirAllocApiRecords() to allow arrays.
        Changed to use LPTSTR etc.
        Changed ExportDirBuildApiRecord's interface.
    23-Mar-1992 JohnRo
        Do a little more checking before we lock things.
    28-Jul-1992 JohnRo
        Added more debug output.
        Avoid compiler warnings.
    13-Nov-1992 JohnRo
        RAID 1537: Repl APIs in wrong role kill svc.
    02-Apr-1993 JohnRo
        Use NetpKdPrint() where possible.

--*/


// These must be included first:

#include <windef.h>             // IN, VOID, LPTSTR, etc.
#include <lmcons.h>             // NET_API_STATUS.
#include <repldefs.h>           // Needed by <master.h>.
#include <master.h>             // PMASTER_LIST_REC.
#include <rpc.h>                // Needed by <repl.h>.

// These can be in any order:

#include <dirname.h>            // ReplIsDirNameValid().
#include <expdir.h>             // ExportDirBuildApiRecord(), etc.
#include <lmerr.h>              // ERROR_ and NERR_ equates; NO_ERROR.
#include <masproto.h>           // GetMasterRec().
#include <netdebug.h>           // NetpAssert().
#include <netlock.h>            // ACQUIRE_LOCK_SHARED(), RELEASE_LOCK().
#include <prefix.h>     // PREFIX_ equates.
#include <repl.h>               // My prototype (in MIDL-generated .h file).
#include <replgbl.h>    // ReplConfigLock, ReplConfigRole.


NET_API_STATUS
NetrReplExportDirGetInfo (
    IN LPTSTR UncServerName OPTIONAL,
    IN LPTSTR DirName,
    IN DWORD Level,
    OUT LPEXPORT_CONTAINER BufPtr       // RPC container (union)
    )

/*++

Routine Description:

    Same as NetReplExportDirGetInfo.

Arguments:

    Same as NetReplExportDirGetInfo.

Return Value:

    Same as NetReplExportDirGetInfo.

--*/

{
    LPVOID ApiRecord = NULL;
    NET_API_STATUS ApiStatus;
    BOOL ConfigLocked = FALSE;
    BOOL ListLocked = FALSE;
    PMASTER_LIST_REC MasterRecord;
    LPVOID StringLocation;

    IF_DEBUG( EXPAPI ) {
        NetpKdPrint(( PREFIX_REPL
                "NetrReplExportDirGetInfo: union at " FORMAT_LPVOID ".\n",
                (LPVOID) BufPtr ));
    }

    //
    // Check for caller errors.
    //
    if (BufPtr == NULL) {
        return (ERROR_INVALID_PARAMETER);
    }

    BufPtr->Info0 = NULL;  // Don't confuse caller about possible alloc'ed data.

    if (ReplIsDirNameValid( DirName ) == FALSE) {
        return (ERROR_INVALID_PARAMETER);
    } else if ( !ExportDirIsLevelValid( Level, FALSE ) ) {  // no setinfo levels
        return (ERROR_INVALID_LEVEL);
    }

    //
    // Get a shared lock on config data so we can see if role includes export.
    //
    ACQUIRE_LOCK_SHARED( ReplConfigLock );
    ConfigLocked = TRUE;

    if ( !ReplRoleIncludesExport( ReplConfigRole ) ) {
        ApiStatus = ExportDirGetApiRecord (
                UncServerName,
                DirName,
                Level,
                (LPBYTE *) (LPVOID) & ApiRecord );
        goto Cleanup;
    }

    //
    // Get read-only lock on master list.
    //
    ACQUIRE_LOCK_SHARED( RMGlobalListLock );
    ListLocked = TRUE;

    //
    // Find the master record for this dir name.
    //
    MasterRecord = GetMasterRec( DirName );
    if (MasterRecord == NULL) {   // Not found.

        ApiStatus = NERR_UnknownDevDir;
        // Don't forget to release lock...

    } else {   // Found.

        //
        // Allocate the output area.
        // Compute size of output area (and check caller's Level too).
        //
        ApiStatus = ExportDirAllocApiRecords (
                Level,
                1,                      // only need one record.
                (LPBYTE *) & ApiRecord,
                (LPBYTE *) (LPVOID) & StringLocation ); // Points past data end.
        if (ApiStatus != NO_ERROR) {

            // ApiStatus is already set to return error to caller.
            // Don't forget to release lock...

        } else {
            NetpAssert( ApiRecord != NULL );

            //
            // Build ApiRecord!
            //
            ApiStatus = ExportDirBuildApiRecord (
                    Level,
                    DirName,
                    MasterRecord->integrity,
                    MasterRecord->extent,
                    MasterRecord->lockcount,
                    MasterRecord->time_of_first_lock,  // Secs since 1970.
                    ApiRecord,
                    (LPBYTE *) (LPVOID) & StringLocation);
            NetpAssert( ApiStatus == NO_ERROR );  // We checked all parms.

            // Don't forget to release lock...

        }

    }

Cleanup:

    //
    // Release locks and tell caller how everything went.
    //

    if (ListLocked) {
        RELEASE_LOCK( RMGlobalListLock );
    }

    if (ConfigLocked) {
        RELEASE_LOCK( ReplConfigLock );
    }

    if (ApiStatus == NO_ERROR) {
        NetpAssert( ApiRecord != NULL );
        NetpAssert( ExportDirIsApiRecordValid( Level, ApiRecord, NULL ) );
    }
    BufPtr->Info2 = (LPVOID) ApiRecord;
    return (ApiStatus);

}