Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/lib/util.c

    r597 r740  
    1212   the Free Software Foundation; either version 3 of the License, or
    1313   (at your option) any later version.
    14    
     14
    1515   This program is distributed in the hope that it will be useful,
    1616   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1717   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1818   GNU General Public License for more details.
    19    
     19
    2020   You should have received a copy of the GNU General Public License
    2121   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2323
    2424#include "includes.h"
     25#include "system/passwd.h"
     26#include "system/filesys.h"
     27#include "util_tdb.h"
     28#include "ctdbd_conn.h"
     29#include "../lib/util/util_pw.h"
     30#include "messages.h"
    2531
    2632extern char *global_clobber_region_function;
     
    7480***********************************************************************/
    7581
    76 static char *smb_myname;
    77 static char *smb_myworkgroup;
    7882static char *smb_scope;
    7983static int smb_num_netbios_names;
    8084static char **smb_my_netbios_names;
    81 
    82 /***********************************************************************
    83  Allocate and set myname. Ensure upper case.
    84 ***********************************************************************/
    85 
    86 bool set_global_myname(const char *myname)
    87 {
    88         SAFE_FREE(smb_myname);
    89         smb_myname = SMB_STRDUP(myname);
    90         if (!smb_myname)
    91                 return False;
    92         strupper_m(smb_myname);
    93         return True;
    94 }
    95 
    96 const char *global_myname(void)
    97 {
    98         return smb_myname;
    99 }
    100 
    101 /***********************************************************************
    102  Allocate and set myworkgroup. Ensure upper case.
    103 ***********************************************************************/
    104 
    105 bool set_global_myworkgroup(const char *myworkgroup)
    106 {
    107         SAFE_FREE(smb_myworkgroup);
    108         smb_myworkgroup = SMB_STRDUP(myworkgroup);
    109         if (!smb_myworkgroup)
    110                 return False;
    111         strupper_m(smb_myworkgroup);
    112         return True;
    113 }
    114 
    115 const char *lp_workgroup(void)
    116 {
    117         return smb_myworkgroup;
    118 }
    11985
    12086/***********************************************************************
     
    185151void gfree_names(void)
    186152{
    187         SAFE_FREE( smb_myname );
    188         SAFE_FREE( smb_myworkgroup );
     153        gfree_netbios_names();
    189154        SAFE_FREE( smb_scope );
    190155        free_netbios_names_array();
     
    262227        if (global_myname() == NULL || *global_myname() == '\0') {
    263228                if (!set_global_myname(myhostname())) {
    264                         DEBUG( 0, ( "init_structs: malloc fail.\n" ) );
     229                        DEBUG( 0, ( "init_names: malloc fail.\n" ) );
    265230                        return False;
    266231                }
     
    268233
    269234        if (!set_netbios_aliases(lp_netbios_aliases())) {
    270                 DEBUG( 0, ( "init_structs: malloc fail.\n" ) );
     235                DEBUG( 0, ( "init_names: malloc fail.\n" ) );
    271236                return False;
    272237        }
     
    281246
    282247        return( True );
    283 }
    284 
    285 /**************************************************************************n
    286   Code to cope with username/password auth options from the commandline.
    287   Used mainly in client tools.
    288 ****************************************************************************/
    289 
    290 struct user_auth_info *user_auth_info_init(TALLOC_CTX *mem_ctx)
    291 {
    292         struct user_auth_info *result;
    293 
    294         result = TALLOC_ZERO_P(mem_ctx, struct user_auth_info);
    295         if (result == NULL) {
    296                 return NULL;
    297         }
    298 
    299         result->signing_state = Undefined;
    300         return result;
    301 }
    302 
    303 const char *get_cmdline_auth_info_username(const struct user_auth_info *auth_info)
    304 {
    305         if (!auth_info->username) {
    306                 return "";
    307         }
    308         return auth_info->username;
    309 }
    310 
    311 void set_cmdline_auth_info_username(struct user_auth_info *auth_info,
    312                                     const char *username)
    313 {
    314         TALLOC_FREE(auth_info->username);
    315         auth_info->username = talloc_strdup(auth_info, username);
    316         if (!auth_info->username) {
    317                 exit(ENOMEM);
    318         }
    319 }
    320 
    321 const char *get_cmdline_auth_info_domain(const struct user_auth_info *auth_info)
    322 {
    323         if (!auth_info->domain) {
    324                 return "";
    325         }
    326         return auth_info->domain;
    327 }
    328 
    329 void set_cmdline_auth_info_domain(struct user_auth_info *auth_info,
    330                                   const char *domain)
    331 {
    332         TALLOC_FREE(auth_info->domain);
    333         auth_info->domain = talloc_strdup(auth_info, domain);
    334         if (!auth_info->domain) {
    335                 exit(ENOMEM);
    336         }
    337 }
    338 
    339 const char *get_cmdline_auth_info_password(const struct user_auth_info *auth_info)
    340 {
    341         if (!auth_info->password) {
    342                 return "";
    343         }
    344         return auth_info->password;
    345 }
    346 
    347 void set_cmdline_auth_info_password(struct user_auth_info *auth_info,
    348                                     const char *password)
    349 {
    350         TALLOC_FREE(auth_info->password);
    351         if (password == NULL) {
    352                 password = "";
    353         }
    354         auth_info->password = talloc_strdup(auth_info, password);
    355         if (!auth_info->password) {
    356                 exit(ENOMEM);
    357         }
    358         auth_info->got_pass = true;
    359 }
    360 
    361 bool set_cmdline_auth_info_signing_state(struct user_auth_info *auth_info,
    362                                          const char *arg)
    363 {
    364         auth_info->signing_state = -1;
    365         if (strequal(arg, "off") || strequal(arg, "no") ||
    366                         strequal(arg, "false")) {
    367                 auth_info->signing_state = false;
    368         } else if (strequal(arg, "on") || strequal(arg, "yes") ||
    369                         strequal(arg, "true") || strequal(arg, "auto")) {
    370                 auth_info->signing_state = true;
    371         } else if (strequal(arg, "force") || strequal(arg, "required") ||
    372                         strequal(arg, "forced")) {
    373                 auth_info->signing_state = Required;
    374         } else {
    375                 return false;
    376         }
    377         return true;
    378 }
    379 
    380 int get_cmdline_auth_info_signing_state(const struct user_auth_info *auth_info)
    381 {
    382         return auth_info->signing_state;
    383 }
    384 
    385 void set_cmdline_auth_info_use_ccache(struct user_auth_info *auth_info, bool b)
    386 {
    387         auth_info->use_ccache = b;
    388 }
    389 
    390 bool get_cmdline_auth_info_use_ccache(const struct user_auth_info *auth_info)
    391 {
    392         return auth_info->use_ccache;
    393 }
    394 
    395 void set_cmdline_auth_info_use_kerberos(struct user_auth_info *auth_info,
    396                                         bool b)
    397 {
    398         auth_info->use_kerberos = b;
    399 }
    400 
    401 bool get_cmdline_auth_info_use_kerberos(const struct user_auth_info *auth_info)
    402 {
    403         return auth_info->use_kerberos;
    404 }
    405 
    406 void set_cmdline_auth_info_fallback_after_kerberos(struct user_auth_info *auth_info,
    407                                         bool b)
    408 {
    409         auth_info->fallback_after_kerberos = b;
    410 }
    411 
    412 bool get_cmdline_auth_info_fallback_after_kerberos(const struct user_auth_info *auth_info)
    413 {
    414         return auth_info->fallback_after_kerberos;
    415 }
    416 
    417 /* This should only be used by lib/popt_common.c JRA */
    418 void set_cmdline_auth_info_use_krb5_ticket(struct user_auth_info *auth_info)
    419 {
    420         auth_info->use_kerberos = true;
    421         auth_info->got_pass = true;
    422 }
    423 
    424 /* This should only be used by lib/popt_common.c JRA */
    425 void set_cmdline_auth_info_smb_encrypt(struct user_auth_info *auth_info)
    426 {
    427         auth_info->smb_encrypt = true;
    428 }
    429 
    430 void set_cmdline_auth_info_use_machine_account(struct user_auth_info *auth_info)
    431 {
    432         auth_info->use_machine_account = true;
    433 }
    434 
    435 bool get_cmdline_auth_info_got_pass(const struct user_auth_info *auth_info)
    436 {
    437         return auth_info->got_pass;
    438 }
    439 
    440 bool get_cmdline_auth_info_smb_encrypt(const struct user_auth_info *auth_info)
    441 {
    442         return auth_info->smb_encrypt;
    443 }
    444 
    445 bool get_cmdline_auth_info_use_machine_account(const struct user_auth_info *auth_info)
    446 {
    447         return auth_info->use_machine_account;
    448 }
    449 
    450 struct user_auth_info *get_cmdline_auth_info_copy(TALLOC_CTX *mem_ctx,
    451                                                   const struct user_auth_info *src)
    452 {
    453         struct user_auth_info *result;
    454 
    455         result = user_auth_info_init(mem_ctx);
    456         if (result == NULL) {
    457                 return NULL;
    458         }
    459 
    460         *result = *src;
    461 
    462         result->username = talloc_strdup(
    463                 result, get_cmdline_auth_info_username(src));
    464         result->password = talloc_strdup(
    465                 result, get_cmdline_auth_info_password(src));
    466         if ((result->username == NULL) || (result->password == NULL)) {
    467                 TALLOC_FREE(result);
    468                 return NULL;
    469         }
    470 
    471         return result;
    472 }
    473 
    474 bool set_cmdline_auth_info_machine_account_creds(struct user_auth_info *auth_info)
    475 {
    476         char *pass = NULL;
    477         char *account = NULL;
    478 
    479         if (!get_cmdline_auth_info_use_machine_account(auth_info)) {
    480                 return false;
    481         }
    482 
    483         if (!secrets_init()) {
    484                 d_printf("ERROR: Unable to open secrets database\n");
    485                 return false;
    486         }
    487 
    488         if (asprintf(&account, "%s$@%s", global_myname(), lp_realm()) < 0) {
    489                 return false;
    490         }
    491 
    492         pass = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL);
    493         if (!pass) {
    494                 d_printf("ERROR: Unable to fetch machine password for "
    495                         "%s in domain %s\n",
    496                         account, lp_workgroup());
    497                 SAFE_FREE(account);
    498                 return false;
    499         }
    500 
    501         set_cmdline_auth_info_username(auth_info, account);
    502         set_cmdline_auth_info_password(auth_info, pass);
    503 
    504         SAFE_FREE(account);
    505         SAFE_FREE(pass);
    506 
    507         return true;
    508 }
    509 
    510 /****************************************************************************
    511  Ensure we have a password if one not given.
    512 ****************************************************************************/
    513 
    514 void set_cmdline_auth_info_getpass(struct user_auth_info *auth_info)
    515 {
    516         char *label = NULL;
    517         char *pass;
    518         TALLOC_CTX *frame;
    519 
    520         if (get_cmdline_auth_info_got_pass(auth_info) ||
    521                         get_cmdline_auth_info_use_kerberos(auth_info)) {
    522                 /* Already got one... */
    523                 return;
    524         }
    525 
    526         frame = talloc_stackframe();
    527         label = talloc_asprintf(frame, "Enter %s's password: ",
    528                         get_cmdline_auth_info_username(auth_info));
    529         pass = getpass(label);
    530         if (pass) {
    531                 set_cmdline_auth_info_password(auth_info, pass);
    532         }
    533         TALLOC_FREE(frame);
    534248}
    535249
     
    596310        attrstr[0] = 0;
    597311
    598         if (mode & aVOLID) fstrcat(attrstr,"V");
    599         if (mode & aDIR) fstrcat(attrstr,"D");
    600         if (mode & aARCH) fstrcat(attrstr,"A");
    601         if (mode & aHIDDEN) fstrcat(attrstr,"H");
    602         if (mode & aSYSTEM) fstrcat(attrstr,"S");
    603         if (mode & aRONLY) fstrcat(attrstr,"R");         
     312        if (mode & FILE_ATTRIBUTE_VOLUME) fstrcat(attrstr,"V");
     313        if (mode & FILE_ATTRIBUTE_DIRECTORY) fstrcat(attrstr,"D");
     314        if (mode & FILE_ATTRIBUTE_ARCHIVE) fstrcat(attrstr,"A");
     315        if (mode & FILE_ATTRIBUTE_HIDDEN) fstrcat(attrstr,"H");
     316        if (mode & FILE_ATTRIBUTE_SYSTEM) fstrcat(attrstr,"S");
     317        if (mode & FILE_ATTRIBUTE_READONLY) fstrcat(attrstr,"R");
    604318
    605319        return talloc_strdup(talloc_tos(), attrstr);
     
    617331        if (!DEBUGLVL(5))
    618332                return;
    619        
     333
    620334        DEBUG(5,("size=%d\nsmb_com=0x%x\nsmb_rcls=%d\nsmb_reh=%d\nsmb_err=%d\nsmb_flg=%d\nsmb_flg2=%d\n",
    621335                        smb_len(buf),
     
    636350                DEBUGADD(5,("smb_vwv[%2d]=%5d (0x%X)\n",i,
    637351                        SVAL(buf,smb_vwv+2*i),SVAL(buf,smb_vwv+2*i)));
    638        
     352
    639353        bcc = (int)SVAL(buf,smb_vwv+2*(CVAL(buf,smb_wct)));
    640354
     
    863577}
    864578
    865 /*******************************************************************
    866  Sleep for a specified number of milliseconds.
    867 ********************************************************************/
    868 
    869 void smb_msleep(unsigned int t)
    870 {
    871 #if defined(HAVE_NANOSLEEP)
    872         struct timespec tval;
    873         int ret;
    874 
    875         tval.tv_sec = t/1000;
    876         tval.tv_nsec = 1000000*(t%1000);
    877 
    878         do {
    879                 errno = 0;
    880                 ret = nanosleep(&tval, &tval);
    881         } while (ret < 0 && errno == EINTR && (tval.tv_sec > 0 || tval.tv_nsec > 0));
    882 #else
    883         unsigned int tdiff=0;
    884         struct timeval tval,t1,t2; 
    885         fd_set fds;
    886 
    887         GetTimeOfDay(&t1);
    888         t2 = t1;
    889  
    890         while (tdiff < t) {
    891                 tval.tv_sec = (t-tdiff)/1000;
    892                 tval.tv_usec = 1000*((t-tdiff)%1000);
    893 
    894                 /* Never wait for more than 1 sec. */
    895                 if (tval.tv_sec > 1) {
    896                         tval.tv_sec = 1;
    897                         tval.tv_usec = 0;
    898                 }
    899 
    900                 FD_ZERO(&fds);
    901                 errno = 0;
    902                 sys_select_intr(0,&fds,NULL,NULL,&tval);
    903 
    904                 GetTimeOfDay(&t2);
    905                 if (t2.tv_sec < t1.tv_sec) {
    906                         /* Someone adjusted time... */
    907                         t1 = t2;
    908                 }
    909 
    910                 tdiff = TvalDiff(&t1,&t2);
    911         }
    912 #endif
    913 }
    914579
    915580NTSTATUS reinit_after_fork(struct messaging_context *msg_ctx,
    916                        struct event_context *ev_ctx,
    917                        bool parent_longlived)
     581                           struct event_context *ev_ctx,
     582                           struct server_id id,
     583                           bool parent_longlived)
    918584{
    919585        NTSTATUS status = NT_STATUS_OK;
     
    932598        }
    933599
    934         if (ev_ctx) {
    935                 event_context_reinit(ev_ctx);
     600        if (ev_ctx && tevent_re_initialise(ev_ctx) != 0) {
     601                smb_panic(__location__ ": Failed to re-initialise event context");
    936602        }
    937603
     
    941607                 * fork
    942608                 */
    943                 status = messaging_reinit(msg_ctx);
     609                status = messaging_reinit(msg_ctx, id);
    944610                if (!NT_STATUS_IS_OK(status)) {
    945611                        DEBUG(0,("messaging_reinit() failed: %s\n",
     
    949615 done:
    950616        return status;
    951 }
    952 
    953 /****************************************************************************
    954  Put up a yes/no prompt.
    955 ****************************************************************************/
    956 
    957 bool yesno(const char *p)
    958 {
    959         char ans[20];
    960         printf("%s",p);
    961 
    962         if (!fgets(ans,sizeof(ans)-1,stdin))
    963                 return(False);
    964 
    965         if (*ans == 'y' || *ans == 'Y')
    966                 return(True);
    967 
    968         return(False);
    969617}
    970618
     
    1208856        if (strequal(str,"CORE+"))
    1209857                return(PROTOCOL_COREPLUS);
    1210  
     858
    1211859        DEBUG(0,("Unrecognised protocol level %s\n",str));
    1212  
     860
    1213861        return(def);
    1214862}
     
    13531001
    13541002#ifdef CLUSTER_SUPPORT
    1355         return ctdbd_process_exists(messaging_ctdbd_connection(), pid.vnn,
    1356                                     pid.pid);
     1003        return ctdbd_process_exists(messaging_ctdbd_connection(),
     1004                                    pid.vnn, pid.pid);
    13571005#else
    13581006        return False;
     
    14111059        uid_t u;
    14121060
    1413         pass = Get_Pwnam_alloc(talloc_autofree_context(), name);
     1061        pass = Get_Pwnam_alloc(talloc_tos(), name);
    14141062        if (pass) {
    14151063                u = pass->pw_uid;
     
    15711219        DEBUG(0, ("BACKTRACE: %lu stack frames:\n",
    15721220                  (unsigned long)backtrace_size));
    1573        
     1221
    15741222        if (backtrace_strings) {
    15751223                int i;
     
    16351283        if (!p)
    16361284                return(NULL);
    1637  
     1285
    16381286        ptr = (SMB_STRUCT_DIRENT *)sys_readdir(p);
    16391287        if (!ptr)
     
    17091357 if possible.
    17101358********************************************************************/
    1711  
     1359
    17121360void set_namearray(name_compare_entry **ppname_array, const char *namelist)
    17131361{
     
    17851433                i++;
    17861434        }
    1787  
     1435
    17881436        (*ppname_array)[i].name = NULL;
    17891437
     
    18451493        *pcount = lock.l_len;
    18461494        *ppid = lock.l_pid;
    1847        
     1495
    18481496        DEBUG(3,("fcntl_getlock: fd %d is returned info %d pid %u\n",
    18491497                        fd, (int)lock.l_type, (unsigned int)lock.l_pid));
     
    19631611                remote_arch_str = "CIFSFS";
    19641612                break;
     1613        case RA_OSX:
     1614                remote_arch_str = "OSX";
     1615                break;
    19651616        default:
    19661617                ra_type = RA_UNKNOWN;
     
    20021653{
    20031654        TDB_DATA key = string_tdb_data(s);
    2004         return jenkins_hash(&key);
     1655        return tdb_jenkins_hash(&key);
    20051656}
    20061657
     
    21461797        static char *ret;
    21471798        if (ret == NULL) {
    2148                 /* This is cached forever so
    2149                  * use talloc_autofree_context() ctx. */
    2150                 ret = get_myname(talloc_autofree_context());
     1799                ret = get_myname(NULL);
    21511800        }
    21521801        return ret;
     
    22951944        char *p;
    22961945        ptrdiff_t len;
    2297  
     1946
    22981947        p = strrchr_m(dir, '/'); /* Find final '/', if any */
    22991948
     
    23712020bool mask_match(const char *string, const char *pattern, bool is_case_sensitive)
    23722021{
    2373         if (strcmp(string,"..") == 0)
     2022        if (ISDOTDOT(string))
    23742023                string = ".";
    2375         if (strcmp(pattern,".") == 0)
     2024        if (ISDOT(pattern))
    23762025                return False;
    2377        
     2026
    23782027        return ms_fnmatch(pattern, string, Protocol <= PROTOCOL_LANMAN2, is_case_sensitive) == 0;
    23792028}
     
    23872036bool mask_match_search(const char *string, const char *pattern, bool is_case_sensitive)
    23882037{
    2389         if (strcmp(string,"..") == 0)
     2038        if (ISDOTDOT(string))
    23902039                string = ".";
    2391         if (strcmp(pattern,".") == 0)
     2040        if (ISDOT(pattern))
    23922041                return False;
    2393        
     2042
    23942043        return ms_fnmatch(pattern, string, True, is_case_sensitive) == 0;
    23952044}
     
    26602309}
    26612310
     2311static uint64_t my_unique_id = 0;
     2312
     2313void set_my_unique_id(uint64_t unique_id)
     2314{
     2315        my_unique_id = unique_id;
     2316}
     2317
    26622318struct server_id pid_to_procid(pid_t pid)
    26632319{
    26642320        struct server_id result;
    26652321        result.pid = pid;
    2666 #ifdef CLUSTER_SUPPORT
     2322        result.unique_id = my_unique_id;
    26672323        result.vnn = my_vnn;
    2668 #endif
    26692324        return result;
    26702325}
     
    26732328{
    26742329        return pid_to_procid(sys_getpid());
    2675 }
    2676 
    2677 struct server_id server_id_self(void)
    2678 {
    2679         return procid_self();
    26802330}
    26812331
     
    26842334        if (p1->pid != p2->pid)
    26852335                return False;
    2686 #ifdef CLUSTER_SUPPORT
    26872336        if (p1->vnn != p2->vnn)
    26882337                return False;
    2689 #endif
    26902338        return True;
    26912339}
     
    27012349        if (pid->pid != sys_getpid())
    27022350                return False;
    2703 #ifdef CLUSTER_SUPPORT
    27042351        if (pid->vnn != my_vnn)
    27052352                return False;
    2706 #endif
    27072353        return True;
    27082354}
     
    27122358        struct server_id result;
    27132359        int pid;
    2714 #ifdef CLUSTER_SUPPORT
    27152360        unsigned int vnn;
    27162361        if (sscanf(pid_string, "%u:%d", &vnn, &pid) == 2) {
     
    27262371                result.pid = -1;
    27272372        }
    2728 #else
    2729         if (sscanf(pid_string, "%d", &pid) != 1) {
    2730                 result.pid = -1;
    2731         } else {
    2732                 result.pid = pid;
    2733         }
    2734 #endif
    27352373        /* Assigning to result.pid may have overflowed
    27362374           Map negative pid to -1: i.e. error */
     
    27382376                result.pid = -1;
    27392377        }
     2378        result.unique_id = 0;
    27402379        return result;
    27412380}
     
    27432382char *procid_str(TALLOC_CTX *mem_ctx, const struct server_id *pid)
    27442383{
    2745 #ifdef CLUSTER_SUPPORT
    27462384        if (pid->vnn == NONCLUSTER_VNN) {
    27472385                return talloc_asprintf(mem_ctx,
     
    27552393                                        (int)pid->pid);
    27562394        }
    2757 #else
    2758         return talloc_asprintf(mem_ctx,
    2759                         "%d",
    2760                         (int)pid->pid);
    2761 #endif
    27622395}
    27632396
     
    27742407bool procid_is_local(const struct server_id *pid)
    27752408{
    2776 #ifdef CLUSTER_SUPPORT
    27772409        return pid->vnn == my_vnn;
    2778 #else
    2779         return True;
    2780 #endif
    2781 }
    2782 
    2783 int this_is_smp(void)
    2784 {
    2785 #if defined(HAVE_SYSCONF)
    2786 
    2787 #if defined(SYSCONF_SC_NPROC_ONLN)
    2788         return (sysconf(_SC_NPROC_ONLN) > 1) ? 1 : 0;
    2789 #elif defined(SYSCONF_SC_NPROCESSORS_ONLN)
    2790         return (sysconf(_SC_NPROCESSORS_ONLN) > 1) ? 1 : 0;
    2791 #else
    2792         return 0;
    2793 #endif
    2794 
    2795 #else
    2796         return 0;
    2797 #endif
    27982410}
    27992411
     
    30292641#endif
    30302642
    3031 bool is_valid_policy_hnd(const struct policy_handle *hnd)
    3032 {
    3033         struct policy_handle tmp;
    3034         ZERO_STRUCT(tmp);
    3035         return (memcmp(&tmp, hnd, sizeof(tmp)) != 0);
    3036 }
    3037 
    3038 bool policy_hnd_equal(const struct policy_handle *hnd1,
    3039                       const struct policy_handle *hnd2)
    3040 {
    3041         if (!hnd1 || !hnd2) {
    3042                 return false;
    3043         }
    3044 
    3045         return (memcmp(hnd1, hnd2, sizeof(*hnd1)) == 0);
    3046 }
    3047 
    30482643/****************************************************************
    30492644 strip off leading '\\' from a hostname
     
    30762671        return ret;
    30772672}
     2673
     2674bool any_nt_status_not_ok(NTSTATUS err1, NTSTATUS err2, NTSTATUS *result)
     2675{
     2676        if (!NT_STATUS_IS_OK(err1)) {
     2677                *result = err1;
     2678                return true;
     2679        }
     2680        if (!NT_STATUS_IS_OK(err2)) {
     2681                *result = err2;
     2682                return true;
     2683        }
     2684        return false;
     2685}
     2686
     2687int timeval_to_msec(struct timeval t)
     2688{
     2689        return t.tv_sec * 1000 + (t.tv_usec+999) / 1000;
     2690}
     2691
     2692/*******************************************************************
     2693 Check a given DOS pathname is valid for a share.
     2694********************************************************************/
     2695
     2696char *valid_share_pathname(TALLOC_CTX *ctx, const char *dos_pathname)
     2697{
     2698        char *ptr = NULL;
     2699
     2700        if (!dos_pathname) {
     2701                return NULL;
     2702        }
     2703
     2704        ptr = talloc_strdup(ctx, dos_pathname);
     2705        if (!ptr) {
     2706                return NULL;
     2707        }
     2708        /* Convert any '\' paths to '/' */
     2709        unix_format(ptr);
     2710        ptr = unix_clean_name(ctx, ptr);
     2711        if (!ptr) {
     2712                return NULL;
     2713        }
     2714
     2715        /* NT is braindead - it wants a C: prefix to a pathname ! So strip it. */
     2716        if (strlen(ptr) > 2 && ptr[1] == ':' && ptr[0] != '/')
     2717                ptr += 2;
     2718
     2719        /* Only absolute paths allowed. */
     2720        if (*ptr != '/')
     2721                return NULL;
     2722
     2723        return ptr;
     2724}
Note: See TracChangeset for help on using the changeset viewer.