📄 users.c
字号:
else { switch (*ptr) { case 'a': /* bell */ *string++ = '\a'; break; case 'b': /* backspace */ *string++ = '\b'; break; case 'f': /* formfeed */ *string++ = '\f'; break; case 'n': /* linefeed */ *string++ = '\n'; break; case 'r': /* return */ *string++ = '\r'; break; case 't': /* tab */ *string++ = '\t'; break; case 'x': /* hex */ case 'X': ptr++; strcpy (hex_buf, ptr); sscanf ("%x", hex_buf, &accum); ptr += strlen (hex_buf); *string++ = accum; break; case '0': /* octal or hex */ ptr++; switch (*ptr) { default: /* \0 */ *string++ = '\0'; ptr--; /* backup */ break; case 'x': /* hex \0x## */ case 'X': /* hex \0X## */ ptr++; strcpy (hex_buf, ptr); sscanf ("%x", hex_buf, &accum); ptr += strlen (hex_buf); *string++ = accum; break; case '1': /* octal */ case '2': case '3': case '4': case '5': case '6': case '7': while ((count < 3) && (*ptr >= '0') && (*ptr <= '7')) { count++; accum = (accum << 3) + (*ptr++ - '0'); } *string++ = accum; } /* end of inner switch */ break; default: *string++ = *ptr; } /* end of switch */ ptr++; } /* end of else count == 0 */ } else /* was not escaped character */ { *string++ = *ptr++; } if (string == end) { /* Done here for logit() call below. */ *string = '\0'; logit (LOG_DAEMON, LOG_INFO, "%s: Truncated string '%s'", func, string); break; } } /* end of while */ *string = '\0'; if (*ptr == '"') { ptr++; } *uptr = ptr; return (string - beg_string); } /* end of if quoted string */ while (*ptr != ' ' && *ptr != '\t' && *ptr != '\0' && *ptr != '\n' && *ptr != '=' && *ptr != ',') { *string++ = *ptr++; if (string == end) { *string = '\0'; /* Done here for logit() call below. */ logit (LOG_DAEMON, LOG_INFO, "%s: Truncated value '%s'", func, string); break; } } *string = '\0'; *uptr = ptr; return (string - beg_string);} /* end of fieldcpy () *//************************************************************************* * * Function: find_auth_ent * * Purpose: Gives access to the private AUTH_ENT for the given realm. * * Returns: pointer to the AUTH_ENT for the given realm, * or, NULL, if error. * *************************************************************************/AUTH_ENTRY *find_auth_ent (u_realm, pfx)char *u_realm;char *pfx;{ int head; int pat_len; FILE_LIST *file_ent; AUTH_ENTRY *auth_ent; AUTH_ENTRY *entry; char *p; static char *func = "find_auth_ent"; dprintf(2, (LOG_AUTH, LOG_DEBUG, "%s: entered", func)); if ((file_ent = find_file_ent (pfx)) == (FILE_LIST *) NULL) { dprintf(2, (LOG_AUTH, LOG_DEBUG, "%s: NULL file_ent", func)); return (AUTH_ENTRY *) NULL; } if ((auth_ent = file_ent->auth_list) == (AUTH_ENTRY *) NULL) { /* If no auth_list for this prefix */ file_ent = file_list; /* Default file_ent is first in file_list */ if ((auth_ent = file_ent->auth_list) == (AUTH_ENTRY *) NULL) { logit (LOG_DAEMON, LOG_ERR, "%s: no default authfile data structure", func); return (AUTH_ENTRY *) NULL; } } /* * Match realm name (either exact match or substring match * based on *.realm syntax) with user supplied string. */ for ( ; auth_ent != (AUTH_ENTRY *) NULL; auth_ent = auth_ent->next) { if (auth_ent->parent == (AUTH_ENTRY *) NULL) /* parent realm */ { entry = auth_ent; } else { entry = auth_ent->parent; } /* Look for name match. */ if (entry->name[0] == '*') /* this is wildcard realm */ { p = &entry->name[1]; pat_len = strlen (p); if ((head = strlen (u_realm) - pat_len) >= 0 && (strncmp ((char *) &u_realm[head], (char *) &entry->name[1], pat_len) == 0)) { return entry; } } else /* not a wildcard realm */ { if (strcasecmp (entry->name, u_realm) == 0) { return entry; } } } dprintf(2, (LOG_AUTH, LOG_DEBUG, "%s: realm not found", func)); return (AUTH_ENTRY *) NULL;} /* end of find_auth_ent () *//************************************************************************* * * Function: find_auth_type * * Purpose: Find the proper AUTH_ENTRY to use for the given authentication * realm name from the FILE_LIST entry with the given file_pfx. * * Returns: The authentication type, name of the authentication agent to * use, the primary realm name and any optional packet filter * to be applied are returned. * * Returns: 0 = normal return, * -1 = error return * *************************************************************************/intfind_auth_type (u_realm, prot, pfx, type, agent, realm, filter)char *u_realm;int prot;char *pfx;int *type; /* receives resultant authentication type value */char **agent; /* receives resultant authentication agent name */char **realm; /* receives resultant primary realm name */char **filter; /* receives resultant authentication filter name */{ int head; int pat_len; FILE_LIST *file_ent; AUTH_ENTRY *auth_ent; AUTH_ENTRY *entry; char *p; char *realm_name; static char temp[AUTH_ID_LEN + 1]; static char *func = "find_auth_type"; dprintf(2, (LOG_AUTH, LOG_DEBUG, "%s: entered", func)); if ((file_ent = find_file_ent (pfx)) == (FILE_LIST *) NULL) { dprintf(2, (LOG_AUTH, LOG_DEBUG, "%s: NULL file_ent", func)); return (-1); } if ((auth_ent = file_ent->auth_list) == (AUTH_ENTRY *) NULL) { /* If no auth_list for this prefix */ file_ent = file_list; /* Default file_ent is first in file_list */ if ((auth_ent = file_ent->auth_list) == (AUTH_ENTRY *) NULL) { logit (LOG_DAEMON, LOG_ERR, "%s: no default authfile data structure", func); return (-1); } } /* * Match realm name (either exact match or substring match * based on *.realm syntax) with user supplied string. */ for ( ; auth_ent ; auth_ent = auth_ent->next ) { realm_name = (char *) NULL; if (auth_ent->parent == (AUTH_ENTRY *) NULL) /* parent realm */ { entry = auth_ent; /* Look for name match. */ if (entry->name[0] == '*') /* this is wildcard realm */ { p = &entry->name[1]; pat_len = strlen (p); head = strlen (u_realm) - pat_len; if (strncmp ((char *) &u_realm[head], (char *) &entry->name[1], pat_len) == 0) { realm_name = u_realm; } else { realm_name = (char *) NULL; } } else /* not a wildcard realm */ { if (strcasecmp (entry->name, u_realm) == 0) { realm_name = entry->name; } } } else /* this entry is an alias name for some real realm */ { entry = auth_ent->parent; /* Look for name match. */ if (entry->name[0] == '*') /* alias in wildcard realm */ { p = &entry->name[1]; pat_len = strlen (p); head = strlen (u_realm) - pat_len; if (strncmp ((char *) &u_realm[head], (char *) &entry->name[1], pat_len) == 0) { /* combine real prefix, parent suffix */ strcpy (temp, u_realm); if (strtok (temp, ".") != (char *) NULL) { realm_name = strcat (temp, &entry->name[1]); } } else { realm_name = (char *) NULL; } } else /* regular alias */ { if (strcasecmp (auth_ent->name, u_realm) == 0) { realm_name = entry->name; } } } if (realm_name != (char *) NULL) /* then we have a name match */ { if (!entry->prot || (entry->prot == prot)) { break; } } } if (auth_ent == (AUTH_ENTRY *) NULL) { dprintf(2, (LOG_AUTH, LOG_DEBUG, "%s: realm not found", func)); return (-1); } *type = entry->type; *agent = entry->host; *realm = realm_name; *filter = entry->filter; dprintf(2, (LOG_AUTH, LOG_DEBUG, "%s: type %d, agent '%s', realm '%s' and filter '%s'", func, entry->type, (entry->host == (char *) NULL) ? "?" : entry->host, (realm_name == (char *) NULL) ? "?" : realm_name, (entry->filter == (char *) NULL) ? "?" : entry->filter)); return 0;} /* end of find_auth_type () *//************************************************************************* * * Function: find_client * * Purpose: Find the CLIENT_ENTRY in client_list for the client with * the given IP address. If the entry is found, a pointer * to the found client structure is returned. * * Returns: 0 = found client entry, * -1 = client not found. * *************************************************************************/intfind_client (ipaddr, client)UINT4 ipaddr;CLIENT_ENTRY **client; /* Pointer to Client entry */{ int count; int ud = 0; CLIENT_ENTRY *client_ent; IP_ADDRESS *an_address; time_t cur_time; static char *func = "find_client"; dprintf(4, (LOG_AUTH, LOG_DEBUG, "%s: entered", func)); /* Check to see if the last match was us. */ if ((last_client_ipaddr != 0) && (last_client_ipaddr == ipaddr)) { client_ent = last_client_found; } else /* Reset cache */ { last_client_found = (CLIENT_ENTRY *) NULL; last_client_ipaddr = 0; last_client_name = (char *) NULL; cur_time = time (0); for (client_ent = client_list; client_ent; client_ent = client_ent->next) { if (cur_time > client_ent->expire_time) { ud = 1; } count = 0; for (an_address = client_ent->addrs; an_address != (IP_ADDRESS *) NULL; an_address = an_address->next) { count++; if (count > MAX_ALIAS) { logit (LOG_AUTH, LOG_ALERT, "%s: FATAL: Too many addresses for client '%s'", func, client_ent->hostname); abort (); } if (an_address->ipaddr.s_addr == ipaddr) { break; } } if (an_address) { break; } } if (ud > 0) { update_clients (); } } /* Don't match host-only entries (those with a null secret) */ if (client_ent != (CLIENT_ENTRY *) NULL && *client_ent->secret == '\0') { client_ent = (CLIENT_ENTRY *) NULL; } if (client != (CLIENT_ENTRY **) NULL) { *client = client_ent; } if (client_ent != (CLIENT_ENTRY *) NULL) { last_client_found = client_ent; last_client_name = client_ent->hostname; last_client_ipaddr = ipaddr; } return client_ent ? 0 : -1;} /* end of find_client () *//************************************************************************* * * Function: find_client_by_name * * Purpose: Find the CLIENT_ENTRY in client_list for the client with * the given hostname. If the entry is found, a pointer * to the found client structure is returned. * * Returns: 0 = found client entry and resolved IP address, * 1 = found client entry but no IP address, * 2 = found host entry but IP address not obtained * (unresolvable DNS name), * -1 = client not found. * *************************************************************************/intfind_client_by_name (hostname, ipaddr, client_entry)char *hostname; /* Match this name */UINT4 *ipaddr; /* Receives resultant address, if found */CLIENT_ENTRY **client_entry; /* Return pointer to structure */{ int ud = 0; time_t cur_time; CLIENT_ENTRY *client_ent; DNS_NAME *name_ent; static char *func = "find_client_by_name"; dprintf(4, (LOG_AUTH, LOG_DEBUG, "%s: entered", func)); *client_entry = (CLIENT_ENTRY *) NULL; *ipaddr = 0; /* Saftey. */ if ((last_client_found != (CLIENT_ENTRY *) NULL) && (last_client_name != (char *) NULL) && (strcmp (last_client_name, hostname) == 0)) { client_ent = last_client_found; } else if (good_ipaddr (hostname) == 0) { /* name == address -- Really just a find_client() call */ *ipaddr = ntohl(inet_addr (hostname)); return find_client (*ipaddr, client_entry); } else /* Reset cache. */ { last_client_found = (CLIENT_ENTRY *) NULL; last_client_name = (char *) NULL; last_client_ipaddr = 0; if (strcmp (hostname, RADIUS_LOCALSERVER) == 0) { hostname = ourhostname; } cur_time = time (0); for (client_ent = client_list; client_ent != (CLIENT_ENTRY *) NULL; client_ent = client_ent->next) { if (cur_time > client_ent->expire_time) { ud = 1; } if (strcmp (client_ent->hostname, hostname) == 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -