return 1;
}
-
-
-extern char *getuser(uid_t uid, char *name, int len);
-extern char *getgroup(gid_t gid, char *name, int len);
-
/*
* This is actually the long form used for "dir"
*/
-static void ls_output(char *buf, const char *fname, const char *tag,
+static void ls_output(guid_list *guid, char *buf, const char *fname, const char *tag,
struct stat *statp, bool dot_cmd)
-
{
char *p;
const char *f;
*p++ = ',';
n = sprintf(p, "%d,", (uint32_t)statp->st_nlink);
p += n;
- n = sprintf(p, "%s,%s,", getuser(statp->st_uid, en1, sizeof(en1)),
- getgroup(statp->st_gid, en2, sizeof(en2)));
+ n = sprintf(p, "%s,%s,",
+ guid->uid_to_name(statp->st_uid, en1, sizeof(en1)),
+ guid->gid_to_name(statp->st_gid, en2, sizeof(en2)));
p += n;
n = sprintf(p, "%s,", edit_uint64(statp->st_size, ec1));
p += n;
} else {
n = sprintf(p, " %2d ", (uint32_t)statp->st_nlink);
p += n;
- n = sprintf(p, "%-8.8s %-8.8s", getuser(statp->st_uid, en1, sizeof(en1)),
- getgroup(statp->st_gid, en2, sizeof(en2)));
+ n = sprintf(p, "%-8.8s %-8.8s",
+ guid->uid_to_name(statp->st_uid, en1, sizeof(en1)),
+ guid->gid_to_name(statp->st_gid, en2, sizeof(en2)));
p += n;
n = sprintf(p, "%10.10s ", edit_uint64(statp->st_size, ec1));
p += n;
struct stat statp;
char buf[1100];
char cwd[1100], *pcwd;
+ guid_list *guid;
if (!tree_node_has_child(tree->node)) {
ua->send_msg(_("Node %s has no children.\n"), tree->node->fname);
return 1;
}
+ guid = new_guid_list();
foreach_child(node, tree->node) {
const char *tag;
if (ua->argc == 1 || fnmatch(ua->argk[1], node->fname, 0) == 0) {
/* Something went wrong getting attributes -- print name */
memset(&statp, 0, sizeof(statp));
}
- ls_output(buf, cwd, tag, &statp, dot_cmd);
+ ls_output(guid, buf, cwd, tag, &statp, dot_cmd);
ua->send_msg("%s\n", buf);
}
}
+ free_guid_list(guid);
return 1;
}
B_DB *db; /* database pointer */
B_DB *db_batch; /* database pointer for batch insert */
ATTR_DBR *ar; /* DB attribute record */
+ guid_list *id_list; /* User/group id to name list */
/* Daemon specific part of JCR */
/* This should be empty in the library */
bnet.c bnet_server.c runscript.c \
bsock.c bpipe.c bsnprintf.c btime.c \
cram-md5.c crc32.c crypto.c daemon.c edit.c fnmatch.c \
- hmac.c idcache.c jcr.c lex.c alist.c dlist.c \
+ guid_to_name.c hmac.c jcr.c lex.c alist.c dlist.c \
md5.c message.c mem_pool.c openssl.c parse_conf.c \
queue.c bregex.c \
res.c rwlock.c scan.c serial.c sha1.c \
LIBOBJS = attr.o base64.o berrno.o bsys.o bget_msg.o \
bnet.o bnet_server.o runscript.o \
bsock.o bpipe.o bsnprintf.o btime.o \
- cram-md5.o crc32.o crypto.o daemon.o edit.o enh_fnmatch.o fnmatch.o \
- hmac.o idcache.o jcr.o lex.o alist.o dlist.o \
+ cram-md5.o crc32.o crypto.o daemon.o edit.o fnmatch.o \
+ guid_to_name.o hmac.o jcr.o lex.o alist.o dlist.o \
md5.o message.o mem_pool.o openssl.o parse_conf.o \
queue.o bregex.o \
res.o rwlock.o scan.o serial.o sha1.o \
-/*
- * attr.c Unpack an Attribute record returned from the tape
- *
- * Kern Sibbald, June MMIII (code pulled from filed/restore.c and updated)
- *
- * Version $Id$
- */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2003-2006 Free Software Foundation Europe e.V.
+ Copyright (C) 2003-2007 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
+/*
+ * attr.c Unpack an Attribute record returned from the tape
+ *
+ * Kern Sibbald, June MMIII (code pulled from filed/restore.c and updated)
+ *
+ * Version $Id$
+ */
+
#include "bacula.h"
#include "jcr.h"
char ec1[30];
char en1[30], en2[30];
char *p, *f;
+ guid_list *guid;
+ if (!jcr->id_list) {
+ jcr->id_list = new_guid_list();
+ }
+ guid = jcr->id_list;
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, en1, sizeof(en1)),
- getgroup(attr->statp.st_gid, en2, sizeof(en2)));
+ p += sprintf(p, "%-8.8s %-8.8s",
+ guid->uid_to_name(attr->statp.st_uid, en1, sizeof(en1)),
+ guid->gid_to_name(attr->statp.st_gid, en2, sizeof(en2)));
p += sprintf(p, "%10.10s ", edit_uint64(attr->statp.st_size, ec1));
p = encode_time(attr->statp.st_ctime, p);
*p++ = ' ';
Switzerland, email:ftf@fsfeurope.org.
*/
/*
- * Written by Kern Sibbald, July 2005 to replace idcache.c
+ * Written by Kern Sibbald, July 2007 to replace idcache.c
*
* Program to convert uid and gid into names, and cache the results
* for preformance reasons.
+ *
+ * Version $Id$
*/
#include "bacula.h"
+#ifndef WIN32
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif
struct guitem {
dlink link;
};
};
-class guid_list {
-public:
- dlist *uid_list;
- dlist *gid_list;
-
- char *uid_to_name(uid_t uid, char *name, int maxlen);
- char *gid_to_name(gid_t gid, char *name, int maxlen);
-};
guid_list *new_guid_list()
{
--- /dev/null
+/*
+ Bacula® - The Network Backup Solution
+
+ Copyright (C) 2007 Kern Sibbald
+
+ The main author of Bacula is Kern Sibbald, with contributions from
+ many others, a complete list can be found in the file AUTHORS.
+ This program is Free Software; you can redistribute it and/or
+ modify it under the terms of version two of the GNU General Public
+ License as published by the Free Software Foundation, which is
+ listed in the file LICENSE.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Bacula® is a registered trademark of John Walker.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
+/*
+ * Written by Kern Sibbald, July 2007 to replace idcache.c
+ *
+ * Program to convert uid and gid into names, and cache the results
+ * for preformance reasons.
+ *
+ * Version $Id$
+ */
+
+class guid_list {
+public:
+ dlist *uid_list;
+ dlist *gid_list;
+
+ char *uid_to_name(uid_t uid, char *name, int maxlen);
+ char *gid_to_name(gid_t gid, char *name, int maxlen);
+};
+
+guid_list *new_guid_list();
+void free_guid_list(guid_list *list);
+
+++ /dev/null
-/* idcache.c -- map user and group IDs, cached for speed
- Copyright (C) 1985, 1988, 1989, 1990 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-
-#include "bacula.h"
-
-struct userid {
- union {
- uid_t u;
- gid_t g;
- } id;
- char *name;
- struct userid *next;
-};
-
-static struct userid *user_alist = NULL;
-/* Use the same struct as for userids. */
-static struct userid *group_alist = NULL;
-
-static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-
-/* Translate UID to a login name or a stringified number,
- with cache. */
-
-char *getuser(uid_t uid, char *name, int len)
-{
- register struct userid *tail;
- char usernum_string[20];
-
- P(mutex);
- for (tail = user_alist; tail; tail = tail->next) {
- if (tail->id.u == uid) {
- goto uid_done;
- }
- }
-
- tail = (struct userid *)malloc(sizeof (struct userid));
- tail->id.u = uid;
- tail->name = NULL;
-
-#if !defined(HAVE_WIN32)
- {
- struct passwd *pwent = getpwuid(uid);
-
- if (pwent != NULL && strcmp(pwent->pw_name, "????????") != 0) {
- tail->name = bstrdup(pwent->pw_name);
- }
- }
-#endif
-
- if (tail->name == NULL) {
- sprintf(usernum_string, "%u", (uint32_t)uid);
- tail->name = bstrdup(usernum_string);
- }
-
- /* Add to the head of the list, so most recently used is first. */
- tail->next = user_alist;
- user_alist = tail;
-
-uid_done:
- bstrncpy(name, tail->name, len);
- V(mutex);
- return name;
-}
-
-void free_getuser_cache()
-{
- register struct userid *tail;
-
- P(mutex);
- for (tail = user_alist; tail; ) {
- struct userid *otail = tail;
- free(tail->name);
- tail = tail->next;
- free(otail);
- }
- user_alist = NULL;
- V(mutex);
-}
-
-
-
-/* Translate GID to a group name or a stringified number,
- with cache. */
-char *getgroup(gid_t gid, char *name, int len)
-{
- register struct userid *tail;
- char groupnum_string[20];
-
- P(mutex);
- for (tail = group_alist; tail; tail = tail->next) {
- if (tail->id.g == gid) {
- goto gid_done;
- }
- }
-
- tail = (struct userid *)malloc(sizeof (struct userid));
- tail->id.g = gid;
- tail->name = NULL;
-
-#if !defined(HAVE_WIN32)
- {
- struct group *grent = getgrgid(gid);
-
- if (grent != NULL && strcmp(grent->gr_name, "????????") != 0) {
- tail->name = bstrdup(grent->gr_name);
- }
- }
-#endif
-
- if (tail->name == NULL) {
- sprintf (groupnum_string, "%u", (uint32_t)gid);
- tail->name = bstrdup(groupnum_string);
- }
-
- /* Add to the head of the list, so most recently used is first. */
- tail->next = group_alist;
- group_alist = tail;
-
-gid_done:
- bstrncpy(name, tail->name, len);
- V(mutex);
- return name;
-}
-
-void free_getgroup_cache()
-{
- register struct userid *tail;
-
- P(mutex);
- for (tail = group_alist; tail; ) {
- struct userid *otail = tail;
- free(tail->name);
- tail = tail->next;
- free(otail);
- }
- group_alist = NULL;
- V(mutex);
-}
jcr->cached_path = NULL;
jcr->cached_pnl = 0;
}
- free_getuser_cache();
- free_getgroup_cache();
+ if (jcr->id_list) {
+ free_guid_list(jcr->id_list);
+ jcr->id_list = NULL;
+ }
free(jcr);
}
#include "attr.h"
#include "var.h"
#include "address_conf.h"
+#include "guid_to_name.h"
#include "protos.h"
BSOCK * bnet_bind (int port);
BSOCK * bnet_accept (BSOCK *bsock, char *who);
-/* idcache.c */
-char *getuser(uid_t uid);
-void free_getuser_cache();
-char *getgroup (gid_t gid);
-void free_getgroup_cache();
-
/* python.c */
typedef int (EVENT_HANDLER)(JCR *jcr, const char *event);
void init_python_interpreter(const char *progname, const char *scripts,
General:
05Sep07
+kes Remove idcache.c
+kes Add guid_to_name.c/h which replace idcache.
kes Remove enh_fnmatch.c. Make code that references it use fnmatch.c
04Sep07
ebl Detect if new PosgreSQL batch insert API is present.