lib/charcnv.c: Improved debug comment.
authorJeremy Allison <jra@samba.org>
Fri, 6 Nov 1998 18:40:51 +0000 (18:40 +0000)
committerJeremy Allison <jra@samba.org>
Fri, 6 Nov 1998 18:40:51 +0000 (18:40 +0000)
libsmb/namequery.c: Fix to remove 2 second wait is we are doing a unicast
                    and got a reply.
smbd/dfree.c:
smbd/noquotas.c:
smbd/quotas.c: Fixes from Dejan Ilic <svedja@lysator.liu.se> for the quota
               code.
utils/smbpasswd.c: Fixes to allow smbpasswd to be called from swat.
Jeremy.
(This used to be commit b5981c0149ad8c6f13ea87db450080616538b5d5)

source3/include/proto.h
source3/lib/charcnv.c
source3/libsmb/namequery.c
source3/smbd/dfree.c
source3/smbd/noquotas.c
source3/smbd/quotas.c
source3/utils/smbpasswd.c

index 472052c807c32ccf28c3edeaeb2bc3b86f955466..9a4a95e9eda1807f24366ada38e0d291eefbfa3e 100644 (file)
@@ -2196,7 +2196,7 @@ int reply_negprot(connection_struct *conn,
 
 /*The following definitions come from  smbd/noquotas.c  */
 
-BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize);
+BOOL disk_quotas(char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize);
 
 /*The following definitions come from  smbd/nttrans.c  */
 
index b016a07fd73efe688ae25284f5e3b7fd0a300b6c..29ef72d7ac3e8627de0872563162639bae59ceda 100644 (file)
@@ -225,6 +225,6 @@ void interpret_character_set(char *str)
     } else if (strequal (str, "koi8-r")) {
         init_koi8_r();
     } else {
-        DEBUG(0,("unrecognized character set\n"));
+        DEBUG(0,("unrecognized character set %s\n", str));
     }
 }
index e95302fcd0c9d38e4d61f390ad337d474e5b9657..0e92e6b5dd815527b9b360a2b1557428da70ad7c 100644 (file)
@@ -247,60 +247,81 @@ struct in_addr *name_query(int fd,char *name,int name_type, BOOL bcast,BOOL recu
   retries--;
 
   while (1)
+  {
+    struct timeval tval2;
+    GetTimeOfDay(&tval2);
+    if (TvalDiff(&tval,&tval2) > retry_time) 
     {
-      struct timeval tval2;
-      GetTimeOfDay(&tval2);
-      if (TvalDiff(&tval,&tval2) > retry_time) {
-       if (!retries) break;
-       if (!found && !send_packet(&p))
-         return NULL;
-       GetTimeOfDay(&tval);
-       retries--;
-      }
+      if (!retries)
+        break;
+      if (!found && !send_packet(&p))
+        return NULL;
+      GetTimeOfDay(&tval);
+      retries--;
+    }
 
-      if ((p2=receive_packet(fd,NMB_PACKET,90)))
-       {     
-         struct nmb_packet *nmb2 = &p2->packet.nmb;
-         debug_nmb_packet(p2);
+    if ((p2=receive_packet(fd,NMB_PACKET,90)))
+    {     
+      struct nmb_packet *nmb2 = &p2->packet.nmb;
+      debug_nmb_packet(p2);
 
-         if (nmb->header.name_trn_id != nmb2->header.name_trn_id ||
-             !nmb2->header.response) {
-           /* its not for us - maybe deal with it later 
-              (put it on the queue?) */
-           if (fn) 
-             fn(p2);
-           else
-             free_packet(p2);
-           continue;
-         }
+      if (nmb->header.name_trn_id != nmb2->header.name_trn_id ||
+          !nmb2->header.response)
+      {
+        /* 
+         * Its not for us - maybe deal with it later 
+         * (put it on the queue?).
+         */
+        if (fn) 
+          fn(p2);
+        else
+          free_packet(p2);
+        continue;
+      }
          
-         if (nmb2->header.opcode != 0 ||
-             nmb2->header.nm_flags.bcast ||
-             nmb2->header.rcode ||
-             !nmb2->header.ancount) {
-           /* XXXX what do we do with this? could be a redirect, but
-              we'll discard it for the moment */
-           free_packet(p2);
-           continue;
-         }
+      if (nmb2->header.opcode != 0 ||
+          nmb2->header.nm_flags.bcast ||
+          nmb2->header.rcode ||
+          !nmb2->header.ancount)
+      {
+           /* 
+         * XXXX what do we do with this? Could be a redirect, but
+         * we'll discard it for the moment.
+         */
+        free_packet(p2);
+        continue;
+      }
 
-         ip_list = (struct in_addr *)Realloc(ip_list, sizeof(ip_list[0]) * 
-                                             ((*count)+nmb2->answers->rdlength/6));
-         if (ip_list) {
-                 DEBUG(fn?3:2,("Got a positive name query response from %s ( ",
-                               inet_ntoa(p2->ip)));
-                 for (i=0;i<nmb2->answers->rdlength/6;i++) {
-                         putip((char *)&ip_list[(*count)],&nmb2->answers->rdata[2+i*6]);
-                         DEBUG(fn?3:2,("%s ",inet_ntoa(ip_list[(*count)])));
-                         (*count)++;
-                 }
-                 DEBUG(fn?3:2,(")\n"));
-         }
-         found=True; retries=0;
-         free_packet(p2);
-         if (fn) break;
-       }
+      ip_list = (struct in_addr *)Realloc(ip_list, sizeof(ip_list[0]) * 
+                                          ((*count)+nmb2->answers->rdlength/6));
+      if (ip_list)
+      {
+        DEBUG(fn?3:2,("Got a positive name query response from %s ( ",
+              inet_ntoa(p2->ip)));
+        for (i=0;i<nmb2->answers->rdlength/6;i++)
+        {
+          putip((char *)&ip_list[(*count)],&nmb2->answers->rdata[2+i*6]);
+          DEBUG(fn?3:2,("%s ",inet_ntoa(ip_list[(*count)])));
+          (*count)++;
+        }
+        DEBUG(fn?3:2,(")\n"));
+      }
+
+      found=True;
+      retries=0;
+      free_packet(p2);
+      if (fn)
+        break;
+
+      /*
+       * If we're doing a unicast lookup we only
+       * expect one reply. Don't wait the full 2
+       * seconds if we got one. JRA.
+       */
+      if(!bcast && found)
+        break;
     }
+  }
 
   return ip_list;
 }
index c96a599e77b0281733bd31a96c9e17f47c70b3e9..020386645c219fb299532796d850412d0fe2307f 100644 (file)
@@ -188,13 +188,24 @@ static int fsusage(const char *path, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
 static SMB_BIG_UINT disk_free(char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize)
 {
        int dfree_retval;
+       SMB_BIG_UINT dfree_q = 0;
+       SMB_BIG_UINT bsize_q = 0;
+       SMB_BIG_UINT dsize_q = 0;
 
        (*dfree) = (*dsize) = 0;
        (*bsize) = 512;
 
        fsusage(path, dfree, dsize);
 
+       if (disk_quotas(path, &bsize_q, &dfree_q, &dsize_q)) {
+               (*bsize) = bsize_q;
+               (*dfree) = MIN(*dfree,dfree_q);
+               (*dsize) = MIN(*dsize,dsize_q);
+       }
+
+       /* FIXME : Any reason for this assumption ? */
        if (*bsize < 256) {
+               DEBUG(5,("disk_free:Warning: bsize == %d < 256 . Changing to assumed correct bsize = 512\n",*bsize));
                *bsize = 512;
        }
 
index c62fb368c742ba61d27b46a9ec3728d58b2ee5c4..5c55bb47c8e4029707a9de86124fcf6b50c2a56e 100644 (file)
  * Needed for auto generation of proto.h.
  */
 
-BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
+BOOL disk_quotas(char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize)
 {
+  (*bsize) = 512; /* This value should be ignored */
+
+  /* And just to be sure we set some values that hopefully */
+  /* will be larger that any possible real-world value     */
+  (*dfree) = (SMB_BIG_UINT)-1;
+  (*dsize) = (SMB_BIG_UINT)-1;
+
+  /* As we have select not to use quotas, allways fail */
   return False;
 }
index d610bbe15a4e2c078dae1786465640e43d776e10..d5ecf73451be59fc341ff949349a66d5b5ced1be 100644 (file)
@@ -45,7 +45,7 @@ _syscall4(int, quotactl, int, cmd, const char *, special, int, id, caddr_t, addr
 try to get the disk space from disk quotas (LINUX version)
 ****************************************************************************/
 
-BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
+BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
 {
   uid_t euser_id;
   int r;
@@ -130,7 +130,8 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
 /****************************************************************************
 try to get the disk space from disk quotas (CRAY VERSION)
 ****************************************************************************/
-BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
+
+BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
 {
   struct mntent *mnt;
   FILE *fd;
@@ -227,6 +228,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
 #elif defined(SUNOS5) || defined(SUNOS4)
 
 #include <fcntl.h>
+#include <sys/param.h>
 #if defined(SUNOS5)
 #include <sys/fs/ufs_quota.h>
 #include <sys/mnttab.h>
@@ -236,10 +238,11 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
 #endif
 
 /****************************************************************************
-try to get the disk space from disk quotas (solaris 2 version)
-****************************************************************************/
+try to get the disk space from disk quotas (SunOS & Solaris2 version)
 /* Quota code by Peter Urbanec (amiga@cse.unsw.edu.au) */
-BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
+****************************************************************************/
+
+BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
 {
   uid_t user_id, euser_id;
   int ret;
@@ -249,7 +252,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
   int file;
   struct mnttab mnt;
   static pstring name;
-#else
+#else /* SunOS4 */
   struct mntent *mnt;
   static pstring name;
 #endif
@@ -285,7 +288,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
     pstrcpy(name,mnt.mnt_mountp) ;
     pstrcat(name,"/quotas") ;
     fclose(fd) ;
-#else
+#else /* SunOS4 */
     if ((fd = setmntent(MOUNTED, "r")) == NULL)
       return(False) ;
     
@@ -336,7 +339,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
   seteuid(euser_id);
 
   if (ret < 0) {
-    DEBUG(2,("disk_quotas ioctl (Solaris) failed\n"));
+    DEBUG(5,("disk_quotas ioctl (Solaris) failed. Error = %s\n", strerror(errno) ));
     return(False);
   }
 
@@ -349,17 +352,18 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
 
   if (D.dqb_bsoftlimit==0)
     return(False);
-  *bsize = 512;
+  *bsize = DEV_BSIZE;
   *dfree = D.dqb_bsoftlimit - D.dqb_curblocks;
   *dsize = D.dqb_bsoftlimit;
+
   if(*dfree < 0)
     {
      *dfree = 0;
      *dsize = D.dqb_curblocks;
     }
       
-DEBUG(5,("disk_quotas for path \"%s\" returning  bsize %d, dfree %d, dsize %d\n",
-         path,*bsize,*dfree,*dsize));
+  DEBUG(5,("disk_quotas for path \"%s\" returning  bsize %.0f, dfree %.0f, dsize %.0f\n",
+         path,(double)*bsize,(double)*dfree,(double)*dsize));
 
       return(True);
 }
@@ -371,7 +375,8 @@ DEBUG(5,("disk_quotas for path \"%s\" returning  bsize %d, dfree %d, dsize %d\n"
 /****************************************************************************
 try to get the disk space from disk quotas - OFS1 version
 ****************************************************************************/
-BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
+
+BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
 {
   uid_t user_id, euser_id;
   int r, save_errno;
@@ -426,7 +431,7 @@ try to get the disk space from disk quotas (IRIX 6.2 version)
 #include <sys/quota.h>
 #include <mntent.h>
 
-BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
+BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
 {
   uid_t euser_id;
   int r;
@@ -518,11 +523,8 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
         (F.d_ino_hardlimit && F.d_icount>=F.d_ino_hardlimit)
        )
     {
-      /*
-       * Fixme!: these are __uint64_t, this may truncate values
-       */
       *dfree = 0;
-      *dsize = (int) F.d_bcount;
+      *dsize = F.d_bcount;
     }
     else if (F.d_blk_softlimit==0 && F.d_blk_hardlimit==0)
     {
@@ -530,8 +532,8 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
     }
     else 
     {
-      *dfree = (int)(F.d_blk_softlimit - F.d_bcount);
-      *dsize = (int)F.d_blk_softlimit;
+      *dfree = (F.d_blk_softlimit - F.d_bcount);
+      *dsize = F.d_blk_softlimit;
     }
 
   }
@@ -565,7 +567,8 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
 /****************************************************************************
 try to get the disk space from disk quotas - default version
 ****************************************************************************/
-BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
+
+BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
 {
   uid_t euser_id;
   int r;
index 2d4ce319e8484bd6f57f402fc27a9a84c64375ab..147e3492af2a85e33da6df279d71239b68622cbf 100644 (file)
@@ -191,7 +191,8 @@ int main(int argc, char **argv)
   extern char *optarg;
   extern int optind;
   extern int DEBUGLEVEL;
-  int             real_uid;
+  uid_t             real_uid;
+  uid_t             eff_uid;
   struct passwd  *pwd = NULL;
   fstring         old_passwd;
   fstring         new_passwd;
@@ -217,7 +218,7 @@ int main(int argc, char **argv)
   char *new_domain = NULL;
   pstring servicesf = CONFIGFILE;
   void           *vp;
-       struct nmb_name calling, called;
+  struct nmb_name calling, called;
   
 
   new_passwd[0] = '\0';
@@ -265,16 +266,17 @@ int main(int argc, char **argv)
 
   codepage_initialise(lp_client_code_page());
 
-  /* Get the real uid */
+  /* Get the real and effective uids */
   real_uid = getuid();
-  
+  eff_uid = geteuid();
   /* Check the effective uid */
-  if ((geteuid() == 0) && (real_uid != 0)) {
+  if ((eff_uid == (uid_t)0) && (real_uid != (uid_t)0)) {
     fprintf(stderr, "%s: Must *NOT* be setuid root.\n", prog_name);
     exit(1);
   }
 
-  is_root = (real_uid == 0);
+  is_root = (eff_uid == (uid_t)0);
 
   while ((ch = getopt(argc, argv, "adehmnj:r:sR:D:U:")) != EOF) {
     switch(ch) {
@@ -434,7 +436,7 @@ int main(int argc, char **argv)
         exit(1);
       }
     } else {
-      if((pwd = getpwuid(real_uid)) != NULL)
+      if((pwd = getpwuid(eff_uid)) != NULL)
         pstrcpy( user_name, pwd->pw_name);
     }
 
@@ -463,7 +465,7 @@ int main(int argc, char **argv)
       got_new_pass = True;
     }
 
-    if(!remote_user_name && ((pwd = getpwuid(real_uid)) != NULL))
+    if(!remote_user_name && ((pwd = getpwuid(eff_uid)) != NULL))
       pstrcpy( user_name, pwd->pw_name);
 
     /*