1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
/*
* Copyright (c) 2004 PADL Software Pty Ltd.
* All rights reserved.
* Use is subject to license.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include "updatedb.h"
static void usage(void)
{
fprintf(stderr, "Usage: nss_updatedb [nameservice] [passwd|group]\n");
exit(NSS_STATUS_UNAVAIL);
}
static const char *nss_err2string(enum nss_status status)
{
const char *serr;
switch (status) {
case NSS_STATUS_SUCCESS:
serr = "success";
break;
case NSS_STATUS_TRYAGAIN:
serr = "out of memory";
break;
case NSS_STATUS_UNAVAIL:
serr = "nameservice unavailable";
break;
case NSS_STATUS_NOTFOUND:
serr = "not found";
break;
default:
serr = "unknown error";
break;
}
return serr;
}
int main(int argc, char *argv[])
{
nss_backend_handle_t *handle;
unsigned maps = 0;
char *dbname;
enum nss_status status;
if (argc < 2 || argc > 3) {
usage();
}
dbname = argv[1];
if (strcmp(dbname, "db") == 0) {
fprintf(stderr, "Cannot run nss_updatedb against nss_db.\n");
exit(NSS_STATUS_UNAVAIL);
}
if (argc == 3) {
char *mapname;
mapname = argv[2];
if (strcmp(mapname, "passwd") == 0)
maps = MAP_PASSWD;
else if (strcmp(mapname, "group") == 0)
maps = MAP_GROUP;
else
usage();
} else {
maps = MAP_ALL;
}
status = nss_backend_open(dbname, &handle);
if (status != NSS_STATUS_SUCCESS) {
exit(status);
}
if (maps & MAP_PASSWD) {
printf("passwd... ");
status = nss_update_db(handle, MAP_PASSWD, DB_PASSWD);
if (status != NSS_STATUS_SUCCESS) {
printf("%s.\n", nss_err2string(status));
exit(status);
}
printf("done.\n");
}
if (maps & MAP_GROUP) {
printf("group... ");
status = nss_update_db(handle, MAP_GROUP, DB_GROUP);
if (status != NSS_STATUS_SUCCESS) {
printf("%s.\n", nss_err2string(status));
exit(status);
}
printf("done.\n");
}
exit(0);
}
|