add directory study
This commit is contained in:
182
study/Ref-docs/POSIX/susv3/functions/crypt.html
Normal file
182
study/Ref-docs/POSIX/susv3/functions/crypt.html
Normal file
@@ -0,0 +1,182 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
||||
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
||||
<title>crypt</title>
|
||||
</head>
|
||||
<body bgcolor="white">
|
||||
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
||||
</script>
|
||||
|
||||
<basefont size="3"> <a name="crypt"></a> <a name="tag_03_94"></a><!-- crypt -->
|
||||
<!--header start-->
|
||||
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
||||
IEEE Std 1003.1-2001<br>
|
||||
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
||||
|
||||
<!--header end-->
|
||||
<hr size="2" noshade>
|
||||
<h4><a name="tag_03_94_01"></a>NAME</h4>
|
||||
|
||||
<blockquote>crypt - string encoding function (<b>CRYPT</b>)</blockquote>
|
||||
|
||||
<h4><a name="tag_03_94_02"></a>SYNOPSIS</h4>
|
||||
|
||||
<blockquote class="synopsis">
|
||||
<div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt=
|
||||
"[Option Start]" border="0"> #include <<a href="../basedefs/unistd.h.html">unistd.h</a>><br>
|
||||
<br>
|
||||
char *crypt(const char *</tt><i>key</i><tt>, const char *</tt><i>salt</i><tt>); <img src="../images/opt-end.gif" alt=
|
||||
"[Option End]" border="0"></tt></code></div>
|
||||
|
||||
<tt><br>
|
||||
</tt></blockquote>
|
||||
|
||||
<h4><a name="tag_03_94_03"></a>DESCRIPTION</h4>
|
||||
|
||||
<blockquote>
|
||||
<p>The <i>crypt</i>() function is a string encoding function. The algorithm is implementation-defined.</p>
|
||||
|
||||
<p>The <i>key</i> argument points to a string to be encoded. The <i>salt</i> argument is a string chosen from the set:</p>
|
||||
|
||||
<pre>
|
||||
<tt>a b c d e f g h i j k l m n o p q r s t u v w x y z
|
||||
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
|
||||
0 1 2 3 4 5 6 7 8 9 . /
|
||||
</tt>
|
||||
</pre>
|
||||
|
||||
<p>The first two characters of this string may be used to perturb the encoding algorithm.</p>
|
||||
|
||||
<p>The return value of <i>crypt</i>() points to static data that is overwritten by each call.</p>
|
||||
|
||||
<p>The <i>crypt</i>() function need not be reentrant. A function that is not required to be reentrant is not required to be
|
||||
thread-safe.</p>
|
||||
</blockquote>
|
||||
|
||||
<h4><a name="tag_03_94_04"></a>RETURN VALUE</h4>
|
||||
|
||||
<blockquote>
|
||||
<p>Upon successful completion, <i>crypt</i>() shall return a pointer to the encoded string. The first two characters of the
|
||||
returned value shall be those of the <i>salt</i> argument. Otherwise, it shall return a null pointer and set <i>errno</i> to
|
||||
indicate the error.</p>
|
||||
</blockquote>
|
||||
|
||||
<h4><a name="tag_03_94_05"></a>ERRORS</h4>
|
||||
|
||||
<blockquote>
|
||||
<p>The <i>crypt</i>() function shall fail if:</p>
|
||||
|
||||
<dl compact>
|
||||
<dt>[ENOSYS]</dt>
|
||||
|
||||
<dd>The functionality is not supported on this implementation.</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
<div class="box"><em>The following sections are informative.</em></div>
|
||||
|
||||
<h4><a name="tag_03_94_06"></a>EXAMPLES</h4>
|
||||
|
||||
<blockquote>
|
||||
<h5><a name="tag_03_94_06_01"></a>Encoding Passwords</h5>
|
||||
|
||||
<p>The following example finds a user database entry matching a particular user name and changes the current password to a new
|
||||
password. The <i>crypt</i>() function generates an encoded version of each password. The first call to <i>crypt</i>() produces an
|
||||
encoded version of the old password; that encoded password is then compared to the password stored in the user database. The second
|
||||
call to <i>crypt</i>() encodes the new password before it is stored.</p>
|
||||
|
||||
<p>The <i>putpwent</i>() function, used in the following example, is not part of IEEE Std 1003.1-2001.</p>
|
||||
|
||||
<pre>
|
||||
<tt>#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
...
|
||||
int valid_change;
|
||||
int pfd; /* Integer for file descriptor returned by open(). */
|
||||
FILE *fpfd; /* File pointer for use in putpwent(). */
|
||||
struct passwd *p;
|
||||
char user[100];
|
||||
char oldpasswd[100];
|
||||
char newpasswd[100];
|
||||
char savepasswd[100];
|
||||
...
|
||||
valid_change = 0;
|
||||
while ((p = getpwent()) != NULL) {
|
||||
/* Change entry if found. */
|
||||
if (strcmp(p->pw_name, user) == 0) {
|
||||
if (strcmp(p->pw_passwd, crypt(oldpasswd, p->pw_passwd)) == 0) {
|
||||
strcpy(savepasswd, crypt(newpasswd, user));
|
||||
p->pw_passwd = savepasswd;
|
||||
valid_change = 1;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Old password is not valid\n");
|
||||
}
|
||||
}
|
||||
/* Put passwd entry into ptmp. */
|
||||
putpwent(p, fpfd);
|
||||
}
|
||||
</tt>
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<h4><a name="tag_03_94_07"></a>APPLICATION USAGE</h4>
|
||||
|
||||
<blockquote>
|
||||
<p>The values returned by this function need not be portable among XSI-conformant systems.</p>
|
||||
</blockquote>
|
||||
|
||||
<h4><a name="tag_03_94_08"></a>RATIONALE</h4>
|
||||
|
||||
<blockquote>
|
||||
<p>None.</p>
|
||||
</blockquote>
|
||||
|
||||
<h4><a name="tag_03_94_09"></a>FUTURE DIRECTIONS</h4>
|
||||
|
||||
<blockquote>
|
||||
<p>None.</p>
|
||||
</blockquote>
|
||||
|
||||
<h4><a name="tag_03_94_10"></a>SEE ALSO</h4>
|
||||
|
||||
<blockquote>
|
||||
<p><a href="encrypt.html"><i>encrypt</i>()</a> , <a href="setkey.html"><i>setkey</i>()</a> , the Base Definitions volume of
|
||||
IEEE Std 1003.1-2001, <a href="../basedefs/unistd.h.html"><i><unistd.h></i></a></p>
|
||||
</blockquote>
|
||||
|
||||
<h4><a name="tag_03_94_11"></a>CHANGE HISTORY</h4>
|
||||
|
||||
<blockquote>
|
||||
<p>First released in Issue 1. Derived from Issue 1 of the SVID.</p>
|
||||
</blockquote>
|
||||
|
||||
<h4><a name="tag_03_94_12"></a>Issue 5</h4>
|
||||
|
||||
<blockquote>
|
||||
<p>Normative text previously in the APPLICATION USAGE section is moved to the DESCRIPTION.</p>
|
||||
</blockquote>
|
||||
|
||||
<div class="box"><em>End of informative text.</em></div>
|
||||
|
||||
<hr>
|
||||
<hr size="2" noshade>
|
||||
<center><font size="2"><!--footer start-->
|
||||
UNIX ® is a registered Trademark of The Open Group.<br>
|
||||
POSIX ® is a registered Trademark of The IEEE.<br>
|
||||
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
||||
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
||||
]</font></center>
|
||||
|
||||
<!--footer end-->
|
||||
<hr size="2" noshade>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user