/*
* Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
* Original Code as defined in and that are subject to the Apple Public
* Source License Version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
/* BEGIN CSTYLED */
/*
* @(#)ui.c *
* (c) 2004 Apple Computer, Inc. All Rights Reserved
*
*
* netshareenum.c -- Routines for getting a list of share information
* from a server.
*
* MODIFICATION HISTORY:
* 27-Nov-2004 Guy Harris New today
*/
/* END CSTYLED */
/*
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <netsmb/smb_netshareenum.h>
#include <smb/charsets.h>
#if 0 /* XXX see below */
#include <dce/exc_handling.h>
#include "srvsvc.h"
#endif
/*
* Don't want RPC client-side code in here.
* It's good code; just doesn't belong here.
*
* The API provided by this library should be
* just files and pipes (and not much more).
* It MAY be useful to provide some of the
* RAP (remote API) functions functions like
* rap_netshareenum below...
*
* XXX: Not sure this file belongs here at all.
* smb_rap.h looks like a reasonable API
* for this library to export.
*/
#if 0 /* XXX */
static int
struct share_info **entries_listp)
{
char *addrstr, *srvnamestr;
unsigned short *usrvnamestr;
static EXCEPTION rpc_x_connect_rejected;
static int exceptions_initialized;
if (binding_status != rpc_s_ok) {
"rpc_string_binding_compose failed with %d"),
0, binding_status);
return (EINVAL);
}
if (binding_status != rpc_s_ok) {
"rpc_binding_from_string_binding failed with %d"), 0,
return (EINVAL);
}
level = 1;
/*
* Convert the server IP address to a string, and send that as
* the "server name" - that's what Windows appears to do, and
* that avoids problems with NetBIOS names containing
* non-ASCII characters.
*/
if (srvnamestr == NULL) {
"can't allocate string for server address"), status);
return (status);
}
if (usrvnamestr == NULL) {
"can't convert string for server address to Unicode"), 0);
return (EINVAL);
}
if (!exceptions_initialized) {
}
/* printf("Calling NetrShareEnum.."); XXX */
if (status != 0)
"error from NetrShareEnum call: status = 0x%08x"),
0, status);
/*CSTYLED*/
/*
* This is what we get if we can't open the pipe.
* That's a normal occurrence when we're talking
* to a system that (presumably) doesn't support
* DCE RPC on the server side, such as Windows 95/98/Me,
* so we don't log an error.
*/
/*CSTYLED*/
/*
* XXX - should we handle some exceptions differently,
* returning different errors, and try RAP only for
* ENOTSUP?
*/
"error from NetrShareEnum call: exception = %u"),
if (status != 0)
return (ENOTSUP);
/*
* XXX - if the IDL is correct, it's not clear whether the
* unmarshalling code will properly handle the case where
* a packet where "share_count" and the max count for the
* array of shares don't match; a valid DCE RPC implementation
* won't marshal something like that, but there's no guarantee
* that the server we're talking to has a valid implementation
* (which could be a *malicious* implementation!).
*/
if (entry_list == NULL) {
goto cleanup_and_return;
}
i++, share++) {
goto fail;
goto fail;
elp++;
}
*totalp = total_entries;
error = 0;
goto cleanup_and_return;
fail:
/*
* elp->netname is set before elp->remark, so if
* elp->netname is null, elp->remark is also null.
* If either of them is null, we haven't done anything
* to any entries after this one.
*/
break;
break;
}
}
/*
* XXX - "share1" should be a unique pointer, but we haven't
* changed the marshalling code to support non-full pointers
* in unions, so we leave it as a full pointer.
*
* That means that this might, or might not, be changed from
* pointing to "share_info_1_container" to pointing to a
* mallocated structure, according to the DCE RPC 1.1 IDL spec;
* we free it only if it's changed.
*/
return (error);
}
#endif /* XXX */
/*
* Enumerate shares using RAP
*/
struct smb_share_info_1 {
char shi1_pad;
};
static int
{
int error;
if (error)
return (error);
if (error == 0) {
*pcTotalAvail = lval;
}
return (error);
}
static int
struct share_info **entries_listp)
{
char *cp;
return (errno);
if (error &&
return (error);
}
if (entry_list == NULL) {
return (error);
}
i++, ep++) {
continue; /* punt on this entry */
/*
* Check for validity of offset.
*/
} else
elp++;
nreturned++;
}
return (0);
}
/*
* First we try the RPC-based NetrShareEnum, and, if that fails, we fall
* back on the RAP-based NetShareEnum.
*/
int
struct share_info **entry_listp)
{
int error;
#ifdef NOTYETDEFINED
/*
* Try getting a list of shares with the SRVSVC RPC service.
*/
if (error == 0)
return (0);
#endif
/*
* OK, that didn't work - try RAP.
* XXX - do so only if it failed because we couldn't open
* the pipe?
*/
return (error);
}