]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/attr.c
- Add a kludge to detect bad date/times, which cause a seg fault in
[bacula/bacula] / bacula / src / lib / attr.c
index 4c5ae2d54f04967c0494b3f68586b70e9714e26e..bd9746c64f1585301e6ad822af35ba978e42c056 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2003-2004 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -93,7 +93,7 @@ int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, ATTR *attr)
    attr->lname = p;                  /* set link position */
    while (*p++ != 0)                 /* skip link */
       { }
-   pm_strcpy(&attr->attrEx, p);       /* copy extended attributes, if any */
+   pm_strcpy(attr->attrEx, p);       /* copy extended attributes, if any */
 
    if (attr->data_stream) {
       int64_t val;
@@ -105,8 +105,8 @@ int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, ATTR *attr)
    Dmsg7(200, "unpack_attr FI=%d Type=%d fname=%s attr=%s lname=%s attrEx=%s ds=%d\n",
       attr->file_index, attr->type, attr->fname, attr->attr, attr->lname,
       attr->attrEx, attr->data_stream);
-   *mp_chr(attr->ofname) = 0;
-   *mp_chr(attr->olname) = 0;
+   *attr->ofname = 0;
+   *attr->olname = 0;
    return 1;
 }
 
@@ -121,27 +121,27 @@ void build_attr_output_fnames(JCR *jcr, ATTR *attr)
     * files are put where the user wants.
     *
     * We do a little jig here to handle Win32 files with
-    *  a drive letter -- we simply strip the drive: from
+    *  a drive letter -- we simply change the drive
+    *  from, for example, c: to c/ for
     *  every filename if a prefix is supplied.
     *    
     */
    if (jcr->where[0] == 0) {
-      pm_strcpy(&attr->ofname, attr->fname);
-      pm_strcpy(&attr->olname, attr->lname);
+      pm_strcpy(attr->ofname, attr->fname);
+      pm_strcpy(attr->olname, attr->lname);
    } else {
       const char *fn;
       int wherelen = strlen(jcr->where);
-      pm_strcpy(&attr->ofname, jcr->where);  /* copy prefix */
+      pm_strcpy(attr->ofname, jcr->where);  /* copy prefix */
       if (win32_client && attr->fname[1] == ':') {
-        fn = attr->fname+2;          /* skip over drive: */
-      } else {
-        fn = attr->fname;            /* take whole name */
+         attr->fname[1] = '/';     /* convert : to / */
       }
+      fn = attr->fname;           /* take whole name */
       /* Ensure where is terminated with a slash */
       if (jcr->where[wherelen-1] != '/' && fn[0] != '/') {
-         pm_strcat(&attr->ofname, "/");
+         pm_strcat(attr->ofname, "/");
       }   
-      pm_strcat(&attr->ofname, fn); /* copy rest of name */
+      pm_strcat(attr->ofname, fn); /* copy rest of name */
       /*
        * Fixup link name -- if it is an absolute path
        */
@@ -152,28 +152,27 @@ void build_attr_output_fnames(JCR *jcr, ATTR *attr)
          */
          if (attr->lname[0] == '/' &&
             (attr->type == FT_LNKSAVED || jcr->prefix_links)) {
-           pm_strcpy(&attr->olname, jcr->where);
+           pm_strcpy(attr->olname, jcr->where);
            add_link = true;
         } else {
-           mp_chr(attr->olname)[0] = 0;
+           attr->olname[0] = 0;
            add_link = false;
         }
          if (win32_client && attr->lname[1] == ':') {
-           fn = attr->lname+2;     /* skip over drive: */
-        } else {
-           fn = attr->lname;       /* take whole name */
+            attr->lname[1] = '/';    /* turn : into / */
         }
+        fn = attr->lname;       /* take whole name */
         /* Ensure where is terminated with a slash */
          if (add_link && jcr->where[wherelen-1] != '/' && fn[0] != '/') {
-            pm_strcat(&attr->olname, "/");
+            pm_strcat(attr->olname, "/");
         }   
-        pm_strcat(&attr->olname, fn);     /* copy rest of link */
+        pm_strcat(attr->olname, fn);     /* copy rest of link */
       }
    }
 }
 
-extern char *getuser(uid_t uid);
-extern char *getgroup(gid_t gid);
+extern char *getuser(uid_t uid, char *name, int len);
+extern char *getgroup(gid_t gid, char *name, int len);
 
 /*
  * Print an ls style message, also send M_RESTORED
@@ -182,16 +181,18 @@ void print_ls_output(JCR *jcr, ATTR *attr)
 {
    char buf[5000]; 
    char ec1[30];
+   char en1[30], en2[30];
    char *p, *f;
 
    p = encode_mode(attr->statp.st_mode, buf);
    p += sprintf(p, "  %2d ", (uint32_t)attr->statp.st_nlink);
-   p += sprintf(p, "%-8.8s %-8.8s", getuser(attr->statp.st_uid), getgroup(attr->statp.st_gid));
+   p += sprintf(p, "%-8.8s %-8.8s", getuser(attr->statp.st_uid, en1, sizeof(en1)),
+               getgroup(attr->statp.st_gid, en2, sizeof(en2)));
    p += sprintf(p, "%8.8s ", edit_uint64(attr->statp.st_size, ec1));
    p = encode_time(attr->statp.st_ctime, p);
    *p++ = ' ';
    *p++ = ' ';
-   for (f=mp_chr(attr->ofname); *f && (p-buf) < (int)sizeof(buf)-10; ) {
+   for (f=attr->ofname; *f && (p-buf) < (int)sizeof(buf)-10; ) {
       *p++ = *f++;
    }
    if (attr->type == FT_LNK) {
@@ -200,7 +201,7 @@ void print_ls_output(JCR *jcr, ATTR *attr)
       *p++ = '>';
       *p++ = ' ';
       /* Copy link name */
-      for (f=mp_chr(attr->olname); *f && (p-buf) < (int)sizeof(buf)-10; ) {
+      for (f=attr->olname; *f && (p-buf) < (int)sizeof(buf)-10; ) {
         *p++ = *f++;
       }
    }