Lines Matching refs:ctx

32  * $Id: ctx.c,v 1.32.70.2 2005/06/02 00:55:40 lindak Exp $
110 rpc_cleanup_smbctx(struct smb_ctx *ctx)
113 (*close_hook)(ctx);
188 dump_ctx(char *where, struct smb_ctx *ctx)
191 dump_ctx_flags(ctx->ct_flags);
193 if (ctx->ct_locname)
194 printf(" localname=\"%s\"", ctx->ct_locname);
198 if (ctx->ct_fullserver)
199 printf(" fullserver=\"%s\"", ctx->ct_fullserver);
203 if (ctx->ct_srvaddr_s)
204 printf(" srvaddr_s=\"%s\"\n", ctx->ct_srvaddr_s);
208 if (ctx->ct_addrinfo)
209 dump_addrinfo(ctx->ct_addrinfo);
213 dump_iod_ssn(&ctx->ct_iod_ssn);
216 ctx->ct_origshare ? ctx->ct_origshare : "",
217 ctx->ct_shtype_req);
219 printf(" ct_home=\"%s\"\n", ctx->ct_home);
220 printf(" ct_rpath=\"%s\"\n", ctx->ct_rpath);
226 smb_ctx_t *ctx;
229 ctx = malloc(sizeof (*ctx));
230 if (ctx == NULL)
232 err = smb_ctx_init(ctx);
234 free(ctx);
237 *ctx_pp = ctx;
245 smb_ctx_init(struct smb_ctx *ctx)
249 bzero(ctx, sizeof (*ctx));
251 error = nb_ctx_create(&ctx->ct_nb);
255 ctx->ct_dev_fd = -1;
256 ctx->ct_door_fd = -1;
257 ctx->ct_tran_fd = -1;
258 ctx->ct_parsedlevel = SMBL_NONE;
259 ctx->ct_minlevel = SMBL_NONE;
260 ctx->ct_maxlevel = SMBL_PATH;
263 ctx->ct_vopt = SMBVOPT_EXT_SEC;
264 ctx->ct_owner = SMBM_ANY_OWNER;
265 ctx->ct_authflags = SMB_AT_DEFAULT;
266 ctx->ct_minauth = SMB_AT_MINAUTH;
271 strlcpy(ctx->ct_domain, default_domain,
272 sizeof (ctx->ct_domain));
273 strlcpy(ctx->ct_user, default_user,
274 sizeof (ctx->ct_user));
315 smb_ctx_scan_argv(struct smb_ctx *ctx, int argc, char **argv,
329 ctx->ct_minlevel = minlevel;
330 ctx->ct_maxlevel = maxlevel;
331 ctx->ct_shtype_req = sharetype;
344 error = smb_ctx_setuser(ctx, "", TRUE);
345 ctx->ct_flags |= SMBCF_NOPWD;
349 error = smb_ctx_setuser(ctx, arg, TRUE);
377 error = smb_ctx_parseunc(ctx, arg,
388 smb_ctx_free(smb_ctx_t *ctx)
390 smb_ctx_done(ctx);
391 free(ctx);
395 smb_ctx_done(struct smb_ctx *ctx)
398 rpc_cleanup_smbctx(ctx);
400 if (ctx->ct_dev_fd != -1) {
401 close(ctx->ct_dev_fd);
402 ctx->ct_dev_fd = -1;
404 if (ctx->ct_door_fd != -1) {
405 close(ctx->ct_door_fd);
406 ctx->ct_door_fd = -1;
408 if (ctx->ct_tran_fd != -1) {
409 close(ctx->ct_tran_fd);
410 ctx->ct_tran_fd = -1;
412 if (ctx->ct_srvaddr_s) {
413 free(ctx->ct_srvaddr_s);
414 ctx->ct_srvaddr_s = NULL;
416 if (ctx->ct_nb) {
417 nb_ctx_done(ctx->ct_nb);
418 ctx->ct_nb = NULL;
420 if (ctx->ct_locname) {
421 free(ctx->ct_locname);
422 ctx->ct_locname = NULL;
424 if (ctx->ct_origshare) {
425 free(ctx->ct_origshare);
426 ctx->ct_origshare = NULL;
428 if (ctx->ct_fullserver) {
429 free(ctx->ct_fullserver);
430 ctx->ct_fullserver = NULL;
432 if (ctx->ct_addrinfo) {
433 freeaddrinfo(ctx->ct_addrinfo);
434 ctx->ct_addrinfo = NULL;
436 if (ctx->ct_home) {
437 free(ctx->ct_home);
438 ctx->ct_home = NULL;
440 if (ctx->ct_rpath) {
441 free(ctx->ct_rpath);
442 ctx->ct_rpath = NULL;
444 if (ctx->ct_srv_OS) {
445 free(ctx->ct_srv_OS);
446 ctx->ct_srv_OS = NULL;
448 if (ctx->ct_srv_LM) {
449 free(ctx->ct_srv_LM);
450 ctx->ct_srv_LM = NULL;
452 if (ctx->ct_mackey) {
453 free(ctx->ct_mackey);
454 ctx->ct_mackey = NULL;
465 smb_ctx_parseunc(struct smb_ctx *ctx, const char *unc,
478 ctx->ct_minlevel = minlevel;
479 ctx->ct_maxlevel = maxlevel;
480 ctx->ct_shtype_req = sharetype;
481 ctx->ct_parsedlevel = SMBL_NONE;
534 error = smb_ctx_setfullserver(ctx, host);
537 ctx->ct_parsedlevel = SMBL_VC;
540 error = smb_ctx_setdomain(ctx, dom, TRUE);
551 if (ctx->ct_maxlevel < SMBL_VC) {
557 error = smb_ctx_setuser(ctx, usr, TRUE);
562 error = smb_ctx_setpassword(ctx, pw, TRUE);
584 if (ctx->ct_maxlevel < SMBL_SHARE) {
600 error = smb_ctx_setshare(ctx, p, sharetype);
603 ctx->ct_parsedlevel = SMBL_SHARE;
610 free(ctx->ct_rpath);
611 ctx->ct_rpath = strdup(path);
613 } else if (ctx->ct_minlevel >= SMBL_SHARE) {
624 dump_ctx("after smb_ctx_parseunc", ctx);
631 smb_ctx_setcharset(struct smb_ctx *ctx, const char *arg)
634 int cslen = sizeof (ctx->ct_ssn.ioc_localcs);
650 localcs = memcpy(ctx->ct_ssn.ioc_localcs, arg, lcslen);
652 servercs = strcpy(ctx->ct_ssn.ioc_servercs, cp);
666 smb_ctx_setauthflags(struct smb_ctx *ctx, int flags)
668 ctx->ct_authflags = flags;
673 smb_ctx_setfullserver(struct smb_ctx *ctx, const char *name)
679 if (ctx->ct_fullserver)
680 free(ctx->ct_fullserver);
681 ctx->ct_fullserver = p;
686 smb_ctx_setserver(struct smb_ctx *ctx, const char *name)
688 strlcpy(ctx->ct_srvname, name,
689 sizeof (ctx->ct_srvname));
694 smb_ctx_setuser(struct smb_ctx *ctx, const char *name, int from_cmd)
697 if (strlen(name) >= sizeof (ctx->ct_user)) {
707 if (!from_cmd && (ctx->ct_flags & SMBCF_CMD_USR))
710 strlcpy(ctx->ct_user, name,
711 sizeof (ctx->ct_user));
715 ctx->ct_flags |= SMBCF_CMD_USR;
726 smb_ctx_setdomain(struct smb_ctx *ctx, const char *name, int from_cmd)
729 if (strlen(name) >= sizeof (ctx->ct_domain)) {
739 if (!from_cmd && (ctx->ct_flags & SMBCF_CMD_DOM))
742 strlcpy(ctx->ct_domain, name,
743 sizeof (ctx->ct_domain));
747 ctx->ct_flags |= SMBCF_CMD_DOM;
753 smb_ctx_setpassword(struct smb_ctx *ctx, const char *passwd, int from_cmd)
759 if (strlen(passwd) >= sizeof (ctx->ct_password)) {
769 if (!from_cmd && (ctx->ct_flags & SMBCF_CMD_PW))
772 memset(ctx->ct_password, 0, sizeof (ctx->ct_password));
774 (void) smb_simpledecrypt(ctx->ct_password, passwd);
776 strlcpy(ctx->ct_password, passwd,
777 sizeof (ctx->ct_password));
782 if (ctx->ct_password[0]) {
783 err = ntlm_compute_nt_hash(ctx->ct_nthash, ctx->ct_password);
786 err = ntlm_compute_lm_hash(ctx->ct_lmhash, ctx->ct_password);
793 ctx->ct_flags |= SMBCF_CMD_PW;
803 smb_ctx_setpwhash(smb_ctx_t *ctx,
808 if (ctx->ct_password[0] == '\0')
809 strlcpy(ctx->ct_password, "$HASH",
810 sizeof (ctx->ct_password));
815 memcpy(ctx->ct_nthash, nthash, NTLM_HASH_SZ);
819 memcpy(ctx->ct_nthash, nthash, NTLM_HASH_SZ);
826 smb_ctx_setshare(struct smb_ctx *ctx, const char *share, int stype)
833 if (ctx->ct_origshare)
834 free(ctx->ct_origshare);
835 if ((ctx->ct_origshare = strdup(share)) == NULL)
838 ctx->ct_shtype_req = stype;
844 smb_ctx_setsrvaddr(struct smb_ctx *ctx, const char *addr)
848 if (ctx->ct_srvaddr_s)
849 free(ctx->ct_srvaddr_s);
850 if ((ctx->ct_srvaddr_s = strdup(addr)) == NULL)
860 smb_ctx_setsigning(struct smb_ctx *ctx, int enable, int require)
862 ctx->ct_vopt &= ~SMBVOPT_SIGNING_MASK;
864 ctx->ct_vopt |= SMBVOPT_SIGNING_ENABLED;
866 ctx->ct_vopt |= SMBVOPT_SIGNING_REQUIRED;
916 smb_parse_secopts(struct smb_ctx *ctx, const char *arg)
935 ctx->ct_vopt &= ~SMBVOPT_EXT_SEC;
956 ctx->ct_authflags = authflags;
967 smb_ctx_opt(struct smb_ctx *ctx, int opt, const char *arg)
979 error = smb_ctx_setsrvaddr(ctx, arg);
983 ctx->ct_flags |= SMBCF_SRIGHTS;
986 ctx->ct_flags |= SMBCF_NOPWD;
993 error = smb_parse_owner(cp, &ctx->ct_owner, NULL);
997 /* ctx->ct_vopt |= SMBCOPT_PERMANENT; */
1004 error = smb_parse_secopts(ctx, arg);
1011 error = smb_ctx_setdomain(ctx, tmp, TRUE);
1045 smb_ctx_resolve(struct smb_ctx *ctx)
1047 struct smbioc_ossn *ssn = &ctx->ct_ssn;
1055 dump_ctx("before smb_ctx_resolve", ctx);
1057 ctx->ct_flags &= ~SMBCF_RESOLVED;
1059 if (ctx->ct_fullserver == NULL) {
1065 if (ctx->ct_minlevel >= SMBL_SHARE &&
1066 ctx->ct_origshare == NULL) {
1069 0, ssn->ssn_user, ctx->ct_fullserver);
1072 error = nb_ctx_resolve(ctx->ct_nb);
1109 error = smb_ctx_getaddr(ctx);
1114 0, ctx->ct_fullserver, ais);
1117 assert(ctx->ct_addrinfo != NULL);
1124 if (ctx->ct_user[0] != '\0') {
1130 if (ctx->ct_password[0] == '\0')
1131 (void) smb_get_keychain(ctx);
1135 ctx->ct_authflags &= ctx->ct_minauth;
1137 if (ctx->ct_authflags == 0) {
1143 ctx->ct_flags |= SMBCF_RESOLVED;
1145 dump_ctx("after smb_ctx_resolve", ctx);
1167 smb_ctx_gethandle(struct smb_ctx *ctx)
1172 if (ctx->ct_dev_fd != -1) {
1173 rpc_cleanup_smbctx(ctx);
1174 close(ctx->ct_dev_fd);
1175 ctx->ct_dev_fd = -1;
1176 ctx->ct_flags &= ~SMBCF_SSNACTIVE;
1199 ctx->ct_dev_fd = fd;
1208 smb_ctx_get_ssn(struct smb_ctx *ctx)
1212 if ((ctx->ct_flags & SMBCF_RESOLVED) == 0)
1215 if (ctx->ct_dev_fd < 0) {
1216 if ((err = smb_ctx_gethandle(ctx)))
1224 err = smb_ctx_findvc(ctx);
1232 err = smb_ctx_newvc(ctx);
1240 err = smb_ctx_findvc(ctx);
1250 smb_ctx_get_tree(struct smb_ctx *ctx)
1255 if (ctx->ct_dev_fd < 0 ||
1256 ctx->ct_origshare == NULL) {
1269 strlcpy(tcon->tc_sh.sh_name, ctx->ct_origshare,
1273 tcon->tc_sh.sh_use = ctx->ct_shtype_req;
1280 if (ioctl(ctx->ct_dev_fd, cmd, tcon) == -1) {
1289 if (ctx->ct_shtype_req != USE_WILDCARD &&
1290 ctx->ct_shtype_req != tcon->tc_sh.sh_type) {
1293 0, ctx->ct_origshare);
1307 smb_ctx_flags2(struct smb_ctx *ctx)
1311 if (ioctl(ctx->ct_dev_fd, SMBIOC_FLAGS2, &flags2) == -1) {
1360 smb_ctx_readrcsection(struct smb_ctx *ctx, const char *sname, int level)
1369 error = smb_ctx_setcharset(ctx, p);
1392 ctx->ct_minauth = nvp->value;
1412 (void) smb_ctx_setsigning(ctx, FALSE, FALSE);
1414 (void) smb_ctx_setsigning(ctx, TRUE, FALSE);
1416 (void) smb_ctx_setsigning(ctx, TRUE, TRUE);
1437 error = smb_ctx_setdomain(ctx, p, 0);
1445 error = smb_ctx_setdomain(ctx, p, 0);
1454 error = smb_ctx_setuser(ctx, p, 0);
1466 error = smb_ctx_setsrvaddr(ctx, p);
1478 error = smb_ctx_setpassword(ctx, p, 0);
1498 smb_ctx_readrc(struct smb_ctx *ctx)
1513 if (ctx->ct_user[0] == 0)
1514 (void) smb_ctx_setuser(ctx, pw.pw_name, B_FALSE);
1515 if (ctx->ct_home == NULL)
1516 ctx->ct_home = strdup(pw.pw_dir);
1519 if ((err = smb_open_rcfile(ctx->ct_home)) != 0) {
1535 smb_ctx_readrcsection(ctx, "default", 0);
1536 nb_ctx_readrcsection(smb_rc, ctx->ct_nb, "default", 0);
1542 if (ctx->ct_fullserver == NULL)
1547 smb_ctx_readrcsection(ctx, ctx->ct_fullserver, 1);
1553 if (ctx->ct_user[0] == 0)
1559 ctx->ct_fullserver,
1560 ctx->ct_user);
1561 smb_ctx_readrcsection(ctx, sname, 2);
1568 if (ctx->ct_origshare == NULL)
1574 ctx->ct_fullserver,
1575 ctx->ct_user,
1576 ctx->ct_origshare);
1577 smb_ctx_readrcsection(ctx, sname, 3);
1584 dump_ctx("after smb_ctx_readrc", ctx);