subr.c revision 4bff34e37def8a90f9194d81bc345c52ba20086a
/*
* Copyright (c) 2000, Boris Popov
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Boris Popov.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: subr.c,v 1.19 2005/02/09 00:23:45 lindak Exp $
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#include <sysexits.h>
#include <libintl.h>
#include <cflib.h>
#include <err.h>
static int smblib_initialized;
int
smb_lib_init(void)
{
int error;
if (smblib_initialized)
return (0);
"%s: can't initialise locale\n"), __progname);
return (error);
}
return (0);
}
/*
* Private version of strerror(3C) that
* knows our special error codes.
*/
char *
smb_strerror(int err)
{
char *msg;
switch (err) {
case EBADRPC:
"remote call failed");
break;
case EAUTH:
"authentication failed");
break;
default:
break;
}
return (msg);
}
/*
* Print a (descriptive) error message
* error values:
* 0 - no specific error code available;
* 1..32767 - system error
*/
void
const char *cp;
int errtype;
if (error == -1) {
} else {
error &= ~SMB_ERRTYPE_MASK;
}
switch (errtype) {
case SMB_SYS_ERROR:
if (error)
else
break;
case SMB_RAP_ERROR:
break;
case SMB_NB_ERROR:
else
break;
default:
}
}
char *
int first = 1;
first = 0;
}
}
return (dest);
}
extern int home_nsmbrc;
#ifdef DEBUG
#include "queue.h"
#include "rcfile_priv.h"
void
dump_props(char *where)
{
printf(" key=%s, value=%s\n",
}
}
}
#endif
/*
* first read ~/.smbrc, next try to merge SMB_CFG_FILE - if that fails
* because SMB_CFG_FILE doesn't exist, try to merge OLD_SMB_CFG_FILE
*/
int
{
#ifdef DEPRECATED
fn = SMB_CFG_FILE;
/*
* OK, try to read a config file in the old location.
*/
}
#endif
#ifdef DEBUG
dump_props("after reading global repository");
#endif
if (home) {
home_nsmbrc = 1;
}
}
home_nsmbrc = 0;
#ifdef DEBUG
dump_props("after reading user settings");
#endif
return (ENOENT);
}
return (0);
}
void
{
*dst++ = '$';
*dst++ = '$';
*dst++ = '1';
pos = 27;
while (*src) {
pos += 13;
dst += 2;
}
*dst = 0;
}
int
{
return (EINVAL);
src += 3;
if (len & 1)
return (EINVAL);
len /= 2;
hexval[2] = 0;
pos = 27;
while (len--) {
if (*ep != 0)
return (EINVAL);
pos += 13;
}
*dst = 0;
return (0);
}
static int
safe_execv(char *args[])
{
int pid;
int status;
if (pid == 0) {
/* Changed from errx() to fprintf(stderr) -Pavan */
"%s: execv %s failed, %s\n"), __progname,
}
if (pid == -1) {
return (1);
}
return (1);
"%s: %s command aborted by signal %d\n"),
return (1);
} else if (WEXITSTATUS(status)) {
"%s: %s command failed, exit status %d: %s\n"),
return (1);
}
return (0);
}
void
dropsuid()
{
/* drop setuid root privs asap */
}
#define KEXTLOAD_COMMAND "/sbin/kextload"
#define FS_KEXT_DIR "/System/Library/Extensions/smbfs.kext"
#define FULL_KEXTNAME "com.apple.filesystems.smbfs"
int
{
int error = 0;
/*
* temporarily revert to root (required for kextload)
*/
return (error);
}
char *__progname = NULL;
char *
{
char *p;
if (__progname == NULL) {
__progname = (char *)getexecname();
__progname = p + 1;
}
return (__progname);
}