int cmd_logout(int argc, char *argv[]) { char *dom, *usr; int err, opt; while ((opt = getopt(argc, argv, "a")) != EOF) { switch (opt) { case 'a': /* smbutil logout -a */ if (optind != argc) logout_usage(); err = smbfs_keychain_del_owner(); if (err) errx(1, gettext("failed to delete keychain entries")); return (0); default: logout_usage(); break; } } /* This part is like login. */ dom = usr = NULL; if (optind < argc) { strcpy(tmp_arg, argv[optind]); err = smbfs_parse_domuser(tmp_arg, &dom, &usr); if (err) errx(1, gettext("failed to parse %s"), argv[optind]); optind++; } if (optind != argc) logout_usage(); if (dom == NULL || usr == NULL) { err = smbfs_default_dom_usr(NULL, NULL, def_dom, sizeof (def_dom), def_usr, sizeof (def_usr)); if (err) errx(1, gettext("failed to get defaults")); } if (dom == NULL) dom = def_dom; else nls_str_upper(dom, dom); if (usr == NULL) usr = def_usr; err = smbfs_keychain_del((uid_t)-1, dom, usr); if (err) errx(1, gettext("failed to delete keychain entry")); return (0); }
int main(int argc, char *argv[]) { int islogin, error; char *p, *p1; struct ncp_conn_loginfo li; islogin = strcmp(__progname, "ncplogin") == 0; if (argc == 2) { if (strcmp(argv[1], "-h") == 0) { if (islogin) login_usage(); else logout_usage(); } } if (ncp_initlib()) exit(1); if (ncp_li_init(&li, argc, argv)) return 1; if (argc >= 2 && argv[argc - 1][0] == '/') { p = argv[argc - 1]; error = 1; do { if (*p++ != '/') break; p1 = strchr(p, ':'); if (p1 == NULL) break; *p1++ = 0; if (ncp_li_setserver(&li, p)) break; if (*p1 == 0) break; if (ncp_li_setuser(&li, p1)) break; error = 0; } while(0); if (error) errx(EX_DATAERR, "an error occurred while parsing '%s'", argv[argc - 1]); } if (ncp_li_readrc(&li)) return 1; if (ncp_rc) rc_close(ncp_rc); if (islogin) login(argc, argv, &li); else logout(argc, argv, &li); return 0; }
static void logout(int argc, char *argv[], struct ncp_conn_loginfo *li) { int error = 0, connid, opt; connid = -1; while ((opt = getopt(argc, argv, STDPARAM_OPT"c:")) != -1){ switch (opt) { case 'c': connid = atoi(optarg); break; case STDPARAM_ARGS: if (ncp_li_arg(li, opt, optarg)) exit(1); break; default: logout_usage(); /*NOTREACHED*/ } } if (connid == -1) { if (li->server[0] == 0) errx(EX_USAGE, "no server name specified"); if (li->user == 0) errx(EX_USAGE, "no user name specified"); if (ncp_conn_scan(li, &connid)) errx(EX_OSERR, "You are not attached to server %s", li->server); } if (ncp_setpermanent(connid, 0) < 0 && errno != EACCES) { ncp_error("Connection isn't valid", errno); exit(EX_OSERR); } error = ncp_disconnect(connid); if (error) { if (errno == EACCES) { warnx("you logged out, but connection belongs" "to other user and not closed"); } else { ncp_error("Can't logout with connid %d", error, connid); error = 1; } } exit(error ? 1 : 0); }