diff options
Diffstat (limited to 'source/lib/system.c')
-rw-r--r-- | source/lib/system.c | 203 |
1 files changed, 184 insertions, 19 deletions
diff --git a/source/lib/system.c b/source/lib/system.c index 4114ce456cf..a402af77c9b 100644 --- a/source/lib/system.c +++ b/source/lib/system.c @@ -21,6 +21,8 @@ #include "includes.h" +extern int DEBUGLEVEL; + /* The idea is that this file will eventually have wrappers around all important system calls in samba. The aims are: @@ -338,7 +340,7 @@ struct hostent *sys_gethostbyname(const char *name) /* Does this name have any dots in it? If so, make no change */ - if (strchr_m(name, '.')) + if (strchr(name, '.')) return(gethostbyname(name)); /* Get my hostname, which should have domain name @@ -348,7 +350,7 @@ struct hostent *sys_gethostbyname(const char *name) gethostname(hostname, sizeof(hostname) - 1); hostname[sizeof(hostname) - 1] = 0; - if ((domain = strchr_m(hostname, '.')) == NULL) + if ((domain = strchr(hostname, '.')) == NULL) return(gethostbyname(name)); /* Attach domain name to query and do modified query. @@ -533,7 +535,7 @@ int sys_getgroups(int setlen, gid_t *gidset) if((ngroups = getgroups(setlen, group_list)) < 0) { int saved_errno = errno; - SAFE_FREE(group_list); + free((char *)group_list); errno = saved_errno; return -1; } @@ -541,7 +543,7 @@ int sys_getgroups(int setlen, gid_t *gidset) for(i = 0; i < ngroups; i++) gidset[i] = (gid_t)group_list[i]; - SAFE_FREE(group_list); + free((char *)group_list); return ngroups; #endif /* HAVE_BROKEN_GETGROUPS */ } @@ -585,12 +587,12 @@ int sys_setgroups(int setlen, gid_t *gidset) if(setgroups(setlen, group_list) != 0) { int saved_errno = errno; - SAFE_FREE(group_list); + free((char *)group_list); errno = saved_errno; return -1; } - SAFE_FREE(group_list); + free((char *)group_list); return 0 ; #endif /* HAVE_BROKEN_GETGROUPS */ } @@ -725,6 +727,176 @@ struct passwd *sys_getpwuid(uid_t uid) } /************************************************************************** + The following are the UNICODE versions of *all* system interface functions + called within Samba. Ok, ok, the exceptions are the gethostbyXX calls, + which currently are left as ascii as they are not used other than in name + resolution. +****************************************************************************/ + +/************************************************************************** + Wide stat. Just narrow and call sys_xxx. +****************************************************************************/ + +int wsys_stat(const smb_ucs2_t *wfname,SMB_STRUCT_STAT *sbuf) +{ + pstring fname; + return sys_stat(unicode_to_unix(fname,wfname,sizeof(fname)), sbuf); +} + +/************************************************************************** + Wide lstat. Just narrow and call sys_xxx. +****************************************************************************/ + +int wsys_lstat(const smb_ucs2_t *wfname,SMB_STRUCT_STAT *sbuf) +{ + pstring fname; + return sys_lstat(unicode_to_unix(fname,wfname,sizeof(fname)), sbuf); +} + +/************************************************************************** + Wide creat. Just narrow and call sys_xxx. +****************************************************************************/ + +int wsys_creat(const smb_ucs2_t *wfname, mode_t mode) +{ + pstring fname; + return sys_creat(unicode_to_unix(fname,wfname,sizeof(fname)), mode); +} + +/************************************************************************** + Wide open. Just narrow and call sys_xxx. +****************************************************************************/ + +int wsys_open(const smb_ucs2_t *wfname, int oflag, mode_t mode) +{ + pstring fname; + return sys_open(unicode_to_unix(fname,wfname,sizeof(fname)), oflag, mode); +} + +/************************************************************************** + Wide fopen. Just narrow and call sys_xxx. +****************************************************************************/ + +FILE *wsys_fopen(const smb_ucs2_t *wfname, const char *type) +{ + pstring fname; + return sys_fopen(unicode_to_unix(fname,wfname,sizeof(fname)), type); +} + +/************************************************************************** + Wide opendir. Just narrow and call sys_xxx. +****************************************************************************/ + +DIR *wsys_opendir(const smb_ucs2_t *wfname) +{ + pstring fname; + return opendir(unicode_to_unix(fname,wfname,sizeof(fname))); +} + +/************************************************************************** + Wide readdir. Return a structure pointer containing a wide filename. +****************************************************************************/ + +SMB_STRUCT_WDIRENT *wsys_readdir(DIR *dirp) +{ + static SMB_STRUCT_WDIRENT retval; + SMB_STRUCT_DIRENT *dirval = sys_readdir(dirp); + + if(!dirval) + return NULL; + + /* + * The only POSIX defined member of this struct is d_name. + */ + + unix_to_unicode(retval.d_name,dirval->d_name,sizeof(retval.d_name)); + + return &retval; +} + +/************************************************************************** + Wide getwd. Call sys_xxx and widen. Assumes s points to a wpstring. +****************************************************************************/ + +smb_ucs2_t *wsys_getwd(smb_ucs2_t *s) +{ + pstring fname; + char *p = sys_getwd(fname); + + if(!p) + return NULL; + + return unix_to_unicode(s, p, sizeof(wpstring)); +} + +/************************************************************************** + Wide chown. Just narrow and call sys_xxx. +****************************************************************************/ + +int wsys_chown(const smb_ucs2_t *wfname, uid_t uid, gid_t gid) +{ + pstring fname; + return chown(unicode_to_unix(fname,wfname,sizeof(fname)), uid, gid); +} + +/************************************************************************** + Wide chroot. Just narrow and call sys_xxx. +****************************************************************************/ + +int wsys_chroot(const smb_ucs2_t *wfname) +{ + pstring fname; + return chroot(unicode_to_unix(fname,wfname,sizeof(fname))); +} + +/************************************************************************** + Wide getpwnam. Return a structure pointer containing wide names. +****************************************************************************/ + +SMB_STRUCT_WPASSWD *wsys_getpwnam(const smb_ucs2_t *wname) +{ + static SMB_STRUCT_WPASSWD retval; + fstring name; + struct passwd *pwret = sys_getpwnam(unicode_to_unix(name,wname,sizeof(name))); + + if(!pwret) + return NULL; + + unix_to_unicode(retval.pw_name, pwret->pw_name, sizeof(retval.pw_name)); + retval.pw_passwd = pwret->pw_passwd; + retval.pw_uid = pwret->pw_uid; + retval.pw_gid = pwret->pw_gid; + unix_to_unicode(retval.pw_gecos, pwret->pw_gecos, sizeof(retval.pw_gecos)); + unix_to_unicode(retval.pw_dir, pwret->pw_dir, sizeof(retval.pw_dir)); + unix_to_unicode(retval.pw_shell, pwret->pw_shell, sizeof(retval.pw_shell)); + + return &retval; +} + +/************************************************************************** + Wide getpwuid. Return a structure pointer containing wide names. +****************************************************************************/ + +SMB_STRUCT_WPASSWD *wsys_getpwuid(uid_t uid) +{ + static SMB_STRUCT_WPASSWD retval; + struct passwd *pwret = sys_getpwuid(uid); + + if(!pwret) + return NULL; + + unix_to_unicode(retval.pw_name, pwret->pw_name, sizeof(retval.pw_name)); + retval.pw_passwd = pwret->pw_passwd; + retval.pw_uid = pwret->pw_uid; + retval.pw_gid = pwret->pw_gid; + unix_to_unicode(retval.pw_gecos, pwret->pw_gecos, sizeof(retval.pw_gecos)); + unix_to_unicode(retval.pw_dir, pwret->pw_dir, sizeof(retval.pw_dir)); + unix_to_unicode(retval.pw_shell, pwret->pw_shell, sizeof(retval.pw_shell)); + + return &retval; +} + +/************************************************************************** Extract a command into an arg list. Uses a static pstring for storage. Caller frees returned arg list (which contains pointers into the static pstring). ****************************************************************************/ @@ -884,7 +1056,7 @@ int sys_popen(const char *command) */ close (child_end); - SAFE_FREE(argl); + free((char *)argl); /* Link into popen_chain. */ entry->next = popen_chain; @@ -895,8 +1067,10 @@ int sys_popen(const char *command) err_exit: - SAFE_FREE(entry); - SAFE_FREE(argl); + if(entry) + free((char *)entry); + if(argl) + free((char *)argl); close(pipe_fds[0]); close(pipe_fds[1]); return -1; @@ -936,7 +1110,7 @@ int sys_pclose(int fd) wait_pid = sys_waitpid (entry->child_pid, &wstatus, 0); } while (wait_pid == -1 && errno == EINTR); - SAFE_FREE(entry); + free((char *)entry); if (wait_pid == -1) return -1; @@ -973,12 +1147,3 @@ int sys_dlclose (void *handle) return 0; #endif } - -const char *sys_dlerror(void) -{ -#ifdef HAVE_LIBDL - return dlerror(); -#else - return NULL; -#endif -} |