fsal_status_t POSIXFSAL_InitClientContext(fsal_op_context_t * thr_context) { posixfsal_op_context_t * p_thr_context = (posixfsal_op_context_t *) thr_context; fsal_posixdb_status_t st; /* sanity check */ if(!p_thr_context) Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_InitClientContext); /* initialy set the export entry to none */ p_thr_context->export_context = NULL; st = fsal_posixdb_connect(&global_posixdb_params, &(p_thr_context->p_conn)); if(FSAL_POSIXDB_IS_ERROR(st)) { LogCrit(COMPONENT_FSAL, "CRITICAL ERROR: Worker could not connect to database !!!"); Return(ERR_FSAL_SERVERFAULT, 0, INDEX_FSAL_InitClientContext); } else { LogEvent(COMPONENT_FSAL, "Worker successfuly connected to database"); } /* sets the credential time */ /* p_thr_context->credential.last_update = time( NULL );*/ /* traces: prints p_credential structure */ /* LogDebug(COMPONENT_FSAL, "credential created:"); LogDebug(COMPONENT_FSAL, "\tuid = %d, gid = %d", p_thr_context->credential.hpss_usercred.SecPWent.Uid, p_thr_context->credential.hpss_usercred.SecPWent.Gid); LogDebug(COMPONENT_FSAL, "\tName = %s", p_thr_context->credential.hpss_usercred.SecPWent.Name); for ( i=0; i< p_thr_context->credential.hpss_usercred.NumGroups; i++ ) LogDebug(COMPONENT_FSAL, "\tAlt grp: %d", p_thr_context->credential.hpss_usercred.AltGroups[i] ); */ Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_InitClientContext); }
int main(int argc, char **argv) { fsal_posixdb_conn_params_t dbparams; char exec_name[MAXPATHLEN]; char c, op = 0; fsal_posixdb_conn *p_conn; fsal_posixdb_status_t statusdb; char path[MAXPATHLEN]; int rc; char options[] = "h@H:P:L:D:K:"; char usage[] = "Usage: %s [-h][-H <host>][-P <port>][-L <login>][-D <dbname>][-K <passwd file>] operation operation_parameters\n" "\t[-h] display this help\n" "\t[-H <host>] Database host\n" "\t[-P <port>] Database port\n" "\t[-L <login>] Database login\n" "\t[-D <dbname>] Name of the database\n" "\t[-K <passwd file>] Path of the file where is stored the password\n" "------------- Default Values -------------\n" "host : localhost\n" "port : default DB port\n" "dbname : posixdb\n" "login : current unix user\n" "passwd file : default path ($PGPASSFILE)\n" "------------- Operations -----------------\n" "test_connection : try to connect to the database\n" "empty_database : Delete all entries in the database\n" "find : Print the entries of the database (as 'find' would do it)\n" "populate <path> : Add (recursively) the object in <path> into the database\n\n"; memset(&dbparams, 0, sizeof(fsal_posixdb_conn_params_t)); strcpy(dbparams.host, "localhost"); strcpy(dbparams.dbname, "posixdb"); /* What is the executable file's name */ if(*exec_name == '\0') strcpy((char *)exec_name, basename(argv[0])); /* now parsing options with getopt */ while((c = getopt(argc, argv, options)) != EOF) { switch (c) { case '@': /* A litlle backdoor to keep track of binary versions */ printf("%s compiled on %s at %s\n", exec_name, __DATE__, __TIME__); exit(0); break; case 'H': strncpy(dbparams.host, optarg, FSAL_MAX_DBHOST_NAME_LEN); break; case 'P': strncpy(dbparams.port, optarg, FSAL_MAX_DBPORT_STR_LEN); break; case 'L': strncpy(dbparams.login, optarg, FSAL_MAX_DB_LOGIN_LEN); break; case 'D': strncpy(dbparams.dbname, optarg, FSAL_MAX_DB_NAME_LEN); break; case 'K': strncpy(dbparams.passwdfile, optarg, PATH_MAX); break; default: /* display the help */ fprintf(stderr, usage, exec_name); exit(0); break; } } if(optind == argc) { fprintf(stderr, "No operation specified.\n"); fprintf(stderr, usage, exec_name); exit(0); } if(optind < argc) { if(!strcmp(argv[optind], "test_connection")) { op = OP_TESTCONN; } else if(!strcmp(argv[optind], "empty_database")) { op = OP_EMPTYDB; } else if(!strcmp(argv[optind], "find")) { op = OP_FIND; } else if(!strcmp(argv[optind], "populate")) { op = OP_POPULATE; optind++; if(optind < argc) { strncpy(path, argv[optind], MAXPATHLEN); } else { fputs("Operation 'populate' need a parameter", stderr); fprintf(stderr, usage, exec_name); exit(-1); } } else { fprintf(stderr, "Unknown operation : %s\n", argv[optind]); fprintf(stderr, usage, exec_name); exit(-1); } } /* Connecting to database */ if(*(dbparams.passwdfile) != '\0') { rc = setenv("PGPASSFILE", dbparams.passwdfile, 1); if(rc != 0) fputs("Could not set POSTGRESQL keytab path.", stderr); } fprintf(stderr, "Opening database connection to %s...\n", dbparams.host); statusdb = fsal_posixdb_connect(&dbparams, &p_conn); if(FSAL_POSIXDB_IS_ERROR(statusdb)) { fprintf(stderr, "Error %i. exiting.\n", statusdb.minor); exit(-1); } else { fprintf(stderr, "Connected.\n"); } /* Execute the operation */ switch (op) { case OP_TESTCONN: /* nothing to do */ break; case OP_EMPTYDB: emptydb(p_conn); break; case OP_FIND: find(p_conn); break; case OP_POPULATE: populatedb(p_conn, path); break; default: puts("Bad operation !!"); fprintf(stderr, usage, exec_name); } fsal_posixdb_disconnect(p_conn); exit(0); }