inspection: Add support for ttylinux (a minimal Linux).
[libguestfs.git] / src / inspect.c
1 /* libguestfs
2  * Copyright (C) 2010-2011 Red Hat Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 #include <config.h>
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stdint.h>
24 #include <inttypes.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <string.h>
28 #include <sys/stat.h>
29 #include <errno.h>
30 #include <endian.h>
31
32 #include <pcre.h>
33
34 #ifdef HAVE_HIVEX
35 #include <hivex.h>
36 #endif
37
38 #include "c-ctype.h"
39 #include "ignore-value.h"
40 #include "xstrtol.h"
41
42 #include "guestfs.h"
43 #include "guestfs-internal.h"
44 #include "guestfs-internal-actions.h"
45 #include "guestfs_protocol.h"
46
47 #if defined(HAVE_HIVEX)
48
49 /* The main inspection code. */
50 char **
51 guestfs__inspect_os (guestfs_h *g)
52 {
53   /* Remove any information previously stored in the handle. */
54   guestfs___free_inspect_info (g);
55
56   if (guestfs_umount_all (g) == -1)
57     return NULL;
58
59   /* Iterate over all possible devices.  Try to mount each
60    * (read-only).  Examine ones which contain filesystems and add that
61    * information to the handle.
62    */
63   /* Look to see if any devices directly contain filesystems (RHBZ#590167). */
64   char **devices;
65   devices = guestfs_list_devices (g);
66   if (devices == NULL)
67     return NULL;
68
69   size_t i;
70   for (i = 0; devices[i] != NULL; ++i) {
71     if (guestfs___check_for_filesystem_on (g, devices[i], 1, 0) == -1) {
72       guestfs___free_string_list (devices);
73       guestfs___free_inspect_info (g);
74       return NULL;
75     }
76   }
77   guestfs___free_string_list (devices);
78
79   /* Look at all partitions. */
80   char **partitions;
81   partitions = guestfs_list_partitions (g);
82   if (partitions == NULL) {
83     guestfs___free_inspect_info (g);
84     return NULL;
85   }
86
87   for (i = 0; partitions[i] != NULL; ++i) {
88     if (guestfs___check_for_filesystem_on (g, partitions[i], 0, i+1) == -1) {
89       guestfs___free_string_list (partitions);
90       guestfs___free_inspect_info (g);
91       return NULL;
92     }
93   }
94   guestfs___free_string_list (partitions);
95
96   /* Look at all LVs. */
97   if (guestfs___feature_available (g, "lvm2")) {
98     char **lvs;
99     lvs = guestfs_lvs (g);
100     if (lvs == NULL) {
101       guestfs___free_inspect_info (g);
102       return NULL;
103     }
104
105     for (i = 0; lvs[i] != NULL; ++i) {
106       if (guestfs___check_for_filesystem_on (g, lvs[i], 0, 0) == -1) {
107         guestfs___free_string_list (lvs);
108         guestfs___free_inspect_info (g);
109         return NULL;
110       }
111     }
112     guestfs___free_string_list (lvs);
113   }
114
115   /* At this point we have, in the handle, a list of all filesystems
116    * found and data about each one.  Now we assemble the list of
117    * filesystems which are root devices and return that to the user.
118    * Fall through to guestfs__inspect_get_roots to do that.
119    */
120   char **ret = guestfs__inspect_get_roots (g);
121   if (ret == NULL)
122     guestfs___free_inspect_info (g);
123   return ret;
124 }
125
126 char **
127 guestfs__inspect_get_roots (guestfs_h *g)
128 {
129   /* NB. Doesn't matter if g->nr_fses == 0.  We just return an empty
130    * list in this case.
131    */
132
133   size_t i;
134   size_t count = 0;
135   for (i = 0; i < g->nr_fses; ++i)
136     if (g->fses[i].is_root)
137       count++;
138
139   char **ret = calloc (count+1, sizeof (char *));
140   if (ret == NULL) {
141     perrorf (g, "calloc");
142     return NULL;
143   }
144
145   count = 0;
146   for (i = 0; i < g->nr_fses; ++i) {
147     if (g->fses[i].is_root) {
148       ret[count] = safe_strdup (g, g->fses[i].device);
149       count++;
150     }
151   }
152   ret[count] = NULL;
153
154   return ret;
155 }
156
157 char *
158 guestfs__inspect_get_type (guestfs_h *g, const char *root)
159 {
160   struct inspect_fs *fs = guestfs___search_for_root (g, root);
161   if (!fs)
162     return NULL;
163
164   char *ret;
165   switch (fs->type) {
166   case OS_TYPE_LINUX: ret = safe_strdup (g, "linux"); break;
167   case OS_TYPE_WINDOWS: ret = safe_strdup (g, "windows"); break;
168   case OS_TYPE_FREEBSD: ret = safe_strdup (g, "freebsd"); break;
169   case OS_TYPE_UNKNOWN: default: ret = safe_strdup (g, "unknown"); break;
170   }
171
172   return ret;
173 }
174
175 char *
176 guestfs__inspect_get_arch (guestfs_h *g, const char *root)
177 {
178   struct inspect_fs *fs = guestfs___search_for_root (g, root);
179   if (!fs)
180     return NULL;
181
182   return safe_strdup (g, fs->arch ? : "unknown");
183 }
184
185 char *
186 guestfs__inspect_get_distro (guestfs_h *g, const char *root)
187 {
188   struct inspect_fs *fs = guestfs___search_for_root (g, root);
189   if (!fs)
190     return NULL;
191
192   char *ret;
193   switch (fs->distro) {
194   case OS_DISTRO_ARCHLINUX: ret = safe_strdup (g, "archlinux"); break;
195   case OS_DISTRO_CENTOS: ret = safe_strdup (g, "centos"); break;
196   case OS_DISTRO_DEBIAN: ret = safe_strdup (g, "debian"); break;
197   case OS_DISTRO_FEDORA: ret = safe_strdup (g, "fedora"); break;
198   case OS_DISTRO_GENTOO: ret = safe_strdup (g, "gentoo"); break;
199   case OS_DISTRO_LINUX_MINT: ret = safe_strdup (g, "linuxmint"); break;
200   case OS_DISTRO_MANDRIVA: ret = safe_strdup (g, "mandriva"); break;
201   case OS_DISTRO_MEEGO: ret = safe_strdup (g, "meego"); break;
202   case OS_DISTRO_PARDUS: ret = safe_strdup (g, "pardus"); break;
203   case OS_DISTRO_REDHAT_BASED: ret = safe_strdup (g, "redhat-based"); break;
204   case OS_DISTRO_RHEL: ret = safe_strdup (g, "rhel"); break;
205   case OS_DISTRO_SCIENTIFIC_LINUX: ret = safe_strdup (g, "scientificlinux"); break;
206   case OS_DISTRO_SLACKWARE: ret = safe_strdup (g, "slackware"); break;
207   case OS_DISTRO_TTYLINUX: ret = safe_strdup (g, "ttylinux"); break;
208   case OS_DISTRO_WINDOWS: ret = safe_strdup (g, "windows"); break;
209   case OS_DISTRO_UBUNTU: ret = safe_strdup (g, "ubuntu"); break;
210   case OS_DISTRO_UNKNOWN: default: ret = safe_strdup (g, "unknown"); break;
211   }
212
213   return ret;
214 }
215
216 int
217 guestfs__inspect_get_major_version (guestfs_h *g, const char *root)
218 {
219   struct inspect_fs *fs = guestfs___search_for_root (g, root);
220   if (!fs)
221     return -1;
222
223   return fs->major_version;
224 }
225
226 int
227 guestfs__inspect_get_minor_version (guestfs_h *g, const char *root)
228 {
229   struct inspect_fs *fs = guestfs___search_for_root (g, root);
230   if (!fs)
231     return -1;
232
233   return fs->minor_version;
234 }
235
236 char *
237 guestfs__inspect_get_product_name (guestfs_h *g, const char *root)
238 {
239   struct inspect_fs *fs = guestfs___search_for_root (g, root);
240   if (!fs)
241     return NULL;
242
243   return safe_strdup (g, fs->product_name ? : "unknown");
244 }
245
246 char *
247 guestfs__inspect_get_product_variant (guestfs_h *g, const char *root)
248 {
249   struct inspect_fs *fs = guestfs___search_for_root (g, root);
250   if (!fs)
251     return NULL;
252
253   return safe_strdup (g, fs->product_variant ? : "unknown");
254 }
255
256 char *
257 guestfs__inspect_get_windows_systemroot (guestfs_h *g, const char *root)
258 {
259   struct inspect_fs *fs = guestfs___search_for_root (g, root);
260   if (!fs)
261     return NULL;
262
263   if (!fs->windows_systemroot) {
264     error (g, _("not a Windows guest, or systemroot could not be determined"));
265     return NULL;
266   }
267
268   return safe_strdup (g, fs->windows_systemroot);
269 }
270
271 char *
272 guestfs__inspect_get_windows_current_control_set (guestfs_h *g,
273                                                   const char *root)
274 {
275   struct inspect_fs *fs = guestfs___search_for_root (g, root);
276   if (!fs)
277     return NULL;
278
279   if (!fs->windows_current_control_set) {
280     error (g, _("not a Windows guest, or CurrentControlSet could not be determined"));
281     return NULL;
282   }
283
284   return safe_strdup (g, fs->windows_current_control_set);
285 }
286
287 char *
288 guestfs__inspect_get_format (guestfs_h *g, const char *root)
289 {
290   struct inspect_fs *fs = guestfs___search_for_root (g, root);
291   if (!fs)
292     return NULL;
293
294   char *ret;
295   switch (fs->format) {
296   case OS_FORMAT_INSTALLED: ret = safe_strdup (g, "installed"); break;
297   case OS_FORMAT_INSTALLER: ret = safe_strdup (g, "installer"); break;
298   case OS_FORMAT_UNKNOWN: default: ret = safe_strdup (g, "unknown"); break;
299   }
300
301   return ret;
302 }
303
304 int
305 guestfs__inspect_is_live (guestfs_h *g, const char *root)
306 {
307   struct inspect_fs *fs = guestfs___search_for_root (g, root);
308   if (!fs)
309     return -1;
310
311   return fs->is_live_disk;
312 }
313
314 int
315 guestfs__inspect_is_netinst (guestfs_h *g, const char *root)
316 {
317   struct inspect_fs *fs = guestfs___search_for_root (g, root);
318   if (!fs)
319     return -1;
320
321   return fs->is_netinst_disk;
322 }
323
324 int
325 guestfs__inspect_is_multipart (guestfs_h *g, const char *root)
326 {
327   struct inspect_fs *fs = guestfs___search_for_root (g, root);
328   if (!fs)
329     return -1;
330
331   return fs->is_multipart_disk;
332 }
333
334 char **
335 guestfs__inspect_get_mountpoints (guestfs_h *g, const char *root)
336 {
337   struct inspect_fs *fs = guestfs___search_for_root (g, root);
338   if (!fs)
339     return NULL;
340
341   char **ret;
342
343   /* If no fstab information (Windows) return just the root. */
344   if (fs->nr_fstab == 0) {
345     ret = calloc (3, sizeof (char *));
346     ret[0] = safe_strdup (g, "/");
347     ret[1] = safe_strdup (g, root);
348     ret[2] = NULL;
349     return ret;
350   }
351
352 #define CRITERION fs->fstab[i].mountpoint[0] == '/'
353   size_t i, count = 0;
354   for (i = 0; i < fs->nr_fstab; ++i)
355     if (CRITERION)
356       count++;
357
358   /* Hashtables have 2N+1 entries. */
359   ret = calloc (2*count+1, sizeof (char *));
360   if (ret == NULL) {
361     perrorf (g, "calloc");
362     return NULL;
363   }
364
365   count = 0;
366   for (i = 0; i < fs->nr_fstab; ++i)
367     if (CRITERION) {
368       ret[2*count] = safe_strdup (g, fs->fstab[i].mountpoint);
369       ret[2*count+1] = safe_strdup (g, fs->fstab[i].device);
370       count++;
371     }
372 #undef CRITERION
373
374   return ret;
375 }
376
377 char **
378 guestfs__inspect_get_filesystems (guestfs_h *g, const char *root)
379 {
380   struct inspect_fs *fs = guestfs___search_for_root (g, root);
381   if (!fs)
382     return NULL;
383
384   char **ret;
385
386   /* If no fstab information (Windows) return just the root. */
387   if (fs->nr_fstab == 0) {
388     ret = calloc (2, sizeof (char *));
389     ret[0] = safe_strdup (g, root);
390     ret[1] = NULL;
391     return ret;
392   }
393
394   ret = calloc (fs->nr_fstab + 1, sizeof (char *));
395   if (ret == NULL) {
396     perrorf (g, "calloc");
397     return NULL;
398   }
399
400   size_t i;
401   for (i = 0; i < fs->nr_fstab; ++i)
402     ret[i] = safe_strdup (g, fs->fstab[i].device);
403
404   return ret;
405 }
406
407 char **
408 guestfs__inspect_get_drive_mappings (guestfs_h *g, const char *root)
409 {
410   char **ret;
411   size_t i, count;
412   struct inspect_fs *fs;
413
414   fs = guestfs___search_for_root (g, root);
415   if (!fs)
416     return NULL;
417
418   /* If no drive mappings, return an empty hashtable. */
419   if (!fs->drive_mappings)
420     count = 0;
421   else {
422     for (count = 0; fs->drive_mappings[count] != NULL; count++)
423       ;
424   }
425
426   ret = calloc (count+1, sizeof (char *));
427   if (ret == NULL) {
428     perrorf (g, "calloc");
429     return NULL;
430   }
431
432   /* We need to make a deep copy of the hashtable since the caller
433    * will free it.
434    */
435   for (i = 0; i < count; ++i)
436     ret[i] = safe_strdup (g, fs->drive_mappings[i]);
437
438   ret[count] = NULL;
439
440   return ret;
441 }
442
443 char *
444 guestfs__inspect_get_package_format (guestfs_h *g, const char *root)
445 {
446   struct inspect_fs *fs = guestfs___search_for_root (g, root);
447   if (!fs)
448     return NULL;
449
450   char *ret;
451   switch (fs->package_format) {
452   case OS_PACKAGE_FORMAT_RPM: ret = safe_strdup (g, "rpm"); break;
453   case OS_PACKAGE_FORMAT_DEB: ret = safe_strdup (g, "deb"); break;
454   case OS_PACKAGE_FORMAT_PACMAN: ret = safe_strdup (g, "pacman"); break;
455   case OS_PACKAGE_FORMAT_EBUILD: ret = safe_strdup (g, "ebuild"); break;
456   case OS_PACKAGE_FORMAT_PISI: ret = safe_strdup (g, "pisi"); break;
457   case OS_PACKAGE_FORMAT_UNKNOWN:
458   default:
459     ret = safe_strdup (g, "unknown");
460     break;
461   }
462
463   return ret;
464 }
465
466 char *
467 guestfs__inspect_get_package_management (guestfs_h *g, const char *root)
468 {
469   struct inspect_fs *fs = guestfs___search_for_root (g, root);
470   if (!fs)
471     return NULL;
472
473   char *ret;
474   switch (fs->package_management) {
475   case OS_PACKAGE_MANAGEMENT_YUM: ret = safe_strdup (g, "yum"); break;
476   case OS_PACKAGE_MANAGEMENT_UP2DATE: ret = safe_strdup (g, "up2date"); break;
477   case OS_PACKAGE_MANAGEMENT_APT: ret = safe_strdup (g, "apt"); break;
478   case OS_PACKAGE_MANAGEMENT_PACMAN: ret = safe_strdup (g, "pacman"); break;
479   case OS_PACKAGE_MANAGEMENT_PORTAGE: ret = safe_strdup (g, "portage"); break;
480   case OS_PACKAGE_MANAGEMENT_PISI: ret = safe_strdup (g, "pisi"); break;
481   case OS_PACKAGE_MANAGEMENT_URPMI: ret = safe_strdup (g, "urpmi"); break;
482   case OS_PACKAGE_MANAGEMENT_UNKNOWN:
483   default:
484     ret = safe_strdup (g, "unknown");
485     break;
486   }
487
488   return ret;
489 }
490
491 char *
492 guestfs__inspect_get_hostname (guestfs_h *g, const char *root)
493 {
494   struct inspect_fs *fs = guestfs___search_for_root (g, root);
495   if (!fs)
496     return NULL;
497
498   return safe_strdup (g, fs->hostname ? : "unknown");
499 }
500
501 /* Download a guest file to a local temporary file.  The file is
502  * cached in the temporary directory, and is not downloaded again.
503  *
504  * The name of the temporary (downloaded) file is returned.  The
505  * caller must free the pointer, but does *not* need to delete the
506  * temporary file.  It will be deleted when the handle is closed.
507  *
508  * Refuse to download the guest file if it is larger than max_size.
509  * On this and other errors, NULL is returned.
510  *
511  * There is actually one cache per 'struct inspect_fs *' in order
512  * to handle the case of multiple roots.
513  */
514 char *
515 guestfs___download_to_tmp (guestfs_h *g, struct inspect_fs *fs,
516                            const char *filename,
517                            const char *basename, int64_t max_size)
518 {
519   char *r;
520   int fd;
521   char devfd[32];
522   int64_t size;
523
524   /* Make the basename unique by prefixing it with the fs number. */
525   if (asprintf (&r, "%s/%ld-%s", g->tmpdir, fs - g->fses, basename) == -1) {
526     perrorf (g, "asprintf");
527     return NULL;
528   }
529
530   /* If the file has already been downloaded, return. */
531   if (access (r, R_OK) == 0)
532     return r;
533
534   /* Check size of remote file. */
535   size = guestfs_filesize (g, filename);
536   if (size == -1)
537     /* guestfs_filesize failed and has already set error in handle */
538     goto error;
539   if (size > max_size) {
540     error (g, _("size of %s is unreasonably large (%" PRIi64 " bytes)"),
541            filename, size);
542     goto error;
543   }
544
545   fd = open (r, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY, 0600);
546   if (fd == -1) {
547     perrorf (g, "open: %s", r);
548     goto error;
549   }
550
551   snprintf (devfd, sizeof devfd, "/dev/fd/%d", fd);
552
553   if (guestfs_download (g, filename, devfd) == -1) {
554     unlink (r);
555     close (fd);
556     goto error;
557   }
558
559   if (close (fd) == -1) {
560     perrorf (g, "close: %s", r);
561     unlink (r);
562     goto error;
563   }
564
565   return r;
566
567  error:
568   free (r);
569   return NULL;
570 }
571
572 struct inspect_fs *
573 guestfs___search_for_root (guestfs_h *g, const char *root)
574 {
575   if (g->nr_fses == 0) {
576     error (g, _("no inspection data: call guestfs_inspect_os first"));
577     return NULL;
578   }
579
580   size_t i;
581   struct inspect_fs *fs;
582   for (i = 0; i < g->nr_fses; ++i) {
583     fs = &g->fses[i];
584     if (fs->is_root && STREQ (root, fs->device))
585       return fs;
586   }
587
588   error (g, _("%s: root device not found: only call this function with a root device previously returned by guestfs_inspect_os"),
589          root);
590   return NULL;
591 }
592
593 #else /* no hivex at compile time */
594
595 /* XXX These functions should be in an optgroup. */
596
597 #define NOT_IMPL(r)                                                     \
598   error (g, _("inspection API not available since this version of libguestfs was compiled without the hivex library")); \
599   return r
600
601 char **
602 guestfs__inspect_os (guestfs_h *g)
603 {
604   NOT_IMPL(NULL);
605 }
606
607 char **
608 guestfs__inspect_get_roots (guestfs_h *g)
609 {
610   NOT_IMPL(NULL);
611 }
612
613 char *
614 guestfs__inspect_get_type (guestfs_h *g, const char *root)
615 {
616   NOT_IMPL(NULL);
617 }
618
619 char *
620 guestfs__inspect_get_arch (guestfs_h *g, const char *root)
621 {
622   NOT_IMPL(NULL);
623 }
624
625 char *
626 guestfs__inspect_get_distro (guestfs_h *g, const char *root)
627 {
628   NOT_IMPL(NULL);
629 }
630
631 int
632 guestfs__inspect_get_major_version (guestfs_h *g, const char *root)
633 {
634   NOT_IMPL(-1);
635 }
636
637 int
638 guestfs__inspect_get_minor_version (guestfs_h *g, const char *root)
639 {
640   NOT_IMPL(-1);
641 }
642
643 char *
644 guestfs__inspect_get_product_name (guestfs_h *g, const char *root)
645 {
646   NOT_IMPL(NULL);
647 }
648
649 char *
650 guestfs__inspect_get_product_variant (guestfs_h *g, const char *root)
651 {
652   NOT_IMPL(NULL);
653 }
654
655 char *
656 guestfs__inspect_get_windows_systemroot (guestfs_h *g, const char *root)
657 {
658   NOT_IMPL(NULL);
659 }
660
661 char *
662 guestfs__inspect_get_windows_current_control_set (guestfs_h *g,
663                                                   const char *root)
664 {
665   NOT_IMPL(NULL);
666 }
667
668 char **
669 guestfs__inspect_get_mountpoints (guestfs_h *g, const char *root)
670 {
671   NOT_IMPL(NULL);
672 }
673
674 char **
675 guestfs__inspect_get_filesystems (guestfs_h *g, const char *root)
676 {
677   NOT_IMPL(NULL);
678 }
679
680 char **
681 guestfs__inspect_get_drive_mappings (guestfs_h *g, const char *root)
682 {
683   NOT_IMPL(NULL);
684 }
685
686 char *
687 guestfs__inspect_get_package_format (guestfs_h *g, const char *root)
688 {
689   NOT_IMPL(NULL);
690 }
691
692 char *
693 guestfs__inspect_get_package_management (guestfs_h *g, const char *root)
694 {
695   NOT_IMPL(NULL);
696 }
697
698 char *
699 guestfs__inspect_get_hostname (guestfs_h *g, const char *root)
700 {
701   NOT_IMPL(NULL);
702 }
703
704 char *
705 guestfs__inspect_get_format (guestfs_h *g, const char *root)
706 {
707   NOT_IMPL(NULL);
708 }
709
710 int
711 guestfs__inspect_is_live (guestfs_h *g, const char *root)
712 {
713   NOT_IMPL(-1);
714 }
715
716 int
717 guestfs__inspect_is_netinst (guestfs_h *g, const char *root)
718 {
719   NOT_IMPL(-1);
720 }
721
722 int
723 guestfs__inspect_is_multipart (guestfs_h *g, const char *root)
724 {
725   NOT_IMPL(-1);
726 }
727
728 #endif /* no hivex at compile time */
729
730 void
731 guestfs___free_inspect_info (guestfs_h *g)
732 {
733   size_t i;
734   for (i = 0; i < g->nr_fses; ++i) {
735     free (g->fses[i].device);
736     free (g->fses[i].product_name);
737     free (g->fses[i].product_variant);
738     free (g->fses[i].arch);
739     free (g->fses[i].hostname);
740     free (g->fses[i].windows_systemroot);
741     free (g->fses[i].windows_current_control_set);
742     size_t j;
743     for (j = 0; j < g->fses[i].nr_fstab; ++j) {
744       free (g->fses[i].fstab[j].device);
745       free (g->fses[i].fstab[j].mountpoint);
746     }
747     free (g->fses[i].fstab);
748     if (g->fses[i].drive_mappings)
749       guestfs___free_string_list (g->fses[i].drive_mappings);
750   }
751   free (g->fses);
752   g->nr_fses = 0;
753   g->fses = NULL;
754 }
755
756 /* In the Perl code this is a public function. */
757 int
758 guestfs___feature_available (guestfs_h *g, const char *feature)
759 {
760   /* If there's an error we should ignore it, so to do that we have to
761    * temporarily replace the error handler with a null one.
762    */
763   guestfs_error_handler_cb old_error_cb = g->error_cb;
764   g->error_cb = NULL;
765
766   const char *groups[] = { feature, NULL };
767   int r = guestfs_available (g, (char * const *) groups);
768
769   g->error_cb = old_error_cb;
770
771   return r == 0 ? 1 : 0;
772 }