📄 secct.c
字号:
{
fprintf(stdout, "\nConnection to %s successful.\n",
sec_args.sname);
}
(CS_VOID)ct_close(conn, CS_UNUSED);
}
/*
** Release allocated control structures.
*/
(CS_VOID)ct_con_drop(conn);
(CS_VOID)ex_ctx_cleanup(cp, CS_UNUSED);
exit(EX_EXIT_SUCCEED);
}
/*
** SecServices() -- Enable all supported
** security services for a connection.
**
** Parameters
** conn -- Pointer to the connection structure.
** mechname -- An optional security mechanism name (if not supplied,
** the default security mechanism is used.)
** mechnamelen -- The length of mechname, in bytes, or 0 if mechname
** is NULL.
**
** Returns
** CS_SUCCEED or CS_FAIL.
*/
CS_STATIC CS_RETCODE SecServices(conn, mechname, mechnamelen)
CS_CONNECTION *conn;
CS_CHAR *mechname;
CS_INT mechnamelen;
{
CS_RETCODE ret;
CS_BOOL boolval;
CS_INT outlen;
CS_CHAR buf[CS_MAX_CHAR];
int i;
/*
** Set the security mechanism name if a mechanism name was supplied.
*/
if (mechnamelen > 0
&& mechname != NULL
&& ct_con_props(conn, CS_SET, CS_SEC_MECHANISM,
mechname, mechnamelen, NULL) != CS_SUCCEED)
{
fprintf(stdout,
"ct_con_props(CS_SEC_MECHANISM) failed.\n");
return CS_FAIL;
}
/*
** Loop through the security service properties to see
** which ones are supported by the security driver.
** If a service is supported, set the property to
** enable the service.
*/
fprintf(stdout, "Requesting security services:\n");
for (i = 0;
Sec_services[i].service != CS_UNUSED;
i++)
{
/*
** Determine whether the driver supports the service.
*/
if (ct_con_props(conn, CS_SUPPORTED,
Sec_services[i].service, &boolval,
CS_UNUSED, NULL) != CS_SUCCEED)
{
fprintf(stdout,
"ct_con_props(CS_SUPPORTED, %s) failed.\n",
Sec_services[i].name);
return CS_FAIL;
}
if (boolval == CS_TRUE)
{
fprintf(stdout, "\t%s\n",
Sec_services[i].name);
}
if (boolval == CS_TRUE
&& ct_con_props(conn, CS_SET,
Sec_services[i].service, &boolval,
CS_UNUSED, NULL) != CS_SUCCEED)
{
fprintf(stdout,
"ct_con_props(CS_SET, %s) failed.\n",
Sec_services[i].name);
return CS_FAIL;
}
}
fprintf(stdout, "\n");
if (ct_con_props(conn, CS_GET, CS_SEC_MECHANISM, buf,
CS_MAX_CHAR, &outlen) != CS_SUCCEED)
{
fprintf(stdout, "Could not get security mechanism name.\n");
return CS_FAIL;
}
fprintf(stdout, "Security mechanism is '%.*s'\n\n",
(int)outlen, buf);
return CS_SUCCEED;
}
/*
** ARG_CP -- Copy a command-line argument.
**
** PARAMETERS
** arg -- argument to copy. Must be null terminated.
** buf -- destination space.
** buflen -- length of buf
** outlen -- length of arg, not including null-terminator,
** or 0 if buffer would overflow.
**
** RETURNS
** 0 to indicate success;
** > 0 to indicate buffer overflow.
*/
CS_STATIC CS_INT arg_cp(arg, buf, buflen, outlen)
CS_CHAR *arg;
CS_CHAR *buf;
CS_INT buflen;
CS_INT *outlen;
{
(CS_VOID)strncpy(buf, arg, buflen);
*outlen = strlen(arg);
if (*outlen >= buflen)
{
buflen = *outlen;
*outlen = 0;
return buflen;
}
return 0;
}
/*
** PROC_SEC_ARGS
**
** This routine parses the command line arguments passed to the
** Open Server application.
**
** The syntax expected is as follows:
**
** sample_name [open server network name]
** [-R server principal name]
** [-K keytab file name]
** [-U user name]
*/
CS_STATIC CS_RETCODE
proc_sec_args(sec_args, argc, argv)
SEC_ARGS *sec_args;
CS_INT argc;
CS_CHAR **argv;
{
CS_CHAR mbuf[CS_MAX_MSG]; /* Message buffer. */
/*
** Initialization.
*/
sec_args->secmech[0] = '\0';
sec_args->secmechlen = 0;
sec_args->sname[0] = '\0';
sec_args->snamelen = 0;
sec_args->principal[0] = '\0';
sec_args->plen = 0;
sec_args->keytab[0] = '\0';
sec_args->klen = 0;
sec_args->uname[0] = '\0';
sec_args->unamelen = 0;
/*
** If we have arguments, the first one should be the
** Open Server name.
*/
if (argc > 1 )
{
if( argv[1][0] == '-')
{
/*
** We don't have a server name
** argument, so just jump to the first flag.
*/
argv++;
}
else
{
/*
** The first argument is the server name.
*/
if (arg_cp(argv[1], sec_args->sname, CS_MAX_CHAR,
&(sec_args->snamelen)) != 0)
{
fprintf(stdout,
"ERROR: Server name too long.\n");
return CS_FAIL;
}
/*
** Skip to the second argument, if any.
*/
argv++;
argv++;
}
}
else
{
/*
** We don't have any arguments, so we're all done.
*/
return CS_SUCCEED;
}
for (; *argv != (CS_CHAR *)NULL; argv++ )
{
/*
** Get the security mechanism name, if available.
*/
if ( strcmp(*argv, "-Z") == 0 )
{
argv++;
if (arg_cp(*argv, sec_args->secmech,
CS_MAX_CHAR, &(sec_args->secmechlen))
!= 0)
{
fprintf(stdout,
"ERROR: Mechanism name too long.\n");
return CS_FAIL;
}
continue;
}
/*
** Get the server principal name, if available.
*/
else if ( strcmp(*argv, "-R") == 0 )
{
argv++;
if (arg_cp(*argv, sec_args->principal,
CS_MAX_CHAR, &(sec_args->plen))
!= 0)
{
fprintf(stdout,
"ERROR: Principal name too long.\n");
return CS_FAIL;
}
continue;
}
/*
** Get the keytab file name, if available.
*/
else if ( strcmp(*argv, "-K") == 0 )
{
argv++;
if (arg_cp(*argv, sec_args->keytab,
CS_MAX_CHAR, &(sec_args->klen))
!= 0)
{
fprintf(stdout,
"ERROR: Keytab filename too long.\n");
return CS_FAIL;
}
continue;
}
/*
** Get the user name, if available.
*/
else if ( strcmp(*argv, "-U") == 0 )
{
argv++;
if (arg_cp(*argv, sec_args->uname,
CS_MAX_CHAR, &(sec_args->unamelen))
!= 0)
{
fprintf(stdout,
"ERROR: user name too long.\n");
return CS_FAIL;
}
continue;
}
/*
** Unknown argument.
*/
else
{
fprintf(stdout,
"ERROR: Unknown argument '%s'.\n",
*argv);
return CS_FAIL;
}
}
/*
** All done.
*/
return CS_SUCCEED;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -