static int unmount_fuse(const char *mnt, int quiet, int lazy) { int res; struct mntent *entp; FILE *fp; FILE *newfp = NULL; const char *user = NULL; char uidstr[32]; unsigned uidlen = 0; int found; int issymlink = 0; struct stat stbuf; const char *mtab = _PATH_MOUNTED; const char *mtab_new = _PATH_MOUNTED "~fuse~"; if (lstat(mtab, &stbuf) != -1 && S_ISLNK(stbuf.st_mode)) issymlink = 1; fp = setmntent(mtab, "r"); if (fp == NULL) { fprintf(stderr, "%s: failed to open %s: %s\n", progname, mtab, strerror(errno)); return -1; } if (!issymlink) { newfp = setmntent(mtab_new, "w"); if (newfp == NULL) { fprintf(stderr, "%s: failed to open %s: %s\n", progname, mtab_new, strerror(errno)); endmntent(fp); return -1; } } if (getuid() != 0) { user = get_user_name(); if (user == NULL) goto err_endmntent; uidlen = sprintf(uidstr, "%u", getuid()); } found = 0; while ((entp = getmntent(fp)) != NULL) { int removed = 0; if (!found && strcmp(entp->mnt_dir, mnt) == 0 && (strcmp(entp->mnt_type, "fuse") == 0 || strcmp(entp->mnt_type, "fuseblk") == 0)) { if (user == NULL) removed = 1; else { char *p = strstr(entp->mnt_opts, "user="******"user_id=")) && (p == entp->mnt_opts || *(p-1) == ',') && strncmp(p + 8, uidstr, uidlen) == 0 && (*(p+8+uidlen) == ',' || *(p+8+uidlen) == '\0')) removed = 1; } } if (removed) found = 1; else if (!issymlink) { res = addmntent(newfp, entp); if (res != 0) { fprintf(stderr, "%s: failed to add entry to %s: %s\n", progname, mtab_new, strerror(errno)); } } } endmntent(fp); if (!issymlink) endmntent(newfp); if (!found) { if (!quiet) fprintf(stderr, "%s: entry for %s not found in %s\n", progname, mnt, mtab); goto err; } drop_privs(); res = do_unmount(mnt, quiet, lazy); restore_privs(); if (res == -1) goto err; if (!issymlink) { res = unmount_rename(mtab, mtab_new); if (res == -1) goto err; } return 0; err_endmntent: if (!issymlink) endmntent(newfp); endmntent(fp); err: if (!issymlink) unlink(mtab_new); return -1; }
void usage(void) { const char *env; const char *user; char *errstr; /* Find default user, in case we need it. */ user = getenv("PGUSER"); if (!user) { user = get_user_name(&errstr); if (!user) { psql_error("%s\n", errstr); exit(EXIT_FAILURE); } } printf(_("psql is the PostgreSQL interactive terminal.\n\n")); printf(_("Usage:\n")); printf(_(" psql [OPTION]... [DBNAME [USERNAME]]\n\n")); printf(_("General options:\n")); /* Display default database */ env = getenv("PGDATABASE"); if (!env) env = user; printf(_(" -c, --command=COMMAND run only single command (SQL or internal) and exit\n")); printf(_(" -d, --dbname=DBNAME database name to connect to (default: \"%s\")\n"), env); printf(_(" -f, --file=FILENAME execute commands from file, then exit\n")); printf(_(" -l, --list list available databases, then exit\n")); printf(_(" -v, --set=, --variable=NAME=VALUE\n" " set psql variable NAME to VALUE\n")); printf(_(" -V, --version output version information, then exit\n")); printf(_(" -X, --no-psqlrc do not read startup file (~/.psqlrc)\n")); printf(_(" -1 (\"one\"), --single-transaction\n" " execute as a single transaction (if non-interactive)\n")); printf(_(" -?, --help show this help, then exit\n")); printf(_("\nInput and output options:\n")); printf(_(" -a, --echo-all echo all input from script\n")); printf(_(" -e, --echo-queries echo commands sent to server\n")); printf(_(" -E, --echo-hidden display queries that internal commands generate\n")); printf(_(" -L, --log-file=FILENAME send session log to file\n")); printf(_(" -n, --no-readline disable enhanced command line editing (readline)\n")); printf(_(" -o, --output=FILENAME send query results to file (or |pipe)\n")); printf(_(" -q, --quiet run quietly (no messages, only query output)\n")); printf(_(" -s, --single-step single-step mode (confirm each query)\n")); printf(_(" -S, --single-line single-line mode (end of line terminates SQL command)\n")); printf(_("\nOutput format options:\n")); printf(_(" -A, --no-align unaligned table output mode\n")); printf(_(" -F, --field-separator=STRING\n" " field separator for unaligned output (default: \"%s\")\n"), DEFAULT_FIELD_SEP); printf(_(" -H, --html HTML table output mode\n")); printf(_(" -P, --pset=VAR[=ARG] set printing option VAR to ARG (see \\pset command)\n")); printf(_(" -R, --record-separator=STRING\n" " record separator for unaligned output (default: newline)\n")); printf(_(" -t, --tuples-only print rows only\n")); printf(_(" -T, --table-attr=TEXT set HTML table tag attributes (e.g., width, border)\n")); printf(_(" -x, --expanded turn on expanded table output\n")); printf(_(" -z, --field-separator-zero\n" " set field separator for unaligned output to zero byte\n")); printf(_(" -0, --record-separator-zero\n" " set record separator for unaligned output to zero byte\n")); printf(_("\nConnection options:\n")); /* Display default host */ env = getenv("PGHOST"); printf(_(" -h, --host=HOSTNAME database server host or socket directory (default: \"%s\")\n"), env ? env : _("local socket")); /* Display default port */ env = getenv("PGPORT"); printf(_(" -p, --port=PORT database server port (default: \"%s\")\n"), env ? env : DEF_PGPORT_STR); /* Display default user */ env = getenv("PGUSER"); if (!env) env = user; printf(_(" -U, --username=USERNAME database user name (default: \"%s\")\n"), env); printf(_(" -w, --no-password never prompt for password\n")); printf(_(" -W, --password force password prompt (should happen automatically)\n")); printf(_("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\n" "commands) from within psql, or consult the psql section in the PostgreSQL\n" "documentation.\n\n")); printf(_("Report bugs to <*****@*****.**>.\n")); }
void figlet(UR_OBJECT user, char *inpstr, int typ) { UR_OBJECT u=NULL; RM_OBJECT rm=NULL; long c; int i=0, row, wordbreakmode, char_not_added; char *p=inpstr, *name; fcharnode *fclsave; char fontname[256]="standard"; set_crash(); if (user->muzzled) { write_user(user, "Si muzzled, nemozes bannerovat\n"); return; } if (word_count<2) { write_user(user,"Pozri si najprv help ...\n"); return; } if (!strcmp(inpstr, "/l")) { show_file(user, FONTLIST); return; } if (typ==0) rm=user->room; if (typ==1) { if (word_count<3) { write_usage(user, "tbanner /<user> [-<font>] text"); return; } /* Check to see if a username is specified */ i=0; if (*p=='/') { /* Get size of font name */ while (*(p+i)!=' ') { i++; if (i==100) break; } strncpy(text, p+1, i); *(text+i-1)='\0'; name=text; p=p+i+1; } else { write_usage(user, "tbanner /<user> [-<font>] text"); return; } if ((u=get_user_name(user, name))==NULL) { write_user(user, notloggedon); return; } if ((check_igusers(u,user))!=-1 && (user->level<GOD || user->level<u->level)) { vwrite_user(user,"%s~RS is ignoring tells from you.\n",u->recap); return; } if (u->ignore.tells && (user->level<WIZ || u->level>user->level)) { vwrite_user(user,"%s~RS is ignoring tells at the moment.\n",u->recap); return; } if (u->ignore.all && (user->level<WIZ || u->level>user->level)) { if (u->malloc_start!=NULL) vwrite_user(user,"%s~RS is using the editor at the moment.\n",u->recap); else vwrite_user(user,"%s~RS is ignoring everyone at the moment.\n",u->recap); return; } #ifdef NETLINKS if (u->room==NULL) { vwrite_user(user,"%s~RS is offsite and would not be able to reply to you.\n",u->recap); return; } #endif if (u->afk) { if (u->afk_mesg[0]) vwrite_user(user,"%s~RS is ~FRAFK~RS, message is: %s\n",u->recap,u->afk_mesg); else vwrite_user(user,"%s~RS is ~FRAFK~RS at the moment.\n",u->recap); write_user(user,"Sending message to their afk review buffer.\n"); } if (u->editing) { vwrite_user(user,"%s~RS is in ~FTEDIT~RS mode at the moment (using the line editor).\n",u->recap); write_user(user,"Sending message to their edit review buffer.\n"); } } /* Check to see if a font is specified */ i=0; if (*p=='-') { /* Get size of font name */ while (*(p+i)!=' ') { i++; if (i==100) break; } strncpy(fontname, p+1, i); *(fontname+i-1)='\0'; p=p+i+1; if ((word_count<3 && typ!=1) || (word_count<4 && typ==1) ) { write_user(user,"Co zabannerovat ?\n"); return; } } if (amsys->ban_swearing && contains_swearing(p) && user->level<MIN_LEV_NOSWR) { switch(amsys->ban_swearing) { case SBMIN: p=censor_swear_words(p); break; case SBMAX: write_user(user,noswearing); return; default : break; /* do nothing as ban_swearing is off */ } } justification = 0; right2left = -1; outputwidth = 80; outlinelenlimit = outputwidth-1; if ((i=readfont(fontname))==-1) { sprintf(text,"Nemozem nahrat font %s\n",fontname); write_user(user,text); return; } name=invisname; if ((typ==1 && u->level>=user->level) || user->vis) name=user->name; write_text_figlet(user, u, rm, p, name, fontname); /* Line alloc... */ outline = (char**)myalloc(sizeof(char*)*charheight); for (row=0;row<charheight;row++) { outline[row] = (char*)myalloc(sizeof(char)*(outlinelenlimit+1)); } inchrlinelenlimit = outputwidth*4+100; inchrline = (long*)myalloc(sizeof(long)*(inchrlinelenlimit+1)); fclearline(); wordbreakmode = 0; while (*p) { c=*p; p=p+1; if (isascii(c) && isspace(c)) { c = (c=='\t' || c==' ') ? ' ' : '\n'; } if ( (c>'\0' && c<' ' && c!='\n' ) || c==127) continue; /* Note: The following code is complex and thoroughly tested. Be careful when modifying! */ do { char_not_added = 0; if (wordbreakmode== -1) { if (c==' ') break; else if (c=='\n') { wordbreakmode = 0; break; } wordbreakmode = 0; } if (c=='\n') { printline(user, u, rm); wordbreakmode = 0; } else if (addchar(c)) { if (c!=' ') wordbreakmode = (wordbreakmode>=2)?3:1; else wordbreakmode = (wordbreakmode>0)?2:0; } else if (outlinelen==0) { for (i=0;i<charheight;i++) { if (right2left && outputwidth>1) putstring(user, u, rm, currchar[i]+MYSTRLEN(currchar[i])-outlinelenlimit); else putstring(user, u, rm, currchar[i]); } wordbreakmode = -1; } else if (c==' ') { if (wordbreakmode==2) splitline(user, u, rm); else printline(user, u, rm); wordbreakmode = -1; } else { if (wordbreakmode>=2) splitline(user, u, rm); else printline(user, u, rm); wordbreakmode = (wordbreakmode==3)?1:0; char_not_added = 1; } } while (char_not_added); } if (outlinelen!=0) printline(user, u, rm); /* Free up memory... */ free(inchrline); for (row=0;row<charheight;row++) free(outline[row]); free(outline); /* Free up font memory... */ do { /* Save pointer to next node */ fclsave=fcharlist->next; /* Free memory used by this node */ for (row=0;row<charheight;row++) free(fcharlist->thechar[row]); free(fcharlist->thechar); free(fcharlist); fcharlist=fclsave; } while (fclsave!=NULL); return; }
if (error != NULL) { g_warning ("switchtogreeter:seat switchtogreeter %s\n", error->message); g_error_free (error); } error = NULL; g_object_unref (seat_proxy); } int main (int argc G_GNUC_UNUSED, char **argv G_GNUC_UNUSED) { gchar *username = NULL; gchar *seat_path = NULL; username = get_user_name (); if (username == NULL) { g_warning ("switch to greeter:username is NULL\n"); return 1; } seat_path = get_seat_path (username); if (seat_path == NULL) { g_warning ("switch to greeter:seat path is NULL\n"); g_free (username); return 1; } switch_to_greeter (seat_path); g_free (username);
int main(int argc, char *argv[]) { static struct option long_options[] = { {"list", no_argument, NULL, 'l'}, {"host", required_argument, NULL, 'h'}, {"port", required_argument, NULL, 'p'}, {"username", required_argument, NULL, 'U'}, {"no-password", no_argument, NULL, 'w'}, {"password", no_argument, NULL, 'W'}, {"dbname", required_argument, NULL, 'd'}, {"echo", no_argument, NULL, 'e'}, {NULL, 0, NULL, 0} }; const char *progname; int optindex; int c; bool listlangs = false; const char *dbname = NULL; char *host = NULL; char *port = NULL; char *username = NULL; enum trivalue prompt_password = TRI_DEFAULT; bool echo = false; char *langname = NULL; char *p; PQExpBufferData sql; PGconn *conn; PGresult *result; progname = get_progname(argv[0]); set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts")); handle_help_version_opts(argc, argv, "createlang", help); while ((c = getopt_long(argc, argv, "lh:p:U:wWd:e", long_options, &optindex)) != -1) { switch (c) { case 'l': listlangs = true; break; case 'h': host = optarg; break; case 'p': port = optarg; break; case 'U': username = optarg; break; case 'w': prompt_password = TRI_NO; break; case 'W': prompt_password = TRI_YES; break; case 'd': dbname = optarg; break; case 'e': echo = true; break; default: fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); exit(1); } } if (argc - optind > 0) { if (listlangs) dbname = argv[optind++]; else { langname = argv[optind++]; if (argc - optind > 0) dbname = argv[optind++]; } } if (argc - optind > 0) { fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), progname, argv[optind]); fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); exit(1); } if (dbname == NULL) { if (getenv("PGDATABASE")) dbname = getenv("PGDATABASE"); else if (getenv("PGUSER")) dbname = getenv("PGUSER"); else dbname = get_user_name(progname); } initPQExpBuffer(&sql); /* * List option */ if (listlangs) { printQueryOpt popt; static const bool translate_columns[] = {false, true}; conn = connectDatabase(dbname, host, port, username, prompt_password, progname); printfPQExpBuffer(&sql, "SELECT lanname as \"%s\", " "(CASE WHEN lanpltrusted THEN '%s' ELSE '%s' END) as \"%s\" " "FROM pg_catalog.pg_language WHERE lanispl;", gettext_noop("Name"), gettext_noop("yes"), gettext_noop("no"), gettext_noop("Trusted?")); result = executeQuery(conn, sql.data, progname, echo); memset(&popt, 0, sizeof(popt)); popt.topt.format = PRINT_ALIGNED; popt.topt.border = 1; popt.topt.start_table = true; popt.topt.stop_table = true; popt.topt.encoding = PQclientEncoding(conn); popt.title = _("Procedural Languages"); popt.translate_header = true; popt.translate_columns = translate_columns; printQuery(result, &popt, stdout, NULL); PQfinish(conn); exit(0); } if (langname == NULL) { fprintf(stderr, _("%s: missing required argument language name\n"), progname); fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); exit(1); } /* lower case language name */ for (p = langname; *p; p++) if (*p >= 'A' && *p <= 'Z') *p += ('a' - 'A'); conn = connectDatabase(dbname, host, port, username, prompt_password, progname); /* * Make sure the language isn't already installed */ printfPQExpBuffer(&sql, "SELECT oid FROM pg_catalog.pg_language WHERE lanname = '%s';", langname); result = executeQuery(conn, sql.data, progname, echo); if (PQntuples(result) > 0) { PQfinish(conn); fprintf(stderr, _("%s: language \"%s\" is already installed in database \"%s\"\n"), progname, langname, dbname); /* separate exit status for "already installed" */ exit(2); } PQclear(result); /* * In 9.1 and up, assume that languages should be installed using CREATE * EXTENSION. However, it's possible this tool could be used against an * older server, and it's easy enough to continue supporting the old way. */ if (PQserverVersion(conn) >= 90100) printfPQExpBuffer(&sql, "CREATE EXTENSION \"%s\";\n", langname); else printfPQExpBuffer(&sql, "CREATE LANGUAGE \"%s\";\n", langname); if (echo) printf("%s", sql.data); result = PQexec(conn, sql.data); if (PQresultStatus(result) != PGRES_COMMAND_OK) { fprintf(stderr, _("%s: language installation failed: %s"), progname, PQerrorMessage(conn)); PQfinish(conn); exit(1); } PQclear(result); PQfinish(conn); exit(0); }
static int check_for_node_usability(const char *pathname) { struct stat st; if(!access(pathname, F_OK)) { ticables_info(_(" node %s: exists"), pathname); } else { ticables_info(_(" node %s: does not exist"), pathname); ticables_info(_(" => you will have to create the node.")); return -1; } if(!access(pathname, R_OK | W_OK)) { ticables_info(_(" node %s: accessible"), pathname); return 0; } if(!stat(pathname, &st)) { ticables_info(_(" permissions/user/group:%s%s %s"), get_attributes(st.st_mode), get_user_name(st.st_uid), get_group_name(st.st_gid)); } else { ticables_warning("can't stat '%s'.", pathname); return -1; } if(getuid() == st.st_uid) { ticables_info(_(" user can r/w on device: yes")); ticables_info(_(" => device is inaccessible for unknown reasons")); return -1; } else { ticables_info(_(" user can r/w on device: no")); } if((st.st_mode & S_IROTH) && (st.st_mode & S_IWOTH)) { ticables_info(_(" others can r/w on device: yes")); } else { char *user, *group; ticables_info(_(" others can r/w on device: no")); user = strdup(get_user_name(getuid())); group = strdup(get_group_name(st.st_gid)); if(!search_for_user_in_group(user, group)) { ticables_info(_(" is the user '%s' in the group '%s': yes"), user, group); } else { ticables_info(_(" is the user '%s' in the group '%s': no"), user, group); ticables_info(_(" => you should add your username at the group '%s' in '/etc/group'"), group); ticables_info(_(" => you will have to restart your session, too")); free(user); free(group); return -1; } free(user); free(group); } ticables_info(_(" => device is inaccessible for unknown reasons")); return -1; }
/* * do a promotion of a user that lasts only for the current session */ void temporary_promote(UR_OBJECT user) { UR_OBJECT u; enum lvl_value lvl; if (word_count < 2) { write_user(user, "Usage: tpromote <user> [<level>]\n"); return; } u = get_user_name(user, word[1]); if (!u) { write_user(user, notloggedon); return; } if (u == user) { write_user(user, "You cannot promote yourself, temporarily or otherwise.\n"); return; } /* determine what level to promote them to */ if (u->level >= user->level) { write_user(user, "You cannot temporarily promote anyone of the same or greater level than you.\n"); return; } if (word_count == 3) { lvl = get_level(word[2]); if (lvl == NUM_LEVELS) { write_user(user, "Usage: tpromote <user> [<level>]\n"); return; } if (lvl <= u->level) { vwrite_user(user, "You must specify a level higher than %s currently is.\n", u->name); return; } } else { lvl = (enum lvl_value) (u->level + 1); } if (lvl == GOD) { vwrite_user(user, "You cannot temporarily promote anyone to level %s.\n", user_level[lvl].name); return; } if (lvl >= user->level) { write_user(user, "You cannot temporarily promote anyone to a higher level than your own.\n"); return; } /* if they have already been temp promoted this session then restore normal level first */ if (u->level > u->real_level) { u->level = u->real_level; } u->real_level = u->level; u->level = lvl; vwrite_user(user, "You temporarily promote %s to %s.\n", u->name, user_level[u->level].name); vwrite_room_except(u->room, u, "~OL~FG%s~RS~OL~FG starts to glow as their power increases...\n", u->bw_recap); vwrite_user(u, "~OL~FGYou have been promoted (temporarily) to level %s.\n", user_level[u->level].name); write_syslog(SYSLOG, 1, "%s TEMPORARILY promote %s to %s.\n", user->name, u->name, user_level[u->level].name); sprintf(text, "Was temporarily to level %s.\n", user_level[u->level].name); add_history(u->name, 1, "%s", text); }
static int may_unmount(const char *mnt, int quiet) { struct mntent *entp; FILE *fp; const char *user = NULL; char uidstr[32]; unsigned uidlen = 0; int found; const char *mtab = _PATH_MOUNTED; user = get_user_name(); if (user == NULL) return -1; fp = setmntent(mtab, "r"); if (fp == NULL) { fprintf(stderr, "%s: failed to open %s: %s\n", progname, mtab, strerror(errno)); return -1; } uidlen = sprintf(uidstr, "%u", getuid()); found = 0; while ((entp = getmntent(fp)) != NULL) { if (!found && strcmp(entp->mnt_dir, mnt) == 0 && (strcmp(entp->mnt_type, "fuse") == 0 || strcmp(entp->mnt_type, "fuseblk") == 0 || strncmp(entp->mnt_type, "fuse.", 5) == 0 || strncmp(entp->mnt_type, "fuseblk.", 8) == 0)) { char *p = strstr(entp->mnt_opts, "user="******"user_id=")) && (p == entp->mnt_opts || *(p-1) == ',') && strncmp(p + 8, uidstr, uidlen) == 0 && (*(p+8+uidlen) == ',' || *(p+8+uidlen) == '\0')) { found = 1; break; } } } endmntent(fp); if (!found) { if (!quiet) fprintf(stderr, "%s: entry for %s not found in %s\n", progname, mnt, mtab); return -1; } return 0; }
void test_drop_privileges() { char *e_user_name_initial = get_effective_user_name(); char *r_user_name_initial = get_user_name(); CU_ASSERT_PTR_NOT_NULL_FATAL(e_user_name_initial); CU_ASSERT_PTR_NOT_NULL_FATAL(r_user_name_initial); // drop_privs temp int response1 = drop_privileges(0); char *e_user_name1 = get_effective_user_name(); char *r_user_name1 = get_user_name(); CU_ASSERT_FALSE(response1); CU_ASSERT_PTR_NOT_NULL_FATAL(e_user_name1); CU_ASSERT_PTR_NOT_NULL_FATAL(r_user_name1); CU_ASSERT_STRING_EQUAL(r_user_name1, e_user_name1); // drop_privs temp again int response2 = drop_privileges(0); char *e_user_name2 = get_effective_user_name(); char *r_user_name2 = get_user_name(); CU_ASSERT_FALSE(response2); CU_ASSERT_PTR_NOT_NULL_FATAL(e_user_name2); CU_ASSERT_PTR_NOT_NULL_FATAL(r_user_name2); CU_ASSERT_STRING_EQUAL(r_user_name2, e_user_name2); // restore privs int response3 = restore_privileges(); char *e_user_name3 = get_effective_user_name(); char *r_user_name3 = get_user_name(); CU_ASSERT_FALSE(response3); CU_ASSERT_PTR_NOT_NULL_FATAL(e_user_name3); CU_ASSERT_PTR_NOT_NULL_FATAL(r_user_name3); CU_ASSERT_STRING_EQUAL(e_user_name_initial, e_user_name3); // drop_privs definitely int response4 = drop_privileges(1); char *e_user_name4 = get_effective_user_name(); char *r_user_name4 = get_user_name(); CU_ASSERT_FALSE(response4); CU_ASSERT_PTR_NOT_NULL_FATAL(e_user_name4); CU_ASSERT_PTR_NOT_NULL_FATAL(r_user_name4); CU_ASSERT_STRING_EQUAL(r_user_name4, e_user_name4); // restore privs int response5 = restore_privileges(); char *e_user_name5 = get_effective_user_name(); char *r_user_name5 = get_user_name(); CU_ASSERT_PTR_NOT_NULL_FATAL(e_user_name5); CU_ASSERT_PTR_NOT_NULL_FATAL(r_user_name5); CU_ASSERT_STRING_EQUAL(r_user_name5, e_user_name5); // drop_privs temp (being dropped definitely) int response6 = drop_privileges(0); char *e_user_name6 = get_effective_user_name(); char *r_user_name6 = get_user_name(); CU_ASSERT_FALSE(response6); CU_ASSERT_PTR_NOT_NULL_FATAL(e_user_name6); CU_ASSERT_PTR_NOT_NULL_FATAL(r_user_name6); CU_ASSERT_STRING_EQUAL(r_user_name6, e_user_name6); // drop_privs definitely again int response7 = drop_privileges(1); char *e_user_name7 = get_effective_user_name(); char *r_user_name7 = get_user_name(); CU_ASSERT_FALSE(response7); CU_ASSERT_PTR_NOT_NULL_FATAL(e_user_name7); CU_ASSERT_PTR_NOT_NULL_FATAL(r_user_name7); CU_ASSERT_STRING_EQUAL(r_user_name7, e_user_name7); }
INLINE const FilePath *System::GetUsername() const { return get_user_name(); }
int main(int argc, char *argv[]) { static struct option long_options[] = { {"host", required_argument, NULL, 'h'}, {"port", required_argument, NULL, 'p'}, {"username", required_argument, NULL, 'U'}, {"no-password", no_argument, NULL, 'w'}, {"password", no_argument, NULL, 'W'}, {"echo", no_argument, NULL, 'e'}, {"quiet", no_argument, NULL, 'q'}, {"dbname", required_argument, NULL, 'd'}, {"analyze", no_argument, NULL, 'z'}, {"analyze-only", no_argument, NULL, 'Z'}, {"freeze", no_argument, NULL, 'F'}, {"all", no_argument, NULL, 'a'}, {"table", required_argument, NULL, 't'}, {"full", no_argument, NULL, 'f'}, {"verbose", no_argument, NULL, 'v'}, {"maintenance-db", required_argument, NULL, 2}, {NULL, 0, NULL, 0} }; const char *progname; int optindex; int c; const char *dbname = NULL; const char *maintenance_db = NULL; char *host = NULL; char *port = NULL; char *username = NULL; enum trivalue prompt_password = TRI_DEFAULT; bool echo = false; bool quiet = false; bool and_analyze = false; bool analyze_only = false; bool freeze = false; bool alldb = false; char *table = NULL; bool full = false; bool verbose = false; progname = get_progname(argv[0]); set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts")); handle_help_version_opts(argc, argv, "vacuumdb", help); while ((c = getopt_long(argc, argv, "h:p:U:wWeqd:zZFat:fv", long_options, &optindex)) != -1) { switch (c) { case 'h': host = optarg; break; case 'p': port = optarg; break; case 'U': username = optarg; break; case 'w': prompt_password = TRI_NO; break; case 'W': prompt_password = TRI_YES; break; case 'e': echo = true; break; case 'q': quiet = true; break; case 'd': dbname = optarg; break; case 'z': and_analyze = true; break; case 'Z': analyze_only = true; break; case 'F': freeze = true; break; case 'a': alldb = true; break; case 't': table = optarg; break; case 'f': full = true; break; case 'v': verbose = true; break; case 2: maintenance_db = optarg; break; default: fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); exit(1); } } /* * Non-option argument specifies database name * as long as it wasn't already specified with -d / --dbname */ if (optind < argc && dbname == NULL) { dbname = argv[optind]; optind++; } if (optind < argc) { fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), progname, argv[optind + 1]); fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); exit(1); } if (analyze_only) { if (full) { fprintf(stderr, _("%s: cannot use the \"full\" option when performing only analyze\n"), progname); exit(1); } if (freeze) { fprintf(stderr, _("%s: cannot use the \"freeze\" option when performing only analyze\n"), progname); exit(1); } /* allow 'and_analyze' with 'analyze_only' */ } setup_cancel_handler(); if (alldb) { if (dbname) { fprintf(stderr, _("%s: cannot vacuum all databases and a specific one at the same time\n"), progname); exit(1); } if (table) { fprintf(stderr, _("%s: cannot vacuum a specific table in all databases\n"), progname); exit(1); } vacuum_all_databases(full, verbose, and_analyze, analyze_only, freeze, maintenance_db, host, port, username, prompt_password, progname, echo, quiet); } else { if (dbname == NULL) { if (getenv("PGDATABASE")) dbname = getenv("PGDATABASE"); else if (getenv("PGUSER")) dbname = getenv("PGUSER"); else dbname = get_user_name(progname); } vacuum_one_database(dbname, full, verbose, and_analyze, analyze_only, freeze, table, host, port, username, prompt_password, progname, echo); } exit(0); }
static int remove_mount(const char *mnt) { int res; const char *mtab = _PATH_MOUNTED; const char *mtab_new = _PATH_MOUNTED "~"; struct mntent *entp; FILE *fp; FILE *newfp; const char *user = NULL; int found; fp = setmntent(mtab, "r"); if(fp == NULL) { fprintf(stderr, "%s failed to open %s: %s\n", progname, mtab, strerror(errno)); return -1; } newfp = setmntent(mtab_new, "w"); if(newfp == NULL) { fprintf(stderr, "%s failed to open %s: %s\n", progname, mtab_new, strerror(errno)); return -1; } if(getuid() != 0) { user = get_user_name(); if(user == NULL) return -1; } found = 0; while((entp = getmntent(fp)) != NULL) { int remove = 0; if(!found && strcmp(entp->mnt_dir, mnt) == 0 && strcmp(entp->mnt_type, "fuse") == 0) { if(user == NULL) remove = 1; else { char *p = strstr(entp->mnt_opts, "user="******"%s: failed to unmount %s: %s\n", progname, mnt, strerror(errno)); found = -1; break; } found = 1; } else { res = addmntent(newfp, entp); if(res != 0) { fprintf(stderr, "%s: failed to add entry to %s: %s", progname, mtab_new, strerror(errno)); } } } endmntent(fp); endmntent(newfp); if(found == 1) { res = rename(mtab_new, mtab); if(res == -1) { fprintf(stderr, "%s: failed to rename %s to %s: %s\n", progname, mtab_new, mtab, strerror(errno)); return -1; } } else { if(!found) fprintf(stderr, "%s: entry for %s not found in %s\n", progname, mnt, mtab); unlink(mtab_new); return -1; } return 0; }